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"
25 #include "Animation.h"
29 extern float multiplier;
30 extern int channels[100];
31 extern Terrain terrain;
33 extern int environment;
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;
55 extern float bonusvalue;
56 extern float bonustotal;
57 extern float bonustime;
58 extern int tutoriallevel;
59 extern int numthrowkill;
60 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
62 void Weapons::DoStuff(){
63 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
64 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
65 static XYZ terrainnormal;
68 static XYZ newpoint1,newpoint2;
69 static float friction=3.5;
70 static float elasticity=.4;
71 static XYZ bounceness;
72 static float frictionness;
73 static float moveamount;
75 static float closestdistance;
76 static float distance;
78 static XYZ closestpoint;
79 static XYZ closestswordpoint;
81 static float proportion;
82 static float tempmult;
86 for(i=0;i<numweapons;i++){
90 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
93 gLoc[0]=tippoint[i].x;
94 gLoc[1]=tippoint[i].y;
95 gLoc[2]=tippoint[i].z;
99 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
100 OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
101 OPENAL_SetVolume(channels[staffbreaksound], 256);
102 OPENAL_SetPaused(channels[staffbreaksound], false);
105 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
108 tempvel.x=float(abs(Random()%100)-50)/20;
109 tempvel.y=float(abs(Random()%100)-50)/20;
110 tempvel.z=float(abs(Random()%100)-50)/20;
112 Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
124 player[tempowner].num_weapons--;
125 if(player[tempowner].num_weapons){
126 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
127 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
129 player[tempowner].weaponactive=-1;
132 oldposition[i]=position[i];
133 oldtippoint[i]=tippoint[i];
134 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
135 position[i]+=velocity[i]*multiplier;
136 tippoint[i]+=velocity[i]*multiplier;
137 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
138 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
139 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
140 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
141 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
142 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
143 start=oldtippoint[i];
145 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
147 if(objects.type[k]==treetrunktype){
148 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
149 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
151 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
152 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
153 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
154 XYZ temppoint1,temppoint2,tempforward;
158 temppoint2=normalrot;
159 distance=findDistance(&temppoint1,&temppoint2);
160 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
161 rotation2[i]*=360/6.28;
164 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
165 rotation1[i]*=360/6.28;
166 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
177 gLoc[0]=position[i].x;
178 gLoc[1]=position[i].y;
179 gLoc[2]=position[i].z;
183 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
184 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
185 OPENAL_SetVolume(channels[knifesheathesound], 128);
186 OPENAL_SetPaused(channels[knifesheathesound], false);
190 Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
195 position[i]-=velocity[i]*multiplier;
196 tippoint[i]-=velocity[i]*multiplier;
197 tipvelocity[i]=velocity[i];
202 if(velocity[i].x||velocity[i].y||velocity[i].z)
203 for(j=0;j<numplayers;j++){
205 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;
206 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]){
207 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]){
209 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)){
212 gLoc[0]=player[j].coords.x;
213 gLoc[1]=player[j].coords.y;
214 gLoc[2]=player[j].coords.z;
215 vel[0]=player[j].velocity.x;
216 vel[1]=player[j].velocity.y;
217 vel[2]=player[j].velocity.z;
218 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
219 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
220 OPENAL_SetVolume(channels[knifedrawsound], 128);
221 OPENAL_SetPaused(channels[knifedrawsound], false);
223 player[j].weaponactive=0;
224 player[j].targetanimation=removeknifeanim;
225 player[j].targetframe=1;
227 owner[i]=player[j].id;
228 if(player[j].num_weapons>0){
229 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
231 player[j].num_weapons++;
232 player[j].weaponids[0]=i;
234 player[j].aitype=attacktypecutoff;
237 if(j!=0)numthrowkill++;
238 player[j].num_weapons++;
239 player[j].weaponstuck=player[j].num_weapons-1;
240 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
241 else player[j].weaponstuckwhere=0;
243 player[j].weaponids[player[j].num_weapons-1]=i;
245 player[j].RagDoll(0);
246 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
247 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
248 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
249 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
250 //player[j].Puff(abdomen);
251 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
252 if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
253 footvel=tippoint[i]-position[i];
255 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
257 if(tutoriallevel!=1){
258 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
259 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
260 player[j].damage+=200/player[j].armorhigh;
261 player[j].deathbleeding=1;
262 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
270 gLoc[0]=position[i].x;
271 gLoc[1]=position[i].y;
272 gLoc[2]=position[i].z;
276 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
277 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
278 OPENAL_SetVolume(channels[fleshstabsound], 128);
279 OPENAL_SetPaused(channels[fleshstabsound], false);
281 if(animation[player[0].targetanimation].height==highheight){
296 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
297 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
299 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
300 position[i]=colpoint*terrain.scale;
302 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
304 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
305 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
307 //position[i]-=normalrot*.1;
308 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
312 glRotatef(bigrotation[i],0,1,0);
313 glRotatef(bigtilt2[i],1,0,0);
314 glRotatef(bigtilt[i],0,0,1);
315 glRotatef(-rotation1[i]+90,0,1,0);
316 glRotatef(-rotation2[i]+90,0,0,1);
317 glRotatef(-rotation3[i],0,1,0);
318 glRotatef(smallrotation[i],1,0,0);
319 glRotatef(smallrotation2[i],0,1,0);
321 glGetFloatv(GL_MODELVIEW_MATRIX,M);
326 position[i]-=tippoint[i]*.15;
327 XYZ temppoint1,temppoint2,tempforward;
339 gLoc[0]=position[i].x;
340 gLoc[1]=position[i].y;
341 gLoc[2]=position[i].z;
345 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
346 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
347 OPENAL_SetVolume(channels[knifesheathesound], 128);
348 OPENAL_SetPaused(channels[knifesheathesound], false);
351 terrainlight=terrain.getLighting(position[i].x,position[i].z);
352 if(environment==snowyenvironment){
353 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
355 else if(environment==grassyenvironment){
356 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
358 else if(environment==desertenvironment){
359 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
367 position[i]-=velocity[i]*multiplier;
368 tippoint[i]-=velocity[i]*multiplier;
369 tipvelocity[i]=velocity[i];
372 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
373 velocity[i].y+=gravity*multiplier;
375 XYZ temppoint1,temppoint2,tempforward;
379 temppoint2=velocity[i];
380 distance=findDistance(&temppoint1,&temppoint2);
381 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
382 rotation2[i]*=360/6.28;
385 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
386 rotation1[i]*=360/6.28;
393 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
403 for(int l=0;l<10;l++){
404 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
406 position[i]+=velocity[i]*multiplier;
407 tippoint[i]+=tipvelocity[i]*multiplier;
410 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
411 vel=tippoint[i]-midp;
413 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
414 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
416 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
417 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
419 position[i]=newpoint1;
420 tippoint[i]=newpoint2;
424 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
425 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
426 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
427 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
428 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
429 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
433 start=position[i]-(tippoint[i]-position[i])/5;
434 end=tippoint[i]+(tippoint[i]-position[i])/30;
435 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
438 diff=(colpoint-tippoint[i]);
442 position[i]+=(colpoint-tippoint[i])+diff*.05;
443 tippoint[i]=colpoint+diff*.05;
444 oldposition[i]=position[i];
445 oldtippoint[i]=tippoint[i];
449 start=tippoint[i]-(position[i]-tippoint[i])/5;
450 end=position[i]+(position[i]-tippoint[i])/30;
451 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
454 diff=(colpoint-position[i]);
458 tippoint[i]+=(colpoint-position[i])+diff*.05;
459 position[i]=colpoint+diff*.05;
460 oldtippoint[i]=tippoint[i];
461 oldposition[i]=tippoint[i];
466 start=oldposition[i];
468 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
471 position[i]=colpoint;
472 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
473 ReflectVector(&velocity[i],&terrainnormal);
474 position[i]+=terrainnormal*.002;
476 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
477 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
478 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
479 velocity[i]-=bounceness;
480 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
482 velocity[i]+=bounceness*elasticity;
484 if(findLengthfast(&bounceness)>1){
487 //int whichsound=clank1sound+abs(Random()%4);
489 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
490 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
491 gLoc[1]=position[i].y;
492 gLoc[2]=position[i].z;
496 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
497 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
498 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
499 OPENAL_SetPaused(channels[whichsound], false);
502 start=oldtippoint[i];
504 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
507 tippoint[i]=colpoint;
508 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
509 ReflectVector(&tipvelocity[i],&terrainnormal);
510 tippoint[i]+=terrainnormal*.002;
512 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
513 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
514 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
515 tipvelocity[i]-=bounceness;
516 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
517 else tipvelocity[i]=0;
518 tipvelocity[i]+=bounceness*elasticity;
520 if(findLengthfast(&bounceness)>1){
523 //int whichsound=clank1sound+abs(Random()%4);
525 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
526 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
527 gLoc[0]=position[i].x;
528 gLoc[1]=position[i].y;
529 gLoc[2]=position[i].z;
533 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
534 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
535 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
536 OPENAL_SetPaused(channels[whichsound], false);
540 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
542 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
544 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
548 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
552 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
553 ReflectVector(&velocity[i],&terrainnormal);
555 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
556 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
557 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
558 velocity[i]-=bounceness;
559 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
561 velocity[i]+=bounceness*elasticity;
563 if(findLengthfast(&bounceness)>1){
566 //int whichsound=clank1sound+abs(Random()%4);
568 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
569 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
575 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
576 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
577 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
578 OPENAL_SetPaused(channels[whichsound], false);
580 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
583 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
585 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
589 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
593 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
594 ReflectVector(&tipvelocity[i],&terrainnormal);
596 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
597 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
598 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
599 tipvelocity[i]-=bounceness;
600 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
601 else tipvelocity[i]=0;
602 tipvelocity[i]+=bounceness*elasticity;
604 if(findLengthfast(&bounceness)>1){
607 //int whichsound=clank1sound+abs(Random()%4);
609 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
610 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
616 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
617 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
618 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
619 OPENAL_SetPaused(channels[whichsound], false);
621 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
628 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
632 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
633 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
634 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
635 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
636 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
637 if(distance<closestdistance||closestdistance==-1){
638 closestpoint=colpoint;
639 closestdistance=distance;
642 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
643 if(distance<closestdistance||closestdistance==-1){
644 closestpoint=colpoint;
645 closestdistance=distance;
648 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
649 if(distance<closestdistance||closestdistance==-1){
650 closestpoint=colpoint;
651 closestdistance=distance;
654 if(closestdistance!=-1&&isnormal(closestdistance)){
655 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
656 closestswordpoint=colpoint;
657 velocity[i]+=(closestpoint-closestswordpoint);
658 tipvelocity[i]+=(closestpoint-closestswordpoint);
659 position[i]+=(closestpoint-closestswordpoint);
660 tippoint[i]+=(closestpoint-closestswordpoint);
669 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
670 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
672 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
673 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
675 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
676 ReflectVector(&velocity[i],&terrainnormal);
677 position[i]+=terrainnormal*.002;
678 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
679 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
680 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
681 velocity[i]-=bounceness;
682 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
684 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
685 else velocity[i]+=bounceness*elasticity;
686 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
687 if(findLengthfast(&bounceness)>1){
691 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
692 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
693 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
695 else whichsound=footstepsound+abs(Random()%2);
696 gLoc[0]=position[i].x;
697 gLoc[1]=position[i].y;
698 gLoc[2]=position[i].z;
702 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
703 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
704 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
705 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
706 OPENAL_SetPaused(channels[whichsound], false);
708 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
710 terrainlight=terrain.getLighting(position[i].x,position[i].z);
711 if(environment==snowyenvironment){
712 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
714 else if(environment==grassyenvironment){
715 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
717 else if(environment==desertenvironment){
718 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
723 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
724 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
725 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
726 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
728 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
729 ReflectVector(&tipvelocity[i],&terrainnormal);
730 tippoint[i]+=terrainnormal*.002;
731 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
732 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
733 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
734 tipvelocity[i]-=bounceness;
735 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
736 else tipvelocity[i]=0;
737 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
738 else tipvelocity[i]+=bounceness*elasticity;
739 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
741 if(findLengthfast(&bounceness)>1){
745 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
746 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
747 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
749 else whichsound=footstepsound+abs(Random()%2);
750 gLoc[0]=tippoint[i].x;
751 gLoc[1]=tippoint[i].y;
752 gLoc[2]=tippoint[i].z;
756 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
757 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
758 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
759 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
760 OPENAL_SetPaused(channels[whichsound], false);
762 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
764 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
765 if(environment==snowyenvironment){
766 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
768 else if(environment==grassyenvironment){
769 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
771 else if(environment==desertenvironment){
772 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
779 mid=position[i]+tippoint[i];
781 mid+=(position[i]-mid)/20;
783 if(mid.y<terrain.getHeight(mid.x,mid.z)){
785 mid.y=terrain.getHeight(mid.x,mid.z);
787 terrainnormal=terrain.getNormal(mid.x,mid.z);
788 ReflectVector(&velocity[i],&terrainnormal);
789 //mid+=terrainnormal*.002;
790 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
791 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
792 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
793 velocity[i]-=bounceness;
794 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
796 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
797 else velocity[i]+=bounceness*elasticity;
799 if(findLengthfast(&bounceness)>1){
803 if(terrain.getOpacity(mid.x,mid.z)>.2){
804 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
805 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
807 else whichsound=footstepsound+abs(Random()%2);
814 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
815 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
816 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
817 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
818 OPENAL_SetPaused(channels[whichsound], false);
820 position[i]+=(mid-oldmid)*20;
823 mid=position[i]+tippoint[i];
825 mid+=(tippoint[i]-mid)/20;
827 if(mid.y<terrain.getHeight(mid.x,mid.z)){
829 mid.y=terrain.getHeight(mid.x,mid.z);
831 terrainnormal=terrain.getNormal(mid.x,mid.z);
832 ReflectVector(&tipvelocity[i],&terrainnormal);
833 //mid+=terrainnormal*.002;
834 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
835 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
836 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
837 tipvelocity[i]-=bounceness;
838 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
839 else tipvelocity[i]=0;
840 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
841 else tipvelocity[i]+=bounceness*elasticity;
843 if(findLengthfast(&bounceness)>1){
847 if(terrain.getOpacity(mid.x,mid.z)>.2){
848 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
849 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
851 else whichsound=footstepsound+abs(Random()%2);
858 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
859 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
860 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
861 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
862 OPENAL_SetPaused(channels[whichsound], false);
864 tippoint[i]+=(mid-oldmid)*20;
867 mid=position[i]+tippoint[i];
869 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
871 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
873 terrainnormal=terrain.getNormal(mid.x,mid.z);
874 ReflectVector(&velocity[i],&terrainnormal);
875 position[i]+=terrainnormal*.002;
876 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
877 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
878 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
879 velocity[i]-=bounceness;
880 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
882 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
883 else velocity[i]+=bounceness*elasticity;
885 if(findLengthfast(&bounceness)>1){
889 if(terrain.getOpacity(mid.x,mid.z)>.2){
890 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
891 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
893 else whichsound=footstepsound+abs(Random()%2);
894 gLoc[0]=position[i].x;
895 gLoc[1]=position[i].y;
896 gLoc[2]=position[i].z;
900 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
901 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
902 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
903 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
904 OPENAL_SetPaused(channels[whichsound], false);
908 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
910 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
912 terrainnormal=terrain.getNormal(mid.x,mid.z);
913 ReflectVector(&tipvelocity[i],&terrainnormal);
914 tippoint[i]+=terrainnormal*.002;
915 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
916 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
917 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
918 tipvelocity[i]-=bounceness;
919 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
920 else tipvelocity[i]=0;
921 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
922 else tipvelocity[i]+=bounceness*elasticity;
924 if(findLengthfast(&bounceness)>1){
928 if(terrain.getOpacity(mid.x,mid.z)>.2){
929 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
930 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
932 else whichsound=footstepsound+abs(Random()%2);
933 gLoc[0]=tippoint[i].x;
934 gLoc[1]=tippoint[i].y;
935 gLoc[2]=tippoint[i].z;
939 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
940 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
941 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
942 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
943 OPENAL_SetPaused(channels[whichsound], false);
947 //Fix terrain edge collision
950 whichhit=terrain.lineTerrain(start,end,&colpoint);
961 tipvelocity[i].y+=.1;
964 whichhit=terrain.lineTerrain(start,end,&colpoint);
966 closestpoint=colpoint*terrain.scale;
971 tipvelocity[i].y-=.1;
974 whichhit=terrain.lineTerrain(start,end,&colpoint);
979 tipvelocity[i].y+=.01;
982 whichhit=terrain.lineTerrain(start,end,&colpoint);
984 closestpoint=colpoint*terrain.scale;
988 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
990 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
991 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
994 position[i].y+=.1*proportion;
995 tippoint[i].y+=.1*(1-proportion);
996 velocity[i].y+=.1*proportion;
997 tipvelocity[i].y+=.1*(1-proportion);
1000 whichhit=terrain.lineTerrain(start,end,&colpoint);
1002 position[i].y-=.1*proportion;
1003 tippoint[i].y-=.1*(1-proportion);
1004 velocity[i].y-=.1*proportion;
1005 tipvelocity[i].y-=.1*(1-proportion);
1008 whichhit=terrain.lineTerrain(start,end,&colpoint);
1009 while(whichhit!=-1){
1010 position[i].y+=.01*proportion;
1011 tippoint[i].y+=.01*(1-proportion);
1012 velocity[i].y+=.01*proportion;
1013 tipvelocity[i].y+=.01*(1-proportion);
1016 whichhit=terrain.lineTerrain(start,end,&colpoint);
1023 velocity[i].y+=gravity*multiplier;
1024 tipvelocity[i].y+=gravity*multiplier;
1025 //position[i].y+=gravity*multiplier*multiplier;
1026 //tippoint[i].y+=gravity*multiplier*multiplier;
1029 XYZ temppoint1,temppoint2,tempforward;
1032 temppoint1=position[i];
1033 temppoint2=tippoint[i];
1034 distance=findDistance(&temppoint1,&temppoint2);
1035 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1036 rotation2[i]*=360/6.28;
1039 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1040 rotation1[i]*=360/6.28;
1042 smallrotation[i]=90;
1043 smallrotation2[i]=0;
1047 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1050 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1051 freetime[i]+=multiplier;
1054 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1055 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1063 multiplier=tempmult;
1064 if(blooddrip[i]&&bloody[i]){
1065 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1066 blooddrip[i]-=multiplier;
1067 if(blooddrip[i]<0)blooddrip[i]=0;
1068 if(blooddrip[i]>5)blooddrip[i]=5;
1069 if(blooddripdelay[i]<0&&bloodtoggle){
1070 blooddripdelay[i]=1;
1073 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1077 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1082 flamedelay[i]-=multiplier;
1083 if(onfire[i]&&flamedelay[i]<=0){
1085 flamedelay[i]-=multiplier;
1088 normalrot=player[owner[i]].velocity;
1092 if(player[owner[i]].onterrain){
1096 Sprite::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);
1097 Sprite::setLastSpriteSpeed(4);
1098 Sprite::setLastSpriteAlivetime(.3);
1102 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1103 flamedelay[i]-=multiplier;
1104 if(flamedelay[i]<=0){
1106 flamedelay[i]-=multiplier;
1108 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1110 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1111 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1112 Sprite::setLastSpriteSpeed(4);
1113 Sprite::setLastSpriteAlivetime(.3);
1123 static XYZ terrainlight;
1124 static GLfloat M[16];
1126 glAlphaFunc(GL_GREATER, 0.9);
1127 glEnable(GL_TEXTURE_2D);
1129 glEnable(GL_CULL_FACE);
1130 glCullFace(GL_FRONT);
1132 for(i=0;i<numweapons;i++)
1134 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1140 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1141 else drawhowmany[i]=1;
1145 if(player[owner[i]].occluded<25)
1146 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)
1148 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)
1152 else drawhowmany[i]=1;
1153 if(player[owner[i]].targetanimation==swordgroundstabanim)
1155 lastdrawnrotation1[i]=rotation1[i];
1156 lastdrawnrotation2[i]=rotation2[i];
1157 lastdrawnrotation3[i]=rotation3[i];
1158 lastdrawnbigrotation[i]=bigrotation[i];
1159 lastdrawnbigtilt[i]=bigtilt[i];
1160 lastdrawnbigtilt2[i]=bigtilt2[i];
1161 lastdrawnsmallrotation[i]=smallrotation[i];
1162 lastdrawnsmallrotation2[i]=smallrotation2[i];
1167 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1168 if(drawhowmany[i]>0)
1170 glAlphaFunc(GL_GREATER, 0.01);
1172 for(j=drawhowmany[i];j>0;j--)
1174 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1176 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1177 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]));
1178 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]));
1179 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1180 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1181 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1182 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1183 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1184 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1185 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1186 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1187 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1191 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1193 glTranslatef(0,0,-.3);
1195 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)
1197 glTranslatef(0,0,-.1);
1200 /*if(type[i]==knife){
1202 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1208 glEnable(GL_LIGHTING);
1209 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1212 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1213 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1218 glEnable(GL_LIGHTING);
1219 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1222 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1223 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1228 glEnable(GL_LIGHTING);
1229 staffmodel.drawdifftex(stafftextureptr);
1235 lastdrawnposition[i]=position[i];
1236 lastdrawntippoint[i]=tippoint[i];
1237 lastdrawnrotation1[i]=rotation1[i];
1238 lastdrawnrotation2[i]=rotation2[i];
1239 lastdrawnrotation3[i]=rotation3[i];
1240 lastdrawnbigrotation[i]=bigrotation[i];
1241 lastdrawnbigtilt[i]=bigtilt[i];
1242 lastdrawnbigtilt2[i]=bigtilt2[i];
1243 lastdrawnsmallrotation[i]=smallrotation[i];
1244 lastdrawnsmallrotation2[i]=smallrotation2[i];
1245 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1249 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1252 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1253 glRotatef(bigrotation[i],0,1,0);
1254 glRotatef(bigtilt2[i],1,0,0);
1255 glRotatef(bigtilt[i],0,0,1);
1256 glRotatef(-rotation1[i]+90,0,1,0);
1257 glRotatef(-rotation2[i]+90,0,0,1);
1258 glRotatef(-rotation3[i],0,1,0);
1259 glRotatef(smallrotation[i],1,0,0);
1260 glRotatef(smallrotation2[i],0,1,0);
1261 glTranslatef(0,0,length[i]);
1262 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1263 tippoint[i].x=M[12];
1264 tippoint[i].y=M[13];
1265 tippoint[i].z=M[14];
1271 shinepoint=position[i];
1272 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1273 Sprite::speed[Sprite::numsprites-1]=4;
1274 Sprite::alivetime[Sprite::numsprites-1]=.3;
1275 shinepoint=tippoint[i];
1276 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1277 Sprite::speed[Sprite::numsprites-1]=4;
1278 Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1288 // Model throwingknifemodel;
1289 knifetextureptr = 0;
1290 lightbloodknifetextureptr = 0;
1291 bloodknifetextureptr = 0;
1293 // Model swordmodel;
1294 swordtextureptr = 0;
1295 lightbloodswordtextureptr = 0;
1296 bloodswordtextureptr = 0;
1298 // Model staffmodel;
1299 stafftextureptr = 0;
1304 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1305 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1306 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1307 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1308 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1309 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1310 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );