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"
27 extern float multiplier;
28 extern Animation animation[animation_count];
29 extern OPENAL_SAMPLE *samp[100];
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;
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 Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
126 player[tempowner].num_weapons--;
127 if(player[tempowner].num_weapons){
128 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
129 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
131 player[tempowner].weaponactive=-1;
134 oldposition[i]=position[i];
135 oldtippoint[i]=tippoint[i];
136 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
137 position[i]+=velocity[i]*multiplier;
138 tippoint[i]+=velocity[i]*multiplier;
139 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
140 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
141 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
142 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
143 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
144 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
145 start=oldtippoint[i];
147 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
149 if(objects.type[k]==treetrunktype){
150 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
151 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
153 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
154 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
155 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
156 XYZ temppoint1,temppoint2,tempforward;
160 temppoint2=normalrot;
161 distance=findDistance(&temppoint1,&temppoint2);
162 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
163 rotation2[i]*=360/6.28;
166 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
167 rotation1[i]*=360/6.28;
168 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
179 gLoc[0]=position[i].x;
180 gLoc[1]=position[i].y;
181 gLoc[2]=position[i].z;
185 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
186 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
187 OPENAL_SetVolume(channels[knifesheathesound], 128);
188 OPENAL_SetPaused(channels[knifesheathesound], false);
192 Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
197 position[i]-=velocity[i]*multiplier;
198 tippoint[i]-=velocity[i]*multiplier;
199 tipvelocity[i]=velocity[i];
204 if(velocity[i].x||velocity[i].y||velocity[i].z)
205 for(j=0;j<numplayers;j++){
207 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;
208 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]){
209 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]){
211 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)){
214 gLoc[0]=player[j].coords.x;
215 gLoc[1]=player[j].coords.y;
216 gLoc[2]=player[j].coords.z;
217 vel[0]=player[j].velocity.x;
218 vel[1]=player[j].velocity.y;
219 vel[2]=player[j].velocity.z;
220 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
221 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
222 OPENAL_SetVolume(channels[knifedrawsound], 128);
223 OPENAL_SetPaused(channels[knifedrawsound], false);
225 player[j].weaponactive=0;
226 player[j].targetanimation=removeknifeanim;
227 player[j].targetframe=1;
229 owner[i]=player[j].id;
230 if(player[j].num_weapons>0){
231 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
233 player[j].num_weapons++;
234 player[j].weaponids[0]=i;
236 player[j].aitype=attacktypecutoff;
239 if(j!=0)numthrowkill++;
240 player[j].num_weapons++;
241 player[j].weaponstuck=player[j].num_weapons-1;
242 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
243 else player[j].weaponstuckwhere=0;
245 player[j].weaponids[player[j].num_weapons-1]=i;
247 player[j].RagDoll(0);
248 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
249 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
250 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
251 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
252 //player[j].Puff(abdomen);
253 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
254 if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
255 footvel=tippoint[i]-position[i];
257 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
259 if(tutoriallevel!=1){
260 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
261 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
262 player[j].damage+=200/player[j].armorhigh;
263 player[j].deathbleeding=1;
264 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
272 gLoc[0]=position[i].x;
273 gLoc[1]=position[i].y;
274 gLoc[2]=position[i].z;
278 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
279 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
280 OPENAL_SetVolume(channels[fleshstabsound], 128);
281 OPENAL_SetPaused(channels[fleshstabsound], false);
283 if(animation[player[0].targetanimation].height==highheight){
298 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
299 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
301 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
302 position[i]=colpoint*terrain.scale;
304 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
306 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
307 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
309 //position[i]-=normalrot*.1;
310 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
314 glRotatef(bigrotation[i],0,1,0);
315 glRotatef(bigtilt2[i],1,0,0);
316 glRotatef(bigtilt[i],0,0,1);
317 glRotatef(-rotation1[i]+90,0,1,0);
318 glRotatef(-rotation2[i]+90,0,0,1);
319 glRotatef(-rotation3[i],0,1,0);
320 glRotatef(smallrotation[i],1,0,0);
321 glRotatef(smallrotation2[i],0,1,0);
323 glGetFloatv(GL_MODELVIEW_MATRIX,M);
328 position[i]-=tippoint[i]*.15;
329 XYZ temppoint1,temppoint2,tempforward;
341 gLoc[0]=position[i].x;
342 gLoc[1]=position[i].y;
343 gLoc[2]=position[i].z;
347 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
348 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
349 OPENAL_SetVolume(channels[knifesheathesound], 128);
350 OPENAL_SetPaused(channels[knifesheathesound], false);
353 terrainlight=terrain.getLighting(position[i].x,position[i].z);
354 if(environment==snowyenvironment){
355 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
357 else if(environment==grassyenvironment){
358 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);
360 else if(environment==desertenvironment){
361 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);
369 position[i]-=velocity[i]*multiplier;
370 tippoint[i]-=velocity[i]*multiplier;
371 tipvelocity[i]=velocity[i];
374 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
375 velocity[i].y+=gravity*multiplier;
377 XYZ temppoint1,temppoint2,tempforward;
381 temppoint2=velocity[i];
382 distance=findDistance(&temppoint1,&temppoint2);
383 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
384 rotation2[i]*=360/6.28;
387 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
388 rotation1[i]*=360/6.28;
395 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
405 for(int l=0;l<10;l++){
406 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
408 position[i]+=velocity[i]*multiplier;
409 tippoint[i]+=tipvelocity[i]*multiplier;
412 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
413 vel=tippoint[i]-midp;
415 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
416 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
418 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
419 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
421 position[i]=newpoint1;
422 tippoint[i]=newpoint2;
426 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
427 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
428 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
429 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
430 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
431 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
435 start=position[i]-(tippoint[i]-position[i])/5;
436 end=tippoint[i]+(tippoint[i]-position[i])/30;
437 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
440 diff=(colpoint-tippoint[i]);
444 position[i]+=(colpoint-tippoint[i])+diff*.05;
445 tippoint[i]=colpoint+diff*.05;
446 oldposition[i]=position[i];
447 oldtippoint[i]=tippoint[i];
451 start=tippoint[i]-(position[i]-tippoint[i])/5;
452 end=position[i]+(position[i]-tippoint[i])/30;
453 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
456 diff=(colpoint-position[i]);
460 tippoint[i]+=(colpoint-position[i])+diff*.05;
461 position[i]=colpoint+diff*.05;
462 oldtippoint[i]=tippoint[i];
463 oldposition[i]=tippoint[i];
468 start=oldposition[i];
470 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
473 position[i]=colpoint;
474 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
475 ReflectVector(&velocity[i],&terrainnormal);
476 position[i]+=terrainnormal*.002;
478 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
479 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
480 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
481 velocity[i]-=bounceness;
482 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
484 velocity[i]+=bounceness*elasticity;
486 if(findLengthfast(&bounceness)>1){
489 //int whichsound=clank1sound+abs(Random()%4);
491 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
492 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
493 gLoc[1]=position[i].y;
494 gLoc[2]=position[i].z;
498 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
499 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
500 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
501 OPENAL_SetPaused(channels[whichsound], false);
504 start=oldtippoint[i];
506 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
509 tippoint[i]=colpoint;
510 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
511 ReflectVector(&tipvelocity[i],&terrainnormal);
512 tippoint[i]+=terrainnormal*.002;
514 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
515 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
516 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
517 tipvelocity[i]-=bounceness;
518 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
519 else tipvelocity[i]=0;
520 tipvelocity[i]+=bounceness*elasticity;
522 if(findLengthfast(&bounceness)>1){
525 //int whichsound=clank1sound+abs(Random()%4);
527 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
528 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
529 gLoc[0]=position[i].x;
530 gLoc[1]=position[i].y;
531 gLoc[2]=position[i].z;
535 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
536 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
537 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
538 OPENAL_SetPaused(channels[whichsound], false);
542 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
544 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
546 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
550 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
554 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
555 ReflectVector(&velocity[i],&terrainnormal);
557 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
558 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
559 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
560 velocity[i]-=bounceness;
561 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
563 velocity[i]+=bounceness*elasticity;
565 if(findLengthfast(&bounceness)>1){
568 //int whichsound=clank1sound+abs(Random()%4);
570 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
571 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
577 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
578 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
579 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
580 OPENAL_SetPaused(channels[whichsound], false);
582 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
585 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
587 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
591 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
595 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
596 ReflectVector(&tipvelocity[i],&terrainnormal);
598 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
599 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
600 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
601 tipvelocity[i]-=bounceness;
602 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
603 else tipvelocity[i]=0;
604 tipvelocity[i]+=bounceness*elasticity;
606 if(findLengthfast(&bounceness)>1){
609 //int whichsound=clank1sound+abs(Random()%4);
611 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
612 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
618 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
619 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
620 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
621 OPENAL_SetPaused(channels[whichsound], false);
623 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
630 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
634 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
635 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
636 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
637 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
638 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
639 if(distance<closestdistance||closestdistance==-1){
640 closestpoint=colpoint;
641 closestdistance=distance;
644 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
645 if(distance<closestdistance||closestdistance==-1){
646 closestpoint=colpoint;
647 closestdistance=distance;
650 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
651 if(distance<closestdistance||closestdistance==-1){
652 closestpoint=colpoint;
653 closestdistance=distance;
656 if(closestdistance!=-1&&isnormal(closestdistance)){
657 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
658 closestswordpoint=colpoint;
659 velocity[i]+=(closestpoint-closestswordpoint);
660 tipvelocity[i]+=(closestpoint-closestswordpoint);
661 position[i]+=(closestpoint-closestswordpoint);
662 tippoint[i]+=(closestpoint-closestswordpoint);
671 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
672 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
674 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
675 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
677 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
678 ReflectVector(&velocity[i],&terrainnormal);
679 position[i]+=terrainnormal*.002;
680 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
681 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
682 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
683 velocity[i]-=bounceness;
684 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
686 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
687 else velocity[i]+=bounceness*elasticity;
688 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
689 if(findLengthfast(&bounceness)>1){
693 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
694 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
695 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
697 else whichsound=footstepsound+abs(Random()%2);
698 gLoc[0]=position[i].x;
699 gLoc[1]=position[i].y;
700 gLoc[2]=position[i].z;
704 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
705 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
706 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
707 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
708 OPENAL_SetPaused(channels[whichsound], false);
710 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
712 terrainlight=terrain.getLighting(position[i].x,position[i].z);
713 if(environment==snowyenvironment){
714 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
716 else if(environment==grassyenvironment){
717 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);
719 else if(environment==desertenvironment){
720 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);
725 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
726 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
727 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
728 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
730 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
731 ReflectVector(&tipvelocity[i],&terrainnormal);
732 tippoint[i]+=terrainnormal*.002;
733 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
734 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
735 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
736 tipvelocity[i]-=bounceness;
737 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
738 else tipvelocity[i]=0;
739 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
740 else tipvelocity[i]+=bounceness*elasticity;
741 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
743 if(findLengthfast(&bounceness)>1){
747 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
748 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
749 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
751 else whichsound=footstepsound+abs(Random()%2);
752 gLoc[0]=tippoint[i].x;
753 gLoc[1]=tippoint[i].y;
754 gLoc[2]=tippoint[i].z;
758 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
759 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
760 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
761 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
762 OPENAL_SetPaused(channels[whichsound], false);
764 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
766 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
767 if(environment==snowyenvironment){
768 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
770 else if(environment==grassyenvironment){
771 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);
773 else if(environment==desertenvironment){
774 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);
781 mid=position[i]+tippoint[i];
783 mid+=(position[i]-mid)/20;
785 if(mid.y<terrain.getHeight(mid.x,mid.z)){
787 mid.y=terrain.getHeight(mid.x,mid.z);
789 terrainnormal=terrain.getNormal(mid.x,mid.z);
790 ReflectVector(&velocity[i],&terrainnormal);
791 //mid+=terrainnormal*.002;
792 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
793 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
794 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
795 velocity[i]-=bounceness;
796 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
798 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
799 else velocity[i]+=bounceness*elasticity;
801 if(findLengthfast(&bounceness)>1){
805 if(terrain.getOpacity(mid.x,mid.z)>.2){
806 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
807 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
809 else whichsound=footstepsound+abs(Random()%2);
816 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
817 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
818 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
819 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
820 OPENAL_SetPaused(channels[whichsound], false);
822 position[i]+=(mid-oldmid)*20;
825 mid=position[i]+tippoint[i];
827 mid+=(tippoint[i]-mid)/20;
829 if(mid.y<terrain.getHeight(mid.x,mid.z)){
831 mid.y=terrain.getHeight(mid.x,mid.z);
833 terrainnormal=terrain.getNormal(mid.x,mid.z);
834 ReflectVector(&tipvelocity[i],&terrainnormal);
835 //mid+=terrainnormal*.002;
836 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
837 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
838 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
839 tipvelocity[i]-=bounceness;
840 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
841 else tipvelocity[i]=0;
842 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
843 else tipvelocity[i]+=bounceness*elasticity;
845 if(findLengthfast(&bounceness)>1){
849 if(terrain.getOpacity(mid.x,mid.z)>.2){
850 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
851 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
853 else whichsound=footstepsound+abs(Random()%2);
860 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
861 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
862 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
863 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
864 OPENAL_SetPaused(channels[whichsound], false);
866 tippoint[i]+=(mid-oldmid)*20;
869 mid=position[i]+tippoint[i];
871 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
873 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
875 terrainnormal=terrain.getNormal(mid.x,mid.z);
876 ReflectVector(&velocity[i],&terrainnormal);
877 position[i]+=terrainnormal*.002;
878 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
879 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
880 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
881 velocity[i]-=bounceness;
882 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
884 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
885 else velocity[i]+=bounceness*elasticity;
887 if(findLengthfast(&bounceness)>1){
891 if(terrain.getOpacity(mid.x,mid.z)>.2){
892 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
893 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
895 else whichsound=footstepsound+abs(Random()%2);
896 gLoc[0]=position[i].x;
897 gLoc[1]=position[i].y;
898 gLoc[2]=position[i].z;
902 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
903 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
904 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
905 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
906 OPENAL_SetPaused(channels[whichsound], false);
910 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
912 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
914 terrainnormal=terrain.getNormal(mid.x,mid.z);
915 ReflectVector(&tipvelocity[i],&terrainnormal);
916 tippoint[i]+=terrainnormal*.002;
917 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
918 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
919 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
920 tipvelocity[i]-=bounceness;
921 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
922 else tipvelocity[i]=0;
923 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
924 else tipvelocity[i]+=bounceness*elasticity;
926 if(findLengthfast(&bounceness)>1){
930 if(terrain.getOpacity(mid.x,mid.z)>.2){
931 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
932 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
934 else whichsound=footstepsound+abs(Random()%2);
935 gLoc[0]=tippoint[i].x;
936 gLoc[1]=tippoint[i].y;
937 gLoc[2]=tippoint[i].z;
941 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
942 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
943 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
944 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
945 OPENAL_SetPaused(channels[whichsound], false);
949 //Fix terrain edge collision
952 whichhit=terrain.lineTerrain(start,end,&colpoint);
963 tipvelocity[i].y+=.1;
966 whichhit=terrain.lineTerrain(start,end,&colpoint);
968 closestpoint=colpoint*terrain.scale;
973 tipvelocity[i].y-=.1;
976 whichhit=terrain.lineTerrain(start,end,&colpoint);
981 tipvelocity[i].y+=.01;
984 whichhit=terrain.lineTerrain(start,end,&colpoint);
986 closestpoint=colpoint*terrain.scale;
990 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
992 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
993 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
996 position[i].y+=.1*proportion;
997 tippoint[i].y+=.1*(1-proportion);
998 velocity[i].y+=.1*proportion;
999 tipvelocity[i].y+=.1*(1-proportion);
1002 whichhit=terrain.lineTerrain(start,end,&colpoint);
1004 position[i].y-=.1*proportion;
1005 tippoint[i].y-=.1*(1-proportion);
1006 velocity[i].y-=.1*proportion;
1007 tipvelocity[i].y-=.1*(1-proportion);
1010 whichhit=terrain.lineTerrain(start,end,&colpoint);
1011 while(whichhit!=-1){
1012 position[i].y+=.01*proportion;
1013 tippoint[i].y+=.01*(1-proportion);
1014 velocity[i].y+=.01*proportion;
1015 tipvelocity[i].y+=.01*(1-proportion);
1018 whichhit=terrain.lineTerrain(start,end,&colpoint);
1025 velocity[i].y+=gravity*multiplier;
1026 tipvelocity[i].y+=gravity*multiplier;
1027 //position[i].y+=gravity*multiplier*multiplier;
1028 //tippoint[i].y+=gravity*multiplier*multiplier;
1031 XYZ temppoint1,temppoint2,tempforward;
1034 temppoint1=position[i];
1035 temppoint2=tippoint[i];
1036 distance=findDistance(&temppoint1,&temppoint2);
1037 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1038 rotation2[i]*=360/6.28;
1041 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1042 rotation1[i]*=360/6.28;
1044 smallrotation[i]=90;
1045 smallrotation2[i]=0;
1049 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1052 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1053 freetime[i]+=multiplier;
1056 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1057 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1065 multiplier=tempmult;
1066 if(blooddrip[i]&&bloody[i]){
1067 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1068 blooddrip[i]-=multiplier;
1069 if(blooddrip[i]<0)blooddrip[i]=0;
1070 if(blooddrip[i]>5)blooddrip[i]=5;
1071 if(blooddripdelay[i]<0&&bloodtoggle){
1072 blooddripdelay[i]=1;
1075 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1079 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1084 flamedelay[i]-=multiplier;
1085 if(onfire[i]&&flamedelay[i]<=0){
1087 flamedelay[i]-=multiplier;
1090 normalrot=player[owner[i]].velocity;
1094 if(player[owner[i]].onterrain){
1098 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);
1099 Sprite::setLastSpriteSpeed(4);
1100 Sprite::setLastSpriteAlivetime(.3);
1104 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1105 flamedelay[i]-=multiplier;
1106 if(flamedelay[i]<=0){
1108 flamedelay[i]-=multiplier;
1110 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1112 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1113 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1114 Sprite::setLastSpriteSpeed(4);
1115 Sprite::setLastSpriteAlivetime(.3);
1125 static XYZ terrainlight;
1126 static GLfloat M[16];
1128 glAlphaFunc(GL_GREATER, 0.9);
1129 glEnable(GL_TEXTURE_2D);
1131 glEnable(GL_CULL_FACE);
1132 glCullFace(GL_FRONT);
1134 for(i=0;i<numweapons;i++)
1136 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1142 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1143 else drawhowmany[i]=1;
1147 if(player[owner[i]].occluded<25)
1148 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)
1150 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)
1154 else drawhowmany[i]=1;
1155 if(player[owner[i]].targetanimation==swordgroundstabanim)
1157 lastdrawnrotation1[i]=rotation1[i];
1158 lastdrawnrotation2[i]=rotation2[i];
1159 lastdrawnrotation3[i]=rotation3[i];
1160 lastdrawnbigrotation[i]=bigrotation[i];
1161 lastdrawnbigtilt[i]=bigtilt[i];
1162 lastdrawnbigtilt2[i]=bigtilt2[i];
1163 lastdrawnsmallrotation[i]=smallrotation[i];
1164 lastdrawnsmallrotation2[i]=smallrotation2[i];
1169 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1170 if(drawhowmany[i]>0)
1172 glAlphaFunc(GL_GREATER, 0.01);
1174 for(j=drawhowmany[i];j>0;j--)
1176 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1178 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1179 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]));
1180 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]));
1181 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1182 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1183 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1184 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1185 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1186 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1187 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1188 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1189 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1193 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1195 glTranslatef(0,0,-.3);
1197 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)
1199 glTranslatef(0,0,-.1);
1202 /*if(type[i]==knife){
1204 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1210 glEnable(GL_LIGHTING);
1211 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1214 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1215 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1220 glEnable(GL_LIGHTING);
1221 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1224 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1225 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1230 glEnable(GL_LIGHTING);
1231 staffmodel.drawdifftex(stafftextureptr);
1237 lastdrawnposition[i]=position[i];
1238 lastdrawntippoint[i]=tippoint[i];
1239 lastdrawnrotation1[i]=rotation1[i];
1240 lastdrawnrotation2[i]=rotation2[i];
1241 lastdrawnrotation3[i]=rotation3[i];
1242 lastdrawnbigrotation[i]=bigrotation[i];
1243 lastdrawnbigtilt[i]=bigtilt[i];
1244 lastdrawnbigtilt2[i]=bigtilt2[i];
1245 lastdrawnsmallrotation[i]=smallrotation[i];
1246 lastdrawnsmallrotation2[i]=smallrotation2[i];
1247 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1251 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1254 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1255 glRotatef(bigrotation[i],0,1,0);
1256 glRotatef(bigtilt2[i],1,0,0);
1257 glRotatef(bigtilt[i],0,0,1);
1258 glRotatef(-rotation1[i]+90,0,1,0);
1259 glRotatef(-rotation2[i]+90,0,0,1);
1260 glRotatef(-rotation3[i],0,1,0);
1261 glRotatef(smallrotation[i],1,0,0);
1262 glRotatef(smallrotation2[i],0,1,0);
1263 glTranslatef(0,0,length[i]);
1264 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1265 tippoint[i].x=M[12];
1266 tippoint[i].y=M[13];
1267 tippoint[i].z=M[14];
1273 shinepoint=position[i];
1274 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1275 Sprite::speed[Sprite::numsprites-1]=4;
1276 Sprite::alivetime[Sprite::numsprites-1]=.3;
1277 shinepoint=tippoint[i];
1278 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1279 Sprite::speed[Sprite::numsprites-1]=4;
1280 Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1290 // Model throwingknifemodel;
1291 knifetextureptr = 0;
1292 lightbloodknifetextureptr = 0;
1293 bloodknifetextureptr = 0;
1295 // Model swordmodel;
1296 swordtextureptr = 0;
1297 lightbloodswordtextureptr = 0;
1298 bloodswordtextureptr = 0;
1300 // Model staffmodel;
1301 stafftextureptr = 0;
1306 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1307 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1308 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1309 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1310 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1311 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1312 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );