objfunc.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. /*
  2. Copyright (C) 2005, 2010 - Cryptic Sea
  3. This file is part of Gish.
  4. Gish is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. void objectcycle(void)
  17. {
  18. int count,count2,count3,count4;
  19. int x,y;
  20. float vec[3],vec2[3];
  21. float veclength,bondlength;
  22. float angle,spin;
  23. float intersectpoint[3];
  24. float normal[3];
  25. float scale,scale2;
  26. for (count=0;count<numofropes;count++)
  27. {
  28. updateogg();
  29. if (rope[count].type>=5 && rope[count].type<9)
  30. {
  31. bond[rope[count].bondnum].length=bond[rope[count].bondnum].maxlength+(rope[count].range-cos(rope[count].angle)*rope[count].range);
  32. if (rope[count].cyclelength==0.0f)
  33. {
  34. if (rope[count].link==-1 || object[rope[count].link].idata[0]==1)
  35. {
  36. rope[count].angle+=2.0f*pi/(50.0f*rope[count].cycle);
  37. if (rope[count].angle>2.0f*pi)
  38. rope[count].angle-=2.0f*pi;
  39. }
  40. }
  41. else
  42. {
  43. if (rope[count].link==-1)
  44. {
  45. if (rope[count].cyclecount<rope[count].cyclelength*2.0f*pi)
  46. {
  47. rope[count].angle+=2.0f*pi/(50.0f*rope[count].cycle);
  48. if (rope[count].angle>2.0f*pi)
  49. rope[count].angle-=2.0f*pi;
  50. rope[count].cyclecount+=2.0f*pi/(50.0f*rope[count].cycle);
  51. }
  52. }
  53. else
  54. {
  55. count2=0;
  56. if (object[rope[count].link].idata[0]==1 && rope[count].cyclecount==0.0f)
  57. count2=1;
  58. if (rope[count].cyclecount>0.0f && rope[count].cyclecount<rope[count].cyclelength*2.0f*pi)
  59. count2=1;
  60. if (rope[count].cyclecount>rope[count].cyclelength*2.0f*pi+2.0f*pi/(50.0f*rope[count].cycle))
  61. count2=1;
  62. if (object[rope[count].link].idata[0]==0 && rope[count].cyclecount>0.0f)
  63. count2=1;
  64. if (count2==1)
  65. {
  66. rope[count].angle+=2.0f*pi/(50.0f*rope[count].cycle);
  67. if (rope[count].angle>2.0f*pi)
  68. rope[count].angle-=2.0f*pi;
  69. rope[count].cyclecount+=2.0f*pi/(50.0f*rope[count].cycle);
  70. if (rope[count].cyclecount>=rope[count].cyclelength*4.0f*pi)
  71. rope[count].cyclecount=0.0f;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. for (count=0;count<numofobjects;count++)
  78. {
  79. updateogg();
  80. if (object[count].damagedelay>0)
  81. object[count].damagedelay--;
  82. if (object[count].numofparticles!=0)
  83. {
  84. zerovector(object[count].velocity);
  85. for (count2=0;count2<object[count].numofparticles;count2++)
  86. addvectors(object[count].velocity,object[count].velocity,particle[object[count].particle[count2]].velocity);
  87. scalevector(object[count].velocity,object[count].velocity,1.0f/(float)object[count].numofparticles);
  88. zerovector(object[count].position);
  89. for (count2=0;count2<object[count].numofparticles;count2++)
  90. addvectors(object[count].position,object[count].position,particle[object[count].particle[count2]].position);
  91. scalevector(object[count].position,object[count].position,1.0f/(float)object[count].numofparticles);
  92. }
  93. objectsound(count);
  94. if (object[count].link!=-1)
  95. {
  96. if (object[count].lighttype==1 || object[count].lighttype==3)
  97. {
  98. if (object[object[count].link].idata[0])
  99. object[count].lighton=0;
  100. else
  101. object[count].lighton=1;
  102. }
  103. if (object[count].lighttype==2)
  104. {
  105. if (object[object[count].link].idata[0])
  106. object[count].lighton=1;
  107. else
  108. object[count].lighton=0;
  109. }
  110. }
  111. if (object[count].lighttype==3)
  112. {
  113. object[count].lightintensity+=((rand()&255)/255.0f-0.5f)*0.2f*object[count].lightintensitymax;
  114. if (object[count].lightintensity<object[count].lightintensitymax*0.5f)
  115. object[count].lightintensity=object[count].lightintensitymax*0.5f;
  116. if (object[count].lightintensity>object[count].lightintensitymax*1.5f)
  117. object[count].lightintensity=object[count].lightintensitymax*1.5f;
  118. }
  119. if (object[count].type==9)
  120. if (object[count].idata[0]==0 || object[count].idata[1]==0)
  121. {
  122. vec[1]=particle[object[count].particle[6]].position[1]-particle[object[count].particle[4]].position[1];
  123. vec[1]*=0.08f;
  124. vec[1]-=particle[object[count].particle[4]].velocity[1];
  125. particle[object[count].particle[4]].velocity[1]+=vec[1];
  126. vec[1]=particle[object[count].particle[6]].position[1]-particle[object[count].particle[5]].position[1];
  127. vec[1]*=0.08f;
  128. vec[1]-=particle[object[count].particle[5]].velocity[1];
  129. particle[object[count].particle[5]].velocity[1]+=vec[1];
  130. if (particle[object[count].particle[4]].position[1]>particle[object[count].particle[6]].position[1]-0.1f)
  131. if (particle[object[count].particle[5]].position[1]>particle[object[count].particle[6]].position[1]-0.1f)
  132. {
  133. if (object[count].idata[0]==1)
  134. playsound(14,object[count].position,NULL,0.2f,0,1.0f,-1,0);
  135. object[count].idata[0]=0;
  136. }
  137. if (particle[object[count].particle[4]].position[1]<particle[object[count].particle[6]].position[1]-0.2f)
  138. if (particle[object[count].particle[5]].position[1]<particle[object[count].particle[6]].position[1]-0.2f)
  139. {
  140. if (object[count].idata[0]==0)
  141. playsound(14,object[count].position,NULL,0.2f,0,1.0f,-1,0);
  142. object[count].idata[0]=1;
  143. }
  144. if (object[count].link!=-1)
  145. if (object[object[count].link].idata[0]==1)
  146. object[count].idata[0]=1;
  147. }
  148. if (object[count].type==9)
  149. if (object[count].idata[0]==1 && object[count].idata[1]==1)
  150. {
  151. vec[1]=particle[object[count].particle[6]].position[1]-0.375f-particle[object[count].particle[4]].position[1];
  152. vec[1]*=0.08f;
  153. vec[1]-=particle[object[count].particle[4]].velocity[1];
  154. particle[object[count].particle[4]].velocity[1]+=vec[1];
  155. vec[1]=particle[object[count].particle[6]].position[1]-0.375f-particle[object[count].particle[5]].position[1];
  156. vec[1]*=0.08f;
  157. vec[1]-=particle[object[count].particle[5]].velocity[1];
  158. particle[object[count].particle[5]].velocity[1]+=vec[1];
  159. }
  160. if (object[count].type==16)
  161. if (object[count].idata[0]==0 || object[count].idata[1]==0)
  162. {
  163. object[count].idata[0]=0;
  164. if (fabs(object[0].position[0]-object[count].position[0])<object[count].size[0]*0.5f)
  165. if (fabs(object[0].position[1]-object[count].position[1])<object[count].size[1]*0.5f)
  166. {
  167. object[count].idata[0]=1;
  168. if (object[count].idata[1]==2)
  169. {
  170. if ((rand()&3)==0)
  171. playsound(8,object[count].position,NULL,1.0f,0,1.0f,-1,0);
  172. else
  173. playsound(9,object[count].position,NULL,1.0f,0,1.0f,-1,0);
  174. game.bonus[8]++;
  175. }
  176. }
  177. if (level.gametype==11)
  178. if (fabs(object[1].position[0]-object[count].position[0])<object[count].size[0]*0.5f)
  179. if (fabs(object[1].position[1]-object[count].position[1])<object[count].size[1]*0.5f)
  180. {
  181. object[count].idata[0]=1;
  182. if (object[count].idata[1]==2)
  183. {
  184. if ((rand()&3)==0)
  185. playsound(8,object[count].position,NULL,1.0f,0,1.0f,-1,0);
  186. else
  187. playsound(9,object[count].position,NULL,1.0f,0,1.0f,-1,0);
  188. game.bonus[8]++;
  189. }
  190. }
  191. }
  192. if (object[count].type==15)
  193. {
  194. if (object[count].link==-1 || object[object[count].link].idata[0]==1)
  195. if ((game.framenum&255)==128)
  196. {
  197. createwheel(object[count].position,object[count].size[0],object[count].size[1],object[count].mass,0.8f,0);
  198. object[numofobjects-1].texturenum=object[count].texturenum;
  199. object[numofobjects-1].timetolive=512;
  200. object[numofobjects-1].link=-1;
  201. for (count2=0;count2<object[numofobjects-1].numofparticles;count2++)
  202. {
  203. particle[object[numofobjects-1].particle[count2]].velocity[0]=object[count].lightcolor[0]/PHYSICSCYCLE;
  204. particle[object[numofobjects-1].particle[count2]].velocity[1]=object[count].lightcolor[1]/PHYSICSCYCLE;
  205. }
  206. }
  207. }
  208. if (object[count].type==10)
  209. {
  210. if (object[count].rotate==0 || object[count].rotate==2)
  211. count3=1;
  212. else
  213. count3=0;
  214. for (count2=1;count2<=2;count2++)
  215. {
  216. vec[count3]=particle[object[count].particle[4]].position[count3]-particle[object[count].particle[count2]].position[count3];
  217. if (vec[count3]<0.0f)
  218. vec[count3]+=0.25f;
  219. else
  220. vec[count3]-=0.25f;
  221. if (vec[count3]<0.0f)
  222. {
  223. vec[2]=-0.04f;
  224. if (vec[2]<vec[count3])
  225. vec[2]=vec[count3];
  226. }
  227. else
  228. {
  229. vec[2]=0.04f;
  230. if (vec[2]>vec[count3])
  231. vec[2]=vec[count3];
  232. }
  233. vec[2]-=particle[object[count].particle[count2]].velocity[count3];
  234. particle[object[count].particle[count2]].velocity[count3]+=vec[2];
  235. if (particle[object[count].particle[count2]].position[count3]>particle[object[count].particle[4]].position[count3]+0.25f)
  236. particle[object[count].particle[count2]].position[count3]=particle[object[count].particle[4]].position[count3]+0.25f;
  237. if (particle[object[count].particle[count2]].position[count3]<particle[object[count].particle[4]].position[count3]-0.25f)
  238. particle[object[count].particle[count2]].position[count3]=particle[object[count].particle[4]].position[count3]-0.25f;
  239. }
  240. vec[0]=particle[object[count].particle[4]].position[count3]-particle[object[count].particle[1]].position[count3];
  241. if (object[count].rotate==3)
  242. vec[0]=-vec[0];
  243. if (vec[0]<-0.2f)
  244. {
  245. if (object[count].idata[0]==1)
  246. playsound(14,object[count].position,NULL,0.2f,0,1.0f,-1,0);
  247. object[count].idata[0]=0;
  248. }
  249. if (vec[0]>0.2f)
  250. {
  251. if (object[count].idata[0]==0)
  252. playsound(14,object[count].position,NULL,0.2f,0,1.0f,-1,0);
  253. object[count].idata[0]=1;
  254. }
  255. if (object[count].link!=-1)
  256. if (object[object[count].link].idata[0]==1)
  257. object[count].idata[0]=1;
  258. }
  259. if (object[count].type==1)
  260. {
  261. if (count!=0)
  262. if (level.gametype==0 && game.levelnum==34)
  263. objectai(count);
  264. for (count2=0;count2<16;count2++)
  265. {
  266. x=particle[object[count].particle[count2]].position[0];
  267. y=particle[object[count].particle[count2]].position[1];
  268. if (x>0 && x<254)
  269. if (y>0 && y<254)
  270. {
  271. if (block[level.foregrid[y][x]].density!=0.0f)
  272. if ((rand()&255)==0)
  273. {
  274. createparticle(5,object[count].position,object[count].velocity,0.125f*0.25f,-1,100+(rand()&63));
  275. particle[numofparticles-1].rendersize=0.125+(float)(rand()&127)/1000.0f;
  276. particle[numofparticles-1].texturenum=366;
  277. }
  278. if (block[level.foregrid[y][x]].foredamage!=0)
  279. object[count].hitpoints-=block[level.foregrid[y][x]].foredamage;
  280. if ((level.grid[y][x]>=248 && level.grid[y][x]<=255 && level.gridmod[y][x]==0) || (level.grid[y][x]>=240 && level.grid[y][x]<=247 && level.gridmod[y][x]==2))
  281. {
  282. vec[0]=(float)x+0.5f;
  283. vec[1]=(float)y+0.5f;
  284. vec[2]=0.0f;
  285. subtractvectors(vec2,vec,particle[object[count].particle[count2]].position);
  286. if (vectorlength(vec2)<0.45f)
  287. {
  288. scale=1.0f;
  289. if (level.grid[y][x]==251 || (level.grid[y][x]==251-8 && level.gridmod[y][x]==2))
  290. {
  291. if (game.numoflives<99 && game.difficulty!=3)
  292. {
  293. game.numoflives++;
  294. createsprite(0,vec);
  295. sprintf(sprite[numofsprites-1].text,"1UP");
  296. sprite[numofsprites-1].size=14;
  297. }
  298. else
  299. {
  300. game.score[0]+=1000;
  301. createsprite(1000,vec);
  302. }
  303. }
  304. if (level.grid[y][x]==252 || (level.grid[y][x]==252-8 && level.gridmod[y][x]==2))
  305. {
  306. if (object[count].hitpoints<900)
  307. object[count].hitpoints+=100;
  308. else
  309. object[count].hitpoints=1000;
  310. }
  311. if (level.grid[y][x]==253 || (level.grid[y][x]==253-8 && level.gridmod[y][x]==2))
  312. {
  313. if (level.gametype!=15)
  314. {
  315. game.score[0]+=50;
  316. createsprite(50,vec);
  317. }
  318. else
  319. game.score[count]++;
  320. }
  321. if (level.grid[y][x]==254 || (level.grid[y][x]==254-8 && level.gridmod[y][x]==2))
  322. {
  323. game.score[0]+=100;
  324. createsprite(100,vec);
  325. if (game.oldschool==0)
  326. scale=0.9f;
  327. }
  328. if (level.grid[y][x]==255 || (level.grid[y][x]==255-8 && level.gridmod[y][x]==2))
  329. {
  330. game.score[0]+=1000;
  331. createsprite(1000,vec);
  332. if (game.oldschool==0)
  333. scale=0.8f;
  334. }
  335. if (level.grid[y][x]==252 || (level.grid[y][x]==252-8 && level.gridmod[y][x]==2))
  336. playsound(20,vec,NULL,0.7f,0,scale,-1,0);
  337. else
  338. playsound(10,vec,NULL,0.4f,0,scale,-1,0);
  339. level.gridmod[y][x]=1;
  340. if (level.grid[y][x]>=248 && level.grid[y][x]<=255)
  341. game.bonus[level.grid[y][x]-248]++;
  342. if (level.grid[y][x]>=240 && level.grid[y][x]<=247)
  343. game.bonus[level.grid[y][x]-240]++;
  344. }
  345. }
  346. }
  347. }
  348. count4=0;
  349. for (count2=0;count2<16;count2++)
  350. for (count3=0;count3<16;count3++)
  351. if (abs(count2-count3)>6)
  352. {
  353. subtractvectors(vec,particle[object[count].particle[count3]].position,particle[object[count].particle[count2]].position);
  354. veclength=vectorlength(vec);
  355. if (veclength<0.15f)
  356. count4++;
  357. //if (veclength<0.15f)
  358. // object[count].hitpoints-=(0.2f-veclength)*500.0f;
  359. }
  360. if (count4>=2)
  361. object[count].hitpoints-=(count4-1)*50;
  362. if (object[count].numoforientations==0)
  363. copyvector(object[count].orientation[1],yaxis);
  364. else
  365. normalizevector(object[count].orientation[1],object[count].orientation[1]);
  366. crossproduct(object[count].orientation[0],zaxis,object[count].orientation[1]);
  367. normalizevector(object[count].orientation[0],object[count].orientation[0]);
  368. if (dotproduct(object[count].velocity,object[count].orientation[0])<-0.02f)
  369. object[count].direction=0;
  370. if (dotproduct(object[count].velocity,object[count].orientation[0])>0.02f)
  371. object[count].direction=1;
  372. angle=atan2(object[count].orientation[0][1],object[count].orientation[0][0]);
  373. spin=cos(angle)*fabs(cos(angle))*object[count].axis[0]+sin(angle)*fabs(sin(angle))*object[count].axis[1];
  374. if (spin<-1.0f)
  375. spin=-1.0f;
  376. if (spin>1.0f)
  377. spin=1.0f;
  378. if (angle<object[count].angle-pi)
  379. angle+=2.0f*pi;
  380. if (angle>object[count].angle+pi)
  381. angle-=2.0f*pi;
  382. /*
  383. scale=(angle-object[count].angle);
  384. if (scale<-0.1f)
  385. scale=-0.1f;
  386. if (scale>0.1f)
  387. scale=0.1f;
  388. object[count].angle+=scale;
  389. */
  390. object[count].angle+=(angle-object[count].angle)*0.05f;
  391. if (object[count].angle<0.0f)
  392. object[count].angle+=2.0f*pi;
  393. if (object[count].angle>2.0f*pi)
  394. object[count].angle-=2.0f*pi;
  395. for (count2=0;count2<16;count2++)
  396. {
  397. subtractvectors(vec,particle[object[count].particle[count2]].position,object[count].position);
  398. crossproduct(vec2,zaxis,vec);
  399. normalizevector(vec2,vec2);
  400. if (object[count].numoforientations!=0)
  401. {
  402. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,vec2,spin*0.004f);
  403. }
  404. //if (object[count].numoforientations==0)
  405. {
  406. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,xaxis,object[count].axis[0]*0.001f);
  407. if (object[count].axis[1]<0.0f)
  408. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,yaxis,object[count].axis[1]*0.001f);
  409. else
  410. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,yaxis,object[count].axis[1]*0.0005f);
  411. }
  412. }
  413. if ((object[count].button&4)==4)
  414. object[count].friction=0.01f;
  415. else
  416. object[count].friction=1.2f;
  417. if ((object[count].button&2)==2 || (object[count].button&8)==8)
  418. {
  419. for (count2=0;count2<numofbonds;count2++)
  420. if (bond[count2].objectnum==count && bond[count2].type==2)
  421. {
  422. bond[count2].cycles=0;
  423. //bond[count2].elasticity=0.02f;
  424. }
  425. }
  426. else
  427. {
  428. for (count2=0;count2<numofbonds;count2++)
  429. if (bond[count2].objectnum==count && bond[count2].type==2)
  430. {
  431. bond[count2].cycles=31;
  432. /*
  433. if ((object[count].button&4)==4)
  434. bond[count2].elasticity=0.005f;
  435. else
  436. bond[count2].elasticity=0.02f;
  437. */
  438. }
  439. }
  440. if ((object[count].button&8)==8)
  441. {
  442. for (count2=0;count2<object[count].numofparticles;count2++)
  443. {
  444. particle[object[count].particle[count2]].gravity=10.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  445. particle[object[count].particle[count2]].mass=0.5f;
  446. }
  447. }
  448. else
  449. {
  450. for (count2=0;count2<object[count].numofparticles;count2++)
  451. {
  452. particle[object[count].particle[count2]].gravity=4.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  453. particle[object[count].particle[count2]].mass=0.25f;
  454. }
  455. }
  456. }
  457. if (object[count].type==20)
  458. {
  459. subtractvectors(object[count].orientation[1],particle[object[count].particle[0]].position,particle[object[count].particle[3]].position);
  460. normalizevector(object[count].orientation[1],object[count].orientation[1]);
  461. object[count].orientation[0][0]=object[count].orientation[1][1];
  462. object[count].orientation[0][1]=-object[count].orientation[1][0];
  463. object[count].orientation[0][2]=0.0f;
  464. object[count].data[0]+=object[count].axis[0]*0.05f;
  465. if (object[count].data[0]<0.0f)
  466. object[count].data[0]+=0.02f;
  467. if (object[count].data[0]>0.0f)
  468. object[count].data[0]-=0.02f;
  469. if (object[count].data[0]<-0.5f)
  470. object[count].data[0]=-0.5f;
  471. if (object[count].data[0]>0.5f)
  472. object[count].data[0]=0.5f;
  473. object[count].data[1]+=object[count].axis[1]*0.008f;
  474. if ((object[count].button&2)==2)
  475. object[count].data[1]=0.0f;
  476. if (object[count].data[1]<0.0f)
  477. object[count].data[1]+=0.004f;
  478. if (object[count].data[1]>0.0f)
  479. object[count].data[1]-=0.004f;
  480. if (object[count].data[1]<-0.3f)
  481. object[count].data[1]=-0.3f;
  482. if (object[count].data[1]>0.3f)
  483. object[count].data[1]=0.3f;
  484. for (count2=0;count2<4;count2++)
  485. {
  486. copyvector(vec,particle[object[count].particle[count2]].velocity);
  487. if (count2==1 || count2==2)
  488. {
  489. //normal[0]=object[count].orientation[0][0]*cos(object[count].data[0])+object[count].orientation[0][1]*sin(object[count].data[0]);
  490. //normal[1]=object[count].orientation[1][1]*cos(object[count].data[0])-object[count].orientation[1][0]*sin(object[count].data[0]);
  491. scalevector(normal,object[count].orientation[0],cos(object[count].data[0]));
  492. scaleaddvectors(normal,normal,object[count].orientation[1],-sin(object[count].data[0]));
  493. calculatefriction(vec,vec2,normal,0.8f);
  494. subtractvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,vec2);
  495. }
  496. else
  497. {
  498. copyvector(normal,object[count].orientation[0]);
  499. scaleaddvectors(vec,vec,normal,-object[count].data[1]);
  500. vec[2]=1.0f/PHYSICSCYCLE;
  501. calculatefriction(vec,vec2,zaxis,0.8f);
  502. vec2[2]=0.0f;
  503. subtractvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,vec2);
  504. }
  505. //copyvector(particle[object[count].particle[count2]].velocity,vec);
  506. }
  507. for (count2=0;count2<4;count2++)
  508. {
  509. subtractvectors(vec,particle[object[count].particle[count2]].position,object[count].position);
  510. crossproduct(vec2,zaxis,vec);
  511. normalizevector(vec2,vec2);
  512. //scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,vec2,object[count].axis[0]*0.002f);
  513. //scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,object[count].orientation[0],object[count].axis[1]*0.003f);
  514. }
  515. }
  516. if (object[count].type==4)
  517. {
  518. for (count2=0;count2<4;count2++)
  519. {
  520. x=particle[object[count].particle[count2]].position[0];
  521. y=particle[object[count].particle[count2]].position[1];
  522. if (x>0 && x<254)
  523. if (y>0 && y<254)
  524. {
  525. if (block[level.foregrid[y][x]].foredamage!=0)
  526. object[count].hitpoints-=block[level.foregrid[y][x]].foredamage*4;
  527. }
  528. }
  529. if (object[count].hitpoints<0)
  530. if (object[count].timetolive>45)
  531. object[count].timetolive=45;
  532. subtractvectors(object[count].orientation[1],particle[object[count].particle[0]].position,particle[object[count].particle[3]].position);
  533. normalizevector(object[count].orientation[1],object[count].orientation[1]);
  534. object[count].orientation[0][0]=object[count].orientation[1][1];
  535. object[count].orientation[0][1]=-object[count].orientation[1][0];
  536. object[count].orientation[0][2]=0.0f;
  537. objectai(count);
  538. if (object[0].position[0]<object[count].position[0])
  539. object[count].direction=0;
  540. else
  541. object[count].direction=1;
  542. if (object[count].velocity[0]<-0.01f)
  543. object[count].direction=0;
  544. if (object[count].velocity[0]>0.01f)
  545. object[count].direction=1;
  546. if (object[count].link!=-1)
  547. object[object[count].link].direction=object[count].direction;
  548. if (dotproduct(object[count].orientation[1],yaxis)>0.7f)
  549. if (object[count].numoforientations!=0)
  550. {
  551. if (object[count].beasttype>=0 && object[count].beasttype<=2)
  552. scale=2.0f;
  553. if (object[count].beasttype==8 || object[count].beasttype==11)
  554. scale=2.0f;
  555. if (object[count].beasttype==16)
  556. scale=2.0f;
  557. if (object[count].beasttype>=3 && object[count].beasttype<=6)
  558. scale=2.0f;
  559. if (object[count].beasttype==9 || object[count].beasttype==10)
  560. scale=2.0f;
  561. if (object[count].beasttype==7 || object[count].beasttype==13)
  562. scale=1.5f;
  563. if (object[count].beasttype==15)
  564. scale=2.5f;
  565. if (object[count].axis[0]==-1.0f)
  566. {
  567. for (count2=0;count2<4;count2++)
  568. if (particle[object[count].particle[count2]].velocity[0]>-3.0f/PHYSICSCYCLE)
  569. particle[object[count].particle[count2]].velocity[0]-=scale/(PHYSICSCYCLE*PHYSICSCYCLE);
  570. }
  571. if (object[count].axis[0]==1.0f)
  572. {
  573. for (count2=0;count2<4;count2++)
  574. if (particle[object[count].particle[count2]].velocity[0]<3.0f/PHYSICSCYCLE)
  575. particle[object[count].particle[count2]].velocity[0]+=scale/(PHYSICSCYCLE*PHYSICSCYCLE);
  576. }
  577. }
  578. if (object[count].beasttype==0 || object[count].beasttype==2 || object[count].beasttype==8 || object[count].beasttype==16)
  579. if (object[count].numoforientations!=0)
  580. if ((object[count].button&2)==2)
  581. for (count2=0;count2<4;count2++)
  582. {
  583. if (object[count].beasttype!=8)
  584. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,yaxis,0.08f);
  585. else
  586. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,yaxis,0.12f);
  587. }
  588. if (object[count].beasttype==15)
  589. if (object[count].numoforientations!=0)
  590. if ((object[count].button&2)==2)
  591. for (count2=0;count2<2;count2++)
  592. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,yaxis,0.08f);
  593. if (object[count].numoforientations!=0)
  594. if (dotproduct(object[count].orientation[1],yaxis)<0.7f)
  595. {
  596. if (object[count].orientation[1][0]<0.0f)
  597. spin=1.0f;
  598. else
  599. spin=-1.0f;
  600. for (count2=0;count2<4;count2++)
  601. {
  602. subtractvectors(vec,particle[object[count].particle[count2]].position,object[count].position);
  603. crossproduct(vec2,zaxis,vec);
  604. normalizevector(vec2,vec2);
  605. scaleaddvectors(particle[object[count].particle[count2]].velocity,particle[object[count].particle[count2]].velocity,vec2,spin*0.003f);
  606. }
  607. }
  608. }
  609. }
  610. }
  611. void objectsound(int objectnum)
  612. {
  613. int x,y;
  614. float vec[3];
  615. float scale;
  616. float pitch;
  617. x=object[objectnum].position[0];
  618. y=object[objectnum].position[1];
  619. if (block[level.foregrid[y][x]].density!=0.0f)
  620. {
  621. x=object[objectnum].prevposition[0];
  622. y=object[objectnum].prevposition[1];
  623. if (block[level.foregrid[y][x]].density==0.0f)
  624. {
  625. pitch=4.0f/object[objectnum].mass;
  626. if (pitch<0.5f)
  627. pitch=0.5f;
  628. if (pitch>1.0f)
  629. pitch=1.0f;
  630. scale=vectorlength(object[objectnum].velocity)*2.5f;
  631. x=object[objectnum].position[0];
  632. y=object[objectnum].position[1];
  633. if (block[level.foregrid[y][x]].foredamage==0)
  634. playsound(17,object[objectnum].position,NULL,scale,0,pitch,objectnum,3);
  635. else
  636. playsound(18,object[objectnum].position,NULL,scale,0,pitch,objectnum,3);
  637. }
  638. }
  639. if (object[objectnum].type==2 || object[objectnum].type==3)
  640. {
  641. subtractvectors(vec,object[objectnum].velocity,object[objectnum].prevvelocity);
  642. scale=vectorlength(vec);
  643. if (scale>0.025f)
  644. {
  645. pitch=1.0f/(object[objectnum].mass*0.2f);
  646. scale*=(1.0f/pitch);
  647. if (pitch<0.2f)
  648. pitch=0.2f;
  649. if (pitch>1.0f)
  650. pitch=1.0f;
  651. playsound(1,object[objectnum].position,NULL,scale*5.0f,0,pitch,objectnum,0);
  652. }
  653. }
  654. /*
  655. if (object[objectnum].type==2 || object[objectnum].type==3)
  656. {
  657. //scale=object[objectnum].frictionapplied;
  658. if (object[objectnum].numoforientations!=0)
  659. {
  660. vec[0]=vectorlength(object[objectnum].velocity);
  661. vec[1]=dotproduct(object[objectnum].velocity,object[objectnum].orientation[1]);
  662. scale=sqrt(vec[0]*vec[0]-vec[1]*vec[1]);
  663. }
  664. else
  665. scale=0.0f;
  666. if (scale>0.01f)
  667. {
  668. pitch=1.0f/(object[objectnum].mass*0.2f);
  669. scale*=(1.0f/pitch);
  670. if (pitch<0.2f)
  671. pitch=0.2f;
  672. if (pitch>1.0f)
  673. pitch=1.0f;
  674. if (object[objectnum].soundnum[1]==-1)
  675. playsound(6,object[objectnum].position,NULL,scale*5.0f,1,pitch,objectnum,1);
  676. }
  677. if (object[objectnum].soundnum[1]!=-1)
  678. {
  679. if (scale<0.005f)
  680. deletesound(object[objectnum].soundnum[1]);
  681. else
  682. {
  683. pitch=1.0f/(object[objectnum].mass*0.2f);
  684. scale*=(1.0f/pitch);
  685. alSourcef(sound[object[objectnum].soundnum[1]].alname,AL_GAIN,scale*5.0f);
  686. }
  687. }
  688. }
  689. */
  690. if (object[objectnum].type==4)
  691. {
  692. subtractvectors(vec,object[objectnum].velocity,object[objectnum].prevvelocity);
  693. scale=vectorlength(vec);
  694. if (scale>0.025f)
  695. {
  696. pitch=1.0f/(object[objectnum].mass*0.2f);
  697. scale*=(2.0f/pitch);
  698. if (pitch<0.2f)
  699. pitch=0.2f;
  700. if (pitch>1.0f)
  701. pitch=1.0f;
  702. playsound(2,object[objectnum].position,NULL,scale*5.0f,0,pitch,objectnum,0);
  703. }
  704. }
  705. if (object[objectnum].type==1)
  706. {
  707. subtractvectors(vec,object[objectnum].velocity,object[objectnum].prevvelocity);
  708. scale=vectorlength(vec);
  709. if (scale>0.025f)
  710. {
  711. if ((object[objectnum].button&8)==0)
  712. playsound(5,object[objectnum].position,NULL,scale*7.0f,0,1.0f,objectnum,0);
  713. else
  714. playsound(2,object[objectnum].position,NULL,scale*7.0f,0,1.0f,objectnum,0);
  715. }
  716. }
  717. copyvector(object[objectnum].prevvelocity,object[objectnum].velocity);
  718. object[objectnum].frictionapplied=0.0f;
  719. }