]> git.jsancho.org Git - lugaru.git/blob - Source/Weapons.cpp
renames for readability
[lugaru.git] / Source / Weapons.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
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.
10
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.
14
15 See the GNU General Public License for more details.
16
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.
20 */
21
22 /**> HEADER FILES <**/
23 #include "Weapons.h"
24 #include "openal_wrapper.h"
25 #include "Animation.h"
26 #include "Sounds.h"
27 #include "Game.h"
28 #include "Awards.h"
29
30 extern float multiplier;
31 extern Terrain terrain;
32 extern float gravity;
33 extern int environment;
34 extern int detail;
35 extern FRUSTUM frustum;
36 extern XYZ viewer;
37 extern float realmultiplier;
38 extern int slomo;
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;
45 extern bool osx;
46 extern bool autoslomo;
47 extern float camerashake;
48 extern float woozy;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
52 extern bool freeze;
53 extern int tutoriallevel;
54 extern int numthrowkill;
55
56 Model Weapon::throwingknifemodel;
57 Texture Weapon::knifetextureptr;
58 Texture Weapon::lightbloodknifetextureptr;
59 Texture Weapon::bloodknifetextureptr;
60
61 Model Weapon::swordmodel;
62 Texture Weapon::swordtextureptr;
63 Texture Weapon::lightbloodswordtextureptr;
64 Texture Weapon::bloodswordtextureptr;
65
66 Model Weapon::staffmodel;
67 Texture Weapon::stafftextureptr;
68
69 Weapon::Weapon(int t, int o) : owner(o) {
70         setType(t);
71         bloody=0;
72         blooddrip=0;
73         blooddripdelay=0;
74         onfire=0;
75         flamedelay=0;
76         damage=0;
77         position=-1000;
78         tippoint=-1000;
79 }
80
81 void Weapon::setType(int t) {
82         type = t;
83         if(type==sword){
84                 mass=1.5;
85                 tipmass=1;
86                 length=.8;
87         }
88         if(type==staff){
89                 mass=2;
90                 tipmass=1;
91                 length=1.5;
92         }
93         if(type==knife){
94                 mass=1;
95                 tipmass=1.2;
96                 length=.25;
97         }
98 }
99
100 void Weapon::DoStuff(int i) {
101         //~ cout << position.x << "," << position.y << "," << position.z << "|" << tippoint.x << "," << tippoint.y << "," << tippoint.z << endl;
102         static int whichpatchx,whichpatchz,whichhit;
103         static XYZ start,end,colpoint,normalrot,footvel,footpoint;
104         static XYZ terrainnormal;
105         static XYZ vel;
106         static XYZ midp;
107         static XYZ newpoint1,newpoint2;
108         static float friction=3.5;
109         static float elasticity=.4;
110         static XYZ bounceness;
111         static float frictionness;
112         static float closestdistance;
113         static float distance;
114         static XYZ point[3];
115         static XYZ closestpoint;
116         static XYZ closestswordpoint;
117         static XYZ extramove;
118         static float tempmult;
119         
120         if(owner!=-1) {
121                 oldowner=owner;
122         }
123         if(damage>=2 && type==staff && owner!=-1) { // the staff breaks
124                 emit_sound_at(staffbreaksound, tippoint);
125                 XYZ tempvel;
126                 for(int j=0;j<40;j++) {
127                         tempvel.x=float(abs(Random()%100)-50)/20;
128                         tempvel.y=float(abs(Random()%100)-50)/20;
129                         tempvel.z=float(abs(Random()%100)-50)/20;
130                         Sprite::MakeSprite(splintersprite, position+(tippoint-position)*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
131                 }
132                 if(owner!=-1) {
133                         player[owner].weaponactive=-1;
134                         player[owner].num_weapons--;
135                         if(player[owner].num_weapons) {
136                                 player[owner].weaponids[0]=player[owner].weaponids[player[owner].num_weapons];
137                                 if(player[owner].weaponstuck==player[owner].num_weapons)
138                                         player[owner].weaponstuck=0;
139                         }
140                 }
141                 owner=-1;
142                 hitsomething=0;
143                 missed=1;
144                 freetime=0;
145                 firstfree=1;
146                 position=0;
147                 physics=0;
148         }
149         oldposition=position;
150         oldtippoint=tippoint;
151         if(owner==-1 && (velocity.x||velocity.y||velocity.z) && !physics) { // if the weapon is flying
152                 position+=velocity*multiplier;
153                 tippoint+=velocity*multiplier;
154                 whichpatchx=position.x/(terrain.size/subdivision*terrain.scale);
155                 whichpatchz=position.z/(terrain.size/subdivision*terrain.scale);
156                 if(whichpatchx>0 && whichpatchz>0 && whichpatchx<subdivision && whichpatchz<subdivision) {
157                         if(terrain.patchobjectnum[whichpatchx][whichpatchz]) { // if there are objects where the weapon is
158                                 for(int j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++) { // check for collision
159                                         int k=terrain.patchobjects[whichpatchx][whichpatchz][j];
160                                         start=oldtippoint;
161                                         end=tippoint;
162                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
163                                         if(whichhit!=-1) {
164                                                 if(objects.type[k]==treetrunktype){
165                                                         objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.yaw[k],0),.1,1,Random()%360);
166                                                         normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.yaw[k],0);
167                                                         velocity=0;
168                                                         if(type==knife)
169                                                                 position=colpoint-normalrot*.1;
170                                                         else if(type==sword)
171                                                                 position=colpoint-normalrot*.2;
172                                                         else if(type==staff)
173                                                                 position=colpoint-normalrot*.2;
174                                                         XYZ temppoint1,temppoint2,tempforward;
175                                                         float distance;
176
177                                                         temppoint1=0;
178                                                         temppoint2=normalrot;
179                                                         distance=findDistance(&temppoint1,&temppoint2);
180                                                         rotation2=asin((temppoint1.y-temppoint2.y)/distance);
181                                                         rotation2*=360/6.28;
182                                                         temppoint1.y=0;
183                                                         temppoint2.y=0;
184                                                         rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
185                                                         rotation1*=360/6.28;
186                                                         if(temppoint1.x>temppoint2.x)
187                                                                 rotation1=360-rotation1;
188
189                                                         rotation3=0;
190                                                         smallrotation=90;
191                                                         smallrotation2=0;
192                                                         bigtilt=0;
193                                                         bigtilt2=0;
194                                                         bigrotation=0;
195
196                                                         emit_sound_at(knifesheathesound, position, 128.);
197
198                                                         bloody=0;
199
200                                                         Sprite::MakeSprite(cloudimpactsprite, position,velocity, 1,1,1, .8, .3);
201                                                 }
202                                                 else {
203                                                         physics=1;
204                                                         firstfree=1;
205                                                         position-=velocity*multiplier;
206                                                         tippoint-=velocity*multiplier;
207                                                         tipvelocity=velocity;
208                                                 }
209                                         }
210                                 }
211                         }
212                 }
213                 
214                 if(velocity.x||velocity.y||velocity.z) {
215                         for(int j=0;j<numplayers;j++) {
216                                 footvel=0;
217                                 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].yaw,0)*player[j].scale+player[j].coords;
218                                 if(owner==-1 && distsqflat(&position,&player[j].coords)<1.5 && 
219                                 distsq(&position,&player[j].coords)<4 && player[j].weaponstuck==-1 &&
220                                 !player[j].skeleton.free && j!=oldowner) {
221                                         if((player[j].aitype!=attacktypecutoff||abs(Random()%6)==0||(player[j].animTarget!=backhandspringanim&&player[j].animTarget!=rollanim&&player[j].animTarget!=flipanim&&Random()%2==0))&&!missed) {
222                                                 if( (player[j].creature==wolftype       &&      Random()%3!=0 && player[j].weaponactive==-1 && (player[j].isIdle()||player[j].isRun()||player[j].animTarget==walkanim))||
223                                                         (player[j].creature==rabbittype &&      Random()%2==0 && player[j].aitype==attacktypecutoff && player[j].weaponactive==-1)) {
224                                                         emit_sound_at(knifedrawsound, player[j].coords, 128.);
225
226                                                         player[j].weaponactive=0;
227                                                         player[j].animTarget=removeknifeanim;
228                                                         player[j].frameTarget=1;
229                                                         player[j].target=1;
230                                                         owner=player[j].id;
231                                                         if(player[j].num_weapons>0){
232                                                                 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
233                                                         }
234                                                         player[j].num_weapons++;
235                                                         player[j].weaponids[0]=i;
236
237                                                         player[j].aitype=attacktypecutoff;
238                                                 }
239                                                 else {
240                                                         if(j!=0) numthrowkill++;
241                                                         player[j].num_weapons++;
242                                                         player[j].weaponstuck=player[j].num_weapons-1;
243                                                         if(normaldotproduct(player[j].facing,velocity)>0)
244                                                                 player[j].weaponstuckwhere=1;
245                                                         else
246                                                                 player[j].weaponstuckwhere=0;
247
248                                                         player[j].weaponids[player[j].num_weapons-1]=i;
249
250                                                         player[j].RagDoll(0);
251                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity*2;
252                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity*2;
253                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity*2;
254                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity*2;
255                                                         if(bloodtoggle&&tutoriallevel!=1)
256                                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
257                                                         if(tutoriallevel==1)
258                                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
259                                                         footvel=tippoint-position;
260                                                         Normalise(&footvel);
261                                                         if(bloodtoggle&&tutoriallevel!=1)
262                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
263
264                                                         if(tutoriallevel!=1) {
265                                                                 if(player[j].weaponstuckwhere==0)
266                                                                         player[j].DoBloodBig(2,205);
267                                                                 if(player[j].weaponstuckwhere==1)
268                                                                         player[j].DoBloodBig(2,200);
269                                                                 player[j].damage+=200/player[j].armorhigh;
270                                                                 player[j].deathbleeding=1;
271                                                                 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
272                                                                 owner=j;
273                                                                 bloody=2;
274                                                                 blooddrip=5;
275                                                         }
276
277                                                         emit_sound_at(fleshstabsound, position, 128.);
278
279                                                         if(animation[player[0].animTarget].height==highheight)
280                                                           award_bonus(0, ninja);
281                                                         else
282                                                           award_bonus(0, Bullseyebonus);
283                                                 }
284                                         }
285                                         else missed=1;
286                                 }
287                         }
288                 }
289                 if(position.y<terrain.getHeight(position.x,position.z)) {
290                         if(terrain.getOpacity(position.x,position.z)<.2) {
291                                 velocity=0;
292                                 if(terrain.lineTerrain(oldposition,position,&colpoint)!=-1) {
293                                         position=colpoint*terrain.scale;
294                                 } else {
295                                         position.y=terrain.getHeight(position.x,position.z);
296                                 }
297
298                                 terrain.MakeDecal(shadowdecalpermanent,position,.06,.5,0);
299                                 normalrot=terrain.getNormal(position.x,position.z)*-1;
300                                 velocity=0;
301                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
302                                 glPushMatrix();
303                                         GLfloat M[16];
304                                         glLoadIdentity();
305                                         glRotatef(bigrotation,0,1,0);
306                                         glRotatef(bigtilt2,1,0,0);
307                                         glRotatef(bigtilt,0,0,1);
308                                         glRotatef(-rotation1+90,0,1,0);
309                                         glRotatef(-rotation2+90,0,0,1);
310                                         glRotatef(-rotation3,0,1,0);
311                                         glRotatef(smallrotation,1,0,0);
312                                         glRotatef(smallrotation2,0,1,0);
313                                         glTranslatef(0,0,1);
314                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
315                                         tippoint.x=M[12];
316                                         tippoint.y=M[13];
317                                         tippoint.z=M[14];
318                                 glPopMatrix();
319                                 position-=tippoint*.15;
320                                 XYZ temppoint1,temppoint2,tempforward;
321
322                                 rotation3=0;
323                                 smallrotation=90;
324                                 smallrotation2=0;
325                                 bigtilt=0;
326                                 bigtilt2=0;
327                                 bigrotation=0;
328
329                                 emit_sound_at(knifesheathesound, position, 128.);
330
331                                 XYZ terrainlight;
332                                 terrainlight=terrain.getLighting(position.x,position.z);
333                                 if(environment==snowyenvironment){
334                                         if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
335                                                 Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
336                                 }
337                                 else if(environment==grassyenvironment){
338                                         if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
339                                                 Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
340                                 }
341                                 else if(environment==desertenvironment){
342                                         if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
343                                                 Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
344                                 }
345
346                                 bloody=0;
347                         }
348                         else {
349                                 physics=1;
350                                 firstfree=1;
351                                 position-=velocity*multiplier;
352                                 tippoint-=velocity*multiplier;
353                                 tipvelocity=velocity;
354                         }
355                 }
356                 if(velocity.x!=0||velocity.z!=0||velocity.y!=0) {
357                         velocity.y+=gravity*multiplier;
358
359                         XYZ temppoint1,temppoint2,tempforward;
360                         float distance;
361
362                         temppoint1=0;
363                         temppoint2=velocity;
364                         distance=findDistance(&temppoint1,&temppoint2);
365                         rotation2=asin((temppoint1.y-temppoint2.y)/distance);
366                         rotation2*=360/6.28;
367                         temppoint1.y=0;
368                         temppoint2.y=0;
369                         rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
370                         rotation1*=360/6.28;
371                         rotation3=0;
372                         smallrotation=90;
373                         smallrotation2=0;
374                         bigtilt=0;
375                         bigtilt2=0;
376                         bigrotation=0;
377                         if(temppoint1.x>temppoint2.x) rotation1=360-rotation1;
378                 }
379
380         }
381         
382         //Sword physics
383         XYZ mid;
384         XYZ oldmid;
385         XYZ oldmid2;
386
387         tempmult=multiplier;
388         multiplier/=10;
389         for(int l=0;l<10;l++) {
390                 if(owner==-1&&(velocity.x||velocity.y||velocity.z)&&physics) {
391                         //move
392                         position+=velocity*multiplier;
393                         tippoint+=tipvelocity*multiplier;
394
395                         //Length constrain
396                         midp=(position*mass+tippoint*tipmass)/(mass+tipmass);
397                         vel=tippoint-midp;
398                         Normalise(&vel);
399                         newpoint1=midp-vel*length*(tipmass/(mass+tipmass));
400                         newpoint2=midp+vel*length*(mass/(mass+tipmass));
401                         if(!freeze){
402                                 if(freetime>.04) {
403                                         velocity=velocity+(newpoint1-position)/multiplier;
404                                         tipvelocity=tipvelocity+(newpoint2-tippoint)/multiplier;
405                                 }
406                         }
407                         position=newpoint1;
408                         tippoint=newpoint2;
409
410
411                         //Object collisions
412                         whichpatchx=(position.x)/(terrain.size/subdivision*terrain.scale);
413                         whichpatchz=(position.z)/(terrain.size/subdivision*terrain.scale);
414                         if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
415                                 if(terrain.patchobjectnum[whichpatchx][whichpatchz]) {
416                                         for(int j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++) {
417                                                 int k=terrain.patchobjects[whichpatchx][whichpatchz][j];
418
419                                                 if(firstfree) {
420                                                         if(type==staff) {
421                                                                 start=tippoint-(position-tippoint)/5;
422                                                                 end=position+(position-tippoint)/30;
423                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
424                                                                 if(whichhit!=-1) {
425                                                                         XYZ diff;
426                                                                         diff=(colpoint-position);
427                                                                         Normalise(&diff);
428                                                                         hitsomething=1;
429
430                                                                         tippoint+=(colpoint-position)+diff*.05;
431                                                                         position=colpoint+diff*.05;
432                                                                         oldtippoint=tippoint;
433                                                                         oldposition=tippoint;
434                                                                 }
435                                                         } else {
436                                                                 start=position-(tippoint-position)/5;
437                                                                 end=tippoint+(tippoint-position)/30;
438                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
439                                                                 if(whichhit!=-1){
440                                                                         XYZ diff;
441                                                                         diff=(colpoint-tippoint);
442                                                                         Normalise(&diff);
443                                                                         hitsomething=1;
444
445                                                                         position+=(colpoint-tippoint)+diff*.05;
446                                                                         tippoint=colpoint+diff*.05;
447                                                                         oldposition=position;
448                                                                         oldtippoint=tippoint;
449                                                                 }
450                                                         }
451                                                 }
452
453                                                 start=oldposition;
454                                                 end=position;
455                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
456                                                 if(whichhit!=-1) {
457                                                         hitsomething=1;
458                                                         position=colpoint;
459                                                         terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.yaw[k],0)*-1;
460                                                         ReflectVector(&velocity,&terrainnormal);
461                                                         position+=terrainnormal*.002;
462
463                                                         bounceness=terrainnormal*findLength(&velocity)*(abs(normaldotproduct(velocity,terrainnormal)));
464                                                         if(findLengthfast(&velocity)<findLengthfast(&bounceness))
465                                                                 bounceness=0;
466                                                         frictionness=abs(normaldotproduct(velocity,terrainnormal));
467                                                         velocity-=bounceness;
468                                                         if(1-friction*frictionness>0)velocity*=1-friction*frictionness;
469                                                         else velocity=0;
470                                                         velocity+=bounceness*elasticity;
471
472                                                         if(findLengthfast(&bounceness)>1) {
473                                                                 int whichsound;
474                                                                 if(type==staff)
475                                                                         whichsound=footstepsound3+abs(Random()%2);
476                                                                 else
477                                                                         whichsound=clank1sound+abs(Random()%4);
478                                                                 emit_sound_at(whichsound, position, 128*findLengthfast(&bounceness));
479                                                         }
480                                                 }
481                                                 start=oldtippoint;
482                                                 end=tippoint;
483                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
484                                                 if(whichhit!=-1) {
485                                                         hitsomething=1;
486                                                         tippoint=colpoint;
487                                                         terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.yaw[k],0)*-1;
488                                                         ReflectVector(&tipvelocity,&terrainnormal);
489                                                         tippoint+=terrainnormal*.002;
490
491                                                         bounceness=terrainnormal*findLength(&tipvelocity)*(abs(normaldotproduct(tipvelocity,terrainnormal)));
492                                                         if(findLengthfast(&tipvelocity)<findLengthfast(&bounceness))bounceness=0;
493                                                         frictionness=abs(normaldotproduct(tipvelocity,terrainnormal));
494                                                         tipvelocity-=bounceness;
495                                                         if(1-friction*frictionness>0)tipvelocity*=1-friction*frictionness;
496                                                         else tipvelocity=0;
497                                                         tipvelocity+=bounceness*elasticity;
498
499                                                         if(findLengthfast(&bounceness)>1){
500                                                                 int whichsound;
501                                                                 if(type==staff)
502                                                                         whichsound=footstepsound3+abs(Random()%2);
503                                                                 else
504                                                                         whichsound=clank1sound+abs(Random()%4);
505                                                                 emit_sound_at(whichsound, position, 128*findLengthfast(&bounceness));
506                                                         }
507                                                 }
508
509                                                 if((objects.type[k]!=boxtype && objects.type[k]!=platformtype && objects.type[k]!=walltype && objects.type[k]!=weirdtype)||objects.pitch[k]!=0)
510                                                         for(int m=0;m<2;m++){
511                                                                 mid=(position*(21+(float)m*10)+tippoint*(19-(float)m*10))/40;
512                                                                 oldmid2=mid;
513                                                                 oldmid=(oldposition*(21+(float)m*10)+oldtippoint*(19-(float)m*10))/40;
514
515                                                                 start=oldmid;
516                                                                 end=mid;
517                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
518                                                                 if(whichhit!=-1) {
519                                                                         hitsomething=1;
520                                                                         mid=colpoint;
521                                                                         terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.yaw[k],0)*-1;
522                                                                         ReflectVector(&velocity,&terrainnormal);
523
524                                                                         bounceness=terrainnormal*findLength(&velocity)*(abs(normaldotproduct(velocity,terrainnormal)));
525                                                                         if(findLengthfast(&velocity)<findLengthfast(&bounceness))bounceness=0;
526                                                                         frictionness=abs(normaldotproduct(velocity,terrainnormal));
527                                                                         velocity-=bounceness;
528                                                                         if(1-friction*frictionness>0)velocity*=1-friction*frictionness;
529                                                                         else velocity=0;
530                                                                         velocity+=bounceness*elasticity;
531
532                                                                         if(findLengthfast(&bounceness)>1){
533                                                                                 int whichsound;
534                                                                                 if(type==staff)
535                                                                                         whichsound=footstepsound3+abs(Random()%2);
536                                                                                 else
537                                                                                         whichsound=clank1sound+abs(Random()%4);
538                                                                                 emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness));
539                                                                         }
540                                                                         position+=(mid-oldmid2)*(20/(1+(float)m*10));
541                                                                 }
542
543                                                                 mid=(position*(19-(float)m*10)+tippoint*(21+(float)m*10))/40;
544                                                                 oldmid2=mid;
545                                                                 oldmid=(oldposition*(19-(float)m*10)+oldtippoint*(21+(float)m*10))/40;
546
547                                                                 start=oldmid;
548                                                                 end=mid;
549                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
550                                                                 if(whichhit!=-1) {
551                                                                         hitsomething=1;
552                                                                         mid=colpoint;
553                                                                         terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.yaw[k],0)*-1;
554                                                                         ReflectVector(&tipvelocity,&terrainnormal);
555
556                                                                         bounceness=terrainnormal*findLength(&tipvelocity)*(abs(normaldotproduct(tipvelocity,terrainnormal)));
557                                                                         if(findLengthfast(&tipvelocity)<findLengthfast(&bounceness))bounceness=0;
558                                                                         frictionness=abs(normaldotproduct(tipvelocity,terrainnormal));
559                                                                         tipvelocity-=bounceness;
560                                                                         if(1-friction*frictionness>0)tipvelocity*=1-friction*frictionness;
561                                                                         else tipvelocity=0;
562                                                                         tipvelocity+=bounceness*elasticity;
563
564                                                                         if(findLengthfast(&bounceness)>1){
565                                                                                 int whichsound;
566                                                                                 if(type==staff)
567                                                                                         whichsound=footstepsound3+abs(Random()%2);
568                                                                                 else
569                                                                                         whichsound=clank1sound+abs(Random()%4);
570                                                                                 emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness));
571                                                                         }
572                                                                         tippoint+=(mid-oldmid2)*(20/(1+(float)m*10));
573                                                                 }
574                                                         }
575                                                 else
576                                                 {
577                                                         start=position;
578                                                         end=tippoint;
579                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.yaw[k]);
580                                                         if(whichhit!=-1) {
581                                                                 hitsomething=1;
582                                                                 closestdistance=-1;
583                                                                 closestswordpoint=colpoint;//(position+tippoint)/2;
584                                                                 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.yaw[k],0)+objects.position[k];
585                                                                 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.yaw[k],0)+objects.position[k];
586                                                                 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.yaw[k],0)+objects.position[k];
587                                                                 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint )) {
588                                                                         if(distance<closestdistance||closestdistance==-1){
589                                                                                 closestpoint=colpoint;
590                                                                                 closestdistance=distance;
591                                                                         }
592                                                                 }
593                                                                 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint )) {
594                                                                         if(distance<closestdistance||closestdistance==-1){
595                                                                                 closestpoint=colpoint;
596                                                                                 closestdistance=distance;
597                                                                         }
598                                                                 }
599                                                                 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint )) {
600                                                                         if(distance<closestdistance||closestdistance==-1){
601                                                                                 closestpoint=colpoint;
602                                                                                 closestdistance=distance;
603                                                                         }
604                                                                 }
605                                                                 if(closestdistance!=-1 && isnormal(closestdistance)) {
606                                                                         if(DistancePointLine(&closestpoint, &position, &tippoint, &distance,&colpoint )) {
607                                                                                 closestswordpoint=colpoint;
608                                                                                 velocity+=(closestpoint-closestswordpoint);
609                                                                                 tipvelocity+=(closestpoint-closestswordpoint);
610                                                                                 position+=(closestpoint-closestswordpoint);
611                                                                                 tippoint+=(closestpoint-closestswordpoint);
612                                                                         }
613                                                                 }
614                                                         }
615                                                 }
616                                         }
617                                 }
618                                 //Terrain collisions
619                                 whichhit=terrain.lineTerrain(oldposition,position,&colpoint);
620                                 if(whichhit!=-1||position.y<terrain.getHeight(position.x,position.z)) {
621                                         hitsomething=1;
622                                         if(whichhit!=-1)
623                                                 position=colpoint*terrain.scale;
624                                         else
625                                                 position.y=terrain.getHeight(position.x,position.z);
626
627                                         terrainnormal=terrain.getNormal(position.x,position.z);
628                                         ReflectVector(&velocity,&terrainnormal);
629                                         position+=terrainnormal*.002;
630                                         bounceness=terrainnormal*findLength(&velocity)*(abs(normaldotproduct(velocity,terrainnormal)));
631                                         if(findLengthfast(&velocity)<findLengthfast(&bounceness))bounceness=0;
632                                         frictionness=abs(normaldotproduct(velocity,terrainnormal));
633                                         velocity-=bounceness;
634                                         if(1-friction*frictionness>0)velocity*=1-friction*frictionness;
635                                         else velocity=0;
636                                         if(terrain.getOpacity(position.x,position.z)<.2)velocity+=bounceness*elasticity*.3;
637                                         else velocity+=bounceness*elasticity;
638
639                                         if(findLengthfast(&bounceness)>1) {
640                                                 int whichsound;
641                                                 if(terrain.getOpacity(position.x,position.z)>.2){
642                                                         if(type==staff)
643                                                                 whichsound=footstepsound3+abs(Random()%2);
644                                                         else
645                                                                 whichsound=clank1sound+abs(Random()%4);
646                                                 } else {
647                                                         whichsound=footstepsound+abs(Random()%2);
648                                                 }
649                                                 emit_sound_at(whichsound, position,
650                                                                   findLengthfast(&bounceness)
651                                                                   * (terrain.getOpacity(position.x,position.z) > .2 ? 128. : 32.));
652
653                                                 if(terrain.getOpacity(position.x,position.z)<.2) {
654                                                         XYZ terrainlight;
655                                                         terrainlight=terrain.getLighting(position.x,position.z);
656                                                         if(environment==snowyenvironment){
657                                                                 if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
658                                                                         Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
659                                                         }
660                                                         else if(environment==grassyenvironment){
661                                                                 if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
662                                                                         Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
663                                                         }
664                                                         else if(environment==desertenvironment){
665                                                                 if(distsq(&position,&viewer)<viewdistance*viewdistance/4)
666                                                                         Sprite::MakeSprite(cloudsprite, position,velocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
667                                                         }
668                                                 }
669                                         }
670                                 }
671                                 whichhit=terrain.lineTerrain(oldtippoint,tippoint,&colpoint);
672                                 if(whichhit!=-1||tippoint.y<terrain.getHeight(tippoint.x,tippoint.z)) {
673                                         if(whichhit!=-1)
674                                                 tippoint=colpoint*terrain.scale;
675                                         else
676                                                 tippoint.y=terrain.getHeight(tippoint.x,tippoint.z);
677
678                                         terrainnormal=terrain.getNormal(tippoint.x,tippoint.z);
679                                         ReflectVector(&tipvelocity,&terrainnormal);
680                                         tippoint+=terrainnormal*.002;
681                                         bounceness=terrainnormal*findLength(&tipvelocity)*(abs(normaldotproduct(tipvelocity,terrainnormal)));
682                                         if(findLengthfast(&tipvelocity)<findLengthfast(&bounceness))bounceness=0;
683                                         frictionness=abs(normaldotproduct(tipvelocity,terrainnormal));
684                                         tipvelocity-=bounceness;
685                                         if(1-friction*frictionness>0)tipvelocity*=1-friction*frictionness;
686                                         else tipvelocity=0;
687                                         if(terrain.getOpacity(tippoint.x,tippoint.z)<.2)tipvelocity+=bounceness*elasticity*.3;
688                                         else tipvelocity+=bounceness*elasticity;
689
690                                         if(findLengthfast(&bounceness)>1){ 
691                                                 int whichsound;
692                                                 if(terrain.getOpacity(tippoint.x,tippoint.z)>.2){
693                                                         if(type==staff)
694                                                                 whichsound=footstepsound3+abs(Random()%2);
695                                                         else
696                                                                 whichsound=clank1sound+abs(Random()%4);
697                                                 } else {
698                                                         whichsound=footstepsound+abs(Random()%2);
699                                                 }
700                                                 emit_sound_at(whichsound, tippoint,
701                                                                   findLengthfast(&bounceness)
702                                                                   * (terrain.getOpacity(tippoint.x,tippoint.z) > .2  ? 128. : 32.));
703
704                                                 if(terrain.getOpacity(tippoint.x,tippoint.z)<.2) {
705                                                         XYZ terrainlight;
706                                                         terrainlight=terrain.getLighting(tippoint.x,tippoint.z);
707                                                         if(environment==snowyenvironment){
708                                                                 if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
709                                                                         Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
710                                                         }
711                                                         else if(environment==grassyenvironment){
712                                                                 if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
713                                                                         Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
714                                                         }
715                                                         else if(environment==desertenvironment){
716                                                                 if(distsq(&tippoint,&viewer)<viewdistance*viewdistance/4)
717                                                                         Sprite::MakeSprite(cloudsprite, tippoint,tipvelocity, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
718                                                         }
719                                                 }
720                                         }
721                                 }
722
723                                 //Edges
724                                 mid=position+tippoint;
725                                 mid/=2;
726                                 mid+=(position-mid)/20;
727                                 oldmid=mid;
728                                 if(mid.y<terrain.getHeight(mid.x,mid.z)){
729                                         hitsomething=1;
730                                         mid.y=terrain.getHeight(mid.x,mid.z);
731
732                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
733                                         ReflectVector(&velocity,&terrainnormal);
734                                         //mid+=terrainnormal*.002;
735                                         bounceness=terrainnormal*findLength(&velocity)*(abs(normaldotproduct(velocity,terrainnormal)));
736                                         if(findLengthfast(&velocity)<findLengthfast(&bounceness))bounceness=0;
737                                         frictionness=abs(normaldotproduct(velocity,terrainnormal));
738                                         velocity-=bounceness;
739                                         if(1-friction*frictionness>0)velocity*=1-friction*frictionness;
740                                         else velocity=0;
741                                         if(terrain.getOpacity(mid.x,mid.z)<.2)velocity+=bounceness*elasticity*.3;
742                                         else velocity+=bounceness*elasticity;
743
744                                         if(findLengthfast(&bounceness)>1){
745                                                 int whichsound;
746                                                 if(terrain.getOpacity(mid.x,mid.z)>.2){
747                                                         if(type==staff)whichsound=footstepsound3+abs(Random()%2);
748                                                         if(type!=staff)whichsound=clank1sound+abs(Random()%4);
749                                                 }
750                                                 else whichsound=footstepsound+abs(Random()%2);
751                                                 emit_sound_at(whichsound, mid,
752                                                                   findLengthfast(&bounceness)
753                                                                   * (terrain.getOpacity(position.x,position.z) > .2
754                                                                  ? 128.
755                                                                  : 32.));
756                                         }
757                                         position+=(mid-oldmid)*20;
758                                 }
759
760                                 mid=position+tippoint;
761                                 mid/=2;
762                                 mid+=(tippoint-mid)/20;
763                                 oldmid=mid;
764                                 if(mid.y<terrain.getHeight(mid.x,mid.z)){
765                                         hitsomething=1;
766                                         mid.y=terrain.getHeight(mid.x,mid.z);
767
768                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
769                                         ReflectVector(&tipvelocity,&terrainnormal);
770                                         //mid+=terrainnormal*.002;
771                                         bounceness=terrainnormal*findLength(&tipvelocity)*(abs(normaldotproduct(tipvelocity,terrainnormal)));
772                                         if(findLengthfast(&tipvelocity)<findLengthfast(&bounceness))bounceness=0;
773                                         frictionness=abs(normaldotproduct(tipvelocity,terrainnormal));
774                                         tipvelocity-=bounceness;
775                                         if(1-friction*frictionness>0)tipvelocity*=1-friction*frictionness;
776                                         else tipvelocity=0;
777                                         if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity+=bounceness*elasticity*.3;
778                                         else tipvelocity+=bounceness*elasticity;
779
780                                         if(findLengthfast(&bounceness)>1){
781                                                 int whichsound;
782                                                 if(terrain.getOpacity(mid.x,mid.z)>.2){
783                                                         if(type==staff)whichsound=footstepsound3+abs(Random()%2);
784                                                         if(type!=staff)whichsound=clank1sound+abs(Random()%4);
785                                                 }
786                                                 else whichsound=footstepsound+abs(Random()%2);
787                                                 emit_sound_at(whichsound, mid,
788                                                                   findLengthfast(&bounceness)
789                                                                   * (terrain.getOpacity(position.x,position.z) > .2
790                                                                  ? 128.
791                                                                  : 32.));
792                                         }
793                                         tippoint+=(mid-oldmid)*20;
794                                 }
795                                 //Gravity
796                                 velocity.y+=gravity*multiplier;
797                                 tipvelocity.y+=gravity*multiplier;
798
799                                 //Rotation
800                                 XYZ temppoint1,temppoint2,tempforward;
801                                 float distance;
802
803                                 temppoint1=position;
804                                 temppoint2=tippoint;
805                                 distance=findDistance(&temppoint1,&temppoint2);
806                                 rotation2=asin((temppoint1.y-temppoint2.y)/distance);
807                                 rotation2*=360/6.28;
808                                 temppoint1.y=0;
809                                 temppoint2.y=0;
810                                 rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
811                                 rotation1*=360/6.28;
812                                 rotation3=0;
813                                 smallrotation=90;
814                                 smallrotation2=0;
815                                 bigtilt=0;
816                                 bigtilt2=0;
817                                 bigrotation=0;
818                                 if(temppoint1.x>temppoint2.x)rotation1=360-rotation1;
819
820                                 //Stop moving
821                                 if(findLengthfast(&velocity)<.3&&findLengthfast(&tipvelocity)<.3&&hitsomething){
822                                         freetime+=multiplier;
823                                 }
824
825                                 if(freetime>.4){
826                                         velocity=0;
827                                         tipvelocity=0;
828                                 }
829                                 firstfree=0;
830                 }
831         }
832         multiplier=tempmult;
833         if(blooddrip && bloody) {
834                 blooddripdelay-=blooddrip*multiplier/2;
835                 blooddrip-=multiplier;
836                 if(blooddrip<0) blooddrip=0;
837                 if(blooddrip>5) blooddrip=5;
838                 if(blooddripdelay<0 && bloodtoggle) {
839                         blooddripdelay=1;
840                         XYZ bloodvel;
841                         XYZ bloodloc;
842                         bloodloc=position+(tippoint-position)*.7;
843                         bloodloc.y-=.05;
844                         if(bloodtoggle) {
845                                 bloodvel=0;
846                                 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
847                         }
848                 }
849         }
850         if(onfire) {
851                 flamedelay-=multiplier;
852                 if(onfire&&flamedelay<=0) {
853                         flamedelay=.020;
854                         flamedelay-=multiplier;
855                         normalrot=0;
856                         if(owner!=-1) {
857                                 normalrot=player[owner].velocity;
858                         }
859                         normalrot.y+=1;
860                         if(owner!=-1) {
861                                 if(player[owner].onterrain) {
862                                         normalrot.y=1;
863                                 }
864                         }
865                         Sprite::MakeSprite(weaponflamesprite, position+tippoint*(((float)abs(Random()%100))/600+.05),normalrot, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*1/3, 1);
866                         Sprite::setLastSpriteSpeed(4);
867                         Sprite::setLastSpriteAlivetime(.3);
868                 }
869         }
870
871         if(!onfire && owner==-1 && type!=staff) {
872                 flamedelay-=multiplier;
873                 if(flamedelay<=0) {
874                         flamedelay=.020;
875                         flamedelay-=multiplier;
876                         normalrot=0;
877                         if(Random()%50==0&&distsq(&position,&viewer)>80) {
878                                 XYZ shinepoint;
879                                 shinepoint=position+(tippoint-position)*(((float)abs(Random()%100))/100);
880                                 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
881                                 Sprite::setLastSpriteSpeed(4);
882                                 Sprite::setLastSpriteAlivetime(.3);
883                         }
884                 }
885         }
886 }
887
888 void Weapons::DoStuff() {
889         //Move
890         int i = 0;
891         for(std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
892                 weapon->DoStuff(i++);
893         }
894 }
895
896 void Weapon::Draw() {
897         static XYZ terrainlight;
898         static GLfloat M[16];
899         
900         if((frustum.SphereInFrustum(position.x,position.y,position.z,1)&&
901                 distsq(&viewer,&position)<viewdistance*viewdistance))
902         {
903                 bool draw=false;
904                 if(owner==-1)
905                 {
906                         draw=true;
907                         if(velocity.x && !physics)
908                                 drawhowmany=10;
909                         else
910                                 drawhowmany=1;
911                 } else {
912                         if(player[owner].occluded<25)
913                                 if((frustum.SphereInFrustum(player[owner].coords.x,player[owner].coords.y+player[owner].scale*3,player[owner].coords.z,player[owner].scale*8)&&distsq(&viewer,&player[owner].coords)<viewdistance*viewdistance)||player[owner].skeleton.free==3)
914                                         draw=true;
915                         if      (
916                                 (player[owner].animTarget==knifeslashstartanim||
917                                  player[owner].animTarget==swordsneakattackanim||
918                                  (player[owner].animCurrent==staffhitanim       &&                              player[owner].frameCurrent>1)||
919                                  (player[owner].animCurrent==staffhitreversedanim       &&              player[owner].frameCurrent>1)||
920                                  (player[owner].animCurrent==staffspinhitanim   &&                      player[owner].frameCurrent>1)||
921                                  (player[owner].animCurrent==staffspinhitreversedanim   &&      player[owner].frameCurrent>1)||
922                                  (player[owner].animCurrent==staffgroundsmashanim       &&              player[owner].frameCurrent>1)||
923                                  (player[owner].animTarget==swordslashanim      &&                              player[owner].frameTarget<7)||
924                                  player[owner].animTarget==crouchstabanim||
925                                  player[owner].animTarget==swordslashreversalanim||
926                                  player[owner].animTarget==swordslashreversedanim||
927                                  player[owner].animTarget==knifefollowanim||
928                                  player[owner].animTarget==swordgroundstabanim||
929                                  player[owner].animTarget==knifethrowanim)&&
930                                  player[owner].animTarget==lastdrawnanim&&
931                                  !player[owner].skeleton.free
932                                 )
933                         {
934                                 drawhowmany=10;
935                         } else {
936                                 drawhowmany=1;
937                         }
938                         if(player[owner].animTarget==swordgroundstabanim)
939                         {
940                                 lastdrawnrotation1=rotation1;
941                                 lastdrawnrotation2=rotation2;
942                                 lastdrawnrotation3=rotation3;
943                                 lastdrawnbigrotation=bigrotation;
944                                 lastdrawnbigtilt=bigtilt;
945                                 lastdrawnbigtilt2=bigtilt2;
946                                 lastdrawnsmallrotation=smallrotation;
947                                 lastdrawnsmallrotation2=smallrotation2;
948                         }
949                 }
950                 if(draw)
951                 {
952                         terrainlight=terrain.getLighting(position.x,position.z);
953                         if(drawhowmany>0)
954                         {
955                                 glAlphaFunc(GL_GREATER, 0.01);
956                         }
957                         for(int j=drawhowmany;j>0;j--)
958                         {
959                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
960                                 glPushMatrix();
961                                         glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany);
962                                         if(owner==-1)
963                                                 glTranslatef(position.x*(((float)(j))/drawhowmany)+lastdrawnposition.x*(1-((float)(j))/drawhowmany),position.y*(((float)(j))/drawhowmany)+lastdrawnposition.y*(1-((float)(j))/drawhowmany),position.z*(((float)(j))/drawhowmany)+lastdrawnposition.z*(1-((float)(j))/drawhowmany));
964                                         else
965                                                 glTranslatef(position.x*(((float)(j))/drawhowmany)+lastdrawnposition.x*(1-((float)(j))/drawhowmany),position.y*(((float)(j))/drawhowmany)-.02+lastdrawnposition.y*(1-((float)(j))/drawhowmany),position.z*(((float)(j))/drawhowmany)+lastdrawnposition.z*(1-((float)(j))/drawhowmany));
966                                         glRotatef(bigrotation*(((float)(j))/drawhowmany)+lastdrawnbigrotation*(1-((float)(j))/drawhowmany),0,1,0);
967                                         glRotatef(bigtilt2*(((float)(j))/drawhowmany)+lastdrawnbigtilt2*(1-((float)(j))/drawhowmany),1,0,0);
968                                         glRotatef(bigtilt*(((float)(j))/drawhowmany)+lastdrawnbigtilt*(1-((float)(j))/drawhowmany),0,0,1);
969                                         glRotatef(-rotation1*(((float)(j))/drawhowmany)-lastdrawnrotation1*(1-((float)(j))/drawhowmany)+90,0,1,0);
970                                         glRotatef(-rotation2*(((float)(j))/drawhowmany)-lastdrawnrotation2*(1-((float)(j))/drawhowmany)+90,0,0,1);
971                                         glRotatef(-rotation3*(((float)(j))/drawhowmany)-lastdrawnrotation3*(1-((float)(j))/drawhowmany),0,1,0);
972                                         glRotatef(smallrotation*(((float)(j))/drawhowmany)+lastdrawnsmallrotation*(1-((float)(j))/drawhowmany),1,0,0);
973                                         glRotatef(smallrotation2*(((float)(j))/drawhowmany)+lastdrawnsmallrotation2*(1-((float)(j))/drawhowmany),0,1,0);
974
975                                         if(owner!=-1)
976                                         {
977                                                 if(player[owner].animTarget==staffhitanim||player[owner].animCurrent==staffhitanim||player[owner].animTarget==staffhitreversedanim||player[owner].animCurrent==staffhitreversedanim)
978                                                 {
979                                                         glTranslatef(0,0,-.3);
980                                                 }
981                                                 if(player[owner].animTarget==staffgroundsmashanim||player[owner].animCurrent==staffgroundsmashanim||player[owner].animTarget==staffspinhitreversedanim||player[owner].animCurrent==staffspinhitreversedanim||player[owner].animTarget==staffspinhitanim||player[owner].animCurrent==staffspinhitanim)
982                                                 {
983                                                         glTranslatef(0,0,-.1);
984                                                 }
985                                         }
986
987                                         glEnable(GL_LIGHTING);
988                                         switch(type) {
989                                                 case knife:
990                                                         if(!bloody||!bloodtoggle)
991                                                                 throwingknifemodel.drawdifftex(knifetextureptr);
992                                                         if(bloodtoggle)
993                                                         {
994                                                                 if(bloody==1)
995                                                                         throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
996                                                                 if(bloody==2)
997                                                                         throwingknifemodel.drawdifftex(bloodknifetextureptr);
998                                                         }
999                                                         break;
1000                                                 case sword:
1001                                                         if(!bloody||!bloodtoggle)
1002                                                                 swordmodel.drawdifftex(swordtextureptr);
1003                                                         if(bloodtoggle)
1004                                                         {
1005                                                                 if(bloody==1)
1006                                                                         swordmodel.drawdifftex(lightbloodswordtextureptr);
1007                                                                 if(bloody==2)
1008                                                                         swordmodel.drawdifftex(bloodswordtextureptr);
1009                                                         }
1010                                                         break;
1011                                                 case staff:
1012                                                         staffmodel.drawdifftex(stafftextureptr);
1013                                                         break;
1014                                         }
1015
1016                                 glPopMatrix();
1017                         }
1018
1019                         lastdrawnposition=position;
1020                         lastdrawntippoint=tippoint;
1021                         lastdrawnrotation1=rotation1;
1022                         lastdrawnrotation2=rotation2;
1023                         lastdrawnrotation3=rotation3;
1024                         lastdrawnbigrotation=bigrotation;
1025                         lastdrawnbigtilt=bigtilt;
1026                         lastdrawnbigtilt2=bigtilt2;
1027                         lastdrawnsmallrotation=smallrotation;
1028                         lastdrawnsmallrotation2=smallrotation2;
1029                         if(owner!=-1)lastdrawnanim=player[owner].animCurrent;
1030                 }
1031                 if(owner!=-1)
1032                 {
1033                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1034                         glPushMatrix();
1035                                 glLoadIdentity();
1036                                 glTranslatef(position.x,position.y-.02,position.z);
1037                                 glRotatef(bigrotation,0,1,0);
1038                                 glRotatef(bigtilt2,1,0,0);
1039                                 glRotatef(bigtilt,0,0,1);
1040                                 glRotatef(-rotation1+90,0,1,0);
1041                                 glRotatef(-rotation2+90,0,0,1);
1042                                 glRotatef(-rotation3,0,1,0);
1043                                 glRotatef(smallrotation,1,0,0);
1044                                 glRotatef(smallrotation2,0,1,0);
1045                                 glTranslatef(0,0,length);
1046                                 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1047                                 tippoint.x=M[12];
1048                                 tippoint.y=M[13];
1049                                 tippoint.z=M[14];
1050                         glPopMatrix();
1051                 }
1052         }
1053 }
1054
1055 int Weapons::Draw()
1056 {
1057         glAlphaFunc(GL_GREATER, 0.9);
1058         glEnable(GL_TEXTURE_2D);
1059         glEnable(GL_BLEND);
1060         glEnable(GL_CULL_FACE);
1061         glCullFace(GL_FRONT);
1062         glDepthMask(1);
1063         
1064         for(std::vector<Weapon>::iterator weapon = begin(); weapon != end(); ++weapon) {
1065                 weapon->Draw();
1066         }
1067         return 0;
1068 }
1069
1070 Weapons::Weapons()
1071 {
1072 }
1073
1074 Weapons::~Weapons()
1075 {
1076         Weapon::stafftextureptr.destroy();
1077         Weapon::knifetextureptr.destroy();
1078         Weapon::lightbloodknifetextureptr.destroy();
1079         Weapon::bloodknifetextureptr.destroy();
1080         Weapon::swordtextureptr.destroy();
1081         Weapon::lightbloodswordtextureptr.destroy();
1082         Weapon::bloodswordtextureptr.destroy();
1083 }
1084