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"
30 extern float multiplier;
31 extern int channels[100];
32 extern Terrain terrain;
34 extern int environment;
36 extern FRUSTUM frustum;
38 extern float realmultiplier;
40 extern float slomodelay;
41 extern bool cellophane;
42 extern float texdetail;
43 extern GLubyte bloodText[512*512*3];
44 extern int bloodtoggle;
45 extern Objects objects;
47 extern bool autoslomo;
48 extern float camerashake;
50 extern float terraindetail;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
55 extern int tutoriallevel;
56 extern int numthrowkill;
57 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
59 void Weapons::DoStuff(){
60 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
61 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
62 static XYZ terrainnormal;
65 static XYZ newpoint1,newpoint2;
66 static float friction=3.5;
67 static float elasticity=.4;
68 static XYZ bounceness;
69 static float frictionness;
70 static float moveamount;
72 static float closestdistance;
73 static float distance;
75 static XYZ closestpoint;
76 static XYZ closestswordpoint;
78 static float proportion;
79 static float tempmult;
83 for(i=0;i<numweapons;i++){
87 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
90 gLoc[0]=tippoint[i].x;
91 gLoc[1]=tippoint[i].y;
92 gLoc[2]=tippoint[i].z;
96 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
97 OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
98 OPENAL_SetVolume(channels[staffbreaksound], 256);
99 OPENAL_SetPaused(channels[staffbreaksound], false);
102 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
105 tempvel.x=float(abs(Random()%100)-50)/20;
106 tempvel.y=float(abs(Random()%100)-50)/20;
107 tempvel.z=float(abs(Random()%100)-50)/20;
109 Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
121 player[tempowner].num_weapons--;
122 if(player[tempowner].num_weapons){
123 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
124 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
126 player[tempowner].weaponactive=-1;
129 oldposition[i]=position[i];
130 oldtippoint[i]=tippoint[i];
131 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
132 position[i]+=velocity[i]*multiplier;
133 tippoint[i]+=velocity[i]*multiplier;
134 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
135 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
136 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
137 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
138 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
139 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
140 start=oldtippoint[i];
142 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
144 if(objects.type[k]==treetrunktype){
145 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
146 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
148 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
149 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
150 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
151 XYZ temppoint1,temppoint2,tempforward;
155 temppoint2=normalrot;
156 distance=findDistance(&temppoint1,&temppoint2);
157 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
158 rotation2[i]*=360/6.28;
161 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
162 rotation1[i]*=360/6.28;
163 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
174 gLoc[0]=position[i].x;
175 gLoc[1]=position[i].y;
176 gLoc[2]=position[i].z;
180 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
181 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
182 OPENAL_SetVolume(channels[knifesheathesound], 128);
183 OPENAL_SetPaused(channels[knifesheathesound], false);
187 Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
192 position[i]-=velocity[i]*multiplier;
193 tippoint[i]-=velocity[i]*multiplier;
194 tipvelocity[i]=velocity[i];
199 if(velocity[i].x||velocity[i].y||velocity[i].z)
200 for(j=0;j<numplayers;j++){
202 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;
203 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]){
204 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]){
206 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)){
209 gLoc[0]=player[j].coords.x;
210 gLoc[1]=player[j].coords.y;
211 gLoc[2]=player[j].coords.z;
212 vel[0]=player[j].velocity.x;
213 vel[1]=player[j].velocity.y;
214 vel[2]=player[j].velocity.z;
215 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
216 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
217 OPENAL_SetVolume(channels[knifedrawsound], 128);
218 OPENAL_SetPaused(channels[knifedrawsound], false);
220 player[j].weaponactive=0;
221 player[j].targetanimation=removeknifeanim;
222 player[j].targetframe=1;
224 owner[i]=player[j].id;
225 if(player[j].num_weapons>0){
226 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
228 player[j].num_weapons++;
229 player[j].weaponids[0]=i;
231 player[j].aitype=attacktypecutoff;
234 if(j!=0)numthrowkill++;
235 player[j].num_weapons++;
236 player[j].weaponstuck=player[j].num_weapons-1;
237 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
238 else player[j].weaponstuckwhere=0;
240 player[j].weaponids[player[j].num_weapons-1]=i;
242 player[j].RagDoll(0);
243 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
244 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
245 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
246 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
247 //player[j].Puff(abdomen);
248 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
249 if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
250 footvel=tippoint[i]-position[i];
252 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
254 if(tutoriallevel!=1){
255 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
256 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
257 player[j].damage+=200/player[j].armorhigh;
258 player[j].deathbleeding=1;
259 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
267 gLoc[0]=position[i].x;
268 gLoc[1]=position[i].y;
269 gLoc[2]=position[i].z;
273 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
274 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
275 OPENAL_SetVolume(channels[fleshstabsound], 128);
276 OPENAL_SetPaused(channels[fleshstabsound], false);
278 if(animation[player[0].targetanimation].height==highheight)
279 award_bonus(0, ninja);
281 award_bonus(0, Bullseyebonus);
287 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
288 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
290 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
291 position[i]=colpoint*terrain.scale;
293 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
295 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
296 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
298 //position[i]-=normalrot*.1;
299 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
303 glRotatef(bigrotation[i],0,1,0);
304 glRotatef(bigtilt2[i],1,0,0);
305 glRotatef(bigtilt[i],0,0,1);
306 glRotatef(-rotation1[i]+90,0,1,0);
307 glRotatef(-rotation2[i]+90,0,0,1);
308 glRotatef(-rotation3[i],0,1,0);
309 glRotatef(smallrotation[i],1,0,0);
310 glRotatef(smallrotation2[i],0,1,0);
312 glGetFloatv(GL_MODELVIEW_MATRIX,M);
317 position[i]-=tippoint[i]*.15;
318 XYZ temppoint1,temppoint2,tempforward;
330 gLoc[0]=position[i].x;
331 gLoc[1]=position[i].y;
332 gLoc[2]=position[i].z;
336 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
337 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
338 OPENAL_SetVolume(channels[knifesheathesound], 128);
339 OPENAL_SetPaused(channels[knifesheathesound], false);
342 terrainlight=terrain.getLighting(position[i].x,position[i].z);
343 if(environment==snowyenvironment){
344 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
346 else if(environment==grassyenvironment){
347 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);
349 else if(environment==desertenvironment){
350 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);
358 position[i]-=velocity[i]*multiplier;
359 tippoint[i]-=velocity[i]*multiplier;
360 tipvelocity[i]=velocity[i];
363 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
364 velocity[i].y+=gravity*multiplier;
366 XYZ temppoint1,temppoint2,tempforward;
370 temppoint2=velocity[i];
371 distance=findDistance(&temppoint1,&temppoint2);
372 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
373 rotation2[i]*=360/6.28;
376 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
377 rotation1[i]*=360/6.28;
384 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
394 for(int l=0;l<10;l++){
395 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
397 position[i]+=velocity[i]*multiplier;
398 tippoint[i]+=tipvelocity[i]*multiplier;
401 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
402 vel=tippoint[i]-midp;
404 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
405 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
407 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
408 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
410 position[i]=newpoint1;
411 tippoint[i]=newpoint2;
415 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
416 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
417 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
418 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
419 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
420 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
424 start=position[i]-(tippoint[i]-position[i])/5;
425 end=tippoint[i]+(tippoint[i]-position[i])/30;
426 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
429 diff=(colpoint-tippoint[i]);
433 position[i]+=(colpoint-tippoint[i])+diff*.05;
434 tippoint[i]=colpoint+diff*.05;
435 oldposition[i]=position[i];
436 oldtippoint[i]=tippoint[i];
440 start=tippoint[i]-(position[i]-tippoint[i])/5;
441 end=position[i]+(position[i]-tippoint[i])/30;
442 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
445 diff=(colpoint-position[i]);
449 tippoint[i]+=(colpoint-position[i])+diff*.05;
450 position[i]=colpoint+diff*.05;
451 oldtippoint[i]=tippoint[i];
452 oldposition[i]=tippoint[i];
457 start=oldposition[i];
459 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
462 position[i]=colpoint;
463 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
464 ReflectVector(&velocity[i],&terrainnormal);
465 position[i]+=terrainnormal*.002;
467 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
468 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
469 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
470 velocity[i]-=bounceness;
471 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
473 velocity[i]+=bounceness*elasticity;
475 if(findLengthfast(&bounceness)>1){
478 //int whichsound=clank1sound+abs(Random()%4);
480 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
481 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
482 gLoc[1]=position[i].y;
483 gLoc[2]=position[i].z;
487 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
488 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
489 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
490 OPENAL_SetPaused(channels[whichsound], false);
493 start=oldtippoint[i];
495 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
498 tippoint[i]=colpoint;
499 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
500 ReflectVector(&tipvelocity[i],&terrainnormal);
501 tippoint[i]+=terrainnormal*.002;
503 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
504 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
505 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
506 tipvelocity[i]-=bounceness;
507 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
508 else tipvelocity[i]=0;
509 tipvelocity[i]+=bounceness*elasticity;
511 if(findLengthfast(&bounceness)>1){
514 //int whichsound=clank1sound+abs(Random()%4);
516 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
517 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
518 gLoc[0]=position[i].x;
519 gLoc[1]=position[i].y;
520 gLoc[2]=position[i].z;
524 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
525 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
526 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
527 OPENAL_SetPaused(channels[whichsound], false);
531 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
533 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
535 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
539 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
543 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
544 ReflectVector(&velocity[i],&terrainnormal);
546 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
547 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
548 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
549 velocity[i]-=bounceness;
550 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
552 velocity[i]+=bounceness*elasticity;
554 if(findLengthfast(&bounceness)>1){
557 //int whichsound=clank1sound+abs(Random()%4);
559 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
560 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
566 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
567 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
568 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
569 OPENAL_SetPaused(channels[whichsound], false);
571 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
574 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
576 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
580 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
584 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
585 ReflectVector(&tipvelocity[i],&terrainnormal);
587 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
588 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
589 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
590 tipvelocity[i]-=bounceness;
591 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
592 else tipvelocity[i]=0;
593 tipvelocity[i]+=bounceness*elasticity;
595 if(findLengthfast(&bounceness)>1){
598 //int whichsound=clank1sound+abs(Random()%4);
600 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
601 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
607 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
608 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
609 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
610 OPENAL_SetPaused(channels[whichsound], false);
612 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
619 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
623 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
624 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
625 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
626 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
627 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
628 if(distance<closestdistance||closestdistance==-1){
629 closestpoint=colpoint;
630 closestdistance=distance;
633 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
634 if(distance<closestdistance||closestdistance==-1){
635 closestpoint=colpoint;
636 closestdistance=distance;
639 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
640 if(distance<closestdistance||closestdistance==-1){
641 closestpoint=colpoint;
642 closestdistance=distance;
645 if(closestdistance!=-1&&isnormal(closestdistance)){
646 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
647 closestswordpoint=colpoint;
648 velocity[i]+=(closestpoint-closestswordpoint);
649 tipvelocity[i]+=(closestpoint-closestswordpoint);
650 position[i]+=(closestpoint-closestswordpoint);
651 tippoint[i]+=(closestpoint-closestswordpoint);
660 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
661 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
663 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
664 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
666 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
667 ReflectVector(&velocity[i],&terrainnormal);
668 position[i]+=terrainnormal*.002;
669 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
670 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
671 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
672 velocity[i]-=bounceness;
673 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
675 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
676 else velocity[i]+=bounceness*elasticity;
677 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
678 if(findLengthfast(&bounceness)>1){
682 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
683 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
684 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
686 else whichsound=footstepsound+abs(Random()%2);
687 gLoc[0]=position[i].x;
688 gLoc[1]=position[i].y;
689 gLoc[2]=position[i].z;
693 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
694 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
695 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
696 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
697 OPENAL_SetPaused(channels[whichsound], false);
699 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
701 terrainlight=terrain.getLighting(position[i].x,position[i].z);
702 if(environment==snowyenvironment){
703 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
705 else if(environment==grassyenvironment){
706 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);
708 else if(environment==desertenvironment){
709 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);
714 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
715 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
716 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
717 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
719 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
720 ReflectVector(&tipvelocity[i],&terrainnormal);
721 tippoint[i]+=terrainnormal*.002;
722 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
723 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
724 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
725 tipvelocity[i]-=bounceness;
726 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
727 else tipvelocity[i]=0;
728 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
729 else tipvelocity[i]+=bounceness*elasticity;
730 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
732 if(findLengthfast(&bounceness)>1){
736 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
737 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
738 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
740 else whichsound=footstepsound+abs(Random()%2);
741 gLoc[0]=tippoint[i].x;
742 gLoc[1]=tippoint[i].y;
743 gLoc[2]=tippoint[i].z;
747 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
748 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
749 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
750 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
751 OPENAL_SetPaused(channels[whichsound], false);
753 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
755 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
756 if(environment==snowyenvironment){
757 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
759 else if(environment==grassyenvironment){
760 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);
762 else if(environment==desertenvironment){
763 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);
770 mid=position[i]+tippoint[i];
772 mid+=(position[i]-mid)/20;
774 if(mid.y<terrain.getHeight(mid.x,mid.z)){
776 mid.y=terrain.getHeight(mid.x,mid.z);
778 terrainnormal=terrain.getNormal(mid.x,mid.z);
779 ReflectVector(&velocity[i],&terrainnormal);
780 //mid+=terrainnormal*.002;
781 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
782 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
783 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
784 velocity[i]-=bounceness;
785 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
787 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
788 else velocity[i]+=bounceness*elasticity;
790 if(findLengthfast(&bounceness)>1){
794 if(terrain.getOpacity(mid.x,mid.z)>.2){
795 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
796 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
798 else whichsound=footstepsound+abs(Random()%2);
805 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
806 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
807 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
808 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
809 OPENAL_SetPaused(channels[whichsound], false);
811 position[i]+=(mid-oldmid)*20;
814 mid=position[i]+tippoint[i];
816 mid+=(tippoint[i]-mid)/20;
818 if(mid.y<terrain.getHeight(mid.x,mid.z)){
820 mid.y=terrain.getHeight(mid.x,mid.z);
822 terrainnormal=terrain.getNormal(mid.x,mid.z);
823 ReflectVector(&tipvelocity[i],&terrainnormal);
824 //mid+=terrainnormal*.002;
825 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
826 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
827 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
828 tipvelocity[i]-=bounceness;
829 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
830 else tipvelocity[i]=0;
831 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
832 else tipvelocity[i]+=bounceness*elasticity;
834 if(findLengthfast(&bounceness)>1){
838 if(terrain.getOpacity(mid.x,mid.z)>.2){
839 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
840 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
842 else whichsound=footstepsound+abs(Random()%2);
849 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
850 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
851 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
852 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
853 OPENAL_SetPaused(channels[whichsound], false);
855 tippoint[i]+=(mid-oldmid)*20;
858 mid=position[i]+tippoint[i];
860 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
862 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
864 terrainnormal=terrain.getNormal(mid.x,mid.z);
865 ReflectVector(&velocity[i],&terrainnormal);
866 position[i]+=terrainnormal*.002;
867 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
868 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
869 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
870 velocity[i]-=bounceness;
871 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
873 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
874 else velocity[i]+=bounceness*elasticity;
876 if(findLengthfast(&bounceness)>1){
880 if(terrain.getOpacity(mid.x,mid.z)>.2){
881 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
882 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
884 else whichsound=footstepsound+abs(Random()%2);
885 gLoc[0]=position[i].x;
886 gLoc[1]=position[i].y;
887 gLoc[2]=position[i].z;
891 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
892 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
893 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
894 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
895 OPENAL_SetPaused(channels[whichsound], false);
899 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
901 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
903 terrainnormal=terrain.getNormal(mid.x,mid.z);
904 ReflectVector(&tipvelocity[i],&terrainnormal);
905 tippoint[i]+=terrainnormal*.002;
906 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
907 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
908 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
909 tipvelocity[i]-=bounceness;
910 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
911 else tipvelocity[i]=0;
912 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
913 else tipvelocity[i]+=bounceness*elasticity;
915 if(findLengthfast(&bounceness)>1){
919 if(terrain.getOpacity(mid.x,mid.z)>.2){
920 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
921 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
923 else whichsound=footstepsound+abs(Random()%2);
924 gLoc[0]=tippoint[i].x;
925 gLoc[1]=tippoint[i].y;
926 gLoc[2]=tippoint[i].z;
930 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
931 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
932 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
933 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
934 OPENAL_SetPaused(channels[whichsound], false);
938 //Fix terrain edge collision
941 whichhit=terrain.lineTerrain(start,end,&colpoint);
952 tipvelocity[i].y+=.1;
955 whichhit=terrain.lineTerrain(start,end,&colpoint);
957 closestpoint=colpoint*terrain.scale;
962 tipvelocity[i].y-=.1;
965 whichhit=terrain.lineTerrain(start,end,&colpoint);
970 tipvelocity[i].y+=.01;
973 whichhit=terrain.lineTerrain(start,end,&colpoint);
975 closestpoint=colpoint*terrain.scale;
979 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
981 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
982 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
985 position[i].y+=.1*proportion;
986 tippoint[i].y+=.1*(1-proportion);
987 velocity[i].y+=.1*proportion;
988 tipvelocity[i].y+=.1*(1-proportion);
991 whichhit=terrain.lineTerrain(start,end,&colpoint);
993 position[i].y-=.1*proportion;
994 tippoint[i].y-=.1*(1-proportion);
995 velocity[i].y-=.1*proportion;
996 tipvelocity[i].y-=.1*(1-proportion);
999 whichhit=terrain.lineTerrain(start,end,&colpoint);
1000 while(whichhit!=-1){
1001 position[i].y+=.01*proportion;
1002 tippoint[i].y+=.01*(1-proportion);
1003 velocity[i].y+=.01*proportion;
1004 tipvelocity[i].y+=.01*(1-proportion);
1007 whichhit=terrain.lineTerrain(start,end,&colpoint);
1014 velocity[i].y+=gravity*multiplier;
1015 tipvelocity[i].y+=gravity*multiplier;
1016 //position[i].y+=gravity*multiplier*multiplier;
1017 //tippoint[i].y+=gravity*multiplier*multiplier;
1020 XYZ temppoint1,temppoint2,tempforward;
1023 temppoint1=position[i];
1024 temppoint2=tippoint[i];
1025 distance=findDistance(&temppoint1,&temppoint2);
1026 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1027 rotation2[i]*=360/6.28;
1030 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1031 rotation1[i]*=360/6.28;
1033 smallrotation[i]=90;
1034 smallrotation2[i]=0;
1038 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1041 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1042 freetime[i]+=multiplier;
1045 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1046 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1054 multiplier=tempmult;
1055 if(blooddrip[i]&&bloody[i]){
1056 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1057 blooddrip[i]-=multiplier;
1058 if(blooddrip[i]<0)blooddrip[i]=0;
1059 if(blooddrip[i]>5)blooddrip[i]=5;
1060 if(blooddripdelay[i]<0&&bloodtoggle){
1061 blooddripdelay[i]=1;
1064 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1068 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1073 flamedelay[i]-=multiplier;
1074 if(onfire[i]&&flamedelay[i]<=0){
1076 flamedelay[i]-=multiplier;
1079 normalrot=player[owner[i]].velocity;
1083 if(player[owner[i]].onterrain){
1087 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);
1088 Sprite::setLastSpriteSpeed(4);
1089 Sprite::setLastSpriteAlivetime(.3);
1093 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1094 flamedelay[i]-=multiplier;
1095 if(flamedelay[i]<=0){
1097 flamedelay[i]-=multiplier;
1099 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1101 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1102 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1103 Sprite::setLastSpriteSpeed(4);
1104 Sprite::setLastSpriteAlivetime(.3);
1114 static XYZ terrainlight;
1115 static GLfloat M[16];
1117 glAlphaFunc(GL_GREATER, 0.9);
1118 glEnable(GL_TEXTURE_2D);
1120 glEnable(GL_CULL_FACE);
1121 glCullFace(GL_FRONT);
1123 for(i=0;i<numweapons;i++)
1125 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1131 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1132 else drawhowmany[i]=1;
1136 if(player[owner[i]].occluded<25)
1137 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)
1139 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)
1143 else drawhowmany[i]=1;
1144 if(player[owner[i]].targetanimation==swordgroundstabanim)
1146 lastdrawnrotation1[i]=rotation1[i];
1147 lastdrawnrotation2[i]=rotation2[i];
1148 lastdrawnrotation3[i]=rotation3[i];
1149 lastdrawnbigrotation[i]=bigrotation[i];
1150 lastdrawnbigtilt[i]=bigtilt[i];
1151 lastdrawnbigtilt2[i]=bigtilt2[i];
1152 lastdrawnsmallrotation[i]=smallrotation[i];
1153 lastdrawnsmallrotation2[i]=smallrotation2[i];
1158 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1159 if(drawhowmany[i]>0)
1161 glAlphaFunc(GL_GREATER, 0.01);
1163 for(j=drawhowmany[i];j>0;j--)
1165 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1167 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1168 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]));
1169 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]));
1170 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1171 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1172 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1173 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1174 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1175 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1176 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1177 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1178 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1182 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1184 glTranslatef(0,0,-.3);
1186 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)
1188 glTranslatef(0,0,-.1);
1191 /*if(type[i]==knife){
1193 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1199 glEnable(GL_LIGHTING);
1200 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1203 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1204 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1209 glEnable(GL_LIGHTING);
1210 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1213 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1214 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1219 glEnable(GL_LIGHTING);
1220 staffmodel.drawdifftex(stafftextureptr);
1226 lastdrawnposition[i]=position[i];
1227 lastdrawntippoint[i]=tippoint[i];
1228 lastdrawnrotation1[i]=rotation1[i];
1229 lastdrawnrotation2[i]=rotation2[i];
1230 lastdrawnrotation3[i]=rotation3[i];
1231 lastdrawnbigrotation[i]=bigrotation[i];
1232 lastdrawnbigtilt[i]=bigtilt[i];
1233 lastdrawnbigtilt2[i]=bigtilt2[i];
1234 lastdrawnsmallrotation[i]=smallrotation[i];
1235 lastdrawnsmallrotation2[i]=smallrotation2[i];
1236 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1240 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1243 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1244 glRotatef(bigrotation[i],0,1,0);
1245 glRotatef(bigtilt2[i],1,0,0);
1246 glRotatef(bigtilt[i],0,0,1);
1247 glRotatef(-rotation1[i]+90,0,1,0);
1248 glRotatef(-rotation2[i]+90,0,0,1);
1249 glRotatef(-rotation3[i],0,1,0);
1250 glRotatef(smallrotation[i],1,0,0);
1251 glRotatef(smallrotation2[i],0,1,0);
1252 glTranslatef(0,0,length[i]);
1253 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1254 tippoint[i].x=M[12];
1255 tippoint[i].y=M[13];
1256 tippoint[i].z=M[14];
1262 shinepoint=position[i];
1263 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1264 Sprite::speed[Sprite::numsprites-1]=4;
1265 Sprite::alivetime[Sprite::numsprites-1]=.3;
1266 shinepoint=tippoint[i];
1267 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1268 Sprite::speed[Sprite::numsprites-1]=4;
1269 Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1279 // Model throwingknifemodel;
1280 knifetextureptr = 0;
1281 lightbloodknifetextureptr = 0;
1282 bloodknifetextureptr = 0;
1284 // Model swordmodel;
1285 swordtextureptr = 0;
1286 lightbloodswordtextureptr = 0;
1287 bloodswordtextureptr = 0;
1289 // Model staffmodel;
1290 stafftextureptr = 0;
1295 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1296 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1297 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1298 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1299 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1300 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1301 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );