2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /**> HEADER FILES <**/
24 #include "openal_wrapper.h"
26 extern float multiplier;
27 extern Animation animation[animation_count];
28 extern OPENAL_SAMPLE *samp[100];
29 extern int channels[100];
30 extern Terrain terrain;
32 extern int environment;
33 extern Sprites sprites;
35 extern FRUSTUM frustum;
37 extern float realmultiplier;
39 extern float slomodelay;
40 extern bool cellophane;
41 extern float texdetail;
42 extern GLubyte bloodText[512*512*3];
43 extern int bloodtoggle;
44 extern Objects objects;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float terraindetail;
50 extern float viewdistance;
51 extern float blackout;
52 extern int difficulty;
53 extern Person player[maxplayers];
54 extern int numplayers;
57 extern float bonusvalue;
58 extern float bonustotal;
59 extern float bonustime;
60 extern int tutoriallevel;
61 extern int numthrowkill;
62 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
64 void Weapons::DoStuff(){
65 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
66 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
67 static XYZ terrainnormal;
70 static XYZ newpoint1,newpoint2;
71 static float friction=3.5;
72 static float elasticity=.4;
73 static XYZ bounceness;
74 static float frictionness;
75 static float moveamount;
77 static float closestdistance;
78 static float distance;
80 static XYZ closestpoint;
81 static XYZ closestswordpoint;
83 static float proportion;
84 static float tempmult;
88 for(i=0;i<numweapons;i++){
92 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
95 gLoc[0]=tippoint[i].x;
96 gLoc[1]=tippoint[i].y;
97 gLoc[2]=tippoint[i].z;
101 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
102 OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
103 OPENAL_SetVolume(channels[staffbreaksound], 256);
104 OPENAL_SetPaused(channels[staffbreaksound], false);
107 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
110 tempvel.x=float(abs(Random()%100)-50)/20;
111 tempvel.y=float(abs(Random()%100)-50)/20;
112 tempvel.z=float(abs(Random()%100)-50)/20;
114 sprites.MakeSprite(cloudimpactsprite, position[i]+(tippoint[i]-position[i])*((float)j-2)/8,tempvel*.5, 115/255,73/255,12/255, .15+float(abs(Random()%100)-50)/1000, .7);
117 tempvel.x=float(abs(Random()%100)-50)/20;
118 tempvel.y=float(abs(Random()%100)-50)/20;
119 tempvel.z=float(abs(Random()%100)-50)/20;
121 sprites.MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
133 player[tempowner].num_weapons--;
134 if(player[tempowner].num_weapons){
135 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
136 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
138 player[tempowner].weaponactive=-1;
141 oldposition[i]=position[i];
142 oldtippoint[i]=tippoint[i];
143 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
144 position[i]+=velocity[i]*multiplier;
145 tippoint[i]+=velocity[i]*multiplier;
146 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
147 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
148 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
149 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
150 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
151 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
152 start=oldtippoint[i];
154 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
156 if(objects.type[k]==treetrunktype){
157 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
158 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
160 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
161 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
162 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
163 XYZ temppoint1,temppoint2,tempforward;
167 temppoint2=normalrot;
168 distance=findDistance(&temppoint1,&temppoint2);
169 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
170 rotation2[i]*=360/6.28;
173 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
174 rotation1[i]*=360/6.28;
175 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
186 gLoc[0]=position[i].x;
187 gLoc[1]=position[i].y;
188 gLoc[2]=position[i].z;
192 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
193 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
194 OPENAL_SetVolume(channels[knifesheathesound], 128);
195 OPENAL_SetPaused(channels[knifesheathesound], false);
199 sprites.MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
204 position[i]-=velocity[i]*multiplier;
205 tippoint[i]-=velocity[i]*multiplier;
206 tipvelocity[i]=velocity[i];
211 if(velocity[i].x||velocity[i].y||velocity[i].z)
212 for(j=0;j<numplayers;j++){
214 footpoint=DoRotation((player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].position+player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].position)/2,0,player[j].rotation,0)*player[j].scale+player[j].coords;
215 if(owner[i]==-1&&findDistancefastflat(&position[i],&player[j].coords)<1.5&&findDistancefast(&position[i],&player[j].coords)<4&&player[j].weaponstuck==-1&&!player[j].skeleton.free&&j!=oldowner[i]){
216 if((player[j].aitype!=attacktypecutoff||abs(Random()%6)==0||(player[j].targetanimation!=backhandspringanim&&player[j].targetanimation!=rollanim&&player[j].targetanimation!=flipanim&&Random()%2==0))&&!missed[i]){
218 if((player[j].creature==wolftype&&Random()%3!=0&&player[j].weaponactive==-1&&(player[j].isIdle()||player[j].isRun()||player[j].targetanimation==walkanim))||(player[j].creature==rabbittype&&Random()%2==0&&player[j].aitype==attacktypecutoff&&player[j].weaponactive==-1)){
221 gLoc[0]=player[j].coords.x;
222 gLoc[1]=player[j].coords.y;
223 gLoc[2]=player[j].coords.z;
224 vel[0]=player[j].velocity.x;
225 vel[1]=player[j].velocity.y;
226 vel[2]=player[j].velocity.z;
227 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
228 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
229 OPENAL_SetVolume(channels[knifedrawsound], 128);
230 OPENAL_SetPaused(channels[knifedrawsound], false);
232 player[j].weaponactive=0;
233 player[j].targetanimation=removeknifeanim;
234 player[j].targetframe=1;
236 owner[i]=player[j].id;
237 if(player[j].num_weapons>0){
238 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
240 player[j].num_weapons++;
241 player[j].weaponids[0]=i;
243 player[j].aitype=attacktypecutoff;
246 if(j!=0)numthrowkill++;
247 player[j].num_weapons++;
248 player[j].weaponstuck=player[j].num_weapons-1;
249 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
250 else player[j].weaponstuckwhere=0;
252 player[j].weaponids[player[j].num_weapons-1]=i;
254 player[j].RagDoll(0);
255 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
256 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
257 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
258 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
259 //player[j].Puff(abdomen);
260 if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
261 if(tutoriallevel==1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
262 footvel=tippoint[i]-position[i];
264 if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
266 if(tutoriallevel!=1){
267 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
268 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
269 player[j].damage+=200/player[j].armorhigh;
270 player[j].deathbleeding=1;
271 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
279 gLoc[0]=position[i].x;
280 gLoc[1]=position[i].y;
281 gLoc[2]=position[i].z;
285 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
286 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
287 OPENAL_SetVolume(channels[fleshstabsound], 128);
288 OPENAL_SetPaused(channels[fleshstabsound], false);
290 if(animation[player[0].targetanimation].height==highheight){
305 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
306 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
308 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
309 position[i]=colpoint*terrain.scale;
311 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
313 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
314 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
316 //position[i]-=normalrot*.1;
317 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
321 glRotatef(bigrotation[i],0,1,0);
322 glRotatef(bigtilt2[i],1,0,0);
323 glRotatef(bigtilt[i],0,0,1);
324 glRotatef(-rotation1[i]+90,0,1,0);
325 glRotatef(-rotation2[i]+90,0,0,1);
326 glRotatef(-rotation3[i],0,1,0);
327 glRotatef(smallrotation[i],1,0,0);
328 glRotatef(smallrotation2[i],0,1,0);
330 glGetFloatv(GL_MODELVIEW_MATRIX,M);
335 position[i]-=tippoint[i]*.15;
336 XYZ temppoint1,temppoint2,tempforward;
348 gLoc[0]=position[i].x;
349 gLoc[1]=position[i].y;
350 gLoc[2]=position[i].z;
354 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
355 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
356 OPENAL_SetVolume(channels[knifesheathesound], 128);
357 OPENAL_SetPaused(channels[knifesheathesound], false);
360 terrainlight=terrain.getLighting(position[i].x,position[i].z);
361 if(environment==snowyenvironment){
362 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
364 else if(environment==grassyenvironment){
365 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
367 else if(environment==desertenvironment){
368 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
376 position[i]-=velocity[i]*multiplier;
377 tippoint[i]-=velocity[i]*multiplier;
378 tipvelocity[i]=velocity[i];
381 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
382 velocity[i].y+=gravity*multiplier;
384 XYZ temppoint1,temppoint2,tempforward;
388 temppoint2=velocity[i];
389 distance=findDistance(&temppoint1,&temppoint2);
390 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
391 rotation2[i]*=360/6.28;
394 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
395 rotation1[i]*=360/6.28;
402 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
412 for(int l=0;l<10;l++){
413 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
415 position[i]+=velocity[i]*multiplier;
416 tippoint[i]+=tipvelocity[i]*multiplier;
419 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
420 vel=tippoint[i]-midp;
422 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
423 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
425 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
426 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
428 position[i]=newpoint1;
429 tippoint[i]=newpoint2;
433 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
434 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
435 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
436 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
437 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
438 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
442 start=position[i]-(tippoint[i]-position[i])/5;
443 end=tippoint[i]+(tippoint[i]-position[i])/30;
444 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
447 diff=(colpoint-tippoint[i]);
451 position[i]+=(colpoint-tippoint[i])+diff*.05;
452 tippoint[i]=colpoint+diff*.05;
453 oldposition[i]=position[i];
454 oldtippoint[i]=tippoint[i];
458 start=tippoint[i]-(position[i]-tippoint[i])/5;
459 end=position[i]+(position[i]-tippoint[i])/30;
460 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
463 diff=(colpoint-position[i]);
467 tippoint[i]+=(colpoint-position[i])+diff*.05;
468 position[i]=colpoint+diff*.05;
469 oldtippoint[i]=tippoint[i];
470 oldposition[i]=tippoint[i];
475 start=oldposition[i];
477 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
480 position[i]=colpoint;
481 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
482 ReflectVector(&velocity[i],&terrainnormal);
483 position[i]+=terrainnormal*.002;
485 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
486 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
487 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
488 velocity[i]-=bounceness;
489 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
491 velocity[i]+=bounceness*elasticity;
493 if(findLengthfast(&bounceness)>1){
496 //int whichsound=clank1sound+abs(Random()%4);
498 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
499 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
500 gLoc[1]=position[i].y;
501 gLoc[2]=position[i].z;
505 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
506 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
507 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
508 OPENAL_SetPaused(channels[whichsound], false);
511 start=oldtippoint[i];
513 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
516 tippoint[i]=colpoint;
517 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
518 ReflectVector(&tipvelocity[i],&terrainnormal);
519 tippoint[i]+=terrainnormal*.002;
521 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
522 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
523 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
524 tipvelocity[i]-=bounceness;
525 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
526 else tipvelocity[i]=0;
527 tipvelocity[i]+=bounceness*elasticity;
529 if(findLengthfast(&bounceness)>1){
532 //int whichsound=clank1sound+abs(Random()%4);
534 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
535 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
536 gLoc[0]=position[i].x;
537 gLoc[1]=position[i].y;
538 gLoc[2]=position[i].z;
542 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
543 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
544 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
545 OPENAL_SetPaused(channels[whichsound], false);
549 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
551 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
553 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
557 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
561 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
562 ReflectVector(&velocity[i],&terrainnormal);
564 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
565 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
566 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
567 velocity[i]-=bounceness;
568 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
570 velocity[i]+=bounceness*elasticity;
572 if(findLengthfast(&bounceness)>1){
575 //int whichsound=clank1sound+abs(Random()%4);
577 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
578 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
584 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
585 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
586 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
587 OPENAL_SetPaused(channels[whichsound], false);
589 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
592 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
594 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
598 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
602 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
603 ReflectVector(&tipvelocity[i],&terrainnormal);
605 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
606 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
607 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
608 tipvelocity[i]-=bounceness;
609 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
610 else tipvelocity[i]=0;
611 tipvelocity[i]+=bounceness*elasticity;
613 if(findLengthfast(&bounceness)>1){
616 //int whichsound=clank1sound+abs(Random()%4);
618 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
619 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
625 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
626 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
627 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
628 OPENAL_SetPaused(channels[whichsound], false);
630 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
637 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
641 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
642 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
643 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
644 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
645 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
646 if(distance<closestdistance||closestdistance==-1){
647 closestpoint=colpoint;
648 closestdistance=distance;
651 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
652 if(distance<closestdistance||closestdistance==-1){
653 closestpoint=colpoint;
654 closestdistance=distance;
657 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
658 if(distance<closestdistance||closestdistance==-1){
659 closestpoint=colpoint;
660 closestdistance=distance;
663 if(closestdistance!=-1&&isnormal(closestdistance)){
664 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
665 closestswordpoint=colpoint;
666 velocity[i]+=(closestpoint-closestswordpoint);
667 tipvelocity[i]+=(closestpoint-closestswordpoint);
668 position[i]+=(closestpoint-closestswordpoint);
669 tippoint[i]+=(closestpoint-closestswordpoint);
678 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
679 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
681 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
682 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
684 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
685 ReflectVector(&velocity[i],&terrainnormal);
686 position[i]+=terrainnormal*.002;
687 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
688 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
689 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
690 velocity[i]-=bounceness;
691 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
693 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
694 else velocity[i]+=bounceness*elasticity;
695 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
696 if(findLengthfast(&bounceness)>1){
700 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
701 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
702 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
704 else whichsound=footstepsound+abs(Random()%2);
705 gLoc[0]=position[i].x;
706 gLoc[1]=position[i].y;
707 gLoc[2]=position[i].z;
711 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
712 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
713 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
714 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
715 OPENAL_SetPaused(channels[whichsound], false);
717 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
719 terrainlight=terrain.getLighting(position[i].x,position[i].z);
720 if(environment==snowyenvironment){
721 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
723 else if(environment==grassyenvironment){
724 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
726 else if(environment==desertenvironment){
727 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
732 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
733 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
734 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
735 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
737 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
738 ReflectVector(&tipvelocity[i],&terrainnormal);
739 tippoint[i]+=terrainnormal*.002;
740 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
741 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
742 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
743 tipvelocity[i]-=bounceness;
744 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
745 else tipvelocity[i]=0;
746 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
747 else tipvelocity[i]+=bounceness*elasticity;
748 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
750 if(findLengthfast(&bounceness)>1){
754 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
755 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
756 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
758 else whichsound=footstepsound+abs(Random()%2);
759 gLoc[0]=tippoint[i].x;
760 gLoc[1]=tippoint[i].y;
761 gLoc[2]=tippoint[i].z;
765 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
766 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
767 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
768 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
769 OPENAL_SetPaused(channels[whichsound], false);
771 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
773 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
774 if(environment==snowyenvironment){
775 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
777 else if(environment==grassyenvironment){
778 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
780 else if(environment==desertenvironment){
781 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
788 mid=position[i]+tippoint[i];
790 mid+=(position[i]-mid)/20;
792 if(mid.y<terrain.getHeight(mid.x,mid.z)){
794 mid.y=terrain.getHeight(mid.x,mid.z);
796 terrainnormal=terrain.getNormal(mid.x,mid.z);
797 ReflectVector(&velocity[i],&terrainnormal);
798 //mid+=terrainnormal*.002;
799 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
800 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
801 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
802 velocity[i]-=bounceness;
803 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
805 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
806 else velocity[i]+=bounceness*elasticity;
808 if(findLengthfast(&bounceness)>1){
812 if(terrain.getOpacity(mid.x,mid.z)>.2){
813 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
814 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
816 else whichsound=footstepsound+abs(Random()%2);
823 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
824 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
825 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
826 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
827 OPENAL_SetPaused(channels[whichsound], false);
829 position[i]+=(mid-oldmid)*20;
832 mid=position[i]+tippoint[i];
834 mid+=(tippoint[i]-mid)/20;
836 if(mid.y<terrain.getHeight(mid.x,mid.z)){
838 mid.y=terrain.getHeight(mid.x,mid.z);
840 terrainnormal=terrain.getNormal(mid.x,mid.z);
841 ReflectVector(&tipvelocity[i],&terrainnormal);
842 //mid+=terrainnormal*.002;
843 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
844 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
845 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
846 tipvelocity[i]-=bounceness;
847 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
848 else tipvelocity[i]=0;
849 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
850 else tipvelocity[i]+=bounceness*elasticity;
852 if(findLengthfast(&bounceness)>1){
856 if(terrain.getOpacity(mid.x,mid.z)>.2){
857 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
858 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
860 else whichsound=footstepsound+abs(Random()%2);
867 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
868 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
869 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
870 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
871 OPENAL_SetPaused(channels[whichsound], false);
873 tippoint[i]+=(mid-oldmid)*20;
876 mid=position[i]+tippoint[i];
878 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
880 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
882 terrainnormal=terrain.getNormal(mid.x,mid.z);
883 ReflectVector(&velocity[i],&terrainnormal);
884 position[i]+=terrainnormal*.002;
885 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
886 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
887 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
888 velocity[i]-=bounceness;
889 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
891 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
892 else velocity[i]+=bounceness*elasticity;
894 if(findLengthfast(&bounceness)>1){
898 if(terrain.getOpacity(mid.x,mid.z)>.2){
899 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
900 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
902 else whichsound=footstepsound+abs(Random()%2);
903 gLoc[0]=position[i].x;
904 gLoc[1]=position[i].y;
905 gLoc[2]=position[i].z;
909 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
910 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
911 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
912 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
913 OPENAL_SetPaused(channels[whichsound], false);
917 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
919 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
921 terrainnormal=terrain.getNormal(mid.x,mid.z);
922 ReflectVector(&tipvelocity[i],&terrainnormal);
923 tippoint[i]+=terrainnormal*.002;
924 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
925 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
926 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
927 tipvelocity[i]-=bounceness;
928 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
929 else tipvelocity[i]=0;
930 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
931 else tipvelocity[i]+=bounceness*elasticity;
933 if(findLengthfast(&bounceness)>1){
937 if(terrain.getOpacity(mid.x,mid.z)>.2){
938 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
939 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
941 else whichsound=footstepsound+abs(Random()%2);
942 gLoc[0]=tippoint[i].x;
943 gLoc[1]=tippoint[i].y;
944 gLoc[2]=tippoint[i].z;
948 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
949 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
950 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
951 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
952 OPENAL_SetPaused(channels[whichsound], false);
956 //Fix terrain edge collision
959 whichhit=terrain.lineTerrain(start,end,&colpoint);
970 tipvelocity[i].y+=.1;
973 whichhit=terrain.lineTerrain(start,end,&colpoint);
975 closestpoint=colpoint*terrain.scale;
980 tipvelocity[i].y-=.1;
983 whichhit=terrain.lineTerrain(start,end,&colpoint);
988 tipvelocity[i].y+=.01;
991 whichhit=terrain.lineTerrain(start,end,&colpoint);
993 closestpoint=colpoint*terrain.scale;
997 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
999 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
1000 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
1002 while(whichhit!=-1){
1003 position[i].y+=.1*proportion;
1004 tippoint[i].y+=.1*(1-proportion);
1005 velocity[i].y+=.1*proportion;
1006 tipvelocity[i].y+=.1*(1-proportion);
1009 whichhit=terrain.lineTerrain(start,end,&colpoint);
1011 position[i].y-=.1*proportion;
1012 tippoint[i].y-=.1*(1-proportion);
1013 velocity[i].y-=.1*proportion;
1014 tipvelocity[i].y-=.1*(1-proportion);
1017 whichhit=terrain.lineTerrain(start,end,&colpoint);
1018 while(whichhit!=-1){
1019 position[i].y+=.01*proportion;
1020 tippoint[i].y+=.01*(1-proportion);
1021 velocity[i].y+=.01*proportion;
1022 tipvelocity[i].y+=.01*(1-proportion);
1025 whichhit=terrain.lineTerrain(start,end,&colpoint);
1032 velocity[i].y+=gravity*multiplier;
1033 tipvelocity[i].y+=gravity*multiplier;
1034 //position[i].y+=gravity*multiplier*multiplier;
1035 //tippoint[i].y+=gravity*multiplier*multiplier;
1038 XYZ temppoint1,temppoint2,tempforward;
1041 temppoint1=position[i];
1042 temppoint2=tippoint[i];
1043 distance=findDistance(&temppoint1,&temppoint2);
1044 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1045 rotation2[i]*=360/6.28;
1048 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1049 rotation1[i]*=360/6.28;
1051 smallrotation[i]=90;
1052 smallrotation2[i]=0;
1056 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1059 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1060 freetime[i]+=multiplier;
1063 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1064 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1072 multiplier=tempmult;
1073 if(blooddrip[i]&&bloody[i]){
1074 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1075 blooddrip[i]-=multiplier;
1076 if(blooddrip[i]<0)blooddrip[i]=0;
1077 if(blooddrip[i]>5)blooddrip[i]=5;
1078 if(blooddripdelay[i]<0&&bloodtoggle){
1079 blooddripdelay[i]=1;
1082 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1086 sprites.MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1091 flamedelay[i]-=multiplier;
1092 if(onfire[i]&&flamedelay[i]<=0){
1094 flamedelay[i]-=multiplier;
1097 normalrot=player[owner[i]].velocity;
1101 if(player[owner[i]].onterrain){
1105 sprites.MakeSprite(weaponflamesprite, position[i]+tippoint[i]*(((float)abs(Random()%100))/600+.05),normalrot, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*1/3, 1);
1106 sprites.speed[sprites.numsprites-1]=4;
1107 sprites.alivetime[sprites.numsprites-1]=.3;
1111 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1112 flamedelay[i]-=multiplier;
1113 if(flamedelay[i]<=0){
1115 flamedelay[i]-=multiplier;
1117 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1119 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1120 sprites.MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1121 sprites.speed[sprites.numsprites-1]=4;
1122 sprites.alivetime[sprites.numsprites-1]=.3;
1132 static XYZ terrainlight;
1133 static GLfloat M[16];
1135 glAlphaFunc(GL_GREATER, 0.9);
1136 glEnable(GL_TEXTURE_2D);
1138 glEnable(GL_CULL_FACE);
1139 glCullFace(GL_FRONT);
1141 for(i=0;i<numweapons;i++)
1143 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1149 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1150 else drawhowmany[i]=1;
1154 if(player[owner[i]].occluded<25)
1155 if((frustum.SphereInFrustum(player[owner[i]].coords.x,player[owner[i]].coords.y+player[owner[i]].scale*3,player[owner[i]].coords.z,player[owner[i]].scale*8)&&findDistancefast(&viewer,&player[owner[i]].coords)<viewdistance*viewdistance)||player[owner[i]].skeleton.free==3)
1157 if((player[owner[i]].targetanimation==knifeslashstartanim||player[owner[i]].targetanimation==swordsneakattackanim||(player[owner[i]].currentanimation==staffhitanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffhitreversedanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffspinhitanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffspinhitreversedanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffgroundsmashanim&&player[owner[i]].currentframe>1)||(player[owner[i]].targetanimation==swordslashanim&&player[owner[i]].targetframe<7)||player[owner[i]].targetanimation==crouchstabanim||player[owner[i]].targetanimation==swordslashreversalanim||player[owner[i]].targetanimation==swordslashreversedanim||player[owner[i]].targetanimation==knifefollowanim||player[owner[i]].targetanimation==swordgroundstabanim||player[owner[i]].targetanimation==knifethrowanim)&&player[owner[i]].targetanimation==lastdrawnanim[i]&&!player[owner[i]].skeleton.free)
1161 else drawhowmany[i]=1;
1162 if(player[owner[i]].targetanimation==swordgroundstabanim)
1164 lastdrawnrotation1[i]=rotation1[i];
1165 lastdrawnrotation2[i]=rotation2[i];
1166 lastdrawnrotation3[i]=rotation3[i];
1167 lastdrawnbigrotation[i]=bigrotation[i];
1168 lastdrawnbigtilt[i]=bigtilt[i];
1169 lastdrawnbigtilt2[i]=bigtilt2[i];
1170 lastdrawnsmallrotation[i]=smallrotation[i];
1171 lastdrawnsmallrotation2[i]=smallrotation2[i];
1176 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1177 if(drawhowmany[i]>0)
1179 glAlphaFunc(GL_GREATER, 0.01);
1181 for(j=drawhowmany[i];j>0;j--)
1183 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1185 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1186 if(owner[i]!=-1)glTranslatef(position[i].x*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].x*(1-((float)(j))/drawhowmany[i]),position[i].y*(((float)(j))/drawhowmany[i])-.02+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));
1187 if(owner[i]==-1)glTranslatef(position[i].x*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].x*(1-((float)(j))/drawhowmany[i]),position[i].y*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));
1188 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1189 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1190 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1191 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1192 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1193 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1194 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1195 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1196 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1200 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1202 glTranslatef(0,0,-.3);
1204 if(player[owner[i]].targetanimation==staffgroundsmashanim||player[owner[i]].currentanimation==staffgroundsmashanim||player[owner[i]].targetanimation==staffspinhitreversedanim||player[owner[i]].currentanimation==staffspinhitreversedanim||player[owner[i]].targetanimation==staffspinhitanim||player[owner[i]].currentanimation==staffspinhitanim)
1206 glTranslatef(0,0,-.1);
1209 /*if(type[i]==knife){
1211 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1217 glEnable(GL_LIGHTING);
1218 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1221 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1222 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1227 glEnable(GL_LIGHTING);
1228 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1231 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1232 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1237 glEnable(GL_LIGHTING);
1238 staffmodel.drawdifftex(stafftextureptr);
1244 lastdrawnposition[i]=position[i];
1245 lastdrawntippoint[i]=tippoint[i];
1246 lastdrawnrotation1[i]=rotation1[i];
1247 lastdrawnrotation2[i]=rotation2[i];
1248 lastdrawnrotation3[i]=rotation3[i];
1249 lastdrawnbigrotation[i]=bigrotation[i];
1250 lastdrawnbigtilt[i]=bigtilt[i];
1251 lastdrawnbigtilt2[i]=bigtilt2[i];
1252 lastdrawnsmallrotation[i]=smallrotation[i];
1253 lastdrawnsmallrotation2[i]=smallrotation2[i];
1254 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1258 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1261 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1262 glRotatef(bigrotation[i],0,1,0);
1263 glRotatef(bigtilt2[i],1,0,0);
1264 glRotatef(bigtilt[i],0,0,1);
1265 glRotatef(-rotation1[i]+90,0,1,0);
1266 glRotatef(-rotation2[i]+90,0,0,1);
1267 glRotatef(-rotation3[i],0,1,0);
1268 glRotatef(smallrotation[i],1,0,0);
1269 glRotatef(smallrotation2[i],0,1,0);
1270 glTranslatef(0,0,length[i]);
1271 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1272 tippoint[i].x=M[12];
1273 tippoint[i].y=M[13];
1274 tippoint[i].z=M[14];
1280 shinepoint=position[i];
1281 sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1282 sprites.speed[sprites.numsprites-1]=4;
1283 sprites.alivetime[sprites.numsprites-1]=.3;
1284 shinepoint=tippoint[i];
1285 sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1286 sprites.speed[sprites.numsprites-1]=4;
1287 sprites.alivetime[sprites.numsprites-1]=.3;*/
1297 // Model throwingknifemodel;
1298 knifetextureptr = 0;
1299 lightbloodknifetextureptr = 0;
1300 bloodknifetextureptr = 0;
1302 // Model swordmodel;
1303 swordtextureptr = 0;
1304 lightbloodswordtextureptr = 0;
1305 bloodswordtextureptr = 0;
1307 // Model staffmodel;
1308 stafftextureptr = 0;
1313 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1314 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1315 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1316 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1317 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1318 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1319 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );