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;
34 extern FRUSTUM frustum;
36 extern float realmultiplier;
38 extern float slomodelay;
39 extern bool cellophane;
40 extern float texdetail;
41 extern GLubyte bloodText[512*512*3];
42 extern int bloodtoggle;
43 extern Objects objects;
45 extern bool autoslomo;
46 extern float camerashake;
48 extern float terraindetail;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
52 extern Person player[maxplayers];
53 extern int numplayers;
56 extern float bonusvalue;
57 extern float bonustotal;
58 extern float bonustime;
59 extern int tutoriallevel;
60 extern int numthrowkill;
61 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
63 void Weapons::DoStuff(){
64 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
65 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
66 static XYZ terrainnormal;
69 static XYZ newpoint1,newpoint2;
70 static float friction=3.5;
71 static float elasticity=.4;
72 static XYZ bounceness;
73 static float frictionness;
74 static float moveamount;
76 static float closestdistance;
77 static float distance;
79 static XYZ closestpoint;
80 static XYZ closestswordpoint;
82 static float proportion;
83 static float tempmult;
87 for(i=0;i<numweapons;i++){
91 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
94 gLoc[0]=tippoint[i].x;
95 gLoc[1]=tippoint[i].y;
96 gLoc[2]=tippoint[i].z;
100 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
101 OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
102 OPENAL_SetVolume(channels[staffbreaksound], 256);
103 OPENAL_SetPaused(channels[staffbreaksound], false);
106 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
109 tempvel.x=float(abs(Random()%100)-50)/20;
110 tempvel.y=float(abs(Random()%100)-50)/20;
111 tempvel.z=float(abs(Random()%100)-50)/20;
113 Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
125 player[tempowner].num_weapons--;
126 if(player[tempowner].num_weapons){
127 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
128 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
130 player[tempowner].weaponactive=-1;
133 oldposition[i]=position[i];
134 oldtippoint[i]=tippoint[i];
135 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
136 position[i]+=velocity[i]*multiplier;
137 tippoint[i]+=velocity[i]*multiplier;
138 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
139 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
140 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
141 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
142 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
143 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
144 start=oldtippoint[i];
146 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
148 if(objects.type[k]==treetrunktype){
149 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
150 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
152 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
153 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
154 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
155 XYZ temppoint1,temppoint2,tempforward;
159 temppoint2=normalrot;
160 distance=findDistance(&temppoint1,&temppoint2);
161 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
162 rotation2[i]*=360/6.28;
165 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
166 rotation1[i]*=360/6.28;
167 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
178 gLoc[0]=position[i].x;
179 gLoc[1]=position[i].y;
180 gLoc[2]=position[i].z;
184 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
185 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
186 OPENAL_SetVolume(channels[knifesheathesound], 128);
187 OPENAL_SetPaused(channels[knifesheathesound], false);
191 Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
196 position[i]-=velocity[i]*multiplier;
197 tippoint[i]-=velocity[i]*multiplier;
198 tipvelocity[i]=velocity[i];
203 if(velocity[i].x||velocity[i].y||velocity[i].z)
204 for(j=0;j<numplayers;j++){
206 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;
207 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]){
208 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]){
210 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)){
213 gLoc[0]=player[j].coords.x;
214 gLoc[1]=player[j].coords.y;
215 gLoc[2]=player[j].coords.z;
216 vel[0]=player[j].velocity.x;
217 vel[1]=player[j].velocity.y;
218 vel[2]=player[j].velocity.z;
219 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
220 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
221 OPENAL_SetVolume(channels[knifedrawsound], 128);
222 OPENAL_SetPaused(channels[knifedrawsound], false);
224 player[j].weaponactive=0;
225 player[j].targetanimation=removeknifeanim;
226 player[j].targetframe=1;
228 owner[i]=player[j].id;
229 if(player[j].num_weapons>0){
230 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
232 player[j].num_weapons++;
233 player[j].weaponids[0]=i;
235 player[j].aitype=attacktypecutoff;
238 if(j!=0)numthrowkill++;
239 player[j].num_weapons++;
240 player[j].weaponstuck=player[j].num_weapons-1;
241 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
242 else player[j].weaponstuckwhere=0;
244 player[j].weaponids[player[j].num_weapons-1]=i;
246 player[j].RagDoll(0);
247 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
248 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
249 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
250 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
251 //player[j].Puff(abdomen);
252 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
253 if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
254 footvel=tippoint[i]-position[i];
256 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
258 if(tutoriallevel!=1){
259 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
260 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
261 player[j].damage+=200/player[j].armorhigh;
262 player[j].deathbleeding=1;
263 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
271 gLoc[0]=position[i].x;
272 gLoc[1]=position[i].y;
273 gLoc[2]=position[i].z;
277 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
278 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
279 OPENAL_SetVolume(channels[fleshstabsound], 128);
280 OPENAL_SetPaused(channels[fleshstabsound], false);
282 if(animation[player[0].targetanimation].height==highheight){
297 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
298 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
300 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
301 position[i]=colpoint*terrain.scale;
303 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
305 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
306 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
308 //position[i]-=normalrot*.1;
309 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
313 glRotatef(bigrotation[i],0,1,0);
314 glRotatef(bigtilt2[i],1,0,0);
315 glRotatef(bigtilt[i],0,0,1);
316 glRotatef(-rotation1[i]+90,0,1,0);
317 glRotatef(-rotation2[i]+90,0,0,1);
318 glRotatef(-rotation3[i],0,1,0);
319 glRotatef(smallrotation[i],1,0,0);
320 glRotatef(smallrotation2[i],0,1,0);
322 glGetFloatv(GL_MODELVIEW_MATRIX,M);
327 position[i]-=tippoint[i]*.15;
328 XYZ temppoint1,temppoint2,tempforward;
340 gLoc[0]=position[i].x;
341 gLoc[1]=position[i].y;
342 gLoc[2]=position[i].z;
346 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
347 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
348 OPENAL_SetVolume(channels[knifesheathesound], 128);
349 OPENAL_SetPaused(channels[knifesheathesound], false);
352 terrainlight=terrain.getLighting(position[i].x,position[i].z);
353 if(environment==snowyenvironment){
354 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
356 else if(environment==grassyenvironment){
357 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);
359 else if(environment==desertenvironment){
360 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);
368 position[i]-=velocity[i]*multiplier;
369 tippoint[i]-=velocity[i]*multiplier;
370 tipvelocity[i]=velocity[i];
373 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
374 velocity[i].y+=gravity*multiplier;
376 XYZ temppoint1,temppoint2,tempforward;
380 temppoint2=velocity[i];
381 distance=findDistance(&temppoint1,&temppoint2);
382 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
383 rotation2[i]*=360/6.28;
386 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
387 rotation1[i]*=360/6.28;
394 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
404 for(int l=0;l<10;l++){
405 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
407 position[i]+=velocity[i]*multiplier;
408 tippoint[i]+=tipvelocity[i]*multiplier;
411 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
412 vel=tippoint[i]-midp;
414 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
415 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
417 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
418 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
420 position[i]=newpoint1;
421 tippoint[i]=newpoint2;
425 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
426 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
427 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
428 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
429 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
430 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
434 start=position[i]-(tippoint[i]-position[i])/5;
435 end=tippoint[i]+(tippoint[i]-position[i])/30;
436 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
439 diff=(colpoint-tippoint[i]);
443 position[i]+=(colpoint-tippoint[i])+diff*.05;
444 tippoint[i]=colpoint+diff*.05;
445 oldposition[i]=position[i];
446 oldtippoint[i]=tippoint[i];
450 start=tippoint[i]-(position[i]-tippoint[i])/5;
451 end=position[i]+(position[i]-tippoint[i])/30;
452 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
455 diff=(colpoint-position[i]);
459 tippoint[i]+=(colpoint-position[i])+diff*.05;
460 position[i]=colpoint+diff*.05;
461 oldtippoint[i]=tippoint[i];
462 oldposition[i]=tippoint[i];
467 start=oldposition[i];
469 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
472 position[i]=colpoint;
473 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
474 ReflectVector(&velocity[i],&terrainnormal);
475 position[i]+=terrainnormal*.002;
477 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
478 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
479 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
480 velocity[i]-=bounceness;
481 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
483 velocity[i]+=bounceness*elasticity;
485 if(findLengthfast(&bounceness)>1){
488 //int whichsound=clank1sound+abs(Random()%4);
490 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
491 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
492 gLoc[1]=position[i].y;
493 gLoc[2]=position[i].z;
497 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
498 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
499 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
500 OPENAL_SetPaused(channels[whichsound], false);
503 start=oldtippoint[i];
505 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
508 tippoint[i]=colpoint;
509 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
510 ReflectVector(&tipvelocity[i],&terrainnormal);
511 tippoint[i]+=terrainnormal*.002;
513 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
514 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
515 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
516 tipvelocity[i]-=bounceness;
517 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
518 else tipvelocity[i]=0;
519 tipvelocity[i]+=bounceness*elasticity;
521 if(findLengthfast(&bounceness)>1){
524 //int whichsound=clank1sound+abs(Random()%4);
526 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
527 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
528 gLoc[0]=position[i].x;
529 gLoc[1]=position[i].y;
530 gLoc[2]=position[i].z;
534 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
535 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
536 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
537 OPENAL_SetPaused(channels[whichsound], false);
541 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
543 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
545 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
549 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
553 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
554 ReflectVector(&velocity[i],&terrainnormal);
556 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
557 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
558 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
559 velocity[i]-=bounceness;
560 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
562 velocity[i]+=bounceness*elasticity;
564 if(findLengthfast(&bounceness)>1){
567 //int whichsound=clank1sound+abs(Random()%4);
569 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
570 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
576 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
577 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
578 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
579 OPENAL_SetPaused(channels[whichsound], false);
581 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
584 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
586 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
590 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
594 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
595 ReflectVector(&tipvelocity[i],&terrainnormal);
597 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
598 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
599 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
600 tipvelocity[i]-=bounceness;
601 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
602 else tipvelocity[i]=0;
603 tipvelocity[i]+=bounceness*elasticity;
605 if(findLengthfast(&bounceness)>1){
608 //int whichsound=clank1sound+abs(Random()%4);
610 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
611 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
617 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
618 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
619 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
620 OPENAL_SetPaused(channels[whichsound], false);
622 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
629 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
633 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
634 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
635 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
636 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
637 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
638 if(distance<closestdistance||closestdistance==-1){
639 closestpoint=colpoint;
640 closestdistance=distance;
643 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
644 if(distance<closestdistance||closestdistance==-1){
645 closestpoint=colpoint;
646 closestdistance=distance;
649 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
650 if(distance<closestdistance||closestdistance==-1){
651 closestpoint=colpoint;
652 closestdistance=distance;
655 if(closestdistance!=-1&&isnormal(closestdistance)){
656 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
657 closestswordpoint=colpoint;
658 velocity[i]+=(closestpoint-closestswordpoint);
659 tipvelocity[i]+=(closestpoint-closestswordpoint);
660 position[i]+=(closestpoint-closestswordpoint);
661 tippoint[i]+=(closestpoint-closestswordpoint);
670 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
671 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
673 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
674 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
676 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
677 ReflectVector(&velocity[i],&terrainnormal);
678 position[i]+=terrainnormal*.002;
679 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
680 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
681 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
682 velocity[i]-=bounceness;
683 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
685 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
686 else velocity[i]+=bounceness*elasticity;
687 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
688 if(findLengthfast(&bounceness)>1){
692 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
693 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
694 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
696 else whichsound=footstepsound+abs(Random()%2);
697 gLoc[0]=position[i].x;
698 gLoc[1]=position[i].y;
699 gLoc[2]=position[i].z;
703 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
704 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
705 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
706 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
707 OPENAL_SetPaused(channels[whichsound], false);
709 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
711 terrainlight=terrain.getLighting(position[i].x,position[i].z);
712 if(environment==snowyenvironment){
713 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
715 else if(environment==grassyenvironment){
716 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);
718 else if(environment==desertenvironment){
719 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);
724 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
725 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
726 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
727 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
729 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
730 ReflectVector(&tipvelocity[i],&terrainnormal);
731 tippoint[i]+=terrainnormal*.002;
732 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
733 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
734 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
735 tipvelocity[i]-=bounceness;
736 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
737 else tipvelocity[i]=0;
738 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
739 else tipvelocity[i]+=bounceness*elasticity;
740 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
742 if(findLengthfast(&bounceness)>1){
746 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
747 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
748 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
750 else whichsound=footstepsound+abs(Random()%2);
751 gLoc[0]=tippoint[i].x;
752 gLoc[1]=tippoint[i].y;
753 gLoc[2]=tippoint[i].z;
757 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
758 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
759 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
760 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
761 OPENAL_SetPaused(channels[whichsound], false);
763 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
765 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
766 if(environment==snowyenvironment){
767 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
769 else if(environment==grassyenvironment){
770 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);
772 else if(environment==desertenvironment){
773 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);
780 mid=position[i]+tippoint[i];
782 mid+=(position[i]-mid)/20;
784 if(mid.y<terrain.getHeight(mid.x,mid.z)){
786 mid.y=terrain.getHeight(mid.x,mid.z);
788 terrainnormal=terrain.getNormal(mid.x,mid.z);
789 ReflectVector(&velocity[i],&terrainnormal);
790 //mid+=terrainnormal*.002;
791 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
792 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
793 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
794 velocity[i]-=bounceness;
795 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
797 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
798 else velocity[i]+=bounceness*elasticity;
800 if(findLengthfast(&bounceness)>1){
804 if(terrain.getOpacity(mid.x,mid.z)>.2){
805 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
806 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
808 else whichsound=footstepsound+abs(Random()%2);
815 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
816 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
817 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
818 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
819 OPENAL_SetPaused(channels[whichsound], false);
821 position[i]+=(mid-oldmid)*20;
824 mid=position[i]+tippoint[i];
826 mid+=(tippoint[i]-mid)/20;
828 if(mid.y<terrain.getHeight(mid.x,mid.z)){
830 mid.y=terrain.getHeight(mid.x,mid.z);
832 terrainnormal=terrain.getNormal(mid.x,mid.z);
833 ReflectVector(&tipvelocity[i],&terrainnormal);
834 //mid+=terrainnormal*.002;
835 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
836 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
837 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
838 tipvelocity[i]-=bounceness;
839 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
840 else tipvelocity[i]=0;
841 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
842 else tipvelocity[i]+=bounceness*elasticity;
844 if(findLengthfast(&bounceness)>1){
848 if(terrain.getOpacity(mid.x,mid.z)>.2){
849 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
850 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
852 else whichsound=footstepsound+abs(Random()%2);
859 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
860 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
861 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
862 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
863 OPENAL_SetPaused(channels[whichsound], false);
865 tippoint[i]+=(mid-oldmid)*20;
868 mid=position[i]+tippoint[i];
870 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
872 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
874 terrainnormal=terrain.getNormal(mid.x,mid.z);
875 ReflectVector(&velocity[i],&terrainnormal);
876 position[i]+=terrainnormal*.002;
877 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
878 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
879 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
880 velocity[i]-=bounceness;
881 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
883 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
884 else velocity[i]+=bounceness*elasticity;
886 if(findLengthfast(&bounceness)>1){
890 if(terrain.getOpacity(mid.x,mid.z)>.2){
891 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
892 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
894 else whichsound=footstepsound+abs(Random()%2);
895 gLoc[0]=position[i].x;
896 gLoc[1]=position[i].y;
897 gLoc[2]=position[i].z;
901 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
902 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
903 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
904 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
905 OPENAL_SetPaused(channels[whichsound], false);
909 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
911 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
913 terrainnormal=terrain.getNormal(mid.x,mid.z);
914 ReflectVector(&tipvelocity[i],&terrainnormal);
915 tippoint[i]+=terrainnormal*.002;
916 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
917 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
918 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
919 tipvelocity[i]-=bounceness;
920 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
921 else tipvelocity[i]=0;
922 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
923 else tipvelocity[i]+=bounceness*elasticity;
925 if(findLengthfast(&bounceness)>1){
929 if(terrain.getOpacity(mid.x,mid.z)>.2){
930 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
931 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
933 else whichsound=footstepsound+abs(Random()%2);
934 gLoc[0]=tippoint[i].x;
935 gLoc[1]=tippoint[i].y;
936 gLoc[2]=tippoint[i].z;
940 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
941 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
942 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
943 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
944 OPENAL_SetPaused(channels[whichsound], false);
948 //Fix terrain edge collision
951 whichhit=terrain.lineTerrain(start,end,&colpoint);
962 tipvelocity[i].y+=.1;
965 whichhit=terrain.lineTerrain(start,end,&colpoint);
967 closestpoint=colpoint*terrain.scale;
972 tipvelocity[i].y-=.1;
975 whichhit=terrain.lineTerrain(start,end,&colpoint);
980 tipvelocity[i].y+=.01;
983 whichhit=terrain.lineTerrain(start,end,&colpoint);
985 closestpoint=colpoint*terrain.scale;
989 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
991 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
992 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
995 position[i].y+=.1*proportion;
996 tippoint[i].y+=.1*(1-proportion);
997 velocity[i].y+=.1*proportion;
998 tipvelocity[i].y+=.1*(1-proportion);
1001 whichhit=terrain.lineTerrain(start,end,&colpoint);
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);
1010 while(whichhit!=-1){
1011 position[i].y+=.01*proportion;
1012 tippoint[i].y+=.01*(1-proportion);
1013 velocity[i].y+=.01*proportion;
1014 tipvelocity[i].y+=.01*(1-proportion);
1017 whichhit=terrain.lineTerrain(start,end,&colpoint);
1024 velocity[i].y+=gravity*multiplier;
1025 tipvelocity[i].y+=gravity*multiplier;
1026 //position[i].y+=gravity*multiplier*multiplier;
1027 //tippoint[i].y+=gravity*multiplier*multiplier;
1030 XYZ temppoint1,temppoint2,tempforward;
1033 temppoint1=position[i];
1034 temppoint2=tippoint[i];
1035 distance=findDistance(&temppoint1,&temppoint2);
1036 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1037 rotation2[i]*=360/6.28;
1040 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1041 rotation1[i]*=360/6.28;
1043 smallrotation[i]=90;
1044 smallrotation2[i]=0;
1048 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1051 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1052 freetime[i]+=multiplier;
1055 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1056 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1064 multiplier=tempmult;
1065 if(blooddrip[i]&&bloody[i]){
1066 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1067 blooddrip[i]-=multiplier;
1068 if(blooddrip[i]<0)blooddrip[i]=0;
1069 if(blooddrip[i]>5)blooddrip[i]=5;
1070 if(blooddripdelay[i]<0&&bloodtoggle){
1071 blooddripdelay[i]=1;
1074 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1078 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1083 flamedelay[i]-=multiplier;
1084 if(onfire[i]&&flamedelay[i]<=0){
1086 flamedelay[i]-=multiplier;
1089 normalrot=player[owner[i]].velocity;
1093 if(player[owner[i]].onterrain){
1097 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);
1098 Sprite::setLastSpriteSpeed(4);
1099 Sprite::setLastSpriteAlivetime(.3);
1103 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1104 flamedelay[i]-=multiplier;
1105 if(flamedelay[i]<=0){
1107 flamedelay[i]-=multiplier;
1109 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1111 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1112 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1113 Sprite::setLastSpriteSpeed(4);
1114 Sprite::setLastSpriteAlivetime(.3);
1124 static XYZ terrainlight;
1125 static GLfloat M[16];
1127 glAlphaFunc(GL_GREATER, 0.9);
1128 glEnable(GL_TEXTURE_2D);
1130 glEnable(GL_CULL_FACE);
1131 glCullFace(GL_FRONT);
1133 for(i=0;i<numweapons;i++)
1135 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1141 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1142 else drawhowmany[i]=1;
1146 if(player[owner[i]].occluded<25)
1147 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)
1149 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)
1153 else drawhowmany[i]=1;
1154 if(player[owner[i]].targetanimation==swordgroundstabanim)
1156 lastdrawnrotation1[i]=rotation1[i];
1157 lastdrawnrotation2[i]=rotation2[i];
1158 lastdrawnrotation3[i]=rotation3[i];
1159 lastdrawnbigrotation[i]=bigrotation[i];
1160 lastdrawnbigtilt[i]=bigtilt[i];
1161 lastdrawnbigtilt2[i]=bigtilt2[i];
1162 lastdrawnsmallrotation[i]=smallrotation[i];
1163 lastdrawnsmallrotation2[i]=smallrotation2[i];
1168 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1169 if(drawhowmany[i]>0)
1171 glAlphaFunc(GL_GREATER, 0.01);
1173 for(j=drawhowmany[i];j>0;j--)
1175 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1177 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,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])-.02+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(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])+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));
1180 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1181 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1182 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1183 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1184 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1185 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1186 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1187 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1188 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1192 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1194 glTranslatef(0,0,-.3);
1196 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)
1198 glTranslatef(0,0,-.1);
1201 /*if(type[i]==knife){
1203 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1209 glEnable(GL_LIGHTING);
1210 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1213 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1214 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1219 glEnable(GL_LIGHTING);
1220 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1223 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1224 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1229 glEnable(GL_LIGHTING);
1230 staffmodel.drawdifftex(stafftextureptr);
1236 lastdrawnposition[i]=position[i];
1237 lastdrawntippoint[i]=tippoint[i];
1238 lastdrawnrotation1[i]=rotation1[i];
1239 lastdrawnrotation2[i]=rotation2[i];
1240 lastdrawnrotation3[i]=rotation3[i];
1241 lastdrawnbigrotation[i]=bigrotation[i];
1242 lastdrawnbigtilt[i]=bigtilt[i];
1243 lastdrawnbigtilt2[i]=bigtilt2[i];
1244 lastdrawnsmallrotation[i]=smallrotation[i];
1245 lastdrawnsmallrotation2[i]=smallrotation2[i];
1246 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1250 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1253 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1254 glRotatef(bigrotation[i],0,1,0);
1255 glRotatef(bigtilt2[i],1,0,0);
1256 glRotatef(bigtilt[i],0,0,1);
1257 glRotatef(-rotation1[i]+90,0,1,0);
1258 glRotatef(-rotation2[i]+90,0,0,1);
1259 glRotatef(-rotation3[i],0,1,0);
1260 glRotatef(smallrotation[i],1,0,0);
1261 glRotatef(smallrotation2[i],0,1,0);
1262 glTranslatef(0,0,length[i]);
1263 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1264 tippoint[i].x=M[12];
1265 tippoint[i].y=M[13];
1266 tippoint[i].z=M[14];
1272 shinepoint=position[i];
1273 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1274 Sprite::speed[Sprite::numsprites-1]=4;
1275 Sprite::alivetime[Sprite::numsprites-1]=.3;
1276 shinepoint=tippoint[i];
1277 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1278 Sprite::speed[Sprite::numsprites-1]=4;
1279 Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1289 // Model throwingknifemodel;
1290 knifetextureptr = 0;
1291 lightbloodknifetextureptr = 0;
1292 bloodknifetextureptr = 0;
1294 // Model swordmodel;
1295 swordtextureptr = 0;
1296 lightbloodswordtextureptr = 0;
1297 bloodswordtextureptr = 0;
1299 // Model staffmodel;
1300 stafftextureptr = 0;
1305 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1306 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1307 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1308 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1309 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1310 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1311 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );