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