]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
466da3ed7f5cae785acc2b96faf596baf2dfa50b
[lugaru.git] / Source / GameTick.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 #if PLATFORM_UNIX
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #else
27 #include <direct.h>
28 #endif
29
30 #include <ctime>
31 #include "Game.h"
32 #include "openal_wrapper.h"
33 #include "Settings.h"
34 #include "Input.h"
35 #include "Animation.h"
36 #include "Awards.h"
37
38 using namespace std;
39
40 // Added more evilness needed for MSVC
41 #ifdef _MSC_VER
42         #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
43         #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
44 #endif
45
46
47 extern float multiplier;
48 extern XYZ viewer;
49 extern int environment;
50 extern float texscale;
51 extern Terrain terrain;
52 extern int channels[100];
53 extern int kTextureSize;
54 extern float screenwidth,screenheight;
55 extern float gravity;
56 extern int detail;
57 extern float texdetail;
58 extern Objects objects;
59 extern int slomo;
60 extern float slomodelay;
61 extern bool floatjump;
62 extern float volume;
63 extern Light light;
64 extern float texdetail;
65 extern GLubyte bloodText[512*512*3];
66 extern GLubyte wolfbloodText[512*512*3];
67 extern float terraindetail;
68 extern float camerashake;
69 extern float woozy;
70 extern float blackout;
71 extern bool cellophane;
72 extern bool musictoggle;
73 extern int difficulty;
74 extern int bloodtoggle;
75 extern bool invertmouse;
76 extern float windvar;
77 extern float precipdelay;
78 extern XYZ viewerfacing;
79 extern bool ambientsound;
80 extern bool mousejump;
81 extern float viewdistance;
82 extern bool freeze;
83 extern bool autoslomo;
84 extern bool keyboardfrozen;
85 extern int netdatanew;
86 extern bool loadingstuff;
87 extern char mapname[256];
88 extern XYZ windvector;
89 extern bool debugmode;
90 static int music1;
91 extern int mainmenu;
92 extern int oldmainmenu;
93 extern bool visibleloading;
94 extern int loadscreencolor;
95 extern float flashamount,flashr,flashg,flashb;
96 extern int flashdelay;
97 extern XYZ envsound[30];
98 extern float envsoundvol[30];
99 extern int numenvsounds;
100 extern float envsoundlife[30];
101 extern float usermousesensitivity;
102 extern bool ismotionblur;
103 extern bool foliage;
104 extern bool trilinear;
105 extern bool damageeffects;
106 extern bool showpoints;
107 extern bool showdamagebar; // (des)activate the damage bar
108 extern bool texttoggle;
109 extern bool alwaysblur;
110 extern float gamespeed;
111 extern bool decals;
112 extern bool vblsync;
113 extern bool immediate;
114 extern bool velocityblur;
115 extern int bonus;
116 extern int oldbonus;
117 extern float bonusvalue;
118 extern float bonustotal;
119 extern float bonustime;
120 extern float startbonustotal;
121 extern float tintr,tintg,tintb;
122 extern float bonusnum[100];
123 extern bool skyboxtexture;
124 extern float skyboxr;
125 extern float skyboxg;
126 extern float skyboxb;
127 extern float skyboxlightr;
128 extern float skyboxlightg;
129 extern float skyboxlightb;
130 extern float fadestart;
131 extern float slomospeed;
132 extern float slomofreq;
133 extern int tutoriallevel;
134 extern float smoketex;
135 extern float tutorialstagetime;
136 extern int tutorialstage;
137 extern float tutorialmaxtime;
138 extern float tutorialsuccess;
139 extern bool againbonus;
140 extern bool reversaltrain;
141 extern bool canattack;
142 extern bool cananger;
143 extern float damagedealt;
144 extern int maptype;
145 extern int editoractive;
146 extern int editorpathtype;
147
148 extern float hostiletime;
149
150 extern bool gamestarted;
151
152 extern int numhotspots;
153 extern int winhotspot;
154 extern int windialogue;
155 extern int killhotspot;
156 extern XYZ hotspot[40];
157 extern int hotspottype[40];
158 extern float hotspotsize[40];
159 extern char hotspottext[40][256];
160 extern int currenthotspot;
161
162 extern int kBitsPerPixel;
163 extern int hostile;
164
165 extern bool stillloading;
166 extern bool winfreeze;
167
168 extern int numdialogues;
169 extern int numdialogueboxes[max_dialogues];
170 extern int dialoguetype[max_dialogues];
171 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
172 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
173 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
174 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
175 extern char dialoguename[max_dialogues][max_dialoguelength][64];
176 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
177 extern XYZ participantlocation[max_dialogues][10];
178 extern int participantfocus[max_dialogues][max_dialoguelength];
179 extern int participantaction[max_dialogues][max_dialoguelength];
180 extern float participantrotation[max_dialogues][10];
181 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
182 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
183 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
184 extern int indialogue;
185 extern int whichdialogue;
186 extern int directing;
187 extern float dialoguetime;
188 extern int dialoguegonethrough[20];
189
190 extern bool campaign;
191
192 extern float oldgamespeed;
193
194 static const char *rabbitskin[] = {
195 ":Data:Textures:Fur3.jpg",
196 ":Data:Textures:Fur.jpg",
197 ":Data:Textures:Fur2.jpg",
198 ":Data:Textures:Lynx.jpg",
199 ":Data:Textures:Otter.jpg",
200 ":Data:Textures:Opal.jpg",
201 ":Data:Textures:Sable.jpg",
202 ":Data:Textures:Chocolate.jpg",
203 ":Data:Textures:BW2.jpg",
204 ":Data:Textures:WB2.jpg"
205 };
206
207 static const char *wolfskin[] = {
208 ":Data:Textures:Wolf.jpg",
209 ":Data:Textures:Darkwolf.jpg",
210 ":Data:Textures:Snowwolf.jpg"
211 };
212
213 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
214 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
215
216 static const char **creatureskin[] = {rabbitskin, wolfskin};
217
218 /* Return true if PFX is a prefix of STR (case-insensitive).  */
219 static bool stripfx(const char *str, const char *pfx)
220 {
221   return !strncasecmp(str, pfx, strlen(pfx));
222 }
223
224 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
225 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
226
227
228 static const char *cmd_names[] = {
229 #define DECLARE_COMMAND(cmd) #cmd " ",
230 #include "ConsoleCmds.h"
231 #undef  DECLARE_COMMAND
232 };
233
234 typedef void (*console_handler)(Game *game, const char *args);
235
236 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
237 #include "ConsoleCmds.h"
238 #undef  DECLARE_COMMAND
239
240 static console_handler cmd_handlers[] = {
241 #define DECLARE_COMMAND(cmd) ch_##cmd,
242 #include "ConsoleCmds.h"
243 #undef  DECLARE_COMMAND
244 };
245
246 static void ch_quit(Game *game, const char *args)
247 {
248   game->tryquit = 1;
249 }
250
251 static void ch_map(Game *game, const char *args)
252 {
253   char buf[64];
254   snprintf(buf, 63, ":Data:Maps:%s", args);
255   game->Loadlevel(buf);
256   game->whichlevel = -2;
257   campaign = 0;
258 }
259
260 static void ch_save(Game *game, const char *args)
261 {
262   char buf[64];
263   int i, j, k, l, m, templength;
264   float headprop, bodyprop, armprop, legprop;
265   snprintf(buf, 63, ":Data:Maps:%s", args);
266
267
268   int mapvers = 12;;
269
270   FILE                  *tfile;
271   tfile=fopen( ConvertFileName(buf), "wb" );
272   fpackf(tfile, "Bi", mapvers);
273   fpackf(tfile, "Bi", maptype);
274   fpackf(tfile, "Bi", hostile);
275   fpackf(tfile, "Bf Bf", viewdistance, fadestart);
276   fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
277   fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
278   fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z, player[0].rotation, player[0].targetrotation, player[0].num_weapons);
279   if(player[0].num_weapons>0&&player[0].num_weapons<5)
280     for(j=0;j<player[0].num_weapons;j++){
281       fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
282     }
283
284   fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
285   fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
286   fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
287   fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
288
289   fpackf(tfile, "Bi", player[0].numclothes);
290
291   fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
292
293   fpackf(tfile, "Bi", numdialogues);
294         for(k=0;k<numdialogues;k++){
295                 fpackf(tfile, "Bi", numdialogueboxes[k]);
296                 fpackf(tfile, "Bi", dialoguetype[k]);
297                 for(l=0;l<10;l++){
298                         fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
299                         fpackf(tfile, "Bf", participantrotation[k][l]);
300                 }
301                 for(l=0;l<numdialogueboxes[k];l++){
302                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
303                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
304                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
305                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
306                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
307
308                         templength=strlen(dialoguetext[k][l]);
309                         fpackf(tfile, "Bi",(templength));
310                         for(m=0;m<templength;m++){
311                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
312                                 if(dialoguetext[k][l][m]=='\0')break;
313                         }
314
315                         templength=strlen(dialoguename[k][l]);
316                         fpackf(tfile, "Bi",templength);
317                         for(m=0;m<templength;m++){
318                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
319                                 if(dialoguename[k][l][m]=='\0')break;
320                         }
321
322                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
323                         fpackf(tfile, "Bi", participantfocus[k][l]);
324                         fpackf(tfile, "Bi", participantaction[k][l]);
325
326                         for(m=0;m<10;m++)
327                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
328
329                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
330                 }
331         }
332
333         for(k=0;k<player[0].numclothes;k++){
334                 templength=strlen(player[0].clothes[k]);
335                 fpackf(tfile, "Bi", templength);
336                 for(l=0;l<templength;l++)
337                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
338                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
339         }
340
341   fpackf(tfile, "Bi", environment);
342
343   fpackf(tfile, "Bi", objects.numobjects);
344
345     for(k=0;k<objects.numobjects;k++){
346       fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k], objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
347     }
348
349   fpackf(tfile, "Bi", numhotspots);
350         for(i=0;i<numhotspots;i++){
351                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
352                 templength=strlen(hotspottext[i]);
353                 fpackf(tfile, "Bi",templength);
354                 for(l=0;l<templength;l++)
355                         fpackf(tfile, "Bb", hotspottext[i][l]);
356         }
357
358   fpackf(tfile, "Bi", numplayers);
359   if(numplayers<maxplayers)
360     for(j=1;j<numplayers;j++){
361                 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
362                 if(player[j].num_weapons<5)
363                         for(k=0;k<player[j].num_weapons;k++){
364                                 fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
365                         }
366                 if(player[j].numwaypoints<30){
367                         fpackf(tfile, "Bi", player[j].numwaypoints);
368                         for(k=0;k<player[j].numwaypoints;k++){
369                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
370                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
371                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
372                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
373                         }
374                         fpackf(tfile, "Bi", player[j].waypoint);
375                 } else {
376                         player[j].numwaypoints=0;
377                         player[j].waypoint=0;
378                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
379                 }
380
381                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
382                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
383                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
384                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
385
386                 if(player[j].creature==wolftype) {
387                         headprop=player[j].proportionhead.x/1.1;
388                         bodyprop=player[j].proportionbody.x/1.1;
389                         armprop=player[j].proportionarms.x/1.1;
390                         legprop=player[j].proportionlegs.x/1.1;
391                 } else if(player[j].creature==rabbittype){
392                         headprop=player[j].proportionhead.x/1.2;
393                         bodyprop=player[j].proportionbody.x/1.05;
394                         armprop=player[j].proportionarms.x/1.00;
395                         legprop=player[j].proportionlegs.x/1.1;
396                 }
397
398                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
399
400                 fpackf(tfile, "Bi", player[j].numclothes);
401                 if(player[j].numclothes)
402                         for(k=0;k<player[j].numclothes;k++){
403                                 int templength;
404                                 templength=strlen(player[j].clothes[k]);
405                                 fpackf(tfile, "Bi", templength);
406                                 for(l=0;l<templength;l++)
407                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
408                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
409                         }
410     }
411
412   fpackf(tfile, "Bi", game->numpathpoints);
413         for(j=0;j<game->numpathpoints;j++){
414                 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
415                 for(k=0;k<game->numpathpointconnect[j];k++){
416                         fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
417                 }
418         }
419
420   fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
421
422   fclose(tfile);
423 }
424
425 static void ch_cellar(Game *game, const char *args)
426 {
427   game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
428 }
429
430 static void ch_tint(Game *game, const char *args)
431 {
432   sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
433 }
434
435 static void ch_tintr(Game *game, const char *args)
436 {
437   tintr = atof(args);
438 }
439
440 static void ch_tintg(Game *game, const char *args)
441 {
442   tintg = atof(args);
443 }
444
445 static void ch_tintb(Game *game, const char *args)
446 {
447   tintb = atof(args);
448 }
449
450 static void ch_speed(Game *game, const char *args)
451 {
452   player[0].speedmult = atof(args);
453 }
454
455 static void ch_strength(Game *game, const char *args)
456 {
457   player[0].power = atof(args);
458 }
459
460 static void ch_power(Game *game, const char *args)
461 {
462   player[0].power = atof(args);
463 }
464
465 static void ch_size(Game *game, const char *args)
466 {
467   player[0].scale = atof(args) * .2;
468 }
469
470 static int find_closest()
471 {
472   int closest = 0;
473   float closestdist = 1.0/0.0;
474
475   for (int i = 1; i < numplayers; i++) {
476     float distance;
477     distance = findDistancefast(&player[i].coords,&player[0].coords);
478     if (distance < closestdist) {
479       closestdist = distance;
480       closest = i;
481     }
482   }
483   return closest;
484 }
485
486 static void ch_sizenear(Game *game, const char *args)
487 {
488   int closest = find_closest();
489
490   if (closest)
491     player[closest].scale = atof(args) * .2;
492 }
493
494 static void set_proportion(int pnum, const char *args)
495 {
496   float headprop,bodyprop,armprop,legprop;
497
498   sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
499
500   if(player[pnum].creature==wolftype){
501     player[pnum].proportionhead=1.1*headprop;
502     player[pnum].proportionbody=1.1*bodyprop;
503     player[pnum].proportionarms=1.1*armprop;
504     player[pnum].proportionlegs=1.1*legprop;
505   } else if(player[pnum].creature==rabbittype){
506     player[pnum].proportionhead=1.2*headprop;
507     player[pnum].proportionbody=1.05*bodyprop;
508     player[pnum].proportionarms=1.00*armprop;
509     player[pnum].proportionlegs=1.1*legprop;
510     player[pnum].proportionlegs.y=1.05*legprop;
511   }
512 }
513
514 static void ch_proportion(Game *game, const char *args)
515 {
516   set_proportion(0, args);
517 }
518
519 static void ch_proportionnear(Game *game, const char *args)
520 {
521   int closest = find_closest();
522   if (closest)
523     set_proportion(closest, args);
524 }
525
526 static void set_protection(int pnum, const char *args)
527 {
528   float head, high, low;
529   sscanf(args, "%f%f%f", &head, &high, &low);
530
531   player[pnum].protectionhead = head;
532   player[pnum].protectionhigh = high;
533   player[pnum].protectionlow  = low;
534 }
535
536 static void ch_protection(Game *game, const char *args)
537 {
538   set_protection(0, args);
539 }
540
541 static void ch_protectionnear(Game *game, const char *args)
542 {
543   int closest = find_closest();
544   if (closest)
545     set_protection(closest, args);
546 }
547
548 static void set_armor(int pnum, const char *args)
549 {
550   float head, high, low;
551   sscanf(args, "%f%f%f", &head, &high, &low);
552
553   player[pnum].armorhead = head;
554   player[pnum].armorhigh = high;
555   player[pnum].armorlow  = low;
556 }
557
558 static void ch_armor(Game *game, const char *args)
559 {
560   set_armor(0, args);
561 }
562
563 static void ch_armornear(Game *game, const char *args)
564 {
565   int closest = find_closest();
566   if (closest)
567     set_armor(closest, args);
568 }
569
570 static void ch_protectionreset(Game *game, const char *args)
571 {
572   set_protection(0, "1 1 1");
573   set_armor(0, "1 1 1");
574 }
575
576 static void set_metal(int pnum, const char *args)
577 {
578   float head, high, low;
579   sscanf(args, "%f%f%f", &head, &high, &low);
580
581   player[pnum].metalhead = head;
582   player[pnum].metalhigh = high;
583   player[pnum].metallow  = low;
584 }
585
586 static void ch_metal(Game *game, const char *args)
587 {
588   set_metal(0, args);
589 }
590
591 static void set_noclothes(int pnum, Game *game, const char *args)
592 {
593   player[pnum].numclothes = 0;
594   game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
595                         &player[pnum].skeleton.drawmodel.textureptr,1,
596                         &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
597 }
598
599 static void ch_noclothes(Game *game, const char *args)
600 {
601   set_noclothes(0, game, args);
602 }
603
604 static void ch_noclothesnear(Game *game, const char *args)
605 {
606   int closest = find_closest();
607   if (closest)
608     set_noclothes(closest, game, args);
609 }
610
611
612 static void set_clothes(int pnum, Game *game, const char *args)
613 {
614   char buf[64];
615   snprintf(buf, 63, ":Data:Textures:%s.png", args);
616
617   if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
618     return;
619
620   player[pnum].DoMipmaps(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize);
621   strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
622   player[pnum].clothestintr[player[pnum].numclothes]=tintr;
623   player[pnum].clothestintg[player[pnum].numclothes]=tintg;
624   player[pnum].clothestintb[player[pnum].numclothes]=tintb;
625   player[pnum].numclothes++;
626 }
627
628 static void ch_clothes(Game *game, const char *args)
629 {
630   set_clothes(0, game, args);
631 }
632
633 static void ch_clothesnear(Game *game, const char *args)
634 {
635   int closest = find_closest();
636   if (closest)
637     set_clothes(closest, game, args);
638 }
639
640 static void ch_belt(Game *game, const char *args)
641 {
642   player[0].skeleton.clothes = !player[0].skeleton.clothes;
643 }
644
645
646 static void ch_cellophane(Game *game, const char *args)
647 {
648   cellophane = !cellophane;
649   float mul = cellophane ? 0 : 1;
650
651   for (int i = 0; i < numplayers; i++) {
652     player[i].proportionhead.z = player[i].proportionhead.x * mul;
653     player[i].proportionbody.z = player[i].proportionbody.x * mul;
654     player[i].proportionarms.z = player[i].proportionarms.x * mul;
655     player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
656   }
657 }
658
659 static void ch_funnybunny(Game *game, const char *args)
660 {
661   player[0].skeleton.id=0;
662   player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
663                           ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
664                           ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
665                           ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
666                           ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
667                           ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
668   game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
669                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
670   player[0].creature=rabbittype;
671   player[0].scale=.2;
672   player[0].headless=0;
673   player[0].damagetolerance=200;
674   set_proportion(0, "1 1 1 1");
675 }
676
677 static void ch_wolfie(Game *game, const char *args)
678 {
679   player[0].skeleton.id=0;
680   player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
681                           ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
682                           ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
683                           ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
684                           ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
685                           ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
686   game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
687                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
688   player[0].creature=wolftype;
689   player[0].damagetolerance=300;
690   set_proportion(0, "1 1 1 1");
691 }
692
693 static void ch_wolfieisgod(Game *game, const char *args)
694 {
695   ch_wolfie(game, args);
696 }
697
698 static void ch_wolf(Game *game, const char *args)
699 {
700   game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
701                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
702 }
703
704 static void ch_snowwolf(Game *game, const char *args)
705 {
706   game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
707                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
708 }
709
710 static void ch_darkwolf(Game *game, const char *args)
711 {
712   game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
713                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
714 }
715
716 static void ch_lizardwolf(Game *game, const char *args)
717 {
718   game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
719                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
720 }
721
722 static void ch_white(Game *game, const char *args)
723 {
724   game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
725                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
726 }
727
728 static void ch_brown(Game *game, const char *args)
729 {
730   game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
731                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
732 }
733
734 static void ch_black(Game *game, const char *args)
735 {
736   game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
737                         &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
738 }
739
740 static void ch_sizemin(Game *game, const char *args)
741 {
742   int i;
743   for (i = 1; i < numplayers; i++)
744     if (player[i].scale < 0.8 * 0.2)
745       player[i].scale = 0.8 * 0.2;
746 }
747
748 static void ch_tutorial(Game *game, const char *args)
749 {
750   tutoriallevel = atoi(args);
751 }
752
753 static void ch_hostile(Game *game, const char *args)
754 {
755   hostile = atoi(args);
756 }
757
758 static void ch_indemo(Game *game, const char *args)
759 {
760   game->indemo=1;
761   hotspot[numhotspots]=player[0].coords;
762   hotspotsize[numhotspots]=0;
763   hotspottype[numhotspots]=-111;
764   strcpy(hotspottext[numhotspots],"mapname");
765   numhotspots++;
766 }
767
768 static void ch_notindemo(Game *game, const char *args)
769 {
770   game->indemo=0;
771   numhotspots--;
772 }
773
774 static void ch_type(Game *game, const char *args)
775 {
776   int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]);
777         for (i = 0; i < n; i++)
778                 if (stripfx(args, editortypenames[i])) {
779                         editoractive = i;
780                         break;
781                 }
782 }
783
784 static void ch_path(Game *game, const char *args)
785 {
786   int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
787   for (i = 0; i < n; i++)
788     if (stripfx(args, pathtypenames[i])) {
789                 editorpathtype = i;
790                 break;
791     }
792 }
793
794 static void ch_hs(Game *game, const char *args)
795 {
796   hotspot[numhotspots]=player[0].coords;
797
798   float size;
799   int type, shift;
800   sscanf(args, "%f%d %n", &size, &type, &shift);
801
802   hotspotsize[numhotspots] = size;
803   hotspottype[numhotspots] = type;
804
805   strcpy(hotspottext[numhotspots], args + shift);
806   strcat(hotspottext[numhotspots], "\n");
807
808   numhotspots++;
809 }
810
811 static void ch_dialogue(Game *game, const char *args)
812 {
813   int dlg, i, j;
814   char buf1[32], buf2[64];
815
816   sscanf(args, "%d %31s", &dlg, buf1);
817   snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
818
819   dialoguetype[numdialogues] = dlg;
820
821   memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
822   memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
823
824   ifstream ipstream(ConvertFileName(buf2));
825   ipstream.ignore(256,':');
826   ipstream >> numdialogueboxes[numdialogues];
827   for(i=0;i<numdialogueboxes[numdialogues];i++){
828     ipstream.ignore(256,':');
829     ipstream.ignore(256,':');
830     ipstream.ignore(256,' ');
831     ipstream >> dialogueboxlocation[numdialogues][i];
832     ipstream.ignore(256,':');
833     ipstream >> dialogueboxcolor[numdialogues][i][0];
834     ipstream >> dialogueboxcolor[numdialogues][i][1];
835     ipstream >> dialogueboxcolor[numdialogues][i][2];
836     ipstream.ignore(256,':');
837     ipstream.getline(dialoguename[numdialogues][i],64);
838     ipstream.ignore(256,':');
839     ipstream.ignore(256,' ');
840     ipstream.getline(dialoguetext[numdialogues][i],128);
841     for(j=0;j<128;j++){
842       if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
843     }
844     ipstream.ignore(256,':');
845     ipstream >> dialogueboxsound[numdialogues][i];
846   }
847
848   for(i=0;i<numdialogueboxes[numdialogues];i++){
849     for(j=0;j<numplayers;j++){
850       participantfacing[numdialogues][i][j]=player[j].facing;
851     }
852   }
853   ipstream.close();
854
855   directing=1;
856   indialogue=0;
857   whichdialogue=numdialogues;
858
859   numdialogues++;
860 }
861
862 static void ch_fixdialogue(Game *game, const char *args)
863 {
864   char buf1[32], buf2[64];
865   int whichdi, i, j;
866
867   sscanf(args, "%d %31s", &whichdi, buf1);
868   snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
869
870   memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
871   memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
872
873   ifstream ipstream(ConvertFileName(buf2));
874   ipstream.ignore(256,':');
875   ipstream >> numdialogueboxes[whichdi];
876   for(i=0;i<numdialogueboxes[whichdi];i++){
877     ipstream.ignore(256,':');
878     ipstream.ignore(256,':');
879     ipstream.ignore(256,' ');
880     ipstream >> dialogueboxlocation[whichdi][i];
881     ipstream.ignore(256,':');
882     ipstream >> dialogueboxcolor[whichdi][i][0];
883     ipstream >> dialogueboxcolor[whichdi][i][1];
884     ipstream >> dialogueboxcolor[whichdi][i][2];
885     ipstream.ignore(256,':');
886     ipstream.getline(dialoguename[whichdi][i],64);
887     ipstream.ignore(256,':');
888     ipstream.ignore(256,' ');
889     ipstream.getline(dialoguetext[whichdi][i],128);
890     for(j=0;j<128;j++){
891       if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
892     }
893     ipstream.ignore(256,':');
894     ipstream >> dialogueboxsound[whichdi][i];
895   }
896
897   ipstream.close();
898 }
899
900 static void ch_fixtype(Game *game, const char *args)
901 {
902   int dlg;
903   sscanf(args, "%d", &dlg);
904   dialoguetype[0] = dlg;
905 }
906
907 static void ch_fixrotation(Game *game, const char *args)
908 {
909   participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
910 }
911
912 static void ch_ddialogue(Game *game, const char *args)
913 {
914   if (numdialogues)
915     numdialogues--;
916 }
917
918 static void ch_dhs(Game *game, const char *args)
919 {
920   if (numhotspots)
921     numhotspots--;
922 }
923
924 static void ch_immobile(Game *game, const char *args)
925 {
926   player[0].immobile = 1;
927 }
928
929 static void ch_allimmobile(Game *game, const char *args)
930 {
931   for (int i = 1; i < numplayers; i++)
932     player[i].immobile = 1;
933 }
934
935 static void ch_mobile(Game *game, const char *args)
936 {
937   player[0].immobile = 0;
938 }
939
940 static void ch_default(Game *game, const char *args)
941 {
942   player[0].armorhead=1;
943   player[0].armorhigh=1;
944   player[0].armorlow=1;
945   player[0].protectionhead=1;
946   player[0].protectionhigh=1;
947   player[0].protectionlow=1;
948   player[0].metalhead=1;
949   player[0].metalhigh=1;
950   player[0].metallow=1;
951   player[0].power=1;
952   player[0].speedmult=1;
953   player[0].scale=1;
954
955   if(player[0].creature==wolftype){
956     player[0].proportionhead=1.1;
957     player[0].proportionbody=1.1;
958     player[0].proportionarms=1.1;
959     player[0].proportionlegs=1.1;
960   } else if(player[0].creature==rabbittype){
961     player[0].proportionhead=1.2;
962     player[0].proportionbody=1.05;
963     player[0].proportionarms=1.00;
964     player[0].proportionlegs=1.1;
965     player[0].proportionlegs.y=1.05;
966   }
967
968   player[0].numclothes=0;
969   game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
970                         &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
971                         &player[0].skeleton.skinsize);
972
973   editoractive=typeactive;
974   player[0].immobile=0;
975 }
976
977 static void ch_play(Game *game, const char *args)
978 {
979   int dlg, i;
980   sscanf(args, "%d", &dlg);
981   whichdialogue = dlg;
982
983   if (whichdialogue >= numdialogues)
984     return;
985
986   for(i=0;i<numdialogueboxes[whichdialogue];i++){
987     player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
988     player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
989     player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
990     player[participantfocus[whichdialogue][i]].velocity=0;
991     player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
992     player[participantfocus[whichdialogue][i]].targetframe=0;
993   }
994
995   directing=0;
996   indialogue=0;
997
998   float gLoc[3];
999   float vel[3];
1000   XYZ temppos;
1001   temppos=player[participantfocus[whichdialogue][indialogue]].coords;
1002   temppos=temppos-viewer;
1003   Normalise(&temppos);
1004   temppos+=viewer;
1005
1006   gLoc[0]=temppos.x;
1007   gLoc[1]=temppos.y;
1008   gLoc[2]=temppos.z;
1009   vel[0]=0;
1010   vel[1]=0;
1011   vel[2]=0;
1012   int whichsoundplay;
1013   whichsoundplay=rabbitchitter;
1014   if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
1015   if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
1016   if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
1017   if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
1018   if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
1019   if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
1020   if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
1021   if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
1022   if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
1023   if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
1024   if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
1025   if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
1026   if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
1027   if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
1028   if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
1029   if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
1030   if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
1031   if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
1032   if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
1033   PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
1034   OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
1035   OPENAL_SetVolume(channels[whichsoundplay], 256);
1036   OPENAL_SetPaused(channels[whichsoundplay], false);
1037 }
1038
1039 static void ch_mapkilleveryone(Game *game, const char *args)
1040 {
1041   maptype = mapkilleveryone;
1042 }
1043
1044 static void ch_mapkillmost(Game *game, const char *args)
1045 {
1046   maptype = mapkillmost;
1047 }
1048
1049 static void ch_mapkillsomeone(Game *game, const char *args)
1050 {
1051   maptype = mapkillsomeone;
1052 }
1053
1054 static void ch_mapgosomewhere(Game *game, const char *args)
1055 {
1056   maptype = mapgosomewhere;
1057 }
1058
1059 static void ch_viewdistance(Game *game, const char *args)
1060 {
1061   viewdistance = atof(args)*100;
1062 }
1063
1064 static void ch_fadestart(Game *game, const char *args)
1065 {
1066   fadestart = atof(args);
1067 }
1068
1069 static void ch_slomo(Game *game, const char *args)
1070 {
1071   slomospeed = atof(args);
1072   slomo = !slomo;
1073   slomodelay = 1000;
1074 }
1075
1076 static void ch_slofreq(Game *game, const char *args)
1077 {
1078   slomofreq = atof(args);
1079 }
1080
1081 static void ch_skytint(Game *game, const char *args)
1082 {
1083   sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1084
1085   skyboxlightr=skyboxr;
1086   skyboxlightg=skyboxg;
1087   skyboxlightb=skyboxb;
1088
1089   game->SetUpLighting();
1090
1091   terrain.DoShadows();
1092   objects.DoShadows();
1093 }
1094
1095 static void ch_skylight(Game *game, const char *args)
1096 {
1097   sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1098
1099   game->SetUpLighting();
1100
1101   terrain.DoShadows();
1102   objects.DoShadows();
1103 }
1104
1105 static void ch_skybox(Game *game, const char *args)
1106 {
1107   skyboxtexture = !skyboxtexture;
1108
1109   game->SetUpLighting();
1110
1111   terrain.DoShadows();
1112   objects.DoShadows();
1113 }
1114
1115 static void cmd_dispatch(Game *game, const char *cmd)
1116 {
1117   int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1118
1119   for (i = 0; i < n_cmds; i++)
1120     if (stripfx(cmd, cmd_names[i]))
1121       {
1122         cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
1123         break;
1124       }
1125   if (i < n_cmds)
1126     {
1127       PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true);
1128       OPENAL_SetVolume(channels[consolesuccesssound], 256);
1129       OPENAL_SetPaused(channels[consolesuccesssound], false);
1130     }
1131   else
1132     {
1133       PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true);
1134       OPENAL_SetVolume(channels[consolefailsound], 256);
1135       OPENAL_SetPaused(channels[consolefailsound], false);
1136     }
1137 }
1138
1139 /********************> Tick() <*****/
1140 extern bool save_image(const char * fname);
1141 void Screenshot (void)
1142 {
1143         char temp[1024];
1144         time_t  t = time(NULL);
1145         struct  tm *tme = localtime(&t);
1146         sprintf(temp, "Screenshots/Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
1147
1148         #if defined(_WIN32)
1149         mkdir("Screenshots");
1150         #else
1151         mkdir("Screenshots", S_IRWXU);
1152         #endif
1153         
1154         save_image(temp);
1155 }
1156
1157
1158
1159 void    Game::SetUpLighting(){
1160         if(environment==snowyenvironment){
1161                 light.color[0]=.65;
1162                 light.color[1]=.65;
1163                 light.color[2]=.7;
1164                 light.ambient[0]=.4;
1165                 light.ambient[1]=.4;
1166                 light.ambient[2]=.44;
1167         }
1168         if(environment==desertenvironment){
1169                 light.color[0]=.95;
1170                 light.color[1]=.95;
1171                 light.color[2]=.95;
1172                 light.ambient[0]=.4;
1173                 light.ambient[1]=.35;
1174                 light.ambient[2]=.3;
1175         }
1176
1177         if(environment==grassyenvironment){
1178                 light.color[0]=.95;
1179                 light.color[1]=.95;
1180                 light.color[2]=1;
1181                 light.ambient[0]=.4;
1182                 light.ambient[1]=.4;
1183                 light.ambient[2]=.44;
1184         }
1185         if(!skyboxtexture){
1186                 light.color[0]=1;
1187                 light.color[1]=1;
1188                 light.color[2]=1;
1189                 light.ambient[0]=.4;
1190                 light.ambient[1]=.4;
1191                 light.ambient[2]=.4;
1192         }
1193         float average;
1194         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1195         light.color[0]*=(skyboxlightr+average)/2;
1196         light.color[1]*=(skyboxlightg+average)/2;
1197         light.color[2]*=(skyboxlightb+average)/2;
1198         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
1199         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
1200         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
1201         /*
1202         light.ambient[0]=0;
1203         light.ambient[1]=0;
1204         light.ambient[2]=0;     */
1205 }
1206
1207 int Game::findPathDist(int start,int end){
1208         int i,j,k,smallestcount,count,connected;
1209         int last,last2,last3,last4;
1210         int closest;
1211
1212         smallestcount=1000;
1213         for(i=0;i<50;i++){
1214                 count=0;
1215                 last=start;
1216                 last2=-1;
1217                 last3=-1;
1218                 last4=-1;
1219                 while(last!=end&&count<30){
1220                         closest=-1;
1221                         for(j=0;j<numpathpoints;j++){
1222                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1223                                 {
1224                                         connected=0;
1225                                         if(numpathpointconnect[j])
1226                                                 for(k=0;k<numpathpointconnect[j];k++){
1227                                                         if(pathpointconnect[j][k]==last)connected=1;
1228                                                 }
1229                                                 if(!connected)
1230                                                         if(numpathpointconnect[last])
1231                                                                 for(k=0;k<numpathpointconnect[last];k++){
1232                                                                         if(pathpointconnect[last][k]==j)connected=1;
1233                                                                 }
1234                                                                 if(connected)
1235                                                                         if(closest==-1||Random()%2==0){
1236                                                                                 closest=j;
1237                                                                         }
1238                                 }
1239                         }
1240                         last4=last3;
1241                         last3=last2;
1242                         last2=last;
1243                         last=closest;
1244                         count++;
1245                 }
1246                 if(count<smallestcount)smallestcount=count;
1247         }
1248         return smallestcount;
1249 }
1250
1251 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1252         static XYZ colpoint,colviewer,coltarget;
1253         static float minx,minz,maxx,maxz,miny,maxy;
1254         static int i;
1255
1256         //startpoint.y+=.7;
1257         //endpoint.y+=.7;
1258         //startpoint.y-=.1;
1259         //endpoint.y-=.1;
1260
1261         minx=startpoint.x;
1262         if(minx>endpoint.x)minx=endpoint.x;
1263         miny=startpoint.y;
1264         if(miny>endpoint.y)miny=endpoint.y;
1265         minz=startpoint.z;
1266         if(minz>endpoint.z)minz=endpoint.z;
1267
1268         maxx=startpoint.x;
1269         if(maxx<endpoint.x)maxx=endpoint.x;
1270         maxy=startpoint.y;
1271         if(maxy<endpoint.y)maxy=endpoint.y;
1272         maxz=startpoint.z;
1273         if(maxz<endpoint.z)maxz=endpoint.z;
1274
1275         minx-=1;
1276         miny-=1;
1277         minz-=1;
1278         maxx+=1;
1279         maxy+=1;
1280         maxz+=1;
1281
1282         for(i=0;i<objects.numobjects;i++){
1283                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1284                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
1285                                 colviewer=startpoint;
1286                                 coltarget=endpoint;
1287                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1288                         }
1289                 }
1290         }
1291
1292         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1293
1294         return -1;
1295 }
1296
1297 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1298         static XYZ colpoint,colviewer,coltarget;
1299         static float minx,minz,maxx,maxz,miny,maxy;
1300         static int i;
1301
1302         //startpoint.y+=.7;
1303         //endpoint.y+=.7;
1304         //startpoint.y-=.1;
1305         //endpoint.y-=.1;
1306
1307         minx=startpoint.x;
1308         if(minx>endpoint.x)minx=endpoint.x;
1309         miny=startpoint.y;
1310         if(miny>endpoint.y)miny=endpoint.y;
1311         minz=startpoint.z;
1312         if(minz>endpoint.z)minz=endpoint.z;
1313
1314         maxx=startpoint.x;
1315         if(maxx<endpoint.x)maxx=endpoint.x;
1316         maxy=startpoint.y;
1317         if(maxy<endpoint.y)maxy=endpoint.y;
1318         maxz=startpoint.z;
1319         if(maxz<endpoint.z)maxz=endpoint.z;
1320
1321         minx-=1;
1322         miny-=1;
1323         minz-=1;
1324         maxx+=1;
1325         maxy+=1;
1326         maxz+=1;
1327
1328         if(what!=1000){
1329                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1330                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
1331                                 colviewer=startpoint;
1332                                 coltarget=endpoint;
1333                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1334                         }
1335                 }
1336         }
1337
1338         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1339
1340         return -1;
1341 }
1342
1343 void    Game::Setenvironment(int which)
1344 {
1345         LOGFUNC;
1346
1347         LOG(" Setting environment...");
1348
1349         float temptexdetail;
1350         environment=which;
1351 /*
1352         OPENAL_SetPaused(channels[music1snow], true);
1353         OPENAL_SetPaused(channels[music1grass], true);
1354         OPENAL_SetPaused(channels[music1desert], true);
1355         OPENAL_SetPaused(channels[wind], true);
1356         OPENAL_SetPaused(channels[desertambient], true);
1357 */
1358         OPENAL_SetPaused(channels[stream_music1snow], true);
1359         OPENAL_SetPaused(channels[stream_music1grass], true);
1360         OPENAL_SetPaused(channels[stream_music1desert], true);
1361         OPENAL_SetPaused(channels[stream_wind], true);
1362         OPENAL_SetPaused(channels[stream_desertambient], true);
1363
1364
1365         if(environment==snowyenvironment){
1366                 windvector=0;
1367                 windvector.z=3;
1368                 if(ambientsound){
1369                         //PlaySoundEx( wind, samp[wind], NULL, true);
1370                         PlayStreamEx(stream_wind, samp[stream_wind], 0, true);
1371                         OPENAL_SetPaused(channels[stream_wind], false);
1372                         OPENAL_SetVolume(channels[stream_wind], 256);
1373                 }
1374
1375                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1376                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1377                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1378                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1379
1380                 footstepsound = footstepsn1;
1381                 footstepsound2 = footstepsn2;
1382                 footstepsound3 = footstepst1;
1383                 footstepsound4 = footstepst2;
1384
1385                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1386
1387                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1388
1389                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1390
1391
1392
1393
1394                 temptexdetail=texdetail;
1395                 if(texdetail>1)texdetail=4;
1396                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
1397                         ":Data:Textures:Skybox(snow):Left.jpg",
1398                         ":Data:Textures:Skybox(snow):Back.jpg",
1399                         ":Data:Textures:Skybox(snow):Right.jpg",
1400                         ":Data:Textures:Skybox(snow):Up.jpg",
1401                         ":Data:Textures:Skybox(snow):Down.jpg",
1402                         ":Data:Textures:Skybox(snow):Cloud.jpg",
1403                         ":Data:Textures:Skybox(snow):Reflect.jpg");
1404
1405
1406
1407
1408                 texdetail=temptexdetail;
1409         }
1410         if(environment==desertenvironment){
1411                 windvector=0;
1412                 windvector.z=2;
1413                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1414                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1415                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1416                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1417
1418
1419                 if(ambientsound){
1420                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
1421                         PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true);
1422                         OPENAL_SetPaused(channels[stream_desertambient], false);
1423                         OPENAL_SetVolume(channels[stream_desertambient], 256);
1424                 }
1425
1426                 footstepsound = footstepsn1;
1427                 footstepsound2 = footstepsn2;
1428                 footstepsound3 = footstepsn1;
1429                 footstepsound4 = footstepsn2;
1430
1431                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1432
1433                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1434
1435                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1436
1437
1438
1439                 temptexdetail=texdetail;
1440                 if(texdetail>1)texdetail=4;
1441                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
1442                         ":Data:Textures:Skybox(sand):Left.jpg",
1443                         ":Data:Textures:Skybox(sand):Back.jpg",
1444                         ":Data:Textures:Skybox(sand):Right.jpg",
1445                         ":Data:Textures:Skybox(sand):Up.jpg",
1446                         ":Data:Textures:Skybox(sand):Down.jpg",
1447                         ":Data:Textures:Skybox(sand):Cloud.jpg",
1448                         ":Data:Textures:Skybox(sand):Reflect.jpg");
1449
1450
1451
1452
1453                 texdetail=temptexdetail;
1454         }
1455         if(environment==grassyenvironment){
1456                 windvector=0;
1457                 windvector.z=2;
1458                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1459                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1460                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1461                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1462
1463                 if(ambientsound){
1464                         PlayStreamEx( stream_wind, samp[stream_wind], NULL, true);
1465                         OPENAL_SetPaused(channels[stream_wind], false);
1466                         OPENAL_SetVolume(channels[stream_wind], 100);
1467                 }
1468
1469                 footstepsound = footstepgr1;
1470                 footstepsound2 = footstepgr2;
1471                 footstepsound3 = footstepst1;
1472                 footstepsound4 = footstepst2;
1473
1474                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1475
1476                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1477
1478                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1479
1480
1481
1482                 temptexdetail=texdetail;
1483                 if(texdetail>1)texdetail=4;
1484                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
1485                         ":Data:Textures:Skybox(grass):Left.jpg",
1486                         ":Data:Textures:Skybox(grass):Back.jpg",
1487                         ":Data:Textures:Skybox(grass):Right.jpg",
1488                         ":Data:Textures:Skybox(grass):Up.jpg",
1489                         ":Data:Textures:Skybox(grass):Down.jpg",
1490                         ":Data:Textures:Skybox(grass):Cloud.jpg",
1491                         ":Data:Textures:Skybox(grass):Reflect.jpg");
1492
1493
1494
1495                 texdetail=temptexdetail;
1496         }
1497         temptexdetail=texdetail;
1498         texdetail=1;
1499         terrain.load(":Data:Textures:heightmap.png");
1500
1501         texdetail=temptexdetail;
1502 }
1503
1504
1505 void    Game::Loadlevel(int which){
1506         stealthloading=0;
1507
1508         if(which==0)Loadlevel((char *)":Data:Maps:map1");
1509         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
1510         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
1511         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
1512         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
1513         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
1514         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
1515         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
1516         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
1517         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
1518         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
1519         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
1520         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
1521         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
1522         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
1523         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
1524         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
1525         else Loadlevel((char *)":Data:Maps:mapsave");
1526
1527         whichlevel=which;
1528 }
1529
1530 void    Game::Loadlevel(char *name){
1531         int i,j,k,l,m;
1532         static int oldlevel;
1533         int templength;
1534         float lamefloat;
1535         int lameint;
1536
1537         float headprop,legprop,armprop,bodyprop;
1538
1539         LOGFUNC;
1540
1541         LOG(std::string("Loading level...") + name);
1542
1543         if(!gameon)visibleloading=1;
1544
1545         if(stealthloading)visibleloading=0;
1546
1547         if(!stillloading)loadtime=0;
1548         gamestarted=1;
1549
1550         numenvsounds=0;
1551         //visibleloading=1;
1552         if(tutoriallevel!=-1)tutoriallevel=0;
1553         else tutoriallevel=1;
1554
1555         if(tutoriallevel==1)tutorialstage=0;
1556         if(tutorialstage==0){
1557                 tutorialstagetime=0;
1558                 tutorialmaxtime=1;
1559         }
1560         loadingstuff=1;
1561         if(!firstload){
1562                 oldlevel=50;
1563         }
1564         OPENAL_SetPaused(channels[whooshsound], true);
1565         OPENAL_SetPaused(channels[stream_firesound], true);
1566
1567         // Change the map filename into something that is os specific
1568         char *FixedFN = ConvertFileName(name);
1569
1570         int mapvers;
1571         FILE                    *tfile;
1572         tfile=fopen( FixedFN, "rb" );
1573         if(tfile)
1574         {
1575                 OPENAL_SetPaused(channels[stream_firesound], true);
1576
1577
1578                 scoreadded=0;
1579                 windialogue=0;
1580
1581                 hostiletime=0;
1582
1583                 won=0;
1584
1585                 //campaign=0;
1586                 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1587
1588                 numdialogues=0;
1589
1590                 for(i=0;i<20;i++)
1591                 {
1592                         dialoguegonethrough[i]=0;
1593                 }
1594
1595                 indialogue=-1;
1596                 cameramode=0;
1597
1598                 damagedealt=0;
1599                 damagetaken=0;
1600
1601                 if(accountactive)difficulty=accountactive->getDifficulty();
1602
1603                 if(difficulty!=2)minimap=1;
1604                 else minimap=0;
1605
1606                 numhotspots=0;
1607                 currenthotspot=-1;
1608                 bonustime=1;
1609
1610                 skyboxtexture=1;
1611                 skyboxr=1;
1612                 skyboxg=1;
1613                 skyboxb=1;
1614
1615                 freeze=0;
1616                 winfreeze=0;
1617
1618                 for(i=0;i<100;i++)
1619                 {
1620                         bonusnum[i]=0;
1621                 }
1622
1623                 numfalls=0;
1624                 numflipfail=0;
1625                 numseen=0;
1626                 numstaffattack=0;
1627                 numswordattack=0;
1628                 numknifeattack=0;
1629                 numunarmedattack=0;
1630                 numescaped=0;
1631                 numflipped=0;
1632                 numwallflipped=0;
1633                 numthrowkill=0;
1634                 numafterkill=0;
1635                 numreversals=0;
1636                 numattacks=0;
1637                 maxalarmed=0;
1638                 numresponded=0;
1639
1640                 bonustotal=startbonustotal;
1641                 bonus=0;
1642                 gameon=1;
1643                 changedelay=0;
1644                 if(console)
1645                 {
1646                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1647                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
1648                         OPENAL_SetPaused(channels[consolesuccesssound], false);
1649                         freeze=0;
1650                         console=0;
1651                 }
1652
1653                 if(!stealthloading)
1654                 {
1655                         terrain.numdecals=0;
1656                         Sprite::deleteSprites();
1657                         for(i=0;i<objects.numobjects;i++)
1658                         {
1659                                 objects.model[i].numdecals=0;
1660                         }
1661
1662                         j=objects.numobjects;
1663                         for(i=0;i<j;i++)
1664                         {
1665                                 objects.DeleteObject(0);
1666                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1667                         }
1668
1669                         for(i=0;i<subdivision;i++)
1670                         {
1671                                 for(j=0;j<subdivision;j++)
1672                                 {
1673                                         terrain.patchobjectnum[i][j]=0;
1674                                 }
1675                         }
1676                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1677                 }
1678
1679                 weapons.numweapons=0;
1680
1681                 funpackf(tfile, "Bi", &mapvers);
1682                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1683                 else indemo=0;
1684                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1685                 else maptype=mapkilleveryone;
1686                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1687                 else hostile=1;
1688                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1689                 else
1690                 {
1691                         viewdistance=100;
1692                         fadestart=.6;
1693                 }
1694                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1695                 else
1696                 {
1697                         skyboxtexture=1;
1698                         skyboxr=1;
1699                         skyboxg=1;
1700                         skyboxb=1;
1701                 }
1702                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1703                 else
1704                 {
1705                         skyboxlightr=skyboxr;
1706                         skyboxlightg=skyboxg;
1707                         skyboxlightb=skyboxb;
1708                 }
1709                 if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
1710                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1711                 player[0].originalcoords=player[0].coords;
1712                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1713                 {
1714                         for(j=0;j<player[0].num_weapons;j++)
1715                         {
1716                                 player[0].weaponids[j]=weapons.numweapons;
1717                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1718                                 weapons.owner[weapons.numweapons]=0;
1719                                 weapons.numweapons++;
1720                         }
1721                 }
1722
1723                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1724
1725                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1726                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1727                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1728                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1729
1730                 funpackf(tfile, "Bi", &player[0].numclothes);
1731
1732                 if(mapvers>=9)
1733                 {
1734                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1735                 }
1736                 else
1737                 {
1738                         player[0].whichskin=0;
1739                         player[0].creature=rabbittype;
1740                 }
1741
1742                 for(i=0;i<max_dialogues;i++)
1743                 {
1744                         for(j=0;j<max_dialoguelength;j++)
1745                         {
1746                                 for(k=0;k<128;k++)
1747                                 {
1748                                         dialoguetext[i][j][k]='\0';
1749                                 }
1750                                 for(k=0;k<64;k++)
1751                                 {
1752                                         dialoguename[i][j][k]='\0';
1753                                 }
1754                         }
1755                 }
1756
1757                 player[0].lastattack=-1;
1758                 player[0].lastattack2=-1;
1759                 player[0].lastattack3=-1;
1760
1761                 if(mapvers>=8)
1762                 {
1763                         funpackf(tfile, "Bi", &numdialogues);
1764                         if(numdialogues)
1765                         {
1766                                 for(k=0;k<numdialogues;k++)
1767                                 {
1768                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1769                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1770                                         for(l=0;l<10;l++)
1771                                         {
1772                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1773                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1774                                         }
1775                                         if(numdialogueboxes)
1776                                         {
1777                                                 for(l=0;l<numdialogueboxes[k];l++)
1778                                                 {
1779                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1780                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1781                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1782                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1783                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1784
1785                                                         bool doneread;
1786
1787                                                         funpackf(tfile, "Bi",&templength);
1788                                                         if(templength>128||templength<=0)templength=128;
1789                                                         for(m=0;m<templength;m++){
1790                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1791                                                                 if(dialoguetext[k][l][m]=='\0')break;
1792                                                         }
1793
1794                                                         funpackf(tfile, "Bi",&templength);
1795                                                         if(templength>64||templength<=0)templength=64;
1796                                                         for(m=0;m<templength;m++){
1797                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1798                                                                 if(dialoguename[k][l][m]=='\0'){
1799                                                                         break;
1800                                                                 }
1801                                                         }
1802                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1803                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1804                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1805
1806                                                         for(m=0;m<10;m++)
1807                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1808
1809                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1810                                                 }
1811                                         }
1812                                 }
1813                         }
1814                 }
1815                 else numdialogues=0;
1816
1817                 if(player[0].numclothes)
1818                 {
1819                         for(k=0;k<player[0].numclothes;k++)
1820                         {
1821                                 funpackf(tfile, "Bi", &templength);
1822                                 for(l=0;l<templength;l++)
1823                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1824                                 player[0].clothes[k][templength]='\0';
1825                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1826                         }
1827                 }
1828
1829                 funpackf(tfile, "Bi", &environment);
1830
1831                 funpackf(tfile, "Bi", &objects.numobjects);
1832                 if(objects.numobjects)
1833                 {
1834                         for(i=0;i<objects.numobjects;i++)
1835                         {
1836                                 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1837                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1838                         }
1839                 }
1840
1841                 if(mapvers>=7)
1842                 {
1843                         funpackf(tfile, "Bi", &numhotspots);
1844                         if(numhotspots)
1845                         {
1846                                 for(i=0;i<numhotspots;i++)
1847                                 {
1848                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1849                                         funpackf(tfile, "Bi", &templength);
1850                                         if(templength)
1851                                                 for(l=0;l<templength;l++)
1852                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1853                                         hotspottext[i][templength]='\0';
1854                                         if(hotspottype[i]==-111)indemo=1;
1855                                 }
1856                         }
1857                 }
1858                 else numhotspots=0;
1859
1860                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1861
1862                 if(!stealthloading)
1863                 {
1864                         objects.center=0;
1865                         for(i=0;i<objects.numobjects;i++)
1866                         {
1867                                 objects.center+=objects.position[i];
1868                         }
1869                         objects.center/=objects.numobjects;
1870
1871
1872                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1873
1874                         float maxdistance=0;
1875                         float tempdist;
1876                         int whichclosest;
1877                         for(i=0;i<objects.numobjects;i++)
1878                         {
1879                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1880                                 if(tempdist>maxdistance)
1881                                 {
1882                                         whichclosest=i;
1883                                         maxdistance=tempdist;
1884                                 }
1885                         }
1886                         objects.radius=fast_sqrt(maxdistance);
1887                 }
1888
1889                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1890                 //mapcenter=objects.center;
1891                 //mapradius=objects.radius;
1892
1893                 funpackf(tfile, "Bi", &numplayers);
1894                 int howmanyremoved=0;
1895                 bool removeanother=0;
1896                 if(numplayers>1&&numplayers<maxplayers)
1897                 {
1898                         for(i=1;i<numplayers;i++)
1899                         {
1900                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1901                                 removeanother=0;
1902
1903                                 funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
1904                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1905                                 else player[i-howmanyremoved].howactive=typeactive;
1906                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1907                                 else player[i-howmanyremoved].scale=-1;
1908                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1909                                 else player[i-howmanyremoved].immobile=0;
1910                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1911                                 else player[i-howmanyremoved].rotation=0;
1912                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1913                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1914                                         removeanother=1;
1915                                         howmanyremoved++;
1916                                 }
1917                                 if(!removeanother)
1918                                 {
1919                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1920                                         {
1921                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1922                                                 {
1923                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1924                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1925                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1926                                                         weapons.numweapons++;
1927                                                 }
1928                                         }
1929                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1930                                         //player[i-howmanyremoved].numwaypoints=10;
1931                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1932                                         {
1933                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1934                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1935                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1936                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1937                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1938                                         }
1939
1940                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1941                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1942
1943                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1944                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1945                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1946                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1947
1948                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1949                                         else
1950                                         {
1951                                                 headprop=1;
1952                                                 bodyprop=1;
1953                                                 armprop=1;
1954                                                 legprop=1;
1955                                         }
1956                                         if(player[i-howmanyremoved].creature==wolftype)
1957                                         {
1958                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1959                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1960                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1961                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1962                                         }
1963
1964                                         if(player[i-howmanyremoved].creature==rabbittype)
1965                                         {
1966                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1967                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1968                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1969                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1970                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1971                                         }
1972
1973                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1974                                         if(player[i-howmanyremoved].numclothes)
1975                                         {
1976                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1977                                                 {
1978                                                         int templength;
1979                                                         funpackf(tfile, "Bi", &templength);
1980                                                         for(l=0;l<templength;l++)
1981                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1982                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1983                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1984                                                 }
1985                                         }
1986                                 }
1987                         }
1988                 }
1989                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1990
1991                 numplayers-=howmanyremoved;
1992                 funpackf(tfile, "Bi", &numpathpoints);
1993                 if(numpathpoints>30||numpathpoints<0)
1994                         numpathpoints=0;
1995                 if(numpathpoints)
1996                 {
1997                         for(j=0;j<numpathpoints;j++)
1998                         {
1999                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
2000                                 for(k=0;k<numpathpointconnect[j];k++){
2001                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
2002                                 }
2003                         }
2004                 }
2005                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2006
2007                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
2008
2009                 SetUpLighting();
2010                 if(environment!=oldenvironment)Setenvironment(environment);
2011                 oldenvironment=environment;
2012
2013                 if(!stealthloading)
2014                 {
2015                         j=objects.numobjects;
2016                         objects.numobjects=0;
2017                         for(i=0;i<j;i++)
2018                         {
2019                                 //if(objects.type[i]!=spiketype)
2020                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
2021                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2022                         }
2023
2024                         //if(skyboxtexture){
2025                         terrain.DoShadows();
2026                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
2027                         objects.DoShadows();
2028                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
2029                         /*}
2030                         else terrain.DoLighting();
2031                         */
2032                 }
2033
2034                 fclose(tfile);
2035
2036                 oldlevel=whichlevel;
2037
2038
2039                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
2040                 for(i=0;i<numplayers;i++)
2041                 {
2042                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
2043                         player[i].burnt=0;
2044                         player[i].bled=0;
2045                         player[i].onfire=0;
2046                         if(i==0||player[i].scale<0)player[i].scale=.2;
2047                         player[i].skeleton.free=0;
2048                         player[i].skeleton.id=i;
2049                         //if(Random()%2==0)player[i].creature=wolftype;
2050                         //else player[i].creature=rabbittype;
2051                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
2052                         if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
2053                         else
2054                         {
2055                                 if(player[i].creature!=wolftype){
2056                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
2057                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
2058                                 }
2059                                 if(player[i].creature==wolftype){
2060                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
2061                                 }
2062                         }
2063
2064
2065                         int texsize;
2066                         texsize=512*512*3/texdetail/texdetail;
2067                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
2068                         //player[i].skeleton.skinText.resize(texsize);
2069
2070                         LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2071
2072                         if(player[i].numclothes)
2073                         {
2074                                 for(j=0;j<player[i].numclothes;j++)
2075                                 {
2076                                         tintr=player[i].clothestintr[j];
2077                                         tintg=player[i].clothestintg[j];
2078                                         tintb=player[i].clothestintb[j];
2079                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2080                                 }
2081                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
2082                         }
2083
2084                         player[i].currentanimation=bounceidleanim;
2085                         player[i].targetanimation=bounceidleanim;
2086                         player[i].currentframe=0;
2087                         player[i].targetframe=1;
2088                         player[i].target=0;
2089                         player[i].speed=1+(float)(Random()%100)/1000;
2090                         if(difficulty==0)player[i].speed-=.2;
2091                         if(difficulty==1)player[i].speed-=.1;
2092
2093                         player[i].velocity=0;
2094                         player[i].oldcoords=player[i].coords;
2095                         player[i].realoldcoords=player[i].coords;
2096
2097                         player[i].id=i;
2098                         player[i].skeleton.id=i;
2099                         player[i].updatedelay=0;
2100                         player[i].normalsupdatedelay=0;
2101
2102                         player[i].aitype=passivetype;
2103                         player[i].aitarget=0;
2104                         player[i].madskills=0;
2105
2106                         if(i==0)
2107                         {
2108                                 player[i].proportionhead=1.2;
2109                                 player[i].proportionbody=1.05;
2110                                 player[i].proportionarms=1.00;
2111                                 player[i].proportionlegs=1.1;
2112                                 player[i].proportionlegs.y=1.05;
2113                         }
2114                         player[i].headless=0;
2115                         player[i].currentoffset=0;
2116                         player[i].targetoffset=0;
2117                         /*player[i].armorhead=1;
2118                         player[i].armorhigh=1;
2119                         player[i].armorlow=1;
2120                         player[i].protectionhead=1;
2121                         player[i].protectionhigh=1;
2122                         player[i].protectionlow=1;
2123                         player[i].metalhead=1;
2124                         player[i].metalhigh=1;
2125                         player[i].metallow=1;
2126                         player[i].power=1;
2127                         player[i].speedmult=1;*/
2128
2129                         player[i].damagetolerance=200;
2130
2131                         if(player[i].creature==wolftype)
2132                         {
2133                                 /*player[i].proportionhead=1.1;
2134                                 player[i].proportionbody=1.1;
2135                                 player[i].proportionarms=1.1;
2136                                 player[i].proportionlegs=1.1;
2137                                 player[i].proportionlegs.y=1.1;*/
2138                                 if(i==0||player[i].scale<0)player[i].scale=.23;
2139
2140                                 player[i].damagetolerance=300;
2141                         }
2142
2143                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
2144                         if(cellophane)
2145                         {
2146                                 player[i].proportionhead.z=0;
2147                                 player[i].proportionbody.z=0;
2148                                 player[i].proportionarms.z=0;
2149                                 player[i].proportionlegs.z=0;
2150                         }
2151
2152                         player[i].tempanimation.Load((char *)"Tempanim",0,0);
2153
2154                         player[i].headmorphness=0;
2155                         player[i].targetheadmorphness=1;
2156                         player[i].headmorphstart=0;
2157                         player[i].headmorphend=0;
2158
2159                         player[i].pausetime=0;
2160
2161                         player[i].dead=0;
2162                         player[i].jumppower=5;
2163                         player[i].damage=0;
2164                         player[i].permanentdamage=0;
2165                         player[i].superpermanentdamage=0;
2166
2167                         player[i].forwardkeydown=0;
2168                         player[i].leftkeydown=0;
2169                         player[i].backkeydown=0;
2170                         player[i].rightkeydown=0;
2171                         player[i].jumpkeydown=0;
2172                         player[i].crouchkeydown=0;
2173                         player[i].throwkeydown=0;
2174
2175                         player[i].collided=-10;
2176                         player[i].loaded=1;
2177                         player[i].bloodloss=0;
2178                         player[i].weaponactive=-1;
2179                         player[i].weaponstuck=-1;
2180                         player[i].bleeding=0;
2181                         player[i].deathbleeding=0;
2182                         player[i].stunned=0;
2183                         player[i].hasvictim=0;
2184                         player[i].wentforweapon=0;
2185                 }
2186
2187                 player[0].aitype=playercontrolled;
2188                 player[0].weaponactive=-1;
2189
2190                 if(difficulty==1)
2191                 {
2192                         //player[0].speedmult=1/.9;
2193                         player[0].power=1/.9;
2194                 }
2195
2196                 if(difficulty==0)
2197                 {
2198                         //player[0].speedmult=1/.8;
2199                         player[0].power=1/.8;
2200                 }
2201
2202                 //player[0].weaponstuck=1;
2203
2204                 if(difficulty==1)player[0].damagetolerance=250;
2205                 if(difficulty==0)player[0].damagetolerance=300;
2206                 if(difficulty==0)player[0].armorhead*=1.5;
2207                 if(difficulty==0)player[0].armorhigh*=1.5;
2208                 if(difficulty==0)player[0].armorlow*=1.5;
2209                 cameraloc=player[0].coords;
2210                 cameraloc.y+=5;
2211                 rotation=player[0].rotation;
2212
2213                 hawkcoords=player[0].coords;
2214                 hawkcoords.y+=30;
2215
2216                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2217                 //weapons.numweapons=numplayers;
2218                 for(i=0;i<weapons.numweapons;i++)
2219                 {
2220                         weapons.bloody[i]=0;
2221                         weapons.blooddrip[i]=0;
2222                         weapons.blooddripdelay[i]=0;
2223                         weapons.onfire[i]=0;
2224                         weapons.flamedelay[i]=0;
2225                         weapons.damage[i]=0;
2226                         //weapons.type[i]=sword;
2227                         if(weapons.type[i]==sword){
2228                                 weapons.mass[i]=1.5;
2229                                 weapons.tipmass[i]=1;
2230                                 weapons.length[i]=.8;
2231                         }
2232                         if(weapons.type[i]==staff){
2233                                 weapons.mass[i]=2;
2234                                 weapons.tipmass[i]=1;
2235                                 weapons.length[i]=1.5;
2236                         }
2237                         if(weapons.type[i]==knife){
2238                                 weapons.mass[i]=1;
2239                                 weapons.tipmass[i]=1.2;
2240                                 weapons.length[i]=.25;
2241                         }
2242                         weapons.position[i]=-1000;
2243                         weapons.tippoint[i]=-1000;
2244                 }
2245                 
2246                 LOG("Starting background music...");
2247
2248                 OPENAL_StopSound(OPENAL_ALL);
2249                 if(environment==snowyenvironment)
2250                 {
2251                         if(ambientsound)
2252                         {
2253                                 PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
2254                                 OPENAL_SetPaused(channels[stream_wind], false);
2255                                 OPENAL_SetVolume(channels[stream_wind], 256);
2256                         }
2257                 }
2258                 else if(environment==desertenvironment)
2259                 {
2260                         if(ambientsound)
2261                         {
2262                                 //PlaySoundEx(desertambient,
2263                                 //      samp[desertambient], NULL, true);
2264                                 PlayStreamEx(stream_desertambient,
2265                                         samp[stream_desertambient], NULL, true);
2266                                 OPENAL_SetPaused(channels[stream_desertambient], false);
2267                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
2268                         }
2269                 }
2270                 else if(environment==grassyenvironment)
2271                 {
2272                         if(ambientsound)
2273                         {
2274                                 //PlaySoundEx(wind, samp[wind], NULL, true);
2275                                 PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
2276                                 OPENAL_SetPaused(channels[stream_wind], false);
2277                                 OPENAL_SetVolume(channels[stream_wind], 100);
2278                         }
2279                 }
2280                 oldmusicvolume[0]=0;
2281                 oldmusicvolume[1]=0;
2282                 oldmusicvolume[2]=0;
2283                 oldmusicvolume[3]=0;
2284
2285                 if(!firstload)
2286                 {
2287                         firstload=1;
2288                 }
2289         }
2290         leveltime=0;
2291         loadingstuff=0;
2292         visibleloading=0;
2293 }
2294
2295 void    Game::Tick()
2296 {
2297         static int i,k,j,l,m;
2298         static XYZ facing,flatfacing,absflatfacing;
2299         static XYZ rotatetarget;
2300         static bool oldkey;
2301         static float oldtargetrotation;
2302         static int target, numgood;
2303         static XYZ tempcoords1,tempcoords2;
2304         static XYZ test;
2305         static XYZ test2;
2306         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
2307         static int whichhit;
2308         static bool oldjumpkeydown;
2309
2310         int templength;
2311
2312         float headprop,bodyprop,armprop,legprop;
2313
2314         for(i=0;i<15;i++){
2315                 displaytime[i]+=multiplier;
2316         }
2317
2318         keyboardfrozen=0;
2319
2320         if (Input::isKeyDown(SDLK_F6) && !freezetogglekeydown) {
2321                 if (Input::isKeyDown(SDLK_LSHIFT)) {
2322                         stereoreverse=true;
2323                 } else {
2324                         stereoreverse=false;
2325                 }
2326
2327                 if (stereoreverse) {
2328                         printf("Stereo reversed\n");
2329                 } else {
2330                         printf("Stereo unreversed\n");
2331                 }
2332                 freezetogglekeydown=1;
2333         }
2334
2335         if (Input::isKeyDown(SDLK_F7)) {
2336                 if (Input::isKeyDown(SDLK_LSHIFT)) {
2337                         stereoseparation -= 0.001;
2338                 } else {
2339                         stereoseparation -= 0.010;
2340                 }
2341
2342                 printf("Stereo decreased increased to %f\n", stereoseparation);
2343         }
2344
2345         if (Input::isKeyDown(SDLK_F8)) {
2346                 if (Input::isKeyDown(SDLK_LSHIFT)) {
2347                         stereoseparation += 0.001;
2348                 } else {
2349                         stereoseparation += 0.010;
2350                 }
2351
2352                 printf("Stereo separation increased to %f\n", stereoseparation);
2353         }
2354
2355
2356         if(!console){
2357                 if(mainmenu&&endgame==1)mainmenu=10;
2358                 if( (Input::isKeyDown(SDLK_ESCAPE)||(mainmenu==0&&((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))
2359                     && !mainmenutogglekeydown
2360                     && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)
2361                   ) { // go back
2362                         selected=-1;
2363                         if(mainmenu==1||mainmenu==2||mainmenu==0){
2364                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
2365                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
2366                                 else if(mainmenu==0&&winfreeze){
2367                                         
2368                                 }
2369                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
2370                                 if(mainmenu&&musictoggle){
2371                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
2372                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2373                                                 PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
2374                                                 OPENAL_SetPaused(channels[stream_music3], false);
2375                                                 OPENAL_SetVolume(channels[stream_music3], 256);
2376                                                 OPENAL_SetPaused(channels[music1], true);
2377                                         }
2378                                 }
2379                                 if(!mainmenu){
2380                                         OPENAL_SetPaused(channels[stream_music3], true);
2381                                         OPENAL_SetPaused(channels[music1], false);
2382                                 }
2383                         }
2384                         if(mainmenu==3){
2385                                 fireSound();
2386
2387                                 flash();
2388
2389                                 if(newdetail>2)newdetail=detail;
2390                                 if(newdetail<0)newdetail=detail;
2391                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2392                                 if(newscreenheight<0)newscreenheight=screenheight;
2393
2394                                 SaveSettings(*this);
2395                         }
2396                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==10||mainmenu==100){
2397                                 fireSound();
2398
2399                                 flash();
2400                         }
2401                         if(mainmenu==3&&gameon)mainmenu=2;
2402                         if(mainmenu==3&&!gameon)mainmenu=1;
2403                         if(mainmenu==5&&gameon)mainmenu=2;
2404                         if(mainmenu==5&&!gameon)mainmenu=1;
2405                         if(mainmenu==4)mainmenu=3;
2406                         if(mainmenu==6)mainmenu=5;
2407                         if(mainmenu==7)mainmenu=1;
2408                         if(mainmenu==9)mainmenu=5;
2409                         if(mainmenu==10)mainmenu=5;
2410                         if(mainmenu==100){
2411                                 mainmenu=5;
2412                                 gameon=0;
2413                                 winfreeze=0;
2414                         }
2415                         mainmenutogglekeydown=1;
2416                 }
2417                 if(!Input::isKeyDown(SDLK_ESCAPE)){
2418                         mainmenutogglekeydown=0;
2419                 }
2420         }
2421
2422         static bool minimaptogglekeydown;
2423         if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
2424                 if(tutorialstage!=51)
2425                         tutorialstagetime=tutorialmaxtime;
2426                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
2427                 OPENAL_SetVolume(channels[consolefailsound], 128);
2428                 OPENAL_SetPaused(channels[consolefailsound], false);
2429                 minimaptogglekeydown=1;
2430         }
2431         if(!Input::isKeyDown(SDLK_TAB)){
2432                 minimaptogglekeydown=0;
2433         }
2434
2435         if(mainmenu){
2436                 //menu buttons
2437                 if(mainmenu==1||mainmenu==2){
2438                         if(Input::Button()&&!oldbutton&&selected==1){
2439                                 if(!gameon){
2440                                         fireSound(firestartsound);
2441
2442                                         flash();
2443
2444                                         //new game
2445                                         if(accountactive) {
2446                                                 mainmenu=5;
2447                                         } else {
2448                                                 mainmenu=7;
2449                                         }
2450                                         selected=-1;
2451                                 }
2452                                 else
2453                                 {
2454                                         //resume
2455                                         mainmenu=0;
2456                                         OPENAL_SetPaused(channels[stream_music3], true);
2457                                         OPENAL_SetPaused(channels[music1], false);
2458                                 }
2459                         }
2460
2461                         if(Input::Button()&&!oldbutton&&selected==2){
2462                                 fireSound();
2463
2464                                 flash();
2465
2466                                 //options
2467
2468                                 mainmenu=3;
2469
2470                                 if(newdetail>2)newdetail=detail;
2471                                 if(newdetail<0)newdetail=detail;
2472                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2473                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2474                                 if(newscreenheight>3000)newscreenheight=screenheight;
2475                                 if(newscreenheight<0)newscreenheight=screenheight;
2476                         }
2477
2478                         if(Input::Button()&&!oldbutton&&selected==3){
2479                                 fireSound();
2480
2481                                 flash();
2482
2483                                 if(!gameon){
2484                                         //quit
2485                                         tryquit=1;
2486                                         OPENAL_SetPaused(channels[stream_music3], true);
2487                                 }
2488                                 else{
2489                                         //end game
2490                                         gameon=0;
2491                                         mainmenu=1;
2492                                 }
2493                         }
2494                 }
2495                 if(mainmenu==3){
2496                         if(Input::Button()&&!oldbutton&&selected!=-1){
2497                                 fireSound();
2498                         }
2499                         if(Input::Button()&&!oldbutton&&selected==0){
2500                         
2501                                 extern SDL_Rect **resolutions;
2502                                 bool isCustomResolution = true;
2503                                 bool found = false;
2504                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2505                                 {
2506                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2507                                                 isCustomResolution = false;
2508
2509                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2510                                         {
2511                                                 i++;
2512                                                 if (resolutions[i] != NULL)
2513                                                 {
2514                                                         newscreenwidth = (int) resolutions[i]->w;
2515                                                         newscreenheight = (int) resolutions[i]->h;
2516                                                 }
2517                                                 else if (isCustomResolution)
2518                                                 {
2519                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2520                                                         {
2521                                                                 newscreenwidth = (int) resolutions[0]->w;
2522                                                                 newscreenheight = (int) resolutions[0]->h;
2523                                                         }
2524                                                         else
2525                                                         {
2526                                                                 newscreenwidth = screenwidth;
2527                                                                 newscreenheight = screenheight;
2528                                                         }
2529                                                 }
2530                                                 else
2531                                                 {
2532                                                         newscreenwidth = (int) resolutions[0]->w;
2533                                                         newscreenheight = (int) resolutions[0]->h;
2534                                                 }
2535                                                 found = true;
2536                                         }
2537                                 }
2538
2539                                 if (!found)
2540                                 {
2541                                         newscreenwidth = (int) resolutions[0]->w;
2542                                         newscreenheight = (int) resolutions[0]->h;
2543                                 }
2544
2545                                 
2546                         }
2547                         if(Input::Button()&&!oldbutton&&selected==1){
2548                                 newdetail++;
2549                                 if(newdetail>2)newdetail=0;
2550                         }
2551                         if(Input::Button()&&!oldbutton&&selected==2){
2552                                 bloodtoggle++;
2553                                 if(bloodtoggle>2)bloodtoggle=0;
2554                         }
2555                         if(Input::Button()&&!oldbutton&&selected==3){
2556                                 difficulty++;
2557                                 if(difficulty>2)difficulty=0;
2558                         }
2559                         if(Input::Button()&&!oldbutton&&selected==4){
2560                                 ismotionblur=1-ismotionblur;
2561                         }
2562                         if(Input::Button()&&!oldbutton&&selected==5){
2563                                 decals=1-decals;
2564                         }
2565                         if(Input::Button()&&!oldbutton&&selected==6){
2566                                 musictoggle=1-musictoggle;
2567
2568                                 if(!musictoggle){
2569                                         OPENAL_SetPaused(channels[music1], true);
2570                                         OPENAL_SetPaused(channels[stream_music2], true);
2571                                         OPENAL_SetPaused(channels[stream_music3], true);
2572
2573                                         for(i=0;i<4;i++){
2574                                                 oldmusicvolume[i]=0;
2575                                                 musicvolume[i]=0;
2576                                         }
2577                                 }
2578
2579                                 if(musictoggle){
2580                                         PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
2581                                         OPENAL_SetPaused(channels[stream_music3], false);
2582                                         OPENAL_SetVolume(channels[stream_music3], 256);
2583                                 }
2584                         }
2585                         if(Input::Button()&&!oldbutton&&selected==9){
2586                                 invertmouse=1-invertmouse;
2587                         }
2588                         if(Input::Button()&&!oldbutton&&selected==10){
2589                                 usermousesensitivity+=.2;
2590                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2591                         }
2592                         if(Input::Button()&&!oldbutton&&selected==11){
2593                                 volume+=.1f;
2594                                 if(volume>1.0001f)volume=0;
2595                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2596                         }
2597                         if(Input::Button()&&!oldbutton&&selected==7){
2598                                 /*fireSound();
2599                                 */
2600                                 flash();
2601
2602                                 //options
2603
2604                                 mainmenu=4;
2605                                 selected=-1;
2606                                 keyselect=-1;
2607                         }
2608                         if(Input::Button() && !oldbutton && selected == 12) {
2609                                 flash();
2610                                 
2611                                 newstereomode = stereomode;
2612                                 mainmenu=18;
2613                                 keyselect=-1;
2614                         }
2615                         if(Input::Button() && !oldbutton && selected == 13) {
2616                                 showdamagebar=!showdamagebar;
2617                         }
2618                         if(Input::Button()&&!oldbutton&&selected==8){
2619                                 fireSound();
2620
2621                                 flash();
2622
2623                                 if(newdetail>2)newdetail=detail;
2624                                 if(newdetail<0)newdetail=detail;
2625                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2626                                 if(newscreenheight<0)newscreenheight=screenheight;
2627
2628
2629                                 SaveSettings(*this);
2630                                 if(mainmenu==3&&gameon)mainmenu=2;
2631                                 if(mainmenu==3&&!gameon)mainmenu=1;
2632                         }
2633                 }
2634                 if(mainmenu==4){
2635                         if(Input::Button()&&!oldbutton&&selected!=-1&&!waiting){
2636                                 fireSound();
2637                                 if(selected<9&&keyselect==-1)
2638                                         keyselect=selected;
2639                                 if(keyselect!=-1)
2640                                         setKeySelected();
2641                                 if(selected==9){
2642                                         flash();
2643
2644                                         mainmenu=3;
2645
2646                                         if(newdetail>2)newdetail=detail;
2647                                         if(newdetail<0)newdetail=detail;
2648                                         if(newscreenwidth>3000)newscreenwidth=screenwidth;
2649                                         if(newscreenwidth<0)newscreenwidth=screenwidth;
2650                                         if(newscreenheight>3000)newscreenheight=screenheight;
2651                                         if(newscreenheight<0)newscreenheight=screenheight;
2652                                 }
2653                         }
2654                 }
2655
2656                 if(mainmenu==5){
2657
2658                         if(endgame==2){
2659                                 accountactive->endGame();
2660                                 endgame=0;
2661                         }
2662
2663                         if(Input::Button()&&!oldbutton&&selected==1){
2664                                 fireSound();
2665
2666                                 flash();
2667
2668                                 startbonustotal=0;
2669
2670                                 loading=2;
2671                                 loadtime=0;
2672                                 targetlevel=-1;
2673                                 if(firstload)TickOnceAfter();
2674                                 if(!firstload)LoadStuff();
2675                                 else {
2676                                         Loadlevel(-1);
2677                                 }
2678
2679                                 mainmenu=0;
2680                                 gameon=1;
2681                                 OPENAL_SetPaused(channels[stream_music3], true);
2682                         }
2683                         if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){
2684                                 fireSound();
2685
2686                                 flash();
2687
2688                                 startbonustotal=0;
2689
2690                                 loading=2;
2691                                 loadtime=0;
2692                                 targetlevel=7;
2693                                 if(firstload) TickOnceAfter();
2694                                 else LoadStuff();
2695                                 for(i=0;i<255;i++){
2696                                         mapname[i]='\0';
2697                                 }
2698                                 mapname[0]=':';
2699                                 mapname[1]='D';
2700                                 mapname[2]='a';
2701                                 mapname[3]='t';
2702                                 mapname[4]='a';
2703                                 mapname[5]=':';
2704                                 mapname[6]='M';
2705                                 mapname[7]='a';
2706                                 mapname[8]='p';
2707                                 mapname[9]='s';
2708                                 mapname[10]=':';
2709                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
2710                                 whichchoice=selected-7-accountactive->getCampaignChoicesMade();
2711                                 visibleloading=1;
2712                                 stillloading=1;
2713                                 Loadlevel(mapname);
2714                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2715                                 campaign=1;
2716                                 mainmenu=0;
2717                                 gameon=1;
2718                                 OPENAL_SetPaused(channels[stream_music3], true);
2719                         }
2720                         if(Input::Button()&&!oldbutton&&selected==4){
2721                                 fireSound();
2722
2723                                 flash();
2724
2725                                 if(mainmenu==5&&gameon)mainmenu=2;
2726                                 if(mainmenu==5&&!gameon)mainmenu=1;
2727                         }
2728                         if(Input::Button()&&!oldbutton&&selected==5){
2729                                 fireSound();
2730
2731                                 flash();
2732
2733                                 mainmenu=7;
2734                         }
2735                         if(Input::Button()&&!oldbutton&&selected==3){
2736                                 fireSound();
2737
2738                                 flash();
2739
2740                                 mainmenu=6;
2741                         }
2742                         if(Input::Button()&&!oldbutton&&selected==2){
2743                                 fireSound();
2744
2745                                 flash();
2746
2747                                 mainmenu=9;
2748                         }
2749                 }
2750                 else if(mainmenu==9){
2751                         if(Input::Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
2752                                 fireSound();
2753
2754                                 flash();
2755
2756                                 startbonustotal=0;
2757
2758                                 loading=2;
2759                                 loadtime=0;
2760                                 targetlevel=selected;
2761                                 if(firstload)TickOnceAfter();
2762                                 if(!firstload)LoadStuff();
2763                                 else {
2764                                         Loadlevel(selected);
2765                                 }
2766                                 campaign=0;
2767
2768                                 mainmenu=0;
2769                                 gameon=1;
2770                                 OPENAL_SetPaused(channels[stream_music3], true);
2771                         }
2772                         if(Input::Button()&&!oldbutton&&selected==numchallengelevels){
2773                                 fireSound();
2774
2775                                 flash();
2776
2777                                 mainmenu=5;
2778                         }
2779                 }
2780                 if(mainmenu==10){
2781                         endgame=2;
2782                         if(Input::Button()&&!oldbutton&&selected==3){
2783                                 fireSound();
2784
2785                                 flash();
2786
2787                                 mainmenu=5;
2788                         }
2789                 }
2790
2791                 if(mainmenu==6){
2792                         if(Input::Button()&&!oldbutton) {
2793                                 if(selected>-1){
2794                                         fireSound();
2795                                         if(selected==1) {
2796                                                 flash();
2797                                                 accountactive = Account::destroy(accountactive);
2798                                                 mainmenu=7;
2799                                         } else if(selected==2) {
2800                                                 flash();
2801                                                 mainmenu=5;
2802                                         }
2803                                 }
2804                         }
2805                 }
2806                 if(mainmenu==7){
2807                         if(Input::Button()&&!oldbutton) {
2808                                 if(selected!=-1){
2809                                         fireSound();
2810                                         if(selected==0&&Account::getNbAccounts()<8){
2811                                                 entername=1;
2812                                         } else if (selected<Account::getNbAccounts()+1) {
2813                                                 accountactive=Account::get(selected-1);
2814                                                 mainmenu=5;
2815                                                 flash();
2816                                         } else if (selected==Account::getNbAccounts()+1) {
2817                                                 flash();
2818
2819                                                 mainmenu=1;
2820
2821                                                 for(j=0;j<255;j++){
2822                                                         displaytext[0][j]=' ';
2823                                                 }
2824                                                 displaychars[0]=0;
2825                                                 displayselected=0;
2826                                                 entername=0;
2827                                         }
2828                                 }
2829                         }
2830                 }
2831                 if(mainmenu==8){
2832                         if(Input::Button()&&!oldbutton&&selected>-1){
2833                                 fireSound();
2834
2835                                 if(selected<=2)
2836                                         accountactive->setDifficulty(selected);
2837
2838                                 mainmenu=5;
2839
2840                                 flash();
2841
2842                         }
2843                 }
2844                 if (mainmenu==18) {                     
2845                         if(Input::Button()&&!oldbutton&&selected==0) {
2846                                 newstereomode = (StereoMode)(newstereomode + 1);
2847                                 while(!CanInitStereo(newstereomode)) {
2848                                         printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
2849                                         newstereomode = (StereoMode)(newstereomode + 1);
2850                                         if ( newstereomode >= stereoCount ) {
2851                                                 newstereomode = stereoNone;
2852                                         }
2853                                 }
2854                         }
2855                         
2856                         if(Input::isKeyDown(MOUSEBUTTON1)&&!oldbutton&&selected==1) {
2857                                 stereoseparation+=0.001;
2858                         }
2859                         if(Input::isKeyDown(MOUSEBUTTON2)&&!oldbutton&&selected==1) {
2860                                 stereoseparation-=0.001;
2861                         }
2862
2863                         if(Input::Button()&&!oldbutton&&selected==2) {
2864                                 stereoreverse =! stereoreverse;
2865                         }
2866                         
2867                         if(Input::Button()&&!oldbutton&&selected==3) {
2868                                 flash();
2869
2870                                 stereomode = newstereomode;
2871                                 InitStereo(stereomode);
2872                                 
2873                                 mainmenu=3;
2874                         }
2875                 }
2876
2877
2878                 if(Input::Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1;
2879                 else oldbutton=0;
2880
2881                 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
2882                         tryquit=1;
2883                         if(mainmenu==3){
2884                                 if(newdetail>2)newdetail=detail;
2885                                 if(newdetail<0)newdetail=detail;
2886                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2887                                 if(newscreenheight<0)newscreenheight=screenheight;
2888
2889                                 SaveSettings(*this);
2890                         }
2891                 }
2892
2893                 if(mainmenu==1||mainmenu==2){
2894                         if(loaddistrib>4)transition+=multiplier/8;
2895                         if(transition>1){
2896                                 transition=0;
2897                                 anim++;
2898                                 if(anim>4)anim=0;
2899                                 loaddistrib=0;
2900                         }
2901                 }
2902                 OPENAL_SetFrequency(channels[stream_music3], 22050);
2903
2904                 if(entername) {
2905                         inputText(displaytext[0],&displayselected,&displaychars[0]);
2906                         if(!waiting) { // the input as finished
2907                                 if(displaychars[0]){ // with enter
2908                                         accountactive = Account::add(string(displaytext[0]));
2909
2910                                         mainmenu=8;
2911
2912                                         flash();
2913
2914                                         fireSound(firestartsound);
2915
2916                                         for(i=0;i<255;i++){
2917                                                 displaytext[0][i]=' ';
2918                                         }
2919                                         displaychars[0]=0;
2920
2921                                         displayselected=0;
2922                                 } else { // with escape or empty
2923                                         mainmenutogglekeydown=1;
2924                                 }
2925                                 entername=0;
2926                         }
2927                         
2928                         displayblinkdelay-=multiplier;
2929                         if(displayblinkdelay<=0){
2930                                 displayblinkdelay=.3;
2931                                 displayblink=1-displayblink;
2932                         }
2933                 }
2934         }
2935
2936         if(!mainmenu){
2937                 if(hostile==1)hostiletime+=multiplier;
2938                 else hostiletime=0;
2939                 if(!winfreeze)leveltime+=multiplier;
2940                 if(Input::isKeyDown(SDLK_ESCAPE)){
2941                         chatting=0;
2942                         console=0;
2943                         freeze=0;
2944                         displaychars[0]=0;
2945                 }
2946
2947                 if(Input::isKeyDown(chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
2948                         chatting=1;
2949                         chattogglekeydown=1;
2950                 }
2951
2952                 if(!Input::isKeyDown(chatkey)){
2953                         chattogglekeydown=0;
2954                 }
2955
2956                 if(chatting){
2957                         inputText(displaytext[0],&displayselected,&displaychars[0]);
2958                         if(!waiting) {
2959                                 if(displaychars[0]){
2960                                         for(int j=0;j<255;j++){
2961                                                 displaytext[0][j]=' ';
2962                                         }
2963                                         displaychars[0]=0;
2964                                         displayselected=0;
2965                                 }       
2966                                 chatting=0;             
2967                         }
2968
2969                         displayblinkdelay-=multiplier;
2970                         if(displayblinkdelay<=0){
2971                                 displayblinkdelay=.3;
2972                                 displayblink=1-displayblink;
2973                         }
2974                 }
2975
2976                 if(chatting)keyboardfrozen=1;
2977
2978                 if(Input::isKeyDown(SDLK_v)&&!freezetogglekeydown&&debugmode){
2979                         freeze=1-freeze;
2980                         if(freeze){
2981                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2982                         }
2983                         freezetogglekeydown=1;
2984                 }
2985
2986                 if(!Input::isKeyDown(SDLK_v)&&!Input::isKeyDown(SDLK_F1)){
2987                         freezetogglekeydown=0;
2988                 }
2989
2990                 if(Input::isKeyDown(SDLK_BACKQUOTE)&&!consoletogglekeydown&&debugmode){
2991                         console=1-console;
2992                         if(console){
2993                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2994                         } else {
2995                                 freeze=0;
2996                                 waiting=false;
2997                         }
2998                         consoletogglekeydown=1;
2999                 }
3000
3001                 if(!Input::isKeyDown(SDLK_BACKQUOTE)){
3002                         consoletogglekeydown=0;
3003                 }
3004
3005                 if(console)freeze=1;
3006
3007                 if(console&&!Input::isKeyDown(SDLK_LMETA)){
3008                         inputText(consoletext[0],&consoleselected,&consolechars[0]);
3009                         if(!waiting) {
3010                                 archiveselected=0;
3011                                 cmd_dispatch(this, consoletext[0]);
3012                                 if(consolechars[0]>0){
3013
3014                                         for(k=14;k>=1;k--){
3015                                                 for(j=0;j<255;j++){
3016                                                         consoletext[k][j]=consoletext[k-1][j];
3017                                                 }
3018                                                 consolechars[k]=consolechars[k-1];
3019                                         }
3020                                         for(j=0;j<255;j++){
3021                                                 consoletext[0][j]=' ';
3022                                         }
3023                                         consolechars[0]=0;
3024                                         consoleselected=0;
3025                                 }
3026                         }
3027
3028                         consoleblinkdelay-=multiplier;
3029                         if(consoleblinkdelay<=0){
3030                                 consoleblinkdelay=.3;
3031                                 consoleblink=1-consoleblink;
3032                         }
3033                 }
3034
3035                 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
3036                         tryquit=1;
3037                         if(mainmenu==3){
3038                                 if(newdetail>2)newdetail=detail;
3039                                 if(newdetail<0)newdetail=detail;
3040                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
3041                                 if(newscreenheight<0)newscreenheight=screenheight;
3042
3043                                 SaveSettings(*this);
3044                         }
3045                 }
3046
3047                 static int oldwinfreeze;
3048                 if(winfreeze&&!oldwinfreeze){
3049                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3050                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3051                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3052                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3053                 }
3054                 if(winfreeze==0)oldwinfreeze=winfreeze;
3055                 else oldwinfreeze++;
3056
3057                 if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))&&!oldjumpkeydown&&!campaign){
3058                         if(winfreeze)winfreeze=0;
3059                         oldjumpkeydown=1;
3060                 }
3061                 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
3062                         if(winfreeze){
3063                                 mainmenu=9;
3064                                 gameon=0;
3065                         }
3066                 }
3067                 if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))){
3068                         oldjumpkeydown=1;
3069                 }
3070                 if(!Input::isKeyDown(jumpkey)&&!Input::isKeyDown(SDLK_SPACE))oldjumpkeydown=0;
3071
3072                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
3073
3074                         static bool oldbuttondialogue;
3075
3076                         if(indialogue!=-1)talkdelay=1;
3077                         talkdelay-=multiplier;
3078
3079                         if(talkdelay<=0)
3080                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
3081                                         for(i=0;i<numdialogues;i++){
3082                                                 int realdialoguetype;
3083                                                 bool special;
3084                                                 if(dialoguetype[i]>49){
3085                                                         realdialoguetype=dialoguetype[i]-50;
3086                                                         special=1;
3087                                                 }
3088                                                 else if(dialoguetype[i]>39){
3089                                                         realdialoguetype=dialoguetype[i]-40;
3090                                                         special=1;
3091                                                 }
3092                                                 else if(dialoguetype[i]>29){
3093                                                         realdialoguetype=dialoguetype[i]-30;
3094                                                         special=1;
3095                                                 }
3096                                                 else if(dialoguetype[i]>19){
3097                                                         realdialoguetype=dialoguetype[i]-20;
3098                                                         special=1;
3099                                                 }
3100                                                 else if(dialoguetype[i]>9){
3101                                                         realdialoguetype=dialoguetype[i]-10;
3102                                                         special=1;
3103                                                 }
3104                                                 else {
3105                                                         realdialoguetype=dialoguetype[i];
3106                                                         special=0;
3107                                                 }
3108                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(Input::isKeyDown(attackkey)&&!oldbuttondialogue))){
3109                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
3110                                                                 whichdialogue=i;
3111                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
3112                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
3113                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
3114                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
3115                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
3116                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
3117                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
3118                                                                 }
3119                                                                 directing=0;
3120                                                                 indialogue=0;
3121                                                                 dialoguetime=0;
3122                                                                 dialoguegonethrough[i]++;
3123                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
3124                                                                         static float gLoc[3];
3125                                                                         static float vel[3];
3126                                                                         XYZ temppos;
3127                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
3128                                                                         temppos=temppos-viewer;
3129                                                                         Normalise(&temppos);
3130                                                                         temppos+=viewer;
3131
3132                                                                         gLoc[0]=temppos.x;
3133                                                                         gLoc[1]=temppos.y;
3134                                                                         gLoc[2]=temppos.z;vel[0]=0;
3135                                                                         vel[1]=0;
3136                                                                         vel[2]=0;
3137                                                                         int whichsoundplay;
3138                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
3139                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
3140                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
3141                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
3142                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
3143                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
3144                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
3145                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
3146                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
3147                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
3148                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
3149                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
3150                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
3151                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
3152                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
3153                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
3154                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
3155                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
3156                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
3157                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
3158                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
3159                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
3160                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
3161                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
3162                                                                 }
3163                                                                 if(Input::isKeyDown(attackkey))oldbuttondialogue=1;
3164                                                         }
3165                                                 }
3166                                         }
3167
3168                                         windvar+=multiplier;
3169                                         smoketex+=multiplier;
3170                                         tutorialstagetime+=multiplier;
3171
3172                                         static float hotspotvisual[40];
3173                                         if(numhotspots){
3174                                                 XYZ hotspotsprite;
3175                                                 if(editorenabled)
3176                                                         for(i=0;i<numhotspots;i++)
3177                                                                 hotspotvisual[i]-=multiplier/320;
3178
3179                                                 for(i=0;i<numhotspots;i++){
3180                                                         //if(hotspottype[i]<=10)
3181                                                         while(hotspotvisual[i]<0){
3182                                                                 hotspotsprite=0;
3183                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
3184                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
3185                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
3186                                                                 hotspotsprite+=hotspot[i];
3187                                                                 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
3188                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
3189                                                         }
3190                                                 }
3191
3192                                                 for(i=0;i<numhotspots;i++){
3193                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
3194                                                                 hotspot[i]=player[hotspottype[i]].coords;
3195                                                         }
3196                                                 }
3197                                         }
3198
3199                                         //Tutorial
3200                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
3201                                                 tutorialstage++;
3202                                                 tutorialsuccess=0;
3203                                                 if(tutorialstage<=1){
3204                                                         canattack=0;
3205                                                         cananger=0;
3206                                                         reversaltrain=0;
3207                                                 }
3208                                                 if(tutorialstage==1){
3209                                                         tutorialmaxtime=5;
3210                                                 } else if(tutorialstage==2){
3211                                                         tutorialmaxtime=2;
3212                                                 } else if(tutorialstage==3){
3213                                                         tutorialmaxtime=600;
3214                                                 } else if(tutorialstage==4){
3215                                                         tutorialmaxtime=1000;
3216                                                 } else if(tutorialstage==5){
3217                                                         tutorialmaxtime=600;
3218                                                 } else if(tutorialstage==6){
3219                                                         tutorialmaxtime=600;
3220                                                 } else if(tutorialstage==7){
3221                                                         tutorialmaxtime=600;
3222                                                 } else if(tutorialstage==8){
3223                                                         tutorialmaxtime=600;
3224                                                 } else if(tutorialstage==9){
3225                                                         tutorialmaxtime=600;
3226                                                 } else if(tutorialstage==10){
3227                                                         tutorialmaxtime=2;
3228                                                 } else if(tutorialstage==11){
3229                                                         tutorialmaxtime=1000;
3230                                                 } else if(tutorialstage==12){
3231                                                         tutorialmaxtime=1000;
3232                                                 } else if(tutorialstage==13){
3233                                                         tutorialmaxtime=2;
3234                                                 } else if(tutorialstage==14){
3235                                                         tutorialmaxtime=3;
3236
3237                                                         XYZ temp,temp2;
3238
3239                                                         temp.x=1011;
3240                                                         temp.y=84;
3241                                                         temp.z=491;
3242                                                         temp2.x=1025;
3243                                                         temp2.y=75;
3244                                                         temp2.z=447;
3245
3246                                                         player[1].coords=(temp+temp2)/2;
3247
3248                                                         float gLoc[3];
3249                                                         float vel[3];
3250                                                         gLoc[0]=player[1].coords.x;
3251                                                         gLoc[1]=player[1].coords.y;
3252                                                         gLoc[2]=player[1].coords.z;
3253                                                         vel[0]=0;
3254                                                         vel[1]=0;
3255                                                         vel[2]=0;
3256                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3257                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3258                                                         OPENAL_SetVolume(channels[fireendsound], 256);
3259                                                         OPENAL_SetPaused(channels[fireendsound], false);
3260
3261                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
3262                                                                 if(Random()%2==0){
3263                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
3264                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
3265                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
3266                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
3267                                                                         Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3268                                                                 }
3269                                                         }
3270
3271                                                 } else if(tutorialstage==15){
3272                                                         tutorialmaxtime=500;
3273                                                 } else if(tutorialstage==16){
3274                                                         tutorialmaxtime=500;
3275                                                 } else if(tutorialstage==17){
3276                                                         tutorialmaxtime=500;
3277                                                 } else if(tutorialstage==18){
3278                                                         tutorialmaxtime=500;
3279                                                 } else if(tutorialstage==19){
3280                                                         tutorialstage=20;
3281                                                         //tutorialmaxtime=500;
3282                                                 } else if(tutorialstage==20){
3283                                                         tutorialmaxtime=500;
3284                                                 } else if(tutorialstage==21){
3285                                                         tutorialmaxtime=500;
3286                                                         if(bonus==cannon){
3287                                                                 bonus=Slicebonus;
3288                                                                 againbonus=1;
3289                                                         }
3290                                                         else againbonus=0;
3291                                                 } else if(tutorialstage==22){
3292                                                         tutorialmaxtime=500;
3293                                                 } else if(tutorialstage==23){
3294                                                         tutorialmaxtime=500;
3295                                                 } else if(tutorialstage==24){
3296                                                         tutorialmaxtime=500;
3297                                                 } else if(tutorialstage==25){
3298                                                         tutorialmaxtime=500;
3299                                                 } else if(tutorialstage==26){
3300                                                         tutorialmaxtime=2;
3301                                                 } else if(tutorialstage==27){
3302                                                         tutorialmaxtime=4;
3303                                                         reversaltrain=1;
3304                                                         cananger=1;
3305                                                         player[1].aitype=attacktypecutoff;
3306                                                 } else if(tutorialstage==28){
3307                                                         tutorialmaxtime=400;
3308                                                 } else if(tutorialstage==29){
3309                                                         tutorialmaxtime=400;
3310                                                         player[0].escapednum=0;
3311                                                 } else if(tutorialstage==30){
3312                                                         tutorialmaxtime=4;
3313                                                         reversaltrain=0;
3314                                                         cananger=0;
3315                                                         player[1].aitype=passivetype;
3316                                                 } else if(tutorialstage==31){
3317                                                         tutorialmaxtime=13;
3318                                                 } else if(tutorialstage==32){
3319                                                         tutorialmaxtime=8;
3320                                                 } else if(tutorialstage==33){
3321                                                         tutorialmaxtime=400;
3322                                                         cananger=1;
3323                                                         canattack=1;
3324                                                         player[1].aitype=attacktypecutoff;
3325                                                 } else if(tutorialstage==34){
3326                                                         tutorialmaxtime=400;
3327                                                 } else if(tutorialstage==35){
3328                                                         tutorialmaxtime=400;
3329                                                 } else if(tutorialstage==36){
3330                                                         tutorialmaxtime=2;
3331                                                         reversaltrain=0;
3332                                                         cananger=0;
3333                                                         player[1].aitype=passivetype;
3334                                                 } else if(tutorialstage==37){
3335                                                         damagedealt=0;
3336                                                         damagetaken=0;
3337                                                         tutorialmaxtime=50;
3338                                                         cananger=1;
3339                                                         canattack=1;
3340                                                         player[1].aitype=attacktypecutoff;
3341                                                 } else if(tutorialstage==38){
3342                                                         tutorialmaxtime=4;
3343                                                         canattack=0;
3344                                                         cananger=0;
3345                                                         player[1].aitype=passivetype;
3346                                                 } else if(tutorialstage==39){
3347                                                         XYZ temp,temp2;
3348
3349                                                         temp.x=1011;
3350                                                         temp.y=84;
3351                                                         temp.z=491;
3352                                                         temp2.x=1025;
3353                                                         temp2.y=75;
3354                                                         temp2.z=447;
3355
3356
3357                                                         weapons.owner[weapons.numweapons]=-1;
3358                                                         weapons.type[weapons.numweapons]=knife;
3359                                                         weapons.damage[weapons.numweapons]=0;
3360                                                         weapons.mass[weapons.numweapons]=1;
3361                                                         weapons.tipmass[weapons.numweapons]=1.2;
3362                                                         weapons.length[weapons.numweapons]=.25;
3363                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
3364                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
3365
3366                                                         weapons.velocity[weapons.numweapons]=0.1;
3367                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
3368                                                         weapons.missed[weapons.numweapons]=1;
3369                                                         weapons.hitsomething[weapons.numweapons]=0;
3370                                                         weapons.freetime[weapons.numweapons]=0;
3371                                                         weapons.firstfree[weapons.numweapons]=1;
3372                                                         weapons.physics[weapons.numweapons]=1;
3373
3374                                                         weapons.numweapons++;
3375                                                 } else if(tutorialstage==40){
3376                                                         tutorialmaxtime=300;
3377                                                 } else if(tutorialstage==41){
3378                                                         tutorialmaxtime=300;
3379                                                 } else if(tutorialstage==42){
3380                                                         tutorialmaxtime=8;
3381                                                 } else if(tutorialstage==43){
3382                                                         tutorialmaxtime=300;
3383                                                 } else if(tutorialstage==44){
3384                                                         weapons.owner[0]=1;
3385                                                         player[0].weaponactive=-1;
3386                                                         player[0].num_weapons=0;
3387                                                         player[1].weaponactive=0;
3388                                                         player[1].num_weapons=1;
3389                                                         player[1].weaponids[0]=0;
3390
3391                                                         cananger=1;
3392                                                         canattack=1;
3393                                                         player[1].aitype=attacktypecutoff;
3394
3395                                                         tutorialmaxtime=300;
3396                                                 } else if(tutorialstage==45){
3397                                                         weapons.owner[0]=1;
3398                                                         player[0].weaponactive=-1;
3399                                                         player[0].num_weapons=0;
3400                                                         player[1].weaponactive=0;
3401                                                         player[1].num_weapons=1;
3402                                                         player[1].weaponids[0]=0;
3403
3404                                                         tutorialmaxtime=300;
3405                                                 } else if(tutorialstage==46){
3406                                                         weapons.owner[0]=1;
3407                                                         player[0].weaponactive=-1;
3408                                                         player[0].num_weapons=0;
3409                                                         player[1].weaponactive=0;
3410                                                         player[1].num_weapons=1;
3411                                                         player[1].weaponids[0]=0;
3412
3413                                                         weapons.type[0]=sword;
3414
3415                                                         tutorialmaxtime=300;
3416                                                 } else if(tutorialstage==47){
3417                                                         tutorialmaxtime=10;
3418
3419                                                         XYZ temp,temp2;
3420
3421                                                         temp.x=1011;
3422                                                         temp.y=84;
3423                                                         temp.z=491;
3424                                                         temp2.x=1025;
3425                                                         temp2.y=75;
3426                                                         temp2.z=447;
3427
3428                                                         weapons.owner[weapons.numweapons]=-1;
3429                                                         weapons.type[weapons.numweapons]=sword;
3430                                                         weapons.damage[weapons.numweapons]=0;
3431                                                         weapons.mass[weapons.numweapons]=1;
3432                                                         weapons.tipmass[weapons.numweapons]=1.2;
3433                                                         weapons.length[weapons.numweapons]=.25;
3434                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
3435                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
3436
3437                                                         weapons.velocity[weapons.numweapons]=0.1;
3438                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
3439                                                         weapons.missed[weapons.numweapons]=1;
3440                                                         weapons.hitsomething[weapons.numweapons]=0;
3441                                                         weapons.freetime[weapons.numweapons]=0;
3442                                                         weapons.firstfree[weapons.numweapons]=1;
3443                                                         weapons.physics[weapons.numweapons]=1;
3444
3445                                                         weapons.owner[0]=1;
3446                                                         weapons.owner[1]=0;
3447                                                         player[0].weaponactive=0;
3448                                                         player[0].num_weapons=1;
3449                                                         player[0].weaponids[0]=1;
3450                                                         player[1].weaponactive=0;
3451                                                         player[1].num_weapons=1;
3452                                                         player[1].weaponids[0]=0;
3453
3454                                                         weapons.numweapons++;
3455                                                 } else if(tutorialstage==48){
3456                                                         canattack=0;
3457                                                         cananger=0;
3458                                                         player[1].aitype=passivetype;
3459
3460                                                         tutorialmaxtime=15;
3461
3462                                                         weapons.owner[0]=1;
3463                                                         weapons.owner[1]=0;
3464                                                         player[0].weaponactive=0;
3465                                                         player[0].num_weapons=1;
3466                                                         player[0].weaponids[0]=1;
3467                                                         player[1].weaponactive=0;
3468                                                         player[1].num_weapons=1;
3469                                                         player[1].weaponids[0]=0;
3470
3471                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
3472                                                         else weapons.type[0]=staff;
3473
3474                                                         weapons.numweapons++;
3475                                                 } else if(tutorialstage==49){
3476                                                         canattack=0;
3477                                                         cananger=0;
3478                                                         player[1].aitype=passivetype;
3479
3480                                                         tutorialmaxtime=200;
3481
3482                                                         weapons.position[1]=1000;
3483                                                         weapons.tippoint[1]=1000;
3484
3485                                                         weapons.numweapons=1;
3486                                                         weapons.owner[0]=0;
3487                                                         player[1].weaponactive=-1;
3488                                                         player[1].num_weapons=0;
3489                                                         player[0].weaponactive=0;
3490                                                         player[0].num_weapons=1;
3491                                                         player[0].weaponids[0]=0;
3492
3493                                                         weapons.type[0]=knife;
3494
3495                                                         weapons.numweapons++;
3496                                                 } else if(tutorialstage==50){
3497                                                         tutorialmaxtime=8;
3498
3499                                                         XYZ temp,temp2;
3500                                                         float gLoc[3];
3501                                                         float vel[3];
3502                                                         gLoc[0]=player[1].coords.x;
3503                                                         gLoc[1]=player[1].coords.y;
3504                                                         gLoc[2]=player[1].coords.z;
3505                                                         vel[0]=0;
3506                                                         vel[1]=0;
3507                                                         vel[2]=0;
3508                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3509                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3510                                                         OPENAL_SetVolume(channels[fireendsound], 256);
3511                                                         OPENAL_SetPaused(channels[fireendsound], false);
3512
3513                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
3514                                                                 if(Random()%2==0){
3515                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
3516                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
3517                                                                         if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
3518                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
3519                                                                         Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3520                                                                 }
3521                                                         }
3522
3523                                                         player[1].num_weapons=0;
3524                                                         player[1].weaponstuck=-1;
3525                                                         player[1].weaponactive=-1;
3526
3527                                                         weapons.numweapons=0;
3528
3529                                                         weapons.owner[0]=-1;
3530                                                         weapons.velocity[0]=0.1;
3531                                                         weapons.tipvelocity[0]=-0.1;
3532                                                         weapons.missed[0]=1;
3533                                                         weapons.hitsomething[0]=0;
3534                                                         weapons.freetime[0]=0;
3535                                                         weapons.firstfree[0]=1;
3536                                                         weapons.physics[0]=1;
3537                                                 } else if(tutorialstage==51){
3538                                                         tutorialmaxtime=80000;
3539                                                 }
3540                                                 if(tutorialstage<=51)tutorialstagetime=0;
3541                                         }
3542
3543                                         //Tutorial success
3544                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
3545                                                 if(tutorialstage==3){
3546                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
3547                                                 }
3548                                                 if(tutorialstage==4){
3549                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
3550                                                 }
3551                                                 if(tutorialstage==5){
3552                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
3553                                                 }
3554                                                 if(tutorialstage==6){
3555                                                         if(player[0].isCrouch())tutorialsuccess=1;
3556                                                 }
3557                                                 if(tutorialstage==7){
3558                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
3559                                                 }
3560                                                 if(tutorialstage==8){
3561                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
3562                                                 }
3563                                                 if(tutorialstage==9){
3564                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
3565                                                 }
3566                                                 if(tutorialstage==11){
3567                                                         if(player[0].isWallJump())tutorialsuccess=1;
3568                                                 }
3569                                                 if(tutorialstage==12){
3570                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
3571                                                 }
3572                                                 if(tutorialstage==15){
3573                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
3574                                                 }
3575                                                 if(tutorialstage==16){
3576                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
3577                                                 }
3578                                                 if(tutorialstage==17){
3579                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
3580                                                 }
3581                                                 if(tutorialstage==18){
3582                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
3583                                                 }
3584                                                 if(tutorialstage==19){
3585                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
3586                                                 }
3587                                                 if(tutorialstage==20){
3588                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
3589                                                 }
3590                                                 if(tutorialstage==21){
3591                                                         if(bonus==cannon)tutorialsuccess=1;
3592                                                 }
3593                                                 if(tutorialstage==22){
3594                                                         if(bonus==spinecrusher)tutorialsuccess=1;
3595                                                 }
3596                                                 if(tutorialstage==23){
3597                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
3598                                                 }
3599                                                 if(tutorialstage==24){
3600                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
3601                                                 }
3602                                                 if(tutorialstage==25){
3603                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
3604                                                 }
3605                                                 if(tutorialstage==28){
3606                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
3607                                                 }
3608                                                 if(tutorialstage==29){
3609                                                         if(player[0].escapednum==2){
3610                                                                 tutorialsuccess=1;
3611                                                                 reversaltrain=0;
3612                                                                 cananger=0;
3613                                                                 player[1].aitype=passivetype;
3614                                                         }
3615                                                 }
3616                                                 if(tutorialstage==33){
3617                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3618                                                 }
3619                                                 if(tutorialstage==34){
3620                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3621                                                 }
3622                                                 if(tutorialstage==35){
3623                                                         if(animation[player[0].targetanimation].attack==reversal){
3624                                                                 tutorialsuccess=1;
3625                                                                 reversaltrain=0;
3626                                                                 cananger=0;
3627                                                                 player[1].aitype=passivetype;
3628                                                         }
3629                                                 }
3630                                                 if(tutorialstage==40){
3631                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
3632                                                 }
3633                                                 if(tutorialstage==41){
3634                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
3635                                                 }
3636                                                 if(tutorialstage==43){
3637                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
3638                                                 }
3639                                                 if(tutorialstage==44){
3640                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3641                                                 }
3642                                                 if(tutorialstage==45){
3643                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3644                                                 }
3645                                                 if(tutorialstage==46){
3646                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3647                                                 }
3648                                                 if(tutorialstage==49){
3649                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
3650                                                 }
3651                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
3652
3653
3654                                                 if(tutorialstagetime==tutorialmaxtime-3){
3655                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3656                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3657                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3658                                                 }
3659
3660                                                 if(tutorialsuccess>=1){
3661                                                         if(tutorialstage==34||tutorialstage==35)
3662                                                                 tutorialstagetime=tutorialmaxtime-1;
3663                                                 }
3664                                         }
3665
3666                                         if(tutoriallevel){
3667                                                 if(tutorialstage<14||tutorialstage>=50){
3668                                                         player[1].coords.y=300;
3669                                                         player[1].velocity=0;
3670                                                 }
3671                                         }
3672
3673                                         if(tutoriallevel!=1){
3674                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
3675                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3676                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3677                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3678                                                 }
3679                                         }
3680                                         else
3681                                                 if(bonustime==0){
3682                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3683                                                         OPENAL_SetVolume(channels[fireendsound], 256);
3684                                                         OPENAL_SetPaused(channels[fireendsound], false);
3685                                                 }
3686                                                 if(bonustime==0){
3687                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
3688                                                         else bonusnum[bonus]+=0.15;
3689                                                         if(tutoriallevel)bonusvalue=0;
3690                                                         bonusvalue/=bonusnum[bonus];
3691                                                         bonustotal+=bonusvalue;
3692                                                 }
3693                                                 bonustime+=multiplier;
3694
3695                                                 if(environment==snowyenvironment){
3696                                                         precipdelay-=multiplier;
3697                                                         while(precipdelay<0){
3698                                                                 precipdelay+=.04;
3699                                                                 if(!detail)precipdelay+=.04;
3700                                                                 XYZ footvel,footpoint;
3701
3702                                                                 footvel=0;
3703                                                                 footpoint=viewer+viewerfacing*6;
3704                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
3705                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
3706                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
3707                                                                 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
3708                                                         }
3709                                                 }
3710                                                 for(k=0;k<numplayers;k++){
3711                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
3712                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
3713
3714                                                         if((player[k].isRun()&&((player[k].targetrotation!=rabbitrunninganim&&player[k].targetrotation!=wolfrunninganim)||player[k].targetframe==4))||player[k].targetanimation==removeknifeanim||player[k].targetanimation==crouchremoveknifeanim||player[k].targetanimation==flipanim||player[k].targetanimation==fightsidestep||player[k].targetanimation==walkanim){
3715                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3716                                                                 else if(player[k].rotation>player[k].targetrotation){
3717                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
3718                                                                 }
3719                                                                 else if(player[k].rotation<player[k].targetrotation){
3720                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
3721                                                                 }
3722                                                         }
3723
3724
3725                                                         if(player[k].isStop()||player[k].isLanding()||player[k].targetanimation==staggerbackhighanim||(player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||player[k].targetanimation==staggerbackhardanim||player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim||player[k].targetanimation==rollanim||(animation[player[k].targetanimation].attack&&player[k].targetanimation!=rabbitkickanim&&(player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&(player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3726                                                                 player[k].turnspeed*=2;
3727                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3728                                                                 else if(player[k].rotation>player[k].targetrotation){
3729                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
3730                                                                 }
3731                                                                 else if(player[k].rotation<player[k].targetrotation){
3732                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
3733                                                                 }
3734                                                                 player[k].turnspeed/=2;
3735                                                         }
3736
3737                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3738                                                                 player[k].turnspeed*=4;
3739                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3740                                                                 else if(player[k].rotation>player[k].targetrotation){
3741                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
3742                                                                 }
3743                                                                 else if(player[k].rotation<player[k].targetrotation){
3744                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
3745                                                                 }
3746                                                                 player[k].turnspeed/=4;
3747                                                         }
3748
3749                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
3750                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
3751
3752                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
3753                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
3754                                                                         bool tempcollide=0;
3755
3756                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
3757                                                                         if(player[k].collide>1)player[k].collide=1;
3758                                                                         player[k].collide-=multiplier*30;
3759
3760                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
3761                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3762                                                                         }
3763                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
3764                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3765                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3766                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
3767                                                                                                 lowpoint=player[k].coords;
3768                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
3769                                                                                                 else lowpoint.y+=1.3;
3770                                                                                                 if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1){
3771                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3772                                                                                                 }
3773                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
3774                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
3775                                                                                                 */
3776                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3777                                                                                                         flatfacing=lowpoint-player[k].coords;
3778                                                                                                         player[k].coords=lowpoint;
3779                                                                                                         player[k].coords.y-=1.3;
3780                                                                                                         player[k].collide=1;
3781                                                                                                         tempcollide=1;
3782                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
3783                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3784                                                                                                                 tempcoords1=lowpoint;
3785                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3786                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3787                                                                                                                         player[k].target=0;
3788                                                                                                                         player[k].targetanimation=walljumpleftanim;
3789                                                                                                                         player[k].targetframe=0;
3790                                                                                                                         float gLoc[3];
3791                                                                                                                         float vel[3];
3792                                                                                                                         gLoc[0]=player[k].coords.x;
3793                                                                                                                         gLoc[1]=player[k].coords.y;
3794                                                                                                                         gLoc[2]=player[k].coords.z;
3795                                                                                                                         vel[0]=0;
3796                                                                                                                         vel[1]=0;
3797                                                                                                                         vel[2]=0;
3798                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3799                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3800                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
3801                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
3802                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3803
3804                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3805                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
3806                                                                                                                         player[k].rotation*=360/6.28;
3807                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3808                                                                                                                         player[k].targetrotation=player[k].rotation;
3809                                                                                                                         player[k].lowrotation=player[k].rotation;
3810                                                                                                                         if(k==0)numwallflipped++;
3811                                                                                                                 }
3812                                                                                                                 else
3813                                                                                                                 {
3814                                                                                                                         lowpoint=tempcoords1;
3815                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3816                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3817                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3818                                                                                                                                 player[k].target=0;
3819                                                                                                                                 player[k].targetanimation=walljumprightanim;
3820                                                                                                                                 player[k].targetframe=0;
3821                                                                                                                                 float gLoc[3];
3822                                                                                                                                 float vel[3];
3823                                                                                                                                 gLoc[0]=player[k].coords.x;
3824                                                                                                                                 gLoc[1]=player[k].coords.y;
3825                                                                                                                                 gLoc[2]=player[k].coords.z;
3826                                                                                                                                 vel[0]=0;
3827                                                                                                                                 vel[1]=0;
3828                                                                                                                                 vel[2]=0;
3829                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3830                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3831                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
3832                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
3833                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3834
3835                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3836                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
3837                                                                                                                                 player[k].rotation*=360/6.28;
3838                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3839                                                                                                                                 player[k].targetrotation=player[k].rotation;
3840                                                                                                                                 player[k].lowrotation=player[k].rotation;
3841                                                                                                                                 if(k==0)numwallflipped++;
3842                                                                                                                         }
3843                                                                                                                         else
3844                                                                                                                         {
3845                                                                                                                                 lowpoint=tempcoords1;
3846                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
3847                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3848                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3849                                                                                                                                         player[k].target=0;
3850                                                                                                                                         player[k].targetanimation=walljumpbackanim;
3851                                                                                                                                         player[k].targetframe=0;
3852                                                                                                                                         float gLoc[3];
3853                                                                                                                                         float vel[3];
3854                                                                                                                                         gLoc[0]=player[k].coords.x;
3855                                                                                                                                         gLoc[1]=player[k].coords.y;
3856                                                                                                                                         gLoc[2]=player[k].coords.z;
3857                                                                                                                                         vel[0]=0;
3858                                                                                                                                         vel[1]=0;
3859                                                                                                                                         vel[2]=0;
3860                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3861                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3862                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
3863                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
3864                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3865
3866                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3867                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
3868                                                                                                                                         player[k].rotation*=360/6.28;
3869                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3870                                                                                                                                         player[k].targetrotation=player[k].rotation;
3871                                                                                                                                         player[k].lowrotation=player[k].rotation;
3872                                                                                                                                         if(k==0)numwallflipped++;
3873                                                                                                                                 }
3874                                                                                                                                 else
3875                                                                                                                                 {
3876                                                                                                                                         lowpoint=tempcoords1;
3877                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
3878                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3879                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3880                                                                                                                                                 player[k].target=0;
3881                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
3882                                                                                                                                                 player[k].targetframe=0;
3883                                                                                                                                                 float gLoc[3];
3884                                                                                                                                                 float vel[3];
3885                                                                                                                                                 gLoc[0]=player[k].coords.x;
3886                                                                                                                                                 gLoc[1]=player[k].coords.y;
3887                                                                                                                                                 gLoc[2]=player[k].coords.z;
3888                                                                                                                                                 vel[0]=0;
3889                                                                                                                                                 vel[1]=0;
3890                                                                                                                                                 vel[2]=0;
3891                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3892                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3893                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
3894                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
3895                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3896
3897                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3898                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
3899                                                                                                                                                 player[k].rotation*=360/6.28;
3900                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3901                                                                                                                                                 player[k].rotation+=180;
3902                                                                                                                                                 player[k].targetrotation=player[k].rotation;
3903                                                                                                                                                 player[k].lowrotation=player[k].rotation;
3904                                                                                                                                                 if(k==0)numwallflipped++;
3905                                                                                                                                         }
3906                                                                                                                                 }
3907                                                                                                                         }
3908                                                                                                                 }
3909                                                                                                         }
3910                                                                                                 }
3911                                                                                         }
3912                                                                                         else if(objects.type[i]==rocktype){
3913                                                                                                 lowpoint2=player[k].coords;
3914                                                                                                 lowpoint=player[k].coords;
3915                                                                                                 lowpoint.y+=2;
3916                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3917                                                                                                         player[k].coords=colpoint;
3918                                                                                                         player[k].collide=1;
3919                                                                                                         tempcollide=1;
3920
3921                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
3922                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
3923
3924                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
3925                                                                                                                 player[k].target=0;
3926                                                                                                                 player[k].targetframe=0;
3927                                                                                                                 player[k].onterrain=1;
3928
3929                                                                                                                 if(player[k].id==0){
3930                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
3931                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
3932                                                                                                                 }
3933
3934                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3935                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
3936                                                                                                                         player[k].targetanimation=player[k].getLanding();
3937                                                                                                                         float gLoc[3];
3938                                                                                                                         float vel[3];
3939                                                                                                                         gLoc[0]=player[k].coords.x;
3940                                                                                                                         gLoc[1]=player[k].coords.y;
3941                                                                                                                         gLoc[2]=player[k].coords.z;
3942                                                                                                                         vel[0]=player[k].velocity.x;
3943                                                                                                                         vel[1]=player[k].velocity.y;
3944                                                                                                                         vel[2]=player[k].velocity.z;
3945                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
3946                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
3947                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
3948                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
3949                                                                                                                         if(k==0){
3950                                                                                                                                 envsound[numenvsounds]=player[k].coords;
3951                                                                                                                                 envsoundvol[numenvsounds]=16;
3952                                                                                                                                 envsoundlife[numenvsounds]=.4;
3953                                                                                                                                 numenvsounds++;
3954                                                                                                                         }
3955
3956                                                                                                                 }
3957                                                                                                         }
3958                                                                                                 }
3959                                                                                         }
3960                                                                                 }
3961                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3962                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3963                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3964                                                                                                 lowpoint=player[k].coords;
3965                                                                                                 lowpoint.y+=1.35;
3966                                                                                                 if(objects.type[i]!=rocktype)
3967                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3968                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
3969                                                                                                                 player[k].coords=lowpoint;
3970                                                                                                                 player[k].coords.y-=1.35;
3971                                                                                                                 player[k].collide=1;
3972
3973                                                                                                                 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&((/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)&&*/player[k].currentanimation!=climbanim&&player[k].currentanimation!=hanganim&&!player[k].isWallJump())||player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
3974                                                                                                                         lowpoint=player[k].coords;
3975                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3976                                                                                                                         lowpoint=player[k].coords;
3977                                                                                                                         lowpoint.y+=.05;
3978                                                                                                                         facing=0;
3979                                                                                                                         facing.z=-1;
3980                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3981                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
3982                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3983                                                                                                                         if(whichhit!=-1){
3984                                                                                                                                 lowpoint=player[k].coords;
3985                                                                                                                                 lowpoint.y+=.1;
3986                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
3987                                                                                                                                 lowpoint2=lowpoint;
3988                                                                                                                                 lowpointtarget2=lowpointtarget;
3989                                                                                                                                 lowpoint3=lowpoint;
3990                                                                                                                                 lowpointtarget3=lowpointtarget;
3991                                                                                                                                 lowpoint4=lowpoint;
3992                                                                                                                                 lowpointtarget4=lowpointtarget;
3993                                                                                                                                 lowpoint5=lowpoint;
3994                                                                                                                                 lowpointtarget5=lowpointtarget;
3995                                                                                                                                 lowpoint6=lowpoint;
3996                                                                                                                                 lowpointtarget6=lowpointtarget;
3997                                                                                                                                 lowpoint7=lowpoint;
3998                                                                                                                                 lowpointtarget7=lowpoint;
3999                                                                                                                                 lowpoint2.x+=.1;
4000                                                                                                                                 lowpointtarget2.x+=.1;
4001                                                                                                                                 lowpoint3.z+=.1;
4002                                                                                                                                 lowpointtarget3.z+=.1;
4003                                                                                                                                 lowpoint4.x-=.1;
4004                                                                                                                                 lowpointtarget4.x-=.1;
4005                                                                                                                                 lowpoint5.z-=.1;
4006                                                                                                                                 lowpointtarget5.z-=.1;
4007                                                                                                                                 lowpoint6.y+=45/13;
4008                                                                                                                                 lowpointtarget6.y+=45/13;
4009                                                                                                                                 lowpointtarget6+=facing*.6;
4010                                                                                                                                 lowpointtarget7.y+=90/13;
4011                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4012                                                                                                                                 if(objects.friction[i]>.5)
4013                                                                                                                                         if(whichhit!=-1){
4014                                                                                                                                                 //if(k==0){
4015                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
4016                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
4017                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
4018                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,&colpoint,&objects.position[i],&objects.rotation[i])!=-1&&objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)
4019                                                                                                                                                                         for(j=0;j<45;j++){
4020                                                                                                                                                                                 lowpoint=player[k].coords;
4021                                                                                                                                                                                 lowpoint.y+=(float)j/13;
4022                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
4023                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
4024                                                                                                                                                                                         if(j<=6){
4025                                                                                                                                                                                                 j=100;
4026                                                                                                                                                                                         }
4027                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
4028                                                                                                                                                                                         j=100;
4029                                                                                                                                                                                         }*/
4030                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
4031                                                                                                                                                                                                 j=100;
4032                                                                                                                                                                                         }
4033                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
4034                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
4035                                                                                                                                                                                                 if(1==1/*dotproduct(&player[k].velocity,&lowpoint)>0||player[k].aitype!=playercontrolled||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim||player[k].targetanimation==jumpupanim)*/){
4036                                                                                                                                                                                                         lowpoint=player[k].coords;
4037                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
4038                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
4039                                                                                                                                                                                                         flatfacing=player[k].coords;
4040                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
4041                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
4042                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
4043
4044                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
4045                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
4046                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
4047                                                                                                                                                                                                                 }
4048                                                                                                                                                                                                                 float gLoc[3];
4049                                                                                                                                                                                                                 float vel[3];
4050                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
4051                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
4052                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
4053                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
4054                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
4055                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
4056                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
4057                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
4058                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
4059                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
4060
4061                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4062                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
4063                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
4064                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
4065                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
4066                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
4067
4068                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
4069                                                                                                                                                                                                                 player[k].velocity=0;
4070
4071                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
4072                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
4073                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
4074                                                                                                                                                                                                                         player[k].jumppower=0;
4075                                                                                                                                                                                                                         player[k].jumpclimb=1;
4076                                                                                                                                                                                                                 }
4077                                                                                                                                                                                                                 player[k].transspeed=6;
4078                                                                                                                                                                                                                 player[k].target=0;
4079
4080                                                                                                                                                                                                                 //player[k].currentframe=1;
4081                                                                                                                                                                                                                 player[k].targetframe=1;
4082                                                                                                                                                                                                                 if(j>25){
4083                                                                                                                                                                                                                         //player[k].currentframe=0;
4084                                                                                                                                                                                                                         player[k].targetframe=0;
4085                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
4086                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
4087                                                                                                                                                                                                                         player[k].jumppower=0;
4088                                                                                                                                                                                                                 }
4089                                                                                                                                                                                                         }
4090                                                                                                                                                                                                         j=100;
4091                                                                                                                                                                                                 }
4092                                                                                                                                                                                         }
4093                                                                                                                                                                                 }
4094                                                                                                                                                                         }
4095                                                                                                                                                                         //}
4096                                                                                                                                         }
4097                                                                                                                         }
4098                                                                                                                 }
4099                                                                                                         }
4100                                                                                         }
4101                                                                                         if(player[k].collide<=0){
4102                                                                                                 if(!player[k].onterrain&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim&&!player[k].isWallJump()&&!player[k].isFlip()){
4103                                                                                                         if(player[k].currentanimation!=climbanim&&player[k].currentanimation!=tempanim&&player[k].targetanimation!=backhandspringanim&&(player[k].targetanimation!=rollanim||player[k].targetframe<2||player[k].targetframe>6)){
4104                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
4105                                                                                                                 player[k].targetanimation=jumpdownanim;
4106                                                                                                                 player[k].targetframe=0;
4107                                                                                                                 player[k].target=0;
4108
4109                                                                                                                 float gLoc[3];
4110                                                                                                                 float vel[3];
4111                                                                                                                 gLoc[0]=player[k].coords.x;
4112                                                                                                                 gLoc[1]=player[k].coords.y;
4113                                                                                                                 gLoc[2]=player[k].coords.z;
4114                                                                                                                 vel[0]=player[k].velocity.x;
4115                                                                                                                 vel[1]=player[k].velocity.y;
4116                                                                                                                 vel[2]=player[k].velocity.z;
4117                                                                                                                 if(k==0){
4118                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
4119                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4120                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
4121                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
4122                                                                                                                 }
4123                                                                                                         }
4124                                                                                                         player[k].velocity.y+=gravity;
4125                                                                                                 }
4126                                                                                         }
4127                                                                 }
4128                                                         }
4129                                                         player[k].realoldcoords=player[k].coords;
4130                                                 }
4131
4132                                                 static XYZ oldviewer;
4133
4134                                                 if(indialogue==-1){
4135                                                         player[0].forwardkeydown=Input::isKeyDown(forwardkey);
4136                                                         player[0].leftkeydown=Input::isKeyDown(leftkey);
4137                                                         player[0].backkeydown=Input::isKeyDown(backkey);
4138                                                         player[0].rightkeydown=Input::isKeyDown(rightkey);
4139                                                         player[0].jumpkeydown=Input::isKeyDown(jumpkey);
4140                                                         player[0].crouchkeydown=Input::isKeyDown(crouchkey);
4141                                                         player[0].drawkeydown=Input::isKeyDown(drawkey);
4142                                                         player[0].throwkeydown=Input::isKeyDown(throwkey);
4143                                                 }
4144                                                 else
4145                                                 {
4146                                                         player[0].forwardkeydown=0;
4147                                                         player[0].leftkeydown=0;
4148                                                         player[0].backkeydown=0;
4149                                                         player[0].rightkeydown=0;
4150                                                         player[0].jumpkeydown=0;
4151                                                         player[0].crouchkeydown=0;
4152                                                         player[0].drawkeydown=0;
4153                                                         player[0].throwkeydown=0;
4154                                                 }
4155
4156                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
4157
4158
4159                                                 static bool endkeydown;
4160                                                 if(indialogue!=-1){
4161                                                         cameramode=1;
4162                                                         if(directing){
4163                                                                 facing=0;
4164                                                                 facing.z=-1;
4165
4166                                                                 facing=DoRotation(facing,-rotation2,0,0);
4167                                                                 facing=DoRotation(facing,0,0-rotation,0);
4168
4169                                                                 flatfacing=0;
4170                                                                 flatfacing.z=-1;
4171
4172                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
4173
4174                                                                 if(Input::isKeyDown(forwardkey))viewer+=facing*multiplier*4;
4175                                                                 if(Input::isKeyDown(backkey))viewer-=facing*multiplier*4;
4176                                                                 if(Input::isKeyDown(leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
4177                                                                 if(Input::isKeyDown(rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
4178                                                                 if(Input::isKeyDown(jumpkey))viewer.y+=multiplier*4;
4179                                                                 if(Input::isKeyDown(crouchkey))viewer.y-=multiplier*4;
4180                                                                 if(!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
4181                                                                         ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
4182                                                                         ||Input::isKeyDown(SDLK_MINUS))){
4183                                                                                 int whichend;
4184                                                                                 if(Input::isKeyDown(SDLK_1))whichend=1;
4185                                                                                 if(Input::isKeyDown(SDLK_2))whichend=2;
4186                                                                                 if(Input::isKeyDown(SDLK_3))whichend=3;
4187                                                                                 if(Input::isKeyDown(SDLK_4))whichend=4;
4188                                                                                 if(Input::isKeyDown(SDLK_5))whichend=5;
4189                                                                                 if(Input::isKeyDown(SDLK_6))whichend=6;
4190                                                                                 if(Input::isKeyDown(SDLK_7))whichend=7;
4191                                                                                 if(Input::isKeyDown(SDLK_8))whichend=8;
4192                                                                                 if(Input::isKeyDown(SDLK_9))whichend=9;
4193                                                                                 if(Input::isKeyDown(SDLK_0))whichend=0;
4194                                                                                 if(Input::isKeyDown(SDLK_MINUS))whichend=-1;
4195                                                                                 if(whichend!=-1){
4196                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
4197                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
4198                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
4199                                                                                 }
4200                                                                                 if(whichend==-1){
4201                                                                                         participantfocus[whichdialogue][indialogue]=-1;
4202                                                                                 }
4203                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
4204                                                                                         indialogue=-1;
4205                                                                                         directing=0;
4206                                                                                         cameramode=0;
4207                                                                                 }
4208                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
4209                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
4210                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
4211                                                                                 indialogue++;
4212                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
4213                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
4214                                                                                                 static float gLoc[3];
4215                                                                                                 static float vel[3];
4216                                                                                                 XYZ temppos;
4217                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4218                                                                                                 temppos=temppos-viewer;
4219                                                                                                 Normalise(&temppos);
4220                                                                                                 temppos+=viewer;
4221
4222                                                                                                 gLoc[0]=temppos.x;
4223                                                                                                 gLoc[1]=temppos.y;
4224                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
4225                                                                                                 vel[1]=0;
4226                                                                                                 vel[2]=0;
4227                                                                                                 int whichsoundplay;
4228                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
4229                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4230                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4231                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4232                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4233                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4234                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4235                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4236                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4237                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4238                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4239                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4240                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4241                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4242                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4243                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4244                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4245                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4246                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4247                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4248                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4249                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4250                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
4251                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
4252                                                                                         }
4253                                                                                 }
4254
4255                                                                                 for(j=0;j<numplayers;j++){
4256                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
4257                                                                                 }
4258
4259                                                                                 endkeydown=1;
4260                                                                         }
4261                                                                         if((Input::isKeyDown(SDLK_KP1)||Input::isKeyDown(SDLK_KP2)||Input::isKeyDown(SDLK_KP3)||Input::isKeyDown(SDLK_KP4)||Input::isKeyDown(SDLK_KP5)
4262                                                                                 ||Input::isKeyDown(SDLK_KP6)||Input::isKeyDown(SDLK_KP7)||Input::isKeyDown(SDLK_KP8)||Input::isKeyDown(SDLK_KP9)||Input::isKeyDown(SDLK_KP0)
4263                                                                                 )){
4264                                                                                         int whichend;
4265                                                                                         if(Input::isKeyDown(SDLK_KP1))whichend=1;
4266                                                                                         if(Input::isKeyDown(SDLK_KP2))whichend=2;
4267                                                                                         if(Input::isKeyDown(SDLK_KP3))whichend=3;
4268                                                                                         if(Input::isKeyDown(SDLK_KP4))whichend=4;
4269                                                                                         if(Input::isKeyDown(SDLK_KP5))whichend=5;
4270                                                                                         if(Input::isKeyDown(SDLK_KP6))whichend=6;
4271                                                                                         if(Input::isKeyDown(SDLK_KP7))whichend=7;
4272                                                                                         if(Input::isKeyDown(SDLK_KP8))whichend=8;
4273                                                                                         if(Input::isKeyDown(SDLK_KP9))whichend=9;
4274                                                                                         if(Input::isKeyDown(SDLK_KP0))whichend=0;
4275                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
4276                                                                                 }
4277                                                                                 if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
4278                                                                                         &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
4279                                                                                         &&!Input::isKeyDown(SDLK_MINUS)){
4280                                                                                                 endkeydown=0;
4281                                                                                         }
4282                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
4283                                                                                                 indialogue=-1;
4284                                                                                                 directing=0;
4285                                                                                                 cameramode=0;
4286                                                                                         }
4287                                                         }
4288                                                         if(!directing){
4289                                                                 OPENAL_SetPaused(channels[whooshsound], true);
4290                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
4291                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
4292                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
4293                                                                 }
4294                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
4295                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
4296                                                                 if(dialoguetime>0.5)
4297                                                                         if((!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
4298                                                                                 ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
4299                                                                                 ||Input::isKeyDown(SDLK_MINUS)))||(Input::isKeyDown(attackkey)&&!oldbuttondialogue)){
4300                                                                                         indialogue++;
4301                                                                                         endkeydown=1;
4302                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
4303                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
4304                                                                                                         static float gLoc[3];
4305                                                                                                         static float vel[3];
4306                                                                                                         XYZ temppos;
4307                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4308                                                                                                         temppos=temppos-viewer;
4309                                                                                                         Normalise(&temppos);
4310                                                                                                         temppos+=viewer;
4311
4312                                                                                                         gLoc[0]=temppos.x;
4313                                                                                                         gLoc[1]=temppos.y;
4314                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
4315                                                                                                         vel[1]=0;
4316                                                                                                         vel[2]=0;
4317                                                                                                         int whichsoundplay;
4318                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
4319                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4320                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4321                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4322                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4323                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4324                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4325                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4326                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4327                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4328                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4329                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4330                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4331                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4332                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4333                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4334                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4335                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4336                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4337                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4338                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
4339                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
4340                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4341                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4342                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
4343                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
4344                                                                                                         }
4345                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
4346                                                                                                                 hotspot[numhotspots]=player[0].coords;
4347                                                                                                                 hotspotsize[numhotspots]=10;
4348                                                                                                                 hotspottype[numhotspots]=-1;
4349
4350                                                                                                                 numhotspots++;
4351                                                                                                         }
4352                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
4353                                                                                                                 hostile=1;
4354                                                                                                         }
4355
4356                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
4357                                                                                                                 indialogue=-1;
4358                                                                                                                 directing=0;
4359                                                                                                                 cameramode=0;
4360                                                                                                         }
4361                                                                                                 }
4362                                                                                         }
4363                                                                                 }
4364                                                                                 if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
4365                                                                                         &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
4366                                                                                         &&!Input::isKeyDown(SDLK_MINUS)){
4367                                                                                                 endkeydown=0;
4368                                                                                         }
4369                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
4370                                                                                                 indialogue=-1;
4371                                                                                                 directing=0;
4372                                                                                                 cameramode=0;
4373                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
4374                                                                                                         hostile=1;
4375                                                                                                 }
4376                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
4377                                                                                                         windialogue=1;
4378                                                                                                 }
4379                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
4380                                                                                                         hostile=1;
4381                                                                                                         for(i=1;i<numplayers;i++){
4382                                                                                                                 player[i].aitype = attacktypecutoff;
4383                                                                                                         }
4384                                                                                                 }
4385                                                                                         }
4386                                                         }
4387                                                 }
4388
4389                                                 if(!Input::isKeyDown(attackkey))oldbuttondialogue=0;
4390                                                 else oldbuttondialogue=1;
4391
4392                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
4393
4394                                                 if(!player[0].jumpkeydown){
4395                                                         player[0].jumptogglekeydown=0;
4396                                                 }
4397                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
4398
4399
4400                                                 dialoguetime+=multiplier;
4401                                                 skybox.cloudmove+=multiplier;
4402                                                 hawkrotation+=multiplier*25;
4403                                                 realhawkcoords=0;
4404                                                 realhawkcoords.x=25;
4405                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
4406                                                 hawkcalldelay-=multiplier/2;
4407
4408                                                 if(hawkcalldelay<=0)
4409                                                 {
4410                                                         static float gLoc[3];
4411                                                         static float vel[3];
4412                                                         gLoc[0]=realhawkcoords.x;
4413                                                         gLoc[1]=realhawkcoords.y;
4414                                                         gLoc[2]=realhawkcoords.z;
4415                                                         vel[0]=0;
4416                                                         vel[1]=0;
4417                                                         vel[2]=0;
4418                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
4419                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
4420                                                         OPENAL_SetVolume(channels[hawksound], 128);
4421                                                         OPENAL_SetPaused(channels[hawksound], false);
4422
4423                                                         hawkcalldelay=16+abs(Random()%8);
4424                                                 }
4425                                                 static float temptexdetail;
4426
4427
4428                                                 if(Input::isKeyDown(SDLK_h)&&debugmode){
4429                                                         player[0].damagetolerance=200000;
4430                                                         player[0].damage=0;
4431                                                         player[0].burnt=0;
4432                                                         player[0].permanentdamage=0;
4433                                                         player[0].superpermanentdamage=0;
4434                                                 }
4435
4436                                                 if(Input::isKeyDown(SDLK_j)&&!envtogglekeydown&&debugmode){
4437                                                         environment++;
4438                                                         if(environment>2)environment=0;
4439                                                         Setenvironment(environment);
4440
4441                                                         envtogglekeydown=1;
4442                                                 }
4443
4444
4445                                                 if(!Input::isKeyDown(SDLK_j)){
4446                                                         envtogglekeydown=0;
4447                                                 }
4448
4449                                                 if(Input::isKeyDown(SDLK_c)&&!cameratogglekeydown&&debugmode){
4450                                                         cameramode=1-cameramode;
4451                                                         cameratogglekeydown=1;
4452                                                 }
4453
4454                                                 if(!Input::isKeyDown(SDLK_c)){
4455                                                         cameratogglekeydown=0;
4456                                                 }
4457
4458                                                 if(Input::isKeyDown(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
4459                                                         if(player[0].num_weapons>0){
4460                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
4461                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
4462                                                                 else weapons.type[player[0].weaponids[0]]=sword;
4463                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
4464                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
4465                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
4466                                                                         weapons.length[player[0].weaponids[0]]=.8;
4467                                                                 }
4468                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
4469                                                                         weapons.mass[player[0].weaponids[0]]=2;
4470                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
4471                                                                         weapons.length[player[0].weaponids[0]]=1.5;
4472                                                                 }
4473
4474                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
4475                                                                         weapons.mass[player[0].weaponids[0]]=1;
4476                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
4477                                                                         weapons.length[player[0].weaponids[0]]=.25;
4478                                                                 }
4479                                                         }
4480                                                         detailtogglekeydown=1;
4481                                                 }
4482
4483                                                 if(Input::isKeyDown(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
4484                                                         int closest=-1;
4485                                                         float closestdist=-1;
4486                                                         float distance;
4487                                                         if(numplayers>1)
4488                                                                 for(i=1;i<numplayers;i++){
4489                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4490                                                                         if(closestdist==-1||distance<closestdist){
4491                                                                                 closestdist=distance;
4492                                                                                 closest=i;
4493                                                                         }
4494                                                                 }
4495                                                                 if(closest!=-1){
4496                                                                         if(player[closest].num_weapons)
4497                                                                         {
4498                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
4499                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
4500                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
4501                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
4502                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
4503                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
4504                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
4505                                                                                 }
4506                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
4507                                                                                         weapons.mass[player[0].weaponids[0]]=2;
4508                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
4509                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
4510                                                                                 }
4511                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
4512                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
4513                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
4514                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
4515                                                                                 }
4516                                                                         }
4517                                                                         if(!player[closest].num_weapons)
4518                                                                         {
4519                                                                                 player[closest].weaponids[0]=weapons.numweapons;
4520                                                                                 weapons.owner[weapons.numweapons]=closest;
4521                                                                                 weapons.type[weapons.numweapons]=knife;
4522                                                                                 weapons.damage[weapons.numweapons]=0;
4523                                                                                 weapons.numweapons++;
4524                                                                                 player[closest].num_weapons=1;
4525                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
4526                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
4527                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
4528                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
4529                                                                                 }
4530                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
4531                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
4532                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
4533                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
4534                                                                                 }
4535                                                                         }
4536                                                                 }
4537                                                                 detailtogglekeydown=1;
4538                                                 }
4539
4540                                                 if(Input::isKeyDown(SDLK_u)&&debugmode){
4541                                                         int closest=-1;
4542                                                         float closestdist=-1;
4543                                                         float distance;
4544                                                         if(numplayers>1)
4545                                                                 for(i=1;i<numplayers;i++){
4546                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4547                                                                         if(closestdist==-1||distance<closestdist){
4548                                                                                 closestdist=distance;
4549                                                                                 closest=i;
4550                                                                         }
4551                                                                 }
4552
4553                                                                 player[closest].rotation+=multiplier*50;
4554                                                                 player[closest].targetrotation=player[closest].rotation;
4555                                                 }
4556
4557
4558                                                 if(Input::isKeyDown(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4559                                                         int closest=-1;
4560                                                         float closestdist=-1;
4561                                                         float distance;
4562                                                         if(numplayers>1)
4563                                                                 for(i=1;i<numplayers;i++){
4564                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4565                                                                         if(closestdist==-1||distance<closestdist){
4566                                                                                 closestdist=distance;
4567                                                                                 closest=i;
4568                                                                         }
4569                                                                 }
4570                                                                 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
4571
4572                                                                 if(closest!=-1){
4573                                                                         player[closest].whichskin++;
4574                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
4575                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
4576
4577                                                                         LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
4578                                                                                         &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4579                                                                 }
4580
4581                                                                 if(player[closest].numclothes){
4582                                                                         for(i=0;i<player[closest].numclothes;i++){
4583                                                                                 tintr=player[closest].clothestintr[i];
4584                                                                                 tintg=player[closest].clothestintg[i];
4585                                                                                 tintb=player[closest].clothestintb[i];
4586                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4587                                                                         }
4588                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
4589                                                                 }
4590
4591                                                                 detailtogglekeydown=1;
4592                                                 }
4593
4594                                                 if(Input::isKeyDown(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4595                                                         int closest=-1;
4596                                                         float closestdist=-1;
4597                                                         float distance;
4598                                                         if(numplayers>1)
4599                                                                 for(i=1;i<numplayers;i++){
4600                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4601                                                                         if(closestdist==-1||distance<closestdist){
4602                                                                                 closestdist=distance;
4603                                                                                 closest=i;
4604                                                                         }
4605                                                                 }
4606                                                                 if(closest!=-1){
4607                                                                         if(player[closest].creature==wolftype){
4608                                                                                 headprop=player[closest].proportionhead.x/1.1;
4609                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
4610                                                                                 armprop=player[closest].proportionarms.x/1.1;
4611                                                                                 legprop=player[closest].proportionlegs.x/1.1;
4612                                                                         }
4613
4614                                                                         if(player[closest].creature==rabbittype){
4615                                                                                 headprop=player[closest].proportionhead.x/1.2;
4616                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
4617                                                                                 armprop=player[closest].proportionarms.x/1.00;
4618                                                                                 legprop=player[closest].proportionlegs.x/1.1;
4619                                                                         }
4620
4621
4622                                                                         if(player[closest].creature==rabbittype){
4623                                                                                 player[closest].skeleton.id=closest;
4624                                                                                 player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
4625                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
4626                                                                                 player[closest].whichskin=0;
4627                                                                                 player[closest].creature=wolftype;
4628
4629                                                                                 player[closest].proportionhead=1.1;
4630                                                                                 player[closest].proportionbody=1.1;
4631                                                                                 player[closest].proportionarms=1.1;
4632                                                                                 player[closest].proportionlegs=1.1;
4633                                                                                 player[closest].proportionlegs.y=1.1;
4634                                                                                 player[closest].scale=.23*5*player[0].scale;
4635
4636                                                                                 player[closest].damagetolerance=300;
4637                                                                         }
4638                                                                         else
4639                                                                         {
4640                                                                                 player[closest].skeleton.id=closest;
4641                                                                                 player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
4642                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4643                                                                                 player[closest].whichskin=0;
4644                                                                                 player[closest].creature=rabbittype;
4645
4646                                                                                 player[closest].proportionhead=1.2;
4647                                                                                 player[closest].proportionbody=1.05;
4648                                                                                 player[closest].proportionarms=1.00;
4649                                                                                 player[closest].proportionlegs=1.1;
4650                                                                                 player[closest].proportionlegs.y=1.05;
4651                                                                                 player[closest].scale=.2*5*player[0].scale;
4652
4653                                                                                 player[closest].damagetolerance=200;
4654                                                                         }
4655
4656                                                                         if(player[closest].creature==wolftype){
4657                                                                                 player[closest].proportionhead=1.1*headprop;
4658                                                                                 player[closest].proportionbody=1.1*bodyprop;
4659                                                                                 player[closest].proportionarms=1.1*armprop;
4660                                                                                 player[closest].proportionlegs=1.1*legprop;
4661                                                                         }
4662
4663                                                                         if(player[closest].creature==rabbittype){
4664                                                                                 player[closest].proportionhead=1.2*headprop;
4665                                                                                 player[closest].proportionbody=1.05*bodyprop;
4666                                                                                 player[closest].proportionarms=1.00*armprop;
4667                                                                                 player[closest].proportionlegs=1.1*legprop;
4668                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4669                                                                         }
4670
4671                                                                 }
4672                                                                 detailtogglekeydown=1;
4673                                                 }
4674
4675                                                 if(!Input::isKeyDown(SDLK_x)){
4676                                                         detailtogglekeydown=0;
4677                                                 }
4678
4679                                                 if(Input::isKeyDown(SDLK_b)&&!slomotogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4680                                                         slomo=1-slomo;
4681                                                         slomodelay=1000;
4682                                                         slomotogglekeydown=1;
4683                                                 }
4684
4685
4686                                                 if(((Input::isKeyDown(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
4687                                                         int closest=-1;
4688                                                         float closestdist=-1;
4689                                                         float distance;
4690                                                         XYZ flatfacing2,flatvelocity2;
4691                                                         XYZ blah;
4692                                                         if(numplayers>1)
4693                                                                 for(i=1;i<numplayers;i++){
4694                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4695                                                                         if(distance<144&&!player[i].headless)
4696                                                                                 if(closestdist==-1||distance<closestdist){
4697                                                                                         closestdist=distance;
4698                                                                                         closest=i;
4699                                                                                         blah = player[i].coords;
4700                                                                                 }
4701                                                                 }
4702
4703                                                                 if(closest!=-1){
4704                                                                         XYZ headspurtdirection;
4705                                                                         int i = player[closest].skeleton.jointlabels[head];
4706                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
4707                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4708                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4709                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
4710                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4711                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4712                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4713                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4714                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
4715                                                                                 Normalise(&headspurtdirection);
4716                                                                                 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
4717                                                                                 flatvelocity2+=headspurtdirection*8;
4718                                                                                 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
4719                                                                         }
4720                                                                         Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
4721
4722                                                                         float gLoc[3];
4723                                                                         float vel[3];
4724                                                                         gLoc[0]=blah.x;
4725                                                                         gLoc[1]=blah.y;
4726                                                                         gLoc[2]=blah.z;
4727                                                                         vel[0]=0;
4728                                                                         vel[1]=0;
4729                                                                         vel[2]=0;
4730                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
4731                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
4732                                                                         OPENAL_SetVolume(channels[splattersound], 256);
4733                                                                         OPENAL_SetPaused(channels[splattersound], false);
4734
4735                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
4736                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
4737                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
4738                                                                         OPENAL_SetPaused(channels[breaksound2], false);
4739
4740                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
4741                                                                         player[closest].RagDoll(0);
4742                                                                         player[closest].dead=2;
4743                                                                         player[closest].headless=1;
4744                                                                         player[closest].DoBloodBig(3,165);
4745
4746                                                                         camerashake+=.3;
4747                                                                 }
4748
4749                                                                 explodetogglekeydown=1;
4750                                                 }
4751
4752                                                 if(((Input::isKeyDown(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
4753                                                         int closest=-1;
4754                                                         float closestdist=-1;
4755                                                         float distance;
4756                                                         XYZ flatfacing2,flatvelocity2;
4757                                                         XYZ blah;
4758                                                         if(numplayers>1)
4759                                                                 for(i=1;i<numplayers;i++){
4760                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4761                                                                         if(distance<144)
4762                                                                                 if(closestdist==-1||distance<closestdist){
4763                                                                                         closestdist=distance;
4764                                                                                         closest=i;
4765                                                                                         blah=player[i].coords;
4766                                                                                 }
4767                                                                 }
4768
4769                                                                 if(closest!=-1){
4770                                                                         float gLoc[3];
4771                                                                         float vel[3];
4772                                                                         gLoc[0]=blah.x;
4773                                                                         gLoc[1]=blah.y;
4774                                                                         gLoc[2]=blah.z;
4775                                                                         vel[0]=0;
4776                                                                         vel[1]=0;
4777                                                                         vel[2]=0;
4778
4779                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
4780                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
4781                                                                         OPENAL_SetVolume(channels[splattersound], 256);
4782                                                                         OPENAL_SetPaused(channels[splattersound], false);
4783
4784                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
4785                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
4786                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
4787                                                                         OPENAL_SetPaused(channels[breaksound2], false);
4788
4789                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
4790                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4791                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4792                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
4793                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4794                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4795                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4796                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4797                                                                                 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
4798                                                                                 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
4799                                                                                 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
4800                                                                         }
4801
4802                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
4803                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4804                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4805                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
4806                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4807                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4808                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4809                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4810                                                                                 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
4811                                                                                 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
4812                                                                         }
4813
4814                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
4815                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4816                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4817                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
4818                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4819                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4820                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4821                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4822                                                                                 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
4823                                                                                 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
4824                                                                         }
4825
4826                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
4827                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4828                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4829                                                                                 if(!player[closest].skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(player[closest].skeleton.joints[i].position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
4830                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4831                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4832                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4833                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4834                                                                                 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
4835                                                                                 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
4836                                                                         }
4837
4838                                                                         XYZ temppos;
4839                                                                         for(j=0;j<numplayers; j++){
4840                                                                                 if(j!=closest){
4841                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
4842                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
4843                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
4844                                                                                                 player[j].skeleton.longdead=0;
4845                                                                                                 player[j].RagDoll(0);
4846                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
4847                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
4848                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
4849                                                                                                                 flatvelocity2=temppos-player[closest].coords;
4850                                                                                                                 Normalise(&flatvelocity2);
4851                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
4852                                                                                                         }
4853                                                                                                 }
4854                                                                                         }
4855                                                                                 }
4856                                                                         }
4857
4858                                                                         player[closest].DoDamage(10000);
4859                                                                         player[closest].RagDoll(0);
4860                                                                         player[closest].dead=2;
4861                                                                         player[closest].coords=20;
4862                                                                         player[closest].skeleton.free=2;
4863
4864                                                                         camerashake+=.6;
4865
4866                                                                 }
4867
4868                                                                 explodetogglekeydown=1;
4869                                                 }
4870
4871                                                 if(!Input::isKeyDown(SDLK_i)){
4872                                                         explodetogglekeydown=0;
4873                                                 }
4874
4875                                                 if(!Input::isKeyDown(SDLK_b)&&!Input::isKeyDown(SDLK_f)&&!Input::isKeyDown(SDLK_k)&&!Input::isKeyDown(SDLK_s)){
4876                                                         slomotogglekeydown=0;
4877                                                 }
4878
4879
4880                                                 if(Input::isKeyDown(SDLK_f)&&!slomotogglekeydown&&debugmode){
4881                                                         player[0].onfire=1-player[0].onfire;
4882                                                         if(player[0].onfire){
4883                                                                 player[0].CatchFire();
4884                                                         }
4885                                                         if(!player[0].onfire){
4886                                                                 float gLoc[3];
4887                                                                 float vel[3];
4888                                                                 gLoc[0]=player[0].coords.x;
4889                                                                 gLoc[1]=player[0].coords.y;
4890                                                                 gLoc[2]=player[0].coords.z;
4891                                                                 vel[0]=0;
4892                                                                 vel[1]=0;
4893                                                                 vel[2]=0;
4894                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
4895                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
4896                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
4897                                                                 OPENAL_SetPaused(channels[fireendsound], false);
4898                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
4899                                                         }
4900                                                         slomotogglekeydown=1;
4901                                                 }
4902
4903                                                 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)){
4904                                                         int closest=-1;
4905                                                         float closestdist=-1;
4906                                                         float distance;
4907                                                         if(numplayers>1)
4908                                                                 for(i=1;i<numplayers;i++){
4909                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
4910                                                                         if(closestdist==-1||distance<closestdist){
4911                                                                                 closestdist=distance;
4912                                                                                 closest=i;
4913                                                                         }
4914                                                                 }
4915                                                                 if(closestdist>0&&closest>=0){
4916                                                                         //player[closest]=player[numplayers-1];
4917                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
4918                                                                         numplayers--;
4919                                                                 }
4920                                                                 drawmodetogglekeydown=1;
4921                                                 }
4922
4923                                                 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)){
4924                                                         int closest=-1;
4925                                                         float closestdist=-1;
4926                                                         float distance;
4927                                                         if(max_objects>1)
4928                                                                 for(i=1;i<max_objects;i++){
4929                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
4930                                                                         if(closestdist==-1||distance<closestdist){
4931                                                                                 closestdist=distance;
4932                                                                                 closest=i;
4933                                                                         }
4934                                                                 }
4935                                                                 if(closestdist>0&&closest>=0){
4936                                                                         objects.position[closest].y-=500;
4937                                                                 }
4938                                                                 drawmodetogglekeydown=1;
4939                                                 }
4940
4941                                                 if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&editorenabled&&debugmode){
4942                                                         //drawmode++;
4943                                                         //if(drawmode>2)drawmode=0;
4944                                                         if(objects.numobjects<max_objects-1){
4945                                                                 XYZ boxcoords;
4946                                                                 boxcoords.x=player[0].coords.x;
4947                                                                 boxcoords.z=player[0].coords.z;
4948                                                                 boxcoords.y=player[0].coords.y-3;
4949                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
4950                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
4951                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
4952                                                                 float temprotat,temprotat2;
4953                                                                 temprotat=editorrotation;
4954                                                                 temprotat2=editorrotation2;
4955                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
4956                                                                 if(temprotat2<0)temprotat2=Random()%360;
4957
4958                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
4959                                                                 if(editortype==treetrunktype)
4960                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
4961                                                         }
4962
4963                                                         drawmodetogglekeydown=1;
4964                                                 }
4965
4966                                                 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
4967                                                         if(numplayers<maxplayers-1){
4968                                                                 player[numplayers].scale=.2*5*player[0].scale;
4969                                                                 player[numplayers].creature=rabbittype;
4970                                                                 player[numplayers].howactive=editoractive;
4971                                                                 player[numplayers].skeleton.id=numplayers;
4972                                                                 player[numplayers].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
4973
4974                                                                 //texsize=512*512*3/texdetail/texdetail;
4975                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
4976                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
4977
4978                                                                 k=abs(Random()%2)+1;
4979                                                                 if(k==0){
4980                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
4981                                                                         player[numplayers].whichskin=0;
4982                                                                 }
4983                                                                 else if(k==1){
4984                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
4985                                                                         player[numplayers].whichskin=1;
4986                                                                 }
4987                                                                 else {
4988                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
4989                                                                         player[numplayers].whichskin=2;
4990                                                                 }
4991
4992                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
4993                                                                 player[numplayers].power=1;
4994                                                                 player[numplayers].speedmult=1;
4995                                                                 player[numplayers].currentanimation=bounceidleanim;
4996                                                                 player[numplayers].targetanimation=bounceidleanim;
4997                                                                 player[numplayers].currentframe=0;
4998                                                                 player[numplayers].targetframe=1;
4999                                                                 player[numplayers].target=0;
5000                                                                 player[numplayers].bled=0;
5001                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
5002
5003                                                                 player[numplayers].targetrotation=player[0].targetrotation;
5004                                                                 player[numplayers].rotation=player[0].rotation;
5005
5006                                                                 player[numplayers].velocity=0;
5007                                                                 player[numplayers].coords=player[0].coords;
5008                                                                 player[numplayers].oldcoords=player[numplayers].coords;
5009                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
5010
5011                                                                 player[numplayers].id=numplayers;
5012                                                                 player[numplayers].skeleton.id=numplayers;
5013                                                                 player[numplayers].updatedelay=0;
5014                                                                 player[numplayers].normalsupdatedelay=0;
5015
5016                                                                 player[numplayers].aitype=passivetype;
5017                                                                 player[numplayers].aitarget=0;
5018
5019                                                                 if(player[0].creature==wolftype){
5020                                                                         headprop=player[0].proportionhead.x/1.1;
5021                                                                         bodyprop=player[0].proportionbody.x/1.1;
5022                                                                         armprop=player[0].proportionarms.x/1.1;
5023                                                                         legprop=player[0].proportionlegs.x/1.1;
5024                                                                 }
5025
5026                                                                 if(player[0].creature==rabbittype){
5027                                                                         headprop=player[0].proportionhead.x/1.2;
5028                                                                         bodyprop=player[0].proportionbody.x/1.05;
5029                                                                         armprop=player[0].proportionarms.x/1.00;
5030                                                                         legprop=player[0].proportionlegs.x/1.1;
5031                                                                 }
5032
5033                                                                 if(player[numplayers].creature==wolftype){
5034                                                                         player[numplayers].proportionhead=1.1*headprop;
5035                                                                         player[numplayers].proportionbody=1.1*bodyprop;
5036                                                                         player[numplayers].proportionarms=1.1*armprop;
5037                                                                         player[numplayers].proportionlegs=1.1*legprop;
5038                                                                 }
5039
5040                                                                 if(player[numplayers].creature==rabbittype){
5041                                                                         player[numplayers].proportionhead=1.2*headprop;
5042                                                                         player[numplayers].proportionbody=1.05*bodyprop;
5043                                                                         player[numplayers].proportionarms=1.00*armprop;
5044                                                                         player[numplayers].proportionlegs=1.1*legprop;
5045                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
5046                                                                 }
5047
5048                                                                 player[numplayers].headless=0;
5049                                                                 player[numplayers].onfire=0;
5050
5051                                                                 if(cellophane){
5052                                                                         player[numplayers].proportionhead.z=0;
5053                                                                         player[numplayers].proportionbody.z=0;
5054                                                                         player[numplayers].proportionarms.z=0;
5055                                                                         player[numplayers].proportionlegs.z=0;
5056                                                                 }
5057
5058                                                                 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
5059
5060                                                                 player[numplayers].damagetolerance=200;
5061
5062                                                                 player[numplayers].protectionhead=player[0].protectionhead;
5063                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
5064                                                                 player[numplayers].protectionlow=player[0].protectionlow;
5065                                                                 player[numplayers].armorhead=player[0].armorhead;
5066                                                                 player[numplayers].armorhigh=player[0].armorhigh;
5067                                                                 player[numplayers].armorlow=player[0].armorlow;
5068                                                                 player[numplayers].metalhead=player[0].metalhead;
5069                                                                 player[numplayers].metalhigh=player[0].metalhigh;
5070                                                                 player[numplayers].metallow=player[0].metallow;
5071
5072                                                                 player[numplayers].immobile=player[0].immobile;
5073
5074                                                                 player[numplayers].numclothes=player[0].numclothes;
5075                                                                 if(player[numplayers].numclothes)
5076                                                                         for(i=0;i<player[numplayers].numclothes;i++){
5077                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
5078                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
5079                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
5080                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
5081                                                                                 tintr=player[numplayers].clothestintr[i];
5082                                                                                 tintg=player[numplayers].clothestintg[i];
5083                                                                                 tintb=player[numplayers].clothestintb[i];
5084                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
5085                                                                         }
5086                                                                         if(player[numplayers].numclothes){
5087                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
5088                                                                         }
5089
5090                                                                         player[numplayers].power=player[0].power;
5091                                                                         player[numplayers].speedmult=player[0].speedmult;
5092
5093                                                                         player[numplayers].damage=0;
5094                                                                         player[numplayers].permanentdamage=0;
5095                                                                         player[numplayers].superpermanentdamage=0;
5096                                                                         player[numplayers].deathbleeding=0;
5097                                                                         player[numplayers].bleeding=0;
5098                                                                         player[numplayers].numwaypoints=0;
5099                                                                         player[numplayers].waypoint=0;
5100                                                                         player[numplayers].jumppath=0;
5101                                                                         player[numplayers].weaponstuck=-1;
5102                                                                         player[numplayers].weaponactive=-1;
5103                                                                         player[numplayers].num_weapons=0;
5104                                                                         player[numplayers].bloodloss=0;
5105                                                                         player[numplayers].dead=0;
5106
5107                                                                         player[numplayers].loaded=1;
5108
5109                                                                         numplayers++;
5110                                                         }
5111                                                         drawmodetogglekeydown=1;
5112                                                 }
5113
5114                                                 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&editorenabled){
5115                                                         if(player[numplayers-1].numwaypoints<90){
5116                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
5117                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
5118                                                                 player[numplayers-1].numwaypoints++;
5119                                                         }
5120                                                         drawmodetogglekeydown=1;
5121                                                 }
5122
5123                                                 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
5124                                                         if(numpathpoints<30){
5125                                                                 bool connected,alreadyconnected;
5126                                                                 connected=0;
5127                                                                 if(numpathpoints>1)
5128                                                                         for(i=0;i<numpathpoints;i++){
5129                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
5130                                                                                         alreadyconnected=0;
5131                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
5132                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
5133                                                                                         }
5134                                                                                         if(!alreadyconnected){
5135                                                                                                 numpathpointconnect[pathpointselected]++;
5136                                                                                                 connected=1;
5137                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
5138                                                                                         }
5139                                                                                 }
5140                                                                         }
5141                                                                         if(!connected){
5142                                                                                 numpathpoints++;
5143                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
5144                                                                                 numpathpointconnect[numpathpoints-1]=0;
5145                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
5146                                                                                         numpathpointconnect[pathpointselected]++;
5147                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
5148                                                                                 }
5149                                                                                 pathpointselected=numpathpoints-1;
5150                                                                         }
5151                                                         }
5152                                                         drawmodetogglekeydown=1;
5153                                                 }
5154
5155                                                 if(Input::isKeyDown(SDLK_PERIOD)&&!drawmodetogglekeydown&&editorenabled){
5156                                                         pathpointselected++;
5157                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
5158                                                         drawmodetogglekeydown=1;
5159                                                 }
5160                                                 if(Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
5161                                                         pathpointselected--;
5162                                                         if(pathpointselected<=-2)
5163                                                                 pathpointselected=numpathpoints-1;
5164                                                         drawmodetogglekeydown=1;
5165                                                 }
5166                                                 if(Input::isKeyDown(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
5167                                                         if(pathpointselected!=-1){
5168                                                                 numpathpoints--;
5169                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
5170                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
5171                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
5172                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
5173                                                                 }
5174                                                                 for(i=0;i<numpathpoints;i++){
5175                                                                         for(j=0;j<numpathpointconnect[i];j++){
5176                                                                                 if(pathpointconnect[i][j]==pathpointselected){
5177                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
5178                                                                                         numpathpointconnect[i]--;
5179                                                                                 }
5180                                                                                 if(pathpointconnect[i][j]==numpathpoints){
5181                                                                                         pathpointconnect[i][j]=pathpointselected;
5182                                                                                 }
5183                                                                         }
5184                                                                 }
5185                                                                 pathpointselected=numpathpoints-1;
5186                                                         }
5187                                                         drawmodetogglekeydown=1;
5188                                                 }
5189
5190                                                 if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
5191                                                         editorenabled=1-editorenabled;
5192                                                         if(editorenabled){
5193                                                                 player[0].damagetolerance=100000;
5194                                                         } else {
5195                                                                 player[0].damagetolerance=200;
5196                                                         }
5197                                                         player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
5198                                                         player[0].permanentdamage=0;
5199                                                         player[0].superpermanentdamage=0;
5200                                                         player[0].bloodloss=0;
5201                                                         player[0].deathbleeding=0;
5202                                                         drawmodetogglekeydown=1;
5203                                                 }
5204
5205                                                 if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5206                                                         editortype--;
5207                                                         if(editortype==treeleavestype||editortype==10)editortype--;
5208                                                         if(editortype<0)editortype=firetype;
5209                                                         drawmodetogglekeydown=1;
5210                                                 }
5211
5212                                                 if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5213                                                         editortype++;
5214                                                         if(editortype==treeleavestype||editortype==10)editortype++;
5215                                                         if(editortype>firetype)editortype=0;
5216                                                         drawmodetogglekeydown=1;
5217                                                 }
5218
5219                                                 if(Input::isKeyDown(SDLK_LEFT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5220                                                         editorrotation-=multiplier*100;
5221                                                         if(editorrotation<-.01)editorrotation=-.01;
5222                                                         drawmodetogglekeydown=1;
5223                                                 }
5224
5225                                                 if(Input::isKeyDown(SDLK_RIGHT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5226                                                         editorrotation+=multiplier*100;
5227                                                         drawmodetogglekeydown=1;
5228                                                 }
5229
5230                                                 if(Input::isKeyDown(SDLK_UP)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
5231                                                         editorsize+=multiplier;
5232                                                         drawmodetogglekeydown=1;
5233                                                 }
5234
5235                                                 if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
5236                                                         editorsize-=multiplier;
5237                                                         if(editorsize<.1)editorsize=.1;
5238                                                         drawmodetogglekeydown=1;
5239                                                 }
5240
5241
5242                                                 if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
5243                                                         mapradius-=multiplier*10;
5244                                                 }
5245
5246                                                 if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
5247                                                         mapradius+=multiplier*10;
5248                                                 }
5249                                                 if(Input::isKeyDown(SDLK_UP)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
5250                                                         editorrotation2+=multiplier*100;
5251                                                 }
5252
5253                                                 if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
5254                                                         editorrotation2-=multiplier*100;
5255                                                         if(editorrotation2<-.01)editorrotation2=-.01;
5256                                                 }
5257                                                 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)){
5258                                                         int closest=-1;
5259                                                         float closestdist=-1;
5260                                                         float distance;
5261                                                         for(i=0;i<objects.numobjects;i++){
5262                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
5263                                                                 if(closestdist==-1||distance<closestdist){
5264                                                                         closestdist=distance;
5265                                                                         closest=i;
5266                                                                 }
5267                                                         }
5268                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
5269                                                         drawmodetogglekeydown=1;
5270                                                 }
5271
5272
5273                                                 if(!Input::isKeyDown(SDLK_m)&&!Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_PERIOD)&&!Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_DELETE)&&!Input::isKeyDown(SDLK_p)){
5274                                                         drawmodetogglekeydown=0;
5275                                                 }
5276
5277                                                 if(Input::isKeyDown(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
5278                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
5279                                                         player[0].RagDoll(0);
5280                                                         //player[0].spurt=1;
5281                                                         //player[0].DoDamage(1000);
5282
5283                                                         float gLoc[3];
5284                                                         float vel[3];
5285                                                         gLoc[0]=player[0].coords.x;
5286                                                         gLoc[1]=player[0].coords.y;
5287                                                         gLoc[2]=player[0].coords.z;
5288                                                         vel[0]=player[0].velocity.x;
5289                                                         vel[1]=player[0].velocity.y;
5290                                                         vel[2]=player[0].velocity.z;
5291                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
5292                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
5293                                                         OPENAL_SetVolume(channels[whooshsound], 128);
5294                                                         OPENAL_SetPaused(channels[whooshsound], false);
5295                                                         //OPENAL_SetPaused(channels[whooshsound], true);
5296
5297                                                         texturesizetogglekeydown=1;
5298                                                 }
5299
5300                                                 if(Input::isKeyDown(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
5301
5302                                                         int closest=-1;
5303                                                         float closestdist=-1;
5304                                                         float distance;
5305                                                         for(i=0;i<objects.numobjects;i++){
5306                                                                 if(objects.type[i]==treeleavestype){
5307                                                                         objects.scale[i]*=.9;
5308                                                                 }
5309                                                         }
5310                                                         texturesizetogglekeydown=1;
5311                                                 }
5312
5313                                                 static XYZ relative;
5314                                                 static int randattack;
5315                                                 //Attack
5316                                                 static bool playerrealattackkeydown=0;
5317
5318                                                 if(!Input::isKeyDown(MOUSEBUTTON1)&&!Input::isKeyDown(MOUSEBUTTON2))oldbutton=0;
5319                                                 if(!Input::isKeyDown(attackkey))oldattackkey=0;
5320                                                 if(oldattackkey)player[0].attackkeydown=0;
5321                                                 if(oldattackkey)playerrealattackkeydown=0;
5322                                                 if(!oldattackkey)playerrealattackkeydown=Input::isKeyDown(attackkey);
5323                                                 if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=Input::isKeyDown(attackkey);
5324                                                 if(Input::isKeyDown(attackkey)&&!oldattackkey&&!player[0].backkeydown){
5325                                                         for(k=0;k<numplayers;k++){
5326                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
5327                                                                         player[k].Reverse();
5328                                                         }
5329                                                 }
5330
5331                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
5332
5333                                                 for(k=0;k<numplayers;k++){
5334                                                         if(indialogue!=-1)player[k].attackkeydown=0;
5335                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
5336                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
5337                                                                 if(player[k].attackkeydown&&player[k].jumppower<=1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
5338                                                                         player[k].jumppower-=2;
5339                                                                 }
5340                                                                 if(player[k].attackkeydown&&player[k].jumppower>1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
5341                                                                         for(i=0;i<numplayers;i++){
5342                                                                                 if(i==k)i++;
5343                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
5344                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
5345                                                                                                 player[k].targetanimation=dodgebackanim;
5346                                                                                                 player[k].target=0;
5347                                                                                                 player[k].targetframe=0;
5348                                                                                                 rotatetarget=player[i].coords-player[k].coords;
5349                                                                                                 Normalise(&rotatetarget);
5350                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
5351                                                                                                 player[k].targetrotation*=360/6.28;
5352                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5353
5354                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
5355                                                                                         }
5356                                                                         }
5357                                                                         if(player[k].targetanimation!=dodgebackanim){
5358                                                                                 if(k==0)numflipped++;
5359                                                                                 player[k].targetanimation=backhandspringanim;
5360                                                                                 player[k].target=0;
5361                                                                                 player[k].targetframe=0;
5362                                                                                 player[k].targetrotation=-rotation+180;
5363                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
5364                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
5365                                                                                 player[k].rotation=player[k].targetrotation;
5366                                                                                 player[k].jumppower-=2;
5367                                                                         }
5368                                                                 }
5369                                                                 if(player[k].attackkeydown&&!animation[player[k].targetanimation].attack&&!player[k].backkeydown&&(player[k].isIdle()||player[k].isRun()||player[k].targetanimation==walkanim||player[k].targetanimation==sneakanim||player[k].isCrouch())){
5370                                                                         player[k].hasvictim=0;
5371                                                                         if(numplayers>1)
5372                                                                                 for(i=0;i<numplayers;i++){
5373                                                                                         if(i==k)i++;
5374                                                                                         if(!player[k].hasvictim)
5375                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
5376                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5&&!player[i].skeleton.free&&player[i].howactive<typedead1&&player[i].targetanimation!=jumpreversedanim&&player[i].targetanimation!=rabbitkickreversedanim&&player[i].targetanimation!=rabbitkickanim&&player[k].targetanimation!=rabbitkickanim&&player[i].targetanimation!=getupfrombackanim&&(player[i].targetanimation!=staggerbackhighanim&&(player[i].targetanimation!=staggerbackhardanim||animation[staggerbackhardanim].label[player[i].targetframe]==6))&&player[i].targetanimation!=jumpdownanim&&player[i].targetanimation!=jumpupanim&&player[i].targetanimation!=getupfromfrontanim){
5377                                                                                                                 player[k].victim=&player[i];
5378                                                                                                                 player[k].hasvictim=1;
5379                                                                                                                 if(player[k].aitype==playercontrolled){
5380                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].crouchkeydown&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
5381                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1&&!reversaltrain)player[k].targetanimation=winduppunchanim;
5382                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
5383                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[i].bloodloss>player[i].damagetolerance/2)player[k].targetanimation=knifefollowanim;
5384                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].forwardkeydown&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
5385                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
5386                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&!player[k].leftkeydown&&!player[k].rightkeydown&&!player[k].forwardkeydown)player[k].targetanimation=staffhitanim;
5387                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight&&!player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0)player[k].targetanimation=staffspinhitanim;
5388                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
5389                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
5390                                                                                                                 }
5391                                                                                                                 else {
5392                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
5393                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
5394                                                                                                                                 else randattack=abs(Random()%5);
5395                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
5396                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
5397                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
5398                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
5399                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
5400                                                                                                                                 }
5401                                                                                                                                 if(player[k].weaponactive!=-1){
5402                                                                                                                                         if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
5403                                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)/*&&animation[player[i].targetanimation].height!=lowheight*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&player[k].weaponmissdelay<=0)player[k].targetanimation=knifeslashstartanim;
5404                                                                                                                                         //else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].weaponactive!=-1&&player[i].staggerdelay>0&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)player[k].targetanimation=knifefollowanim;
5405                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword&&player[k].weaponmissdelay<=0)player[k].targetanimation=swordslashanim;
5406                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack<3)player[k].targetanimation=staffhitanim;
5407                                                                                                                                         else if(!(player[0].victim==&player[i]&&player[0].hasvictim&&player[0].targetanimation==swordslashanim)&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff&&player[k].weaponmissdelay<=0&&randattack>=3)player[k].targetanimation=staffspinhitanim;
5408                                                                                                                                         else if((tutoriallevel!=1||player[k].weaponactive==-1)&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&randattack==1&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
5409                                                                                                                                         else if(findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)&&animation[player[i].targetanimation].height==lowheight&&animation[player[k].targetanimation].attack!=normalattack)player[k].targetanimation=lowkickanim;
5410                                                                                                                                 }
5411                                                                                                                         }
5412                                                                                                                 }
5413                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
5414                                                                                                         }
5415                                                                                                         if((tutoriallevel!=1||tutorialstage==22)&&player[i].howactive<typedead1&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)&&!player[i].skeleton.free&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&(((player[i].stunned>0&&player[k].madskills)||(player[i].surprised>0)||player[i].aitype==passivetype)||(player[k].weaponactive!=-1&&player[i].stunned>0))&&normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0&&(k==0)){
5416                                                                                                                 if(player[k].weaponactive==-1){
5417                                                                                                                         player[i].targetanimation=sneakattackedanim;
5418                                                                                                                         player[i].currentanimation=sneakattackedanim;
5419                                                                                                                         player[k].currentanimation=sneakattackanim;
5420                                                                                                                         player[k].targetanimation=sneakattackanim;
5421                                                                                                                         player[k].oldcoords=player[k].coords;
5422                                                                                                                         player[k].coords=player[i].coords;
5423                                                                                                                 }
5424                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
5425                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
5426                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
5427                                                                                                                         player[k].currentanimation=knifesneakattackanim;
5428                                                                                                                         player[k].targetanimation=knifesneakattackanim;
5429                                                                                                                         player[i].oldcoords=player[i].coords;
5430                                                                                                                         player[i].coords=player[k].coords;
5431                                                                                                                 }
5432                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
5433                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
5434                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
5435                                                                                                                         player[k].currentanimation=swordsneakattackanim;
5436                                                                                                                         player[k].targetanimation=swordsneakattackanim;
5437                                                                                                                         player[i].oldcoords=player[i].coords;
5438                                                                                                                         player[i].coords=player[k].coords;
5439                                                                                                                 }
5440                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
5441                                                                                                                         player[k].victim=&player[i];
5442                                                                                                                         player[k].hasvictim=1;
5443                                                                                                                         player[i].targettilt2=0;
5444                                                                                                                         player[i].targetframe=1;
5445                                                                                                                         player[i].currentframe=0;
5446                                                                                                                         player[i].target=0;
5447                                                                                                                         player[i].velocity=0;
5448                                                                                                                         player[k].targettilt2=player[i].targettilt2;
5449                                                                                                                         player[k].currentframe=player[i].currentframe;
5450                                                                                                                         player[k].targetframe=player[i].targetframe;
5451                                                                                                                         player[k].target=player[i].target;
5452                                                                                                                         player[k].velocity=0;
5453                                                                                                                         player[k].targetrotation=player[i].rotation;
5454                                                                                                                         player[k].rotation=player[i].rotation;
5455                                                                                                                         player[i].targetrotation=player[i].rotation;
5456                                                                                                                 }
5457                                                                                                         }
5458                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
5459                                                                                                                 oldattackkey=1;
5460                                                                                                                 player[k].targetframe=0;
5461                                                                                                                 player[k].target=0;
5462                                                                                                                 //player[k].velocity=0;
5463
5464                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
5465                                                                                                                 Normalise(&rotatetarget);
5466                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
5467                                                                                                                 player[k].targetrotation*=360/6.28;
5468                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5469
5470                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5471
5472                                                                                                                 player[k].lastattack3=player[k].lastattack2;
5473                                                                                                                 player[k].lastattack2=player[k].lastattack;
5474                                                                                                                 player[k].lastattack=player[k].targetanimation;
5475                                                                                                                 //player[k].targettilt2=0;
5476                                                                                                                 //slomo=1;
5477                                                                                                                 //slomodelay=.2;
5478                                                                                                         }
5479                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
5480                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
5481                                                                                                                 Normalise(&rotatetarget);
5482                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
5483                                                                                                                 player[k].targetrotation*=360/6.28;
5484                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5485                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5486                                                                                                                 oldattackkey=1;
5487                                                                                                                 player[k].victim=&player[i];
5488                                                                                                                 player[k].hasvictim=1;
5489                                                                                                                 player[i].targetanimation=knifefollowedanim;
5490                                                                                                                 player[i].currentanimation=knifefollowedanim;
5491                                                                                                                 player[i].targettilt2=0;
5492                                                                                                                 player[i].targettilt2=player[k].targettilt2;
5493                                                                                                                 player[i].targetframe=1;
5494                                                                                                                 player[i].currentframe=0;
5495                                                                                                                 player[i].target=0;
5496                                                                                                                 player[i].velocity=0;
5497                                                                                                                 player[k].currentanimation=knifefollowanim;
5498                                                                                                                 player[k].targetanimation=knifefollowanim;
5499                                                                                                                 player[k].targettilt2=player[i].targettilt2;
5500                                                                                                                 player[k].currentframe=player[i].currentframe;
5501                                                                                                                 player[k].targetframe=player[i].targetframe;
5502                                                                                                                 player[k].target=player[i].target;
5503                                                                                                                 player[k].velocity=0;
5504                                                                                                                 player[k].oldcoords=player[k].coords;
5505                                                                                                                 player[i].coords=player[k].coords;
5506                                                                                                                 player[i].targetrotation=player[k].targetrotation;
5507                                                                                                                 player[i].rotation=player[k].targetrotation;
5508                                                                                                                 player[k].rotation=player[k].targetrotation;
5509                                                                                                                 player[i].rotation=player[k].targetrotation;
5510                                                                                                         }
5511                                                                                                 }
5512                                                                                 }
5513                                                                                 bool hasstaff=0;
5514                                                                                 if(player[k].weaponactive!=-1){
5515                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
5516                                                                                 }
5517                                                                                 if(numplayers>1)
5518                                                                                         for(i=0;i<numplayers;i++){
5519                                                                                                 if(i==k)i++;
5520                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
5521                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
5522                                                                                                                 if(player[i].skeleton.free)
5523                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)&&(player[i].dead||player[i].skeleton.longdead>1000||player[k].isRun()||(hasstaff)||(player[k].weaponactive!=-1&&player[i].skeleton.free&&(player[i].skeleton.longdead>2000||player[i].damage>player[i].damagetolerance/8||player[i].bloodloss>player[i].damagetolerance/2)&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)))){
5524                                                                                                                                 player[k].victim=&player[i];
5525                                                                                                                                 player[k].hasvictim=1;
5526                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
5527                                                                                                                                         if(player[k].crouchkeydown&&player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5))player[k].targetanimation=crouchstabanim;
5528                                                                                                                                         if(player[k].crouchkeydown&&findDistancefast(&player[k].coords,&player[i].coords)<1.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)player[k].targetanimation=swordgroundstabanim;
5529                                                                                                                                         if(/*(player[k].crouchkeydown||!player[i].dead)&&*/findDistancefast(&player[k].coords,&player[i].coords)<3.5*(player[k].scale*5)*(player[k].scale*5)/*&&player[i].dead!=2*/&&weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)player[k].targetanimation=staffgroundsmashanim;
5530                                                                                                                                 }
5531                                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<2.5&&player[k].crouchkeydown&&player[k].targetanimation!=crouchstabanim&&(player[k].weaponactive==-1)&&player[i].dead&&player[i].skeleton.free&&player[i].skeleton.longdead>1000){
5532                                                                                                                                         player[k].targetanimation=killanim;
5533                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
5534                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
5535                                                                                                                                                         terrain.DeleteDecal(j);
5536                                                                                                                                                 }
5537                                                                                                                                         }
5538                                                                                                                                         for(l=0;l<objects.numobjects;l++){
5539                                                                                                                                                 if(objects.model[l].type==decalstype)
5540                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
5541                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
5542                                                                                                                                                                         objects.model[l].DeleteDecal(j);
5543                                                                                                                                                                 }
5544                                                                                                                                                         }
5545                                                                                                                                         }
5546                                                                                                                                 }
5547                                                                                                                                 if(!player[i].dead||musictype!=2)
5548                                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<3.5&&(player[k].isRun()||(player[k].isIdle()&&player[k].attackkeydown))&&(player[k].staggerdelay<=0&&(player[i].dead||(player[i].skeleton.longdead<300&&player[k].lastattack!=spinkickanim&&player[i].skeleton.free)))&&(!player[i].dead||musictype!=stream_music2)){
5549                                                                                                                                                 player[k].targetanimation=dropkickanim;
5550                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
5551                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
5552                                                                                                                                                                 terrain.DeleteDecal(j);
5553                                                                                                                                                         }
5554                                                                                                                                                 }
5555                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
5556                                                                                                                                                         if(objects.model[l].type==decalstype)
5557                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
5558                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
5559                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
5560                                                                                                                                                                         }
5561                                                                                                                                                                 }
5562                                                                                                                                                 }
5563                                                                                                                                         }
5564                                                                                                                         }
5565                                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free||player[k].targetanimation==killanim||player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim||player[k].targetanimation==dropkickanim)){
5566                                                                                                                                 oldattackkey=1;
5567                                                                                                                                 player[k].targetframe=0;
5568                                                                                                                                 player[k].target=0;
5569                                                                                                                                 //player[k].velocity=0;
5570
5571                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
5572                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
5573                                                                                                                                         rotatetarget=(player[i].coords+(player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position+player[i].skeleton.joints[player[i].skeleton.jointlabels[neck]].position)/2*player[i].scale)-player[k].coords;
5574                                                                                                                                 }
5575                                                                                                                                 Normalise(&rotatetarget);
5576                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
5577                                                                                                                                 player[k].targetrotation*=360/6.28;
5578                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5579
5580                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
5581                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
5582                                                                                                                                 }
5583
5584                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5585                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
5586
5587                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
5588                                                                                                                                 player[k].lastattack2=player[k].lastattack;
5589                                                                                                                                 player[k].lastattack=player[k].targetanimation;
5590
5591                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
5592                                                                                                                                         player[k].targetrotation+=30;
5593                                                                                                                                 }
5594                                                                                                                                 //player[k].targettilt2=0;
5595                                                                                                                                 //slomo=1;
5596                                                                                                                                 //slomodelay=.2;
5597                                                                                                                         }
5598                                                                                                 }
5599                                                                                         }
5600                                                                                         if(!player[k].hasvictim){
5601                                                                                                 for(i=0;i<numplayers;i++){
5602                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
5603                                                                                                                 player[k].victim=&player[i];
5604                                                                                                                 player[k].hasvictim=1;
5605                                                                                                         }
5606                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
5607                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
5608                                                                                                                         player[k].victim=&player[i];
5609                                                                                                                 }
5610                                                                                                 }
5611                                                                                         }
5612                                                                                         if(player[k].aitype==playercontrolled)
5613                                                                                                 if(player[k].attackkeydown&&(player[k].isRun())&&player[k].wasRun()&&((player[k].hasvictim&&findDistancefast(&player[k].coords,&player[k].victim->coords)<12*(player[k].scale*5)*(player[k].scale*5)&&findDistancefast(&player[k].coords,&player[k].victim->coords)>7*(player[k].scale*5)*(player[k].scale*5)&&!player[k].victim->skeleton.free&&player[k].victim->targetanimation!=getupfrombackanim&&player[k].victim->targetanimation!=getupfromfrontanim&&animation[player[k].victim->targetanimation].height!=lowheight&&player[k].aitype!=playercontrolled&&normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&player[k].rabbitkickenabled)||player[k].jumpkeydown)){
5614                                                                                                         oldattackkey=1;
5615                                                                                                         player[k].targetanimation=rabbitkickanim;
5616                                                                                                         player[k].targetframe=0;
5617                                                                                                         player[k].target=0;
5618                                                                                                 }
5619                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
5620                                                                                                         numattacks++;
5621                                                                                                         bool armedstaff=0;
5622                                                                                                         if(player[k].weaponactive!=-1){
5623                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
5624                                                                                                         }
5625                                                                                                         bool armedsword=0;
5626                                                                                                         if(player[k].weaponactive!=-1){
5627                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
5628                                                                                                         }
5629                                                                                                         bool armedknife=0;
5630                                                                                                         if(player[k].weaponactive!=-1){
5631                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
5632                                                                                                         }
5633                                                                                                         if(armedstaff)numstaffattack++;
5634                                                                                                         else if(armedsword)numswordattack++;
5635                                                                                                         else if(armedknife)numknifeattack++;
5636                                                                                                         else numunarmedattack++;
5637                                                                                                 }
5638                                                                 }
5639                                                         }
5640                                                 }
5641
5642                                                 //Collisions
5643                                                 static float collisionradius;
5644                                                 if(numplayers>1)
5645                                                         for(k=0;k<numplayers;k++){
5646                                                                 for(i=k;i<numplayers;i++){
5647                                                                         if(i==k)i++;
5648                                                                         if(i<numplayers)
5649                                                                                 if((animation[player[i].targetanimation].attack!=reversed&&animation[player[i].targetanimation].attack!=reversal&&animation[player[k].targetanimation].attack!=reversed&&animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
5650                                                                                         if((animation[player[i].currentanimation].attack!=reversed&&animation[player[i].currentanimation].attack!=reversal&&animation[player[k].currentanimation].attack!=reversed&&animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
5651                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
5652                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
5653                                                                                                                 if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz&&player[k].skeleton.oldfree==player[k].skeleton.free&&player[i].skeleton.oldfree==player[i].skeleton.free&&player[i].targetanimation!=climbanim&&player[i].targetanimation!=hanganim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim)
5654                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
5655                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
5656                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
5657                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
5658                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
5659                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
5660                                                                                                                                                                         if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
5661                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
5662                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
5663                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
5664                                                                                                                                                                                 }
5665                                                                                                                                                                         }
5666
5667                                                                                                                                                                         tempcoords1=player[i].coords;
5668                                                                                                                                                                         tempcoords2=player[k].coords;
5669                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
5670                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
5671                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
5672                                                                                                                                                                         if(player[0].hasvictim)
5673                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
5674                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
5675                                                                                                                                                                                 if(k==0)
5676                                                                                                                                                                                         if(player[k].targetanimation==jumpdownanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[i].skeleton.oldfree&&player[i].skeleton.free&&player[i].dead&&player[k].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
5677                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
5678                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
5679                                                                                                                                                                                                 player[i].skeleton.free=0;
5680                                                                                                                                                                                                 player[i].rotation=0;
5681                                                                                                                                                                                                 player[i].RagDoll(0);
5682                                                                                                                                                                                                 player[i].DoDamage(20);
5683                                                                                                                                                                                                 if(k==0)camerashake+=.3;
5684                                                                                                                                                                                                 player[i].skeleton.longdead=0;
5685                                                                                                                                                                                                 player[k].lastcollide=1;
5686                                                                                                                                                                                         }
5687                                                                                                                                                                                         if(i==0)
5688                                                                                                                                                                                                 if(player[i].targetanimation==jumpdownanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[k].skeleton.oldfree&&player[k].skeleton.free&&player[k].dead&&player[i].lastcollide<=0&&abs(player[i].coords.y-player[k].coords.y)<.2&&findDistancefast(&player[k].coords,&player[i].coords)<.7*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
5689                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
5690                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
5691                                                                                                                                                                                                         player[k].skeleton.free=0;
5692                                                                                                                                                                                                         player[k].rotation=0;
5693                                                                                                                                                                                                         player[k].RagDoll(0);
5694                                                                                                                                                                                                         player[k].DoDamage(20);
5695                                                                                                                                                                                                         if(i==0)camerashake+=.3;
5696                                                                                                                                                                                                         player[k].skeleton.longdead=0;
5697                                                                                                                                                                                                         player[i].lastcollide=1;
5698                                                                                                                                                                                                 }
5699
5700                                                                                                                                                                                                 if((player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||(player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
5701                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
5702                                                                                                                                                                                                         if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
5703                                                                                                                                                                                                                 if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
5704                                                                                                                                                                                                                         //If hit by body
5705                                                                                                                                                                                                                         if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
5706                                                                                                                                                                                                                                 static float gLoc[3];
5707                                                                                                                                                                                                                                 static float vel[3];
5708                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
5709                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
5710                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
5711                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
5712                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
5713                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
5714                                                                                                                                                                                                                                 if(tutoriallevel!=1){
5715                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
5716                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
5717                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
5718                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
5719                                                                                                                                                                                                                                 }
5720                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
5721                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
5722
5723                                                                                                                                                                                                                                 player[i].RagDoll(0);
5724                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
5725                                                                                                                                                                                                                                         bonus=aimbonus;
5726                                                                                                                                                                                                                                         bonustime=0;
5727                                                                                                                                                                                                                                         bonusvalue=150;
5728                                                                                                                                                                                                                                 }
5729                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
5730                                                                                                                                                                                                                                 player[k].RagDoll(0);
5731                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
5732                                                                                                                                                                                                                                         bonus=aimbonus;
5733                                                                                                                                                                                                                                         bonustime=0;
5734                                                                                                                                                                                                                                         bonusvalue=150;
5735                                                                                                                                                                                                                                 }
5736                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
5737
5738                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
5739                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
5740                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
5741                                                                                                                                                                                                                                 }
5742                                                                                                                                                                                                                                 //}
5743                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
5744                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
5745                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
5746                                                                                                                                                                                                                                 }
5747                                                                                                                                                                                                                                 //}
5748
5749                                                                                                                                                                                                                         }
5750                                                                                                                                                                                                                 }
5751                                                                                                                                                                                                                 if((animation[player[i].targetanimation].attack==neutral||animation[player[i].targetanimation].attack==normalattack)&&(animation[player[k].targetanimation].attack==neutral||animation[player[k].targetanimation].attack==normalattack)){
5752                                                                                                                                                                                                                         //If bumped
5753                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
5754                                                                                                                                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
5755                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
5756                                                                                                                                                                                                                                         Normalise(&rotatetarget);
5757                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
5758                                                                                                                                                                                                                                         player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
5759                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
5760                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
5761                                                                                                                                                                                                                                                 if(player[k].isIdle()){
5762                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
5763                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
5764                                                                                                                                                                                                                                                                 player[k].targetframe=0;
5765                                                                                                                                                                                                                                                                 player[k].target=0;
5766                                                                                                                                                                                                                                                         }
5767                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
5768                                                                                                                                                                                                                                                         {
5769                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
5770                                                                                                                                                                                                                                                                 player[k].targetframe=0;
5771                                                                                                                                                                                                                                                                 player[k].target=0;
5772                                                                                                                                                                                                                                                         }
5773                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
5774                                                                                                                                                                                                                                                 }
5775                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
5776                                                                                                                                                                                                                                                         if(player[i].isIdle()){
5777                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
5778                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
5779                                                                                                                                                                                                                                                                         player[i].targetframe=0;
5780                                                                                                                                                                                                                                                                         player[i].target=0;
5781                                                                                                                                                                                                                                                                 }
5782                                                                                                                                                                                                                                                                 else
5783                                                                                                                                                                                                                                                                 {
5784                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
5785                                                                                                                                                                                                                                                                         player[i].targetframe=0;
5786                                                                                                                                                                                                                                                                         player[i].target=0;
5787                                                                                                                                                                                                                                                                 }
5788                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
5789                                                                                                                                                                                                                                                         }
5790                                                                                                                                                                                                                                 }
5791                                                                                                                                                                                                                                 if(hostile){
5792                                                                                                                                                                                                                                         if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&!player[i].isCrouch()&&player[i].targetanimation!=rollanim&&!player[k].skeleton.oldfree&&!player[k].skeleton.free&&player[k].lastcollide<=0&&player[k].velocity.y<-10){
5793                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
5794                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
5795                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
5796                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
5797                                                                                                                                                                                                                                                 player[i].DoDamage(20);
5798                                                                                                                                                                                                                                                 player[i].RagDoll(0);
5799                                                                                                                                                                                                                                                 player[k].lastcollide=1;
5800                                                                                                                                                                                                                                                 if(k==0){
5801                                                                                                                                                                                                                                                         bonus=AboveBonus;
5802                                                                                                                                                                                                                                                         bonustime=0;
5803                                                                                                                                                                                                                                                         bonusvalue=50;
5804                                                                                                                                                                                                                                                 }
5805                                                                                                                                                                                                                                         }
5806                                                                                                                                                                                                                                         if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&!player[k].isCrouch()&&player[k].targetanimation!=rollanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[i].lastcollide<=0&&player[i].velocity.y<-10){
5807                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
5808                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
5809                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
5810                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
5811                                                                                                                                                                                                                                                 player[k].DoDamage(20);
5812                                                                                                                                                                                                                                                 player[k].RagDoll(0);
5813                                                                                                                                                                                                                                                 player[i].lastcollide=1;
5814                                                                                                                                                                                                                                                 if(i==0){
5815                                                                                                                                                                                                                                                         bonus=AboveBonus;
5816                                                                                                                                                                                                                                                         bonustime=0;
5817                                                                                                                                                                                                                                                         bonusvalue=50;
5818                                                                                                                                                                                                                                                 }
5819                                                                                                                                                                                                                                         }
5820                                                                                                                                                                                                                                 }
5821                                                                                                                                                                                                                         }
5822                                                                                                                                                                                                                 }
5823                                                                                                                                                                                                 }
5824                                                                                                                                                                                                 player[i].CheckKick();
5825                                                                                                                                                                                                 player[k].CheckKick();
5826                                                                                                                                                                         }
5827                                                                                                                                                                 }
5828                                                                 }
5829                                                         }
5830
5831                                                         for(k=0;k<numplayers;k++){
5832                                                                 for(i=k;i<numplayers;i++){
5833                                                                         if(i==k)i++;
5834                                                                         if(i<numplayers&&i!=k&&player[k].skeleton.free==0&&player[i].skeleton.oldfree==0&&(player[i].targetanimation==jumpupanim||player[k].targetanimation==jumpupanim)&&(player[i].aitype==playercontrolled||player[k].aitype==playercontrolled)&&((player[i].aitype==attacktypecutoff&&player[i].stunned<=0)||(player[k].aitype==attacktypecutoff&&player[k].stunned<=0))){
5835                                                                                 if(findDistancefast(&player[i].coords,&player[k].coords)<10*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)&&findDistancefastflat(&player[i].coords,&player[k].coords)<2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
5836                                                                                         if(player[i].targetanimation==jumpupanim&&player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim&&animation[player[k].targetanimation].height==middleheight&&normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&((player[k].aitype==playercontrolled&&player[k].attackkeydown)||player[k].aitype!=playercontrolled)){
5837                                                                                                 player[i].victim=&player[k];
5838                                                                                                 player[i].targetanimation=jumpreversedanim;
5839                                                                                                 player[i].currentanimation=jumpreversedanim;
5840                                                                                                 player[k].currentanimation=jumpreversalanim;
5841                                                                                                 player[k].targetanimation=jumpreversalanim;
5842                                                                                                 player[i].targettilt2=0;
5843                                                                                                 player[i].currentframe=0;
5844                                                                                                 player[i].targetframe=1;
5845                                                                                                 player[k].currentframe=0;
5846                                                                                                 player[k].targetframe=1;
5847                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
5848                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
5849                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
5850                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
5851                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
5852                                                                                                         player[k].currentframe=1;
5853                                                                                                         player[k].targetframe=2;
5854                                                                                                         player[i].currentframe=1;
5855                                                                                                         player[i].targetframe=2;
5856                                                                                                 }
5857                                                                                                 player[k].targettilt2=0;
5858                                                                                                 player[i].target=0;
5859                                                                                                 player[i].velocity=0;
5860                                                                                                 player[k].velocity=0;
5861                                                                                                 player[k].oldcoords=player[k].coords;
5862                                                                                                 player[i].coords=player[k].coords;
5863                                                                                                 player[k].targetrotation=player[i].targetrotation;
5864                                                                                                 player[k].rotation=player[i].targetrotation;
5865                                                                                                 player[k].victim=&player[i];
5866                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
5867                                                                                         }
5868                                                                                         if(player[k].targetanimation==jumpupanim&&player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim&&animation[player[i].targetanimation].height==middleheight&&normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&((player[i].aitype==playercontrolled&&player[i].attackkeydown)||player[i].aitype!=playercontrolled)){
5869                                                                                                 player[k].victim=&player[i];
5870                                                                                                 player[k].targetanimation=jumpreversedanim;
5871                                                                                                 player[k].currentanimation=jumpreversedanim;
5872                                                                                                 player[i].currentanimation=jumpreversalanim;
5873                                                                                                 player[i].targetanimation=jumpreversalanim;
5874                                                                                                 player[k].targettilt2=0;
5875                                                                                                 player[i].targettilt2=0;
5876                                                                                                 player[k].currentframe=0;
5877                                                                                                 player[k].targetframe=1;
5878                                                                                                 player[i].currentframe=0;
5879                                                                                                 player[i].targetframe=1;
5880                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
5881                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
5882                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
5883                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
5884                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
5885                                                                                                         player[k].currentframe=1;
5886                                                                                                         player[k].targetframe=2;
5887                                                                                                         player[i].currentframe=1;
5888                                                                                                         player[i].targetframe=2;
5889                                                                                                 }
5890                                                                                                 player[k].target=0;
5891                                                                                                 player[k].velocity=0;
5892                                                                                                 player[i].velocity=0;
5893                                                                                                 player[i].oldcoords=player[i].coords;
5894                                                                                                 player[k].coords=player[i].coords;
5895                                                                                                 player[i].targetrotation=player[k].targetrotation;
5896                                                                                                 player[i].rotation=player[k].targetrotation;
5897                                                                                                 player[i].victim=&player[k];
5898                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
5899                                                                                         }
5900                                                                                 }
5901                                                                         }
5902                                                                 }
5903                                                         }
5904
5905                                                         for(k=0;k<numplayers;k++)
5906                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
5907
5908
5909                                                         //pile
5910                                                         if(!Input::isKeyDown(SDLK_n)){
5911                                                                 texturesizetogglekeydown=0;
5912                                                         }
5913
5914                                                         for(k=0;k<numplayers;k++){
5915                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
5916                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
5917                                                                                 player[k].DoDamage(1000);
5918                                                                         }
5919                                                                 }
5920                                                         }
5921
5922                                                         static bool respawnkeydown;
5923                                                         if(!editorenabled&&(whichlevel!=-2&&(Input::isKeyDown(SDLK_z)&&Input::isKeyDown(SDLK_LMETA)&&debugmode&&!editorenabled)||(Input::isKeyDown(jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
5924                                                                 targetlevel=whichlevel;
5925                                                                 loading=1;
5926                                                                 leveltime=5;
5927                                                         }
5928                                                         if(!Input::isKeyDown(jumpkey))respawnkeydown=0;
5929                                                         if(Input::isKeyDown(jumpkey))respawnkeydown=1;
5930
5931
5932
5933
5934                                                         if(whichlevel!=-2&&Input::isKeyDown(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!slomotogglekeydown&&debugmode&&!editorenabled){
5935                                                                 targetlevel++;
5936                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
5937                                                                 loading=1;
5938                                                                 leveltime=5;
5939                                                                 slomotogglekeydown=1;
5940                                                         }
5941                                                         static bool movekey;
5942                                                         static bool connected;
5943                                                         
5944                 for(int i=0;i<numplayers;i++){
5945                                                                 if(!player[i].skeleton.free){
5946                                                                         oldtargetrotation=player[i].targetrotation;
5947                                                                         if(i==0&&indialogue==-1){
5948                                                                                 if(!animation[player[0].targetanimation].attack&&player[0].targetanimation!=staggerbackhighanim&&player[0].targetanimation!=staggerbackhardanim&&player[0].targetanimation!=crouchremoveknifeanim&&player[0].targetanimation!=removeknifeanim&&player[0].targetanimation!=backhandspringanim&&player[0].targetanimation!=dodgebackanim&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
5949                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
5950                                                                                         if(cameramode)player[0].targetrotation=0;
5951                                                                                 }
5952
5953                                                                                 facing=0;
5954                                                                                 facing.z=-1;
5955
5956                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5957                                                                                 if(cameramode){facing=flatfacing;}
5958                                                                                 else{
5959                                                                                         facing=DoRotation(facing,-rotation2,0,0);
5960                                                                                         facing=DoRotation(facing,0,0-rotation,0);
5961                                                                                 }
5962
5963                                                                                 player[0].lookrotation=-rotation;
5964
5965                                                                                 player[i].targetheadrotation=rotation;
5966                                                                                 player[i].targetheadrotation2=rotation2;
5967                                                                         }
5968                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
5969                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim&&player[i].targetanimation!=walljumprightkickanim&&player[i].targetanimation!=walljumpleftkickanim){
5970                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
5971                                                                                 }
5972
5973                                                                                 facing=0;
5974                                                                                 facing.z=-1;
5975
5976                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5977
5978                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
5979                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
5980
5981                                                                                 player[i].targetheadrotation=player[i].lookrotation;
5982                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
5983                                                                         }
5984                                                                         if(indialogue!=-1){
5985                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
5986                                                                                 Normalise(&rotatetarget);
5987                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
5988                                                                                 player[i].targetheadrotation*=360/6.28;
5989                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
5990
5991                                                                                 player[i].targetheadrotation*=-1;
5992                                                                                 player[i].targetheadrotation+=180;
5993                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
5994                                                                         }
5995
5996                                                                         bool pause;
5997
5998                                                                         if(leveltime<.5)
5999                                                                                 numenvsounds=0;
6000
6001                                                                         player[i].avoidsomething=0;
6002
6003                                                                         for(j=0;j<objects.numobjects;j++){
6004                                                                                 if(objects.onfire[j]){
6005                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
6006                                                                                         {
6007                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
6008                                                                                                         player[i].collided=0;
6009                                                                                                         player[i].avoidcollided=1;
6010                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
6011                                                                                                                 player[i].avoidwhere=objects.position[j];
6012                                                                                                 }
6013                                                                                         }
6014                                                                                 }
6015                                                                         }
6016
6017                                                                         //Add avoidwhere to players
6018
6019                                                                         for(j=0;j<numplayers;j++){
6020                                                                                 if(player[j].onfire){
6021                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
6022                                                                                         {
6023                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
6024                                                                                                         player[i].collided=0;
6025                                                                                                         player[i].avoidcollided=1;
6026                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
6027                                                                                                                 player[i].avoidwhere=objects.position[j];
6028                                                                                                 }
6029                                                                                         }
6030                                                                                 }
6031                                                                         }
6032
6033                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
6034                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
6035                                                                                 player[i].jumpclimb=0;
6036                                                                                 //AI
6037                                                                                 if(editorenabled)player[i].stunned=1;
6038
6039                                                                                 player[i].pause=0;
6040                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
6041                                                                                 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&player[0].coords.y>player[i].coords.y+2&&!player[0].onterrain)player[i].pause=1;
6042
6043                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
6044                                                                                 player[i].forwardkeydown=0;
6045                                                                                 player[i].leftkeydown=0;
6046                                                                                 player[i].backkeydown=0;
6047                                                                                 player[i].rightkeydown=0;
6048                                                                                 player[i].crouchkeydown=0;
6049                                                                                 player[i].attackkeydown=0;
6050                                                                                 player[i].jumpkeydown=0;
6051                                                                                 player[i].throwkeydown=0;
6052                                                                                 }*/
6053
6054                                                                                 if(player[i].aitype==pathfindtype){
6055                                                                                         if(player[i].finalpathfindpoint==-1){
6056                                                                                                 float closestdistance;
6057                                                                                                 float tempdist;
6058                                                                                                 int closest;
6059                                                                                                 XYZ colpoint;
6060                                                                                                 closest=-1;
6061                                                                                                 closestdistance=-1;
6062                                                                                                 for(j=0;j<numpathpoints;j++){
6063                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
6064                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
6065                                                                                                                 closest=j;
6066                                                                                                                 player[i].finaltarget=pathpoint[j];
6067                                                                                                         }
6068                                                                                                 }
6069                                                                                                 player[i].finalpathfindpoint=closest;
6070                                                                                                 for(j=0;j<numpathpoints;j++){
6071                                                                                                         if(numpathpointconnect[j])
6072                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
6073                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
6074                                                                                                                         if(tempdist*tempdist<closestdistance){
6075                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
6076                                                                                                                                         closestdistance=tempdist*tempdist;
6077                                                                                                                                         closest=j;
6078                                                                                                                                         player[i].finaltarget=colpoint;
6079                                                                                                                                 }
6080                                                                                                                         }
6081                                                                                                                 }
6082                                                                                                 }
6083                                                                                                 player[i].finalpathfindpoint=closest;
6084
6085                                                                                         }
6086                                                                                         if(player[i].targetpathfindpoint==-1){
6087                                                                                                 float closestdistance;
6088                                                                                                 float tempdist;
6089                                                                                                 int closest;
6090                                                                                                 XYZ colpoint;
6091                                                                                                 closest=-1;
6092                                                                                                 closestdistance=-1;
6093                                                                                                 if(player[i].lastpathfindpoint==-1){
6094                                                                                                         for(j=0;j<numpathpoints;j++){
6095                                                                                                                 if(j!=player[i].lastpathfindpoint)
6096                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
6097                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
6098                                                                                                                                 closest=j;
6099                                                                                                                         }
6100                                                                                                         }
6101                                                                                                         player[i].targetpathfindpoint=closest;
6102                                                                                                         for(j=0;j<numpathpoints;j++){
6103                                                                                                                 if(j!=player[i].lastpathfindpoint)
6104                                                                                                                         if(numpathpointconnect[j])
6105                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
6106                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
6107                                                                                                                                         if(tempdist*tempdist<closestdistance){
6108                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
6109                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
6110                                                                                                                                                         closestdistance=tempdist*tempdist;
6111                                                                                                                                                         closest=j;
6112                                                                                                                                                         //}
6113                                                                                                                                                 }
6114                                                                                                                                         }
6115                                                                                                                                 }
6116                                                                                                         }
6117                                                                                                         player[i].targetpathfindpoint=closest;
6118                                                                                                 }
6119                                                                                                 else
6120                                                                                                 {
6121                                                                                                         for(j=0;j<numpathpoints;j++){
6122                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
6123                                                                                                                 {
6124                                                                                                                         connected=0;
6125                                                                                                                         if(numpathpointconnect[j])
6126                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
6127                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
6128                                                                                                                                 }
6129                                                                                                                                 if(!connected)
6130                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
6131                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
6132                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
6133                                                                                                                                                 }
6134                                                                                                                                                 if(connected){
6135                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
6136                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
6137                                                                                                                                                                 closestdistance=tempdist;
6138                                                                                                                                                                 closest=j;
6139                                                                                                                                                         }
6140                                                                                                                                                 }
6141                                                                                                                 }
6142                                                                                                         }
6143                                                                                                         player[i].targetpathfindpoint=closest;
6144                                                                                                 }
6145                                                                                         }
6146                                                                                         player[i].losupdatedelay-=multiplier;
6147
6148                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
6149                                                                                         Normalise(&rotatetarget);
6150                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
6151                                                                                         player[i].targetrotation*=360/6.28;
6152                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6153                                                                                         player[i].lookrotation=player[i].targetrotation;
6154                                                                                         //player[i].aiupdatedelay=.05;
6155
6156                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
6157                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
6158                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
6159                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
6160                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
6161                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
6162                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
6163                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
6164                                                                                                 player[i].targetpathfindpoint=-1;
6165                                                                                         }
6166                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<findDistancefastflat(&player[i].coords,&player[i].finaltarget)||findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*(player[i].scale*5)*(player[i].scale*5)||player[i].lastpathfindpoint==player[i].finalpathfindpoint){
6167                                                                                                 player[i].aitype=passivetype;
6168                                                                                         }
6169
6170                                                                                         player[i].forwardkeydown=1;
6171                                                                                         player[i].leftkeydown=0;
6172                                                                                         player[i].backkeydown=0;
6173                                                                                         player[i].rightkeydown=0;
6174                                                                                         player[i].crouchkeydown=0;
6175                                                                                         player[i].attackkeydown=0;
6176                                                                                         player[i].throwkeydown=0;
6177
6178                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6179
6180                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6181                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6182
6183                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
6184                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled&&(player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
6185                                                                                                         player[i].aitype=attacktypecutoff;
6186                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
6187                                                                                                         player[i].aitype=attacktypecutoff;
6188
6189                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
6190                                                                                                         player[i].losupdatedelay=.2;
6191                                                                                                         for(j=0;j<numplayers;j++){
6192                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
6193                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
6194                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
6195                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
6196                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
6197                                                                                                                                                         if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
6198                                                                                                                                                                 player[i].aitype=searchtype;
6199                                                                                                                                                                 player[i].lastchecktime=12;
6200                                                                                                                                                                 player[i].lastseen=player[j].coords;
6201                                                                                                                                                                 player[i].lastseentime=12;
6202                                                                                                                                                         }
6203                                                                                                                 }
6204                                                                                                         }
6205                                                                                                 }
6206                                                                                         }
6207                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
6208                                                                                                 if(player[i].creature!=wolftype){
6209                                                                                                         player[i].stunned=.6;
6210                                                                                                         player[i].surprised=.6;
6211                                                                                                 }
6212                                                                                         }
6213                                                                                 }
6214
6215                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
6216                                                                                         player[i].howactive=typeactive;
6217                                                                                 }
6218
6219                                                                                 if(player[i].aitype==passivetype){
6220                                                                                         player[i].aiupdatedelay-=multiplier;
6221                                                                                         player[i].losupdatedelay-=multiplier;
6222                                                                                         player[i].lastseentime+=multiplier;
6223                                                                                         player[i].pausetime-=multiplier;
6224                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
6225
6226                                                                                         if(player[i].aiupdatedelay<0){
6227                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
6228                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
6229                                                                                                         Normalise(&rotatetarget);
6230                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
6231                                                                                                         player[i].targetrotation*=360/6.28;
6232                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6233                                                                                                         player[i].lookrotation=player[i].targetrotation;
6234                                                                                                         player[i].aiupdatedelay=.05;
6235
6236                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
6237                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
6238                                                                                                                 player[i].waypoint++;
6239                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
6240
6241                                                                                                         }
6242                                                                                                 }
6243
6244                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
6245                                                                                                 else player[i].forwardkeydown=0;
6246                                                                                                 player[i].leftkeydown=0;
6247                                                                                                 player[i].backkeydown=0;
6248                                                                                                 player[i].rightkeydown=0;
6249                                                                                                 player[i].crouchkeydown=0;
6250                                                                                                 player[i].attackkeydown=0;
6251                                                                                                 player[i].throwkeydown=0;
6252
6253                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6254                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6255                                                                                                         else{
6256                                                                                                                 XYZ leftpos,rightpos;
6257                                                                                                                 float leftdist,rightdist;
6258                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6259                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6260                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6261                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6262                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
6263                                                                                                                 else player[i].targetrotation-=90;
6264                                                                                                         }
6265                                                                                                 }
6266                                                                                         }
6267                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6268                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6269
6270
6271                                                                                         if(!editorenabled){
6272                                                                                                 if(player[i].howactive<typesleeping)
6273                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
6274                                                                                                                 for(j=0;j<numenvsounds;j++){
6275                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
6276                                                                                                                                 player[i].aitype=attacktypecutoff;
6277                                                                                                                         }
6278                                                                                                                 }
6279
6280                                                                                                                 if(player[i].howactive==typesleeping)
6281                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
6282                                                                                                                                 for(j=0;j<numenvsounds;j++){
6283                                                                                                                                         if(envsoundvol[j]>14)
6284                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
6285                                                                                                                                                         player[i].aitype=attacktypecutoff;
6286                                                                                                                                                 }
6287                                                                                                                                 }
6288
6289                                                                                                                                 if(player[i].aitype!=passivetype){
6290                                                                                                                                         if(player[i].howactive==typesleeping){
6291                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
6292                                                                                                                                                 player[i].targetframe=0;
6293                                                                                                                                                 player[i].target=0;
6294                                                                                                                                         }
6295
6296                                                                                                                                         player[i].howactive=typeactive;
6297                                                                                                                                 }
6298                                                                                         }
6299
6300                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
6301                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
6302                                                                                                         player[i].aitype=attacktypecutoff;
6303                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
6304                                                                                                         player[i].aitype=attacktypecutoff;
6305
6306                                                                                                 if(player[i].creature==wolftype){
6307                                                                                                         XYZ windsmell;
6308                                                                                                         float smelldistance;
6309                                                                                                         smelldistance=50;
6310                                                                                                         for(j=0;j<numplayers;j++){
6311                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
6312                                                                                                                         if(j==0&&player[j].num_weapons>0){
6313                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
6314                                                                                                                                 if(player[j].num_weapons==2)
6315                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
6316                                                                                                                         }
6317                                                                                                                         if(j!=0){
6318                                                                                                                                 smelldistance=100;
6319                                                                                                                         }
6320                                                                                                                         windsmell=windvector;
6321                                                                                                                         Normalise(&windsmell);
6322                                                                                                                         windsmell=windsmell*2+player[j].coords;
6323                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
6324                                                                                                                                 player[i].aitype=attacktypecutoff;
6325                                                                                                                 }
6326                                                                                                         }
6327                                                                                                 }
6328
6329                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
6330                                                                                                         player[i].losupdatedelay=.2;
6331                                                                                                         for(j=0;j<numplayers;j++){
6332                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
6333                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
6334                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
6335                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
6336                                                                                                                                                 if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords)&&!player[j].isWallJump())||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
6337                                                                                                                                                         player[i].lastseentime-=.2;
6338                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
6339                                                                                                                                                         else player[i].lastseentime-=.6;
6340                                                                                                                                                 }
6341                                                                                                                                                 if(player[i].lastseentime<=0){
6342                                                                                                                                                         player[i].aitype=searchtype;
6343                                                                                                                                                         player[i].lastchecktime=12;
6344                                                                                                                                                         player[i].lastseen=player[j].coords;
6345                                                                                                                                                         player[i].lastseentime=12;
6346                                                                                                                                                 }
6347                                                                                                                 }
6348                                                                                                         }
6349                                                                                                 }
6350                                                                                         }
6351                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
6352                                                                                                 if(player[i].creature!=wolftype){
6353                                                                                                         player[i].stunned=.6;
6354                                                                                                         player[i].surprised=.6;
6355                                                                                                 }
6356                                                                                                 if(player[i].creature==wolftype){
6357                                                                                                         player[i].stunned=.47;
6358                                                                                                         player[i].surprised=.47;
6359                                                                                                 }
6360                                                                                                 numseen++;
6361                                                                                         }
6362                                                                                 }
6363
6364                                                                                 if(player[i].aitype==searchtype){
6365                                                                                         player[i].aiupdatedelay-=multiplier;
6366                                                                                         player[i].losupdatedelay-=multiplier;
6367                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
6368                                                                                         player[i].lastchecktime-=multiplier;
6369
6370                                                                                         if(player[i].isRun()&&!player[i].onground){
6371                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
6372                                                                                                         test2=player[i].coords+player[i].facing;
6373                                                                                                         test2.y+=5;
6374                                                                                                         test=player[i].coords+player[i].facing;
6375                                                                                                         test.y-=10;
6376                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
6377                                                                                                         if(j==-1)j=checkcollide(test2,test);
6378                                                                                                         if(j==-1){
6379                                                                                                                 player[i].velocity=0;
6380                                                                                                                 player[i].targetanimation=player[i].getStop();
6381                                                                                                                 player[i].targetframe=0;
6382                                                                                                                 player[i].target=0;
6383                                                                                                                 player[i].targetrotation+=180;
6384                                                                                                                 player[i].stunned=.5;
6385                                                                                                                 //player[i].aitype=passivetype;
6386                                                                                                                 player[i].aitype=pathfindtype;
6387                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6388                                                                                                                 player[i].finalpathfindpoint=-1;
6389                                                                                                                 player[i].targetpathfindpoint=-1;
6390                                                                                                                 player[i].lastpathfindpoint=-1;
6391                                                                                                                 player[i].lastpathfindpoint2=-1;
6392                                                                                                                 player[i].lastpathfindpoint3=-1;
6393                                                                                                                 player[i].lastpathfindpoint4=-1;
6394                                                                                                         }
6395                                                                                                         else player[i].laststanding=j;
6396                                                                                                 }
6397                                                                                         }
6398                                                                                         if(player[i].aiupdatedelay<0){
6399                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
6400                                                                                                 Normalise(&rotatetarget);
6401                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
6402                                                                                                 player[i].targetrotation*=360/6.28;
6403                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6404                                                                                                 player[i].lookrotation=player[i].targetrotation;
6405                                                                                                 player[i].aiupdatedelay=.05;
6406                                                                                                 player[i].forwardkeydown=1;
6407
6408                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
6409                                                                                                         player[i].forwardkeydown=0;
6410                                                                                                         player[i].aiupdatedelay=1;
6411                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
6412                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
6413                                                                                                         player[i].lastchecktime=3;
6414                                                                                                 }
6415
6416                                                                                                 player[i].leftkeydown=0;
6417                                                                                                 player[i].backkeydown=0;
6418                                                                                                 player[i].rightkeydown=0;
6419                                                                                                 player[i].crouchkeydown=0;
6420                                                                                                 player[i].attackkeydown=0;
6421                                                                                                 player[i].throwkeydown=0;
6422
6423                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6424                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6425                                                                                                         else{
6426                                                                                                                 XYZ leftpos,rightpos;
6427                                                                                                                 float leftdist,rightdist;
6428                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6429                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6430                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6431                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6432                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
6433                                                                                                                 else player[i].targetrotation-=90;
6434                                                                                                         }
6435                                                                                                 }
6436                                                                                         }
6437                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6438                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6439
6440                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
6441                                                                                                 for(j=0;j<numenvsounds;j++){
6442                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
6443                                                                                                                 player[i].aitype=attacktypecutoff;
6444                                                                                                         }
6445                                                                                                 }
6446
6447                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
6448                                                                                                         player[i].losupdatedelay=.2;
6449                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
6450                                                                                                         {player[i].aitype=attacktypecutoff;
6451                                                                                                         player[i].lastseentime=1;}
6452                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
6453                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
6454                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
6455                                                                                                                                 if((-1==checkcollide(DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords,DoRotation(player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position,0,player[0].rotation,0)*player[0].scale+player[0].coords))||(player[j].targetanimation==hanganim&&normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
6456                                                                                                                                         player[i].aitype=attacktypecutoff;
6457                                                                                                                                         player[i].lastseentime=1;
6458                                                                                                                                 }
6459                                                                                                 }
6460                                                                                                 if(player[i].lastseentime<0){
6461                                                                                                         //player[i].aitype=passivetype;
6462                                                                                                         numescaped++;
6463                                                                                                         player[i].aitype=pathfindtype;
6464                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6465                                                                                                         player[i].finalpathfindpoint=-1;
6466                                                                                                         player[i].targetpathfindpoint=-1;
6467                                                                                                         player[i].lastpathfindpoint=-1;
6468                                                                                                         player[i].lastpathfindpoint2=-1;
6469                                                                                                         player[i].lastpathfindpoint3=-1;
6470                                                                                                         player[i].lastpathfindpoint4=-1;
6471                                                                                                 }
6472                                                                                 }
6473
6474                                                                                 if(player[i].aitype!=gethelptype){
6475                                                                                         player[i].runninghowlong=0;
6476                                                                                 }
6477
6478                                                                                 if(player[i].aitype==gethelptype){
6479                                                                                         player[i].runninghowlong+=multiplier;
6480                                                                                         player[i].aiupdatedelay-=multiplier;
6481
6482                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
6483                                                                                                 player[i].aiupdatedelay=.2;
6484
6485                                                                                                 int closest;
6486                                                                                                 float closestdist;
6487                                                                                                 closest=-1;
6488                                                                                                 closestdist=-1;
6489                                                                                                 float distance;
6490
6491                                                                                                 if(!player[i].ally){
6492                                                                                                         for(j=0;j<numplayers;j++){
6493                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
6494                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
6495                                                                                                                         if(closestdist==-1||distance<closestdist){
6496                                                                                                                                 closestdist=distance;
6497                                                                                                                                 closest=j;
6498                                                                                                                         }
6499                                                                                                                         closest=j;
6500                                                                                                                 }
6501                                                                                                         }
6502                                                                                                         if(closest!=-1)player[i].ally=closest;
6503                                                                                                         else player[i].ally=0;
6504                                                                                                         player[i].lastseen=player[0].coords;
6505                                                                                                         player[i].lastseentime=12;
6506                                                                                                 }
6507
6508
6509                                                                                                 player[i].lastchecktime=12;
6510                                                                                                 //player[i].lastseentime-=.5;
6511
6512                                                                                                 facing=player[i].coords;
6513                                                                                                 flatfacing=player[player[i].ally].coords;
6514                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
6515                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
6516                                                                                                 if(-1!=checkcollide(facing,flatfacing))
6517                                                                                                         player[i].lastseentime-=.1;
6518
6519                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
6520                                                                                                         player[i].aitype=searchtype;
6521                                                                                                         player[i].lastseentime=12;
6522                                                                                                 }
6523
6524                                                                                                 if(player[i].ally>0){
6525                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
6526                                                                                                         Normalise(&rotatetarget);
6527                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
6528                                                                                                         player[i].targetrotation*=360/6.28;
6529                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6530                                                                                                         player[i].lookrotation=player[i].targetrotation;
6531                                                                                                         player[i].aiupdatedelay=.05;
6532                                                                                                         player[i].forwardkeydown=1;
6533
6534                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
6535                                                                                                                 player[i].aitype=searchtype;
6536                                                                                                                 player[i].lastseentime=12;
6537                                                                                                                 player[player[i].ally].aitype=searchtype;
6538                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
6539                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
6540                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
6541                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
6542                                                                                                                 }
6543                                                                                                         }
6544
6545                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6546                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6547                                                                                                                 else{
6548                                                                                                                         XYZ leftpos,rightpos;
6549                                                                                                                         float leftdist,rightdist;
6550                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6551                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6552                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6553                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6554                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
6555                                                                                                                         else player[i].targetrotation-=90;
6556                                                                                                                 }
6557                                                                                                         }
6558                                                                                                 }
6559
6560                                                                                                 player[i].leftkeydown=0;
6561                                                                                                 player[i].backkeydown=0;
6562                                                                                                 player[i].rightkeydown=0;
6563                                                                                                 player[i].crouchkeydown=0;
6564                                                                                                 player[i].attackkeydown=0;
6565                                                                                         }
6566                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6567                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6568                                                                                 }
6569
6570                                                                                 if(player[i].aitype==getweapontype){
6571                                                                                         player[i].aiupdatedelay-=multiplier;
6572                                                                                         player[i].lastchecktime-=multiplier;
6573
6574                                                                                         if(player[i].aiupdatedelay<0){
6575                                                                                                 player[i].aiupdatedelay=.2;
6576
6577                                                                                                 int closest;
6578                                                                                                 float closestdist;
6579                                                                                                 closest=-1;
6580                                                                                                 closestdist=-1;
6581                                                                                                 float distance;
6582
6583                                                                                                 if(player[i].ally<0){
6584                                                                                                         for(j=0;j<weapons.numweapons;j++){
6585                                                                                                                 if(weapons.owner[j]==-1){
6586                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
6587                                                                                                                         if(closestdist==-1||distance<closestdist){
6588                                                                                                                                 closestdist=distance;
6589                                                                                                                                 closest=j;
6590                                                                                                                         }
6591                                                                                                                         closest=j;
6592                                                                                                                 }
6593                                                                                                         }
6594                                                                                                         if(closest!=-1)player[i].ally=closest;
6595                                                                                                         else player[i].ally=-1;
6596                                                                                                 }
6597
6598                                                                                                 player[i].lastseentime=12;
6599
6600                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
6601                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
6602                                                                                                                 player[i].aitype=attacktypecutoff;
6603                                                                                                                 player[i].lastseentime=1;
6604                                                                                                         }
6605                                                                                                         if(!player[0].dead)
6606                                                                                                                 if(player[i].ally>=0){
6607                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
6608                                                                                                                                 player[i].aitype=attacktypecutoff;
6609                                                                                                                                 player[i].lastseentime=1;
6610                                                                                                                         }
6611                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
6612                                                                                                                         Normalise(&rotatetarget);
6613                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
6614                                                                                                                         player[i].targetrotation*=360/6.28;
6615                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6616                                                                                                                         player[i].lookrotation=player[i].targetrotation;
6617                                                                                                                         player[i].aiupdatedelay=.05;
6618                                                                                                                         player[i].forwardkeydown=1;
6619
6620
6621                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6622                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6623                                                                                                                                 else{
6624                                                                                                                                         XYZ leftpos,rightpos;
6625                                                                                                                                         float leftdist,rightdist;
6626                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6627                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6628                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6629                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6630                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
6631                                                                                                                                         else player[i].targetrotation-=90;
6632                                                                                                                                 }
6633                                                                                                                         }
6634                                                                                                                 }
6635
6636                                                                                                                 player[i].leftkeydown=0;
6637                                                                                                                 player[i].backkeydown=0;
6638                                                                                                                 player[i].rightkeydown=0;
6639                                                                                                                 player[i].attackkeydown=0;
6640                                                                                                                 player[i].throwkeydown=1;
6641                                                                                                                 player[i].crouchkeydown=0;
6642                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
6643                                                                                                                 player[i].drawkeydown=0;
6644                                                                                         }
6645                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6646                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6647                                                                                 }
6648
6649                                                                                 if(player[i].aitype==attacktypecutoff){
6650                                                                                         player[i].aiupdatedelay-=multiplier;
6651                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
6652                                                                                                 if((player[0].targetanimation==rabbitkickanim||player[0].targetanimation==knifethrowanim||(player[0].isFlip()&&normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&!player[0].skeleton.free&&(player[i].aiupdatedelay<.1)){
6653                                                                                                         player[i].attackkeydown=0;
6654                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
6655                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
6656                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
6657                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
6658                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
6659                                                                                                                                 else player[i].targetanimation=rollanim;
6660                                                                                                                                 player[i].target=0;
6661                                                                                                                                 player[i].targetframe=0;
6662                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
6663                                                                                                                                 player[i].wentforweapon=0;
6664                                                                                                                         }
6665                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
6666                                                                                                                                 player[i].targetanimation=flipanim;
6667                                                                                                                                 player[i].target=0;
6668                                                                                                                                 player[i].targetframe=0;
6669                                                                                                                         }
6670                                                                                                                 }
6671                                                                                                         }
6672                                                                                                         player[i].forwardkeydown=0;
6673                                                                                                         player[i].aiupdatedelay=.02;
6674                                                                                                 }
6675                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
6676                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
6677                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
6678                                                                                                 }
6679                                                                                                 if(player[i].wentforweapon<3)
6680                                                                                                         for(j=0;j<weapons.numweapons;j++){
6681                                                                                                                 if(player[i].creature!=wolftype)
6682                                                                                                                         if(player[i].num_weapons==0&&weapons.owner[j]==-1&&weapons.velocity[i].x==0&&weapons.velocity[i].z==0&&weapons.velocity[i].y==0){
6683                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
6684                                                                                                                                         player[i].wentforweapon++;
6685                                                                                                                                         player[i].lastchecktime=6;
6686                                                                                                                                         player[i].aitype=getweapontype;
6687                                                                                                                                         player[i].ally=-1;
6688                                                                                                                                 }
6689                                                                                                                         }
6690                                                                                                         }
6691                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
6692                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
6693                                                                                                                         if(player[i].damage<player[i].damagetolerance*.5&&((player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)&&((player[i].aiupdatedelay<.15&&difficulty==2)||(player[i].aiupdatedelay<.08&&difficulty!=2)))){
6694                                                                                                                                 player[i].crouchkeydown=1;
6695                                                                                                                         }
6696                                                                                                                         if(player[i].isRun()&&!player[i].onground){
6697                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
6698                                                                                                                                         test2=player[i].coords+player[i].facing;
6699                                                                                                                                         test2.y+=5;
6700                                                                                                                                         test=player[i].coords+player[i].facing;
6701                                                                                                                                         test.y-=10;
6702                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
6703                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
6704                                                                                                                                         if(j==-1){
6705                                                                                                                                                 player[i].velocity=0;
6706                                                                                                                                                 player[i].targetanimation=player[i].getStop();
6707                                                                                                                                                 player[i].targetframe=0;
6708                                                                                                                                                 player[i].target=0;
6709                                                                                                                                                 player[i].targetrotation+=180;
6710                                                                                                                                                 player[i].stunned=.5;
6711                                                                                                                                                 //player[i].aitype=passivetype;
6712                                                                                                                                                 player[i].aitype=pathfindtype;
6713                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6714                                                                                                                                                 player[i].finalpathfindpoint=-1;
6715                                                                                                                                                 player[i].targetpathfindpoint=-1;
6716                                                                                                                                                 player[i].lastpathfindpoint=-1;
6717                                                                                                                                                 player[i].lastpathfindpoint2=-1;
6718                                                                                                                                                 player[i].lastpathfindpoint3=-1;
6719                                                                                                                                                 player[i].lastpathfindpoint4=-1;
6720                                                                                                                                         }
6721                                                                                                                                         else player[i].laststanding=j;
6722                                                                                                                                 }
6723                                                                                                                         }
6724                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
6725                                                                                                                                 player[i].aitype=pathfindtype;
6726                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6727                                                                                                                                 player[i].finalpathfindpoint=-1;
6728                                                                                                                                 player[i].targetpathfindpoint=-1;
6729                                                                                                                                 player[i].lastpathfindpoint=-1;
6730                                                                                                                                 player[i].lastpathfindpoint2=-1;
6731                                                                                                                                 player[i].lastpathfindpoint3=-1;
6732                                                                                                                                 player[i].lastpathfindpoint4=-1;
6733                                                                                                                         }
6734                                                                                                                         if(player[i].aiupdatedelay<0&&!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
6735                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
6736                                                                                                                                 else player[i].drawkeydown=0;
6737                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
6738                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
6739                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
6740                                                                                                                                         rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity*findDistance(&player[player[i].aitarget].coords,&player[i].coords)/findLength(&player[i].velocity)-player[i].coords;
6741                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
6742                                                                                                                                 Normalise(&rotatetarget);
6743                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
6744                                                                                                                                 player[i].targetrotation*=360/6.28;
6745                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6746                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
6747                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
6748
6749                                                                                                                                 oldkey=player[i].forwardkeydown;
6750                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
6751                                                                                                                                 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||findDistancefast(&player[i].coords,&player[0].coords)<9)&&player[0].weaponactive!=-1)player[i].forwardkeydown=1;
6752                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
6753                                                                                                                                 else player[i].forwardkeydown=0;
6754                                                                                                                                 if(player[0].dead){
6755                                                                                                                                         player[i].forwardkeydown=0;
6756                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
6757                                                                                                                                         if(Random()%100==0){
6758                                                                                                                                                 player[i].aitype=pathfindtype;
6759                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6760                                                                                                                                                 player[i].finalpathfindpoint=-1;
6761                                                                                                                                                 player[i].targetpathfindpoint=-1;
6762                                                                                                                                                 player[i].lastpathfindpoint=-1;
6763                                                                                                                                                 player[i].lastpathfindpoint2=-1;
6764                                                                                                                                                 player[i].lastpathfindpoint3=-1;
6765                                                                                                                                                 player[i].lastpathfindpoint4=-1;
6766                                                                                                                                         }
6767                                                                                                                                 }
6768                                                                                                                                 player[i].leftkeydown=0;
6769                                                                                                                                 player[i].backkeydown=0;
6770                                                                                                                                 player[i].rightkeydown=0;
6771                                                                                                                                 player[i].crouchkeydown=0;
6772                                                                                                                                 player[i].throwkeydown=0;
6773
6774                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6775                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
6776                                                                                                                                 else player[i].attackkeydown=0;
6777                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
6778
6779                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
6780                                                                                                                                         target=-2;
6781                                                                                                                                         for(j=0;j<numplayers;j++){
6782                                                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].hasvictim&&((tutoriallevel==1&&reversaltrain)||(Random()%2==0&&difficulty==2)||(Random()%4==0&&difficulty==1)||(Random()%8==0&&difficulty==0)||(player[j].lastattack2==player[j].targetanimation&&player[j].lastattack3==player[j].targetanimation&&(Random()%2==0||difficulty==2))||((player[i].isIdle()||player[i].isRun())&&player[j].weaponactive!=-1)||(player[j].targetanimation==swordslashanim&&player[i].weaponactive!=-1)||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)){
6783                                                                                                                                                         if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==spinkickanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim||player[j].targetanimation==winduppunchanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||player[j].targetanimation==knifeslashstartanim||((player[j].targetanimation==swordslashanim)&&(findDistancefast(&player[j].coords,&player[i].coords)<2||(player[i].weaponactive!=-1))))){
6784                                                                                                                                                                 if(target>=0)target=-1;
6785                                                                                                                                                                 else target=j;
6786                                                                                                                                                         }
6787                                                                                                                                                 }
6788                                                                                                                                         }
6789                                                                                                                                         if(target>=0)player[target].Reverse();
6790                                                                                                                                 }
6791
6792                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
6793                                                                                                                                 if((player[i].collided>.8&&player[i].jumppower>=5)||(findDistancefast(&player[i].coords,&player[0].coords)>400&&player[i].onterrain&&player[i].creature==rabbittype))player[i].jumpkeydown=1;
6794                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
6795                                                                                                                                         player[0].jumpkeydown=0;
6796                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
6797                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
6798                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
6799
6800                                                                                                                                 if(tutoriallevel==1){
6801                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
6802                                                                                                                                 }
6803
6804
6805                                                                                                                                 facing=player[i].coords;
6806                                                                                                                                 flatfacing=player[0].coords;
6807                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
6808                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
6809                                                                                                                                 if(player[i].occluded>=2)
6810                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
6811                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
6812                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
6813                                                                                                                                                         player[i].aitype=searchtype;
6814                                                                                                                                                         player[i].lastchecktime=12;
6815                                                                                                                                                         player[i].lastseen=player[0].coords;
6816                                                                                                                                                         player[i].lastseentime=12;
6817                                                                                                                                                 }
6818                                                                                                                                         }
6819                                                                                                                                         else player[i].lastseentime=1;
6820                                                                                                                         }
6821                                                                                 }
6822                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
6823                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
6824                                                                                                 test=player[0].coords;
6825                                                                                                 test.y-=40;
6826                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
6827                                                                                         }
6828                                                                                 }
6829                                                                                 // NOTE: Ask about logic of this call : NOTE
6830                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
6831                                                                                         player[i].stunned>0 ||
6832                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
6833                                                                                 {
6834                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
6835                                                                                         player[i].targetrotation=player[i].rotation;
6836                                                                                         player[i].forwardkeydown=0;
6837                                                                                         player[i].leftkeydown=0;
6838                                                                                         player[i].backkeydown=0;
6839                                                                                         player[i].rightkeydown=0;
6840                                                                                         player[i].jumpkeydown=0;
6841                                                                                         player[i].attackkeydown=0;
6842                                                                                         player[i].crouchkeydown=0;
6843                                                                                         player[i].throwkeydown=0;
6844                                                                                 }
6845
6846
6847                                                                                 facing=0;
6848                                                                                 facing.z=-1;
6849
6850                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6851                                                                                 facing=flatfacing;
6852
6853                                                                                 if(player[i].aitype==attacktypecutoff){
6854                                                                                         rotatetarget=player[0].coords-player[i].coords;
6855                                                                                         Normalise(&rotatetarget);
6856                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
6857                                                                                         player[i].targetheadrotation*=360/6.28;
6858                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
6859
6860                                                                                         player[i].targetheadrotation*=-1;
6861                                                                                         player[i].targetheadrotation+=180;
6862                                                                                         //player[i].targetheadrotation2=0;
6863                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
6864                                                                                 }
6865                                                                                 else if(player[i].howactive>=typesleeping){
6866                                                                                         player[i].targetheadrotation=player[i].targetrotation;
6867                                                                                         player[i].targetheadrotation2=0;
6868                                                                                 }
6869                                                                                 else {
6870                                                                                         if(player[i].interestdelay<=0){
6871                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
6872                                                                                                 player[i].headtarget=player[i].coords;
6873                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
6874                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
6875                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
6876                                                                                                 player[i].headtarget+=player[i].facing*1.5;
6877                                                                                         }
6878                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
6879                                                                                         Normalise(&rotatetarget);
6880                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
6881                                                                                         player[i].targetheadrotation*=360/6.28;
6882                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
6883
6884                                                                                         player[i].targetheadrotation*=-1;
6885                                                                                         player[i].targetheadrotation+=180;
6886                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
6887                                                                                 }
6888                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
6889                                                                         }
6890                                                                         if(animation[player[i].targetanimation].attack==reversed){
6891                                                                                 //player[i].targetrotation=player[i].rotation;
6892                                                                                 player[i].forwardkeydown=0;
6893                                                                                 player[i].leftkeydown=0;
6894                                                                                 player[i].backkeydown=0;
6895                                                                                 player[i].rightkeydown=0;
6896                                                                                 player[i].jumpkeydown=0;
6897                                                                                 player[i].attackkeydown=0;
6898                                                                                 //player[i].crouchkeydown=0;
6899                                                                                 player[i].throwkeydown=0;
6900                                                                         }
6901
6902                                                                         if(indialogue!=-1){
6903                                                                                 player[i].forwardkeydown=0;
6904                                                                                 player[i].leftkeydown=0;
6905                                                                                 player[i].backkeydown=0;
6906                                                                                 player[i].rightkeydown=0;
6907                                                                                 player[i].jumpkeydown=0;
6908                                                                                 player[i].crouchkeydown=0;
6909                                                                                 player[i].drawkeydown=0;
6910                                                                                 player[i].throwkeydown=0;
6911                                                                         }
6912
6913                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
6914                                                                         if(player[i].collided>1)player[i].collided=1;
6915                                                                         player[i].collided-=multiplier*4;
6916                                                                         player[i].whichdirectiondelay-=multiplier;
6917                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6918                                                                                 player[i].avoidcollided=-.3;
6919                                                                                 player[i].whichdirection=abs(Random()%2);
6920                                                                                 player[i].whichdirectiondelay=.4;
6921                                                                         }
6922                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
6923                                                                         player[i].avoidcollided-=multiplier/4;
6924                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
6925                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
6926                                                                         if(player[i].surprised<=0&&player[i].aitype==attacktypecutoff&&i!=0&&!player[i].dead&&!player[i].skeleton.free&&animation[player[i].targetanimation].attack==neutral)numresponded=1;
6927
6928                                                                         if(!player[i].throwkeydown){
6929                                                                                 player[i].throwtogglekeydown=0;
6930                                                                         }
6931                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6932                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons<2&&(player[i].isIdle()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim||player[i].isFlip()||player[i].isFlip()||player[i].aitype!=playercontrolled)){
6933                                                                                         for(j=0;j<weapons.numweapons;j++){
6934                                                                                                 if(((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1&&player[i].weaponactive==-1)
6935                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
6936                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
6937                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
6938                                                                                                                                 player[i].throwtogglekeydown=1;
6939                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
6940                                                                                                                                 player[i].target=0;
6941                                                                                                                                 player[i].targetframe=0;
6942                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
6943                                                                                                                                 Normalise(&rotatetarget);
6944                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
6945                                                                                                                                 player[i].targetrotation*=360/6.28;
6946                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6947                                                                                                                                 player[i].hasvictim=0;
6948                                                                                                                         }
6949                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6950                                                                                                                                 player[i].throwtogglekeydown=1;
6951                                                                                                                                 player[i].hasvictim=0;
6952
6953                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
6954                                                                                                                                 if((((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1)||(player[i].victim&&weapons.owner[j]==player[i].victim->id))
6955                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
6956                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
6957                                                                                                                                                         float gLoc[3];
6958                                                                                                                                                         float vel[3];
6959                                                                                                                                                         gLoc[0]=player[i].coords.x;
6960                                                                                                                                                         gLoc[1]=player[i].coords.y;
6961                                                                                                                                                         gLoc[2]=player[i].coords.z;
6962                                                                                                                                                         vel[0]=player[i].velocity.x;
6963                                                                                                                                                         vel[1]=player[i].velocity.y;
6964                                                                                                                                                         vel[2]=player[i].velocity.z;
6965                                                                                                                                                         if(weapons.type[j]!=staff){
6966                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
6967                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
6968                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
6969                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
6970                                                                                                                                                         }
6971
6972                                                                                                                                                         player[i].weaponactive=0;
6973                                                                                                                                                         weapons.owner[j]=player[i].id;
6974                                                                                                                                                         if(player[i].num_weapons>0){
6975                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6976                                                                                                                                                         }
6977                                                                                                                                                         player[i].num_weapons++;
6978                                                                                                                                                         player[i].weaponids[0]=j;
6979                                                                                                                                                 }
6980                                                                                                                                         }
6981                                                                                                                                         //}
6982                                                                                                                         }
6983                                                                                                                 }
6984                                                                                                                 else if ((player[i].isIdle()||player[i].isFlip()||player[i].aitype!=playercontrolled)&&findDistancefast(&player[i].coords,&weapons.position[j])<5&&player[i].coords.y<weapons.position[j].y){
6985                                                                                                                         if(!player[i].isFlip()){
6986                                                                                                                                 player[i].throwtogglekeydown=1;
6987                                                                                                                                 player[i].targetanimation=removeknifeanim;
6988                                                                                                                                 player[i].target=0;
6989                                                                                                                                 player[i].targetframe=0;
6990                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
6991                                                                                                                                 Normalise(&rotatetarget);
6992                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
6993                                                                                                                                 player[i].targetrotation*=360/6.28;
6994                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6995                                                                                                                         }
6996                                                                                                                         if(player[i].isFlip()){
6997                                                                                                                                 player[i].throwtogglekeydown=1;
6998                                                                                                                                 player[i].hasvictim=0;
6999
7000                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
7001                                                                                                                                         if(player[i].weaponactive==-1)
7002                                                                                                                                                 if((((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[k]==-1)||(player[i].victim&&weapons.owner[k]==player[i].victim->id))
7003                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
7004                                                                                                                                                                 float gLoc[3];
7005                                                                                                                                                                 float vel[3];
7006                                                                                                                                                                 gLoc[0]=player[i].coords.x;
7007                                                                                                                                                                 gLoc[1]=player[i].coords.y;
7008                                                                                                                                                                 gLoc[2]=player[i].coords.z;
7009                                                                                                                                                                 vel[0]=player[i].velocity.x;
7010                                                                                                                                                                 vel[1]=player[i].velocity.y;
7011                                                                                                                                                                 vel[2]=player[i].velocity.z;
7012                                                                                                                                                                 if(weapons.type[k]!=staff){
7013                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
7014                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
7015                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
7016                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
7017                                                                                                                                                                 }
7018
7019                                                                                                                                                                 player[i].weaponactive=0;
7020                                                                                                                                                                 weapons.owner[k]=player[i].id;
7021                                                                                                                                                                 if(player[i].num_weapons>0){
7022                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7023                                                                                                                                                                 }
7024                                                                                                                                                                 player[i].num_weapons++;
7025                                                                                                                                                                 player[i].weaponids[0]=k;
7026                                                                                                                                                         }
7027                                                                                                                                 }
7028                                                                                                                         }
7029                                                                                                                 }
7030                                                                                                         }
7031                                                                                         }
7032                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7033                                                                                                 if(numplayers>1)
7034                                                                                                         for(j=0;j<numplayers;j++){
7035                                                                                                                 if(player[i].weaponactive==-1)
7036                                                                                                                         if(j!=i)
7037                                                                                                                                 if(player[j].num_weapons&&player[j].skeleton.free&&findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&(((player[j].skeleton.forward.y<0&&player[j].weaponstuckwhere==0)||(player[j].skeleton.forward.y>0&&player[j].weaponstuckwhere==1))||player[j].weaponstuck==-1||player[j].num_weapons>1)){
7038                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
7039                                                                                                                                                 player[i].throwtogglekeydown=1;
7040                                                                                                                                                 player[i].victim=&player[j];
7041                                                                                                                                                 player[i].hasvictim=1;
7042                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
7043                                                                                                                                                 player[i].target=0;
7044                                                                                                                                                 player[i].targetframe=0;
7045                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
7046                                                                                                                                                 Normalise(&rotatetarget);
7047                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
7048                                                                                                                                                 player[i].targetrotation*=360/6.28;
7049                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7050                                                                                                                                         }
7051                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7052                                                                                                                                                 player[i].throwtogglekeydown=1;
7053                                                                                                                                                 player[i].victim=&player[j];
7054                                                                                                                                                 player[i].hasvictim=1;
7055                                                                                                                                                 int k = player[j].weaponids[0];
7056                                                                                                                                                 if(player[i].hasvictim){
7057                                                                                                                                                         float gLoc[3];
7058                                                                                                                                                         float vel[3];
7059                                                                                                                                                         gLoc[0]=player[i].coords.x;
7060                                                                                                                                                         gLoc[1]=player[i].coords.y;
7061                                                                                                                                                         gLoc[2]=player[i].coords.z;
7062                                                                                                                                                         vel[0]=player[i].velocity.x;
7063                                                                                                                                                         vel[1]=player[i].velocity.y;
7064                                                                                                                                                         vel[2]=player[i].velocity.z;
7065                                                                                                                                                         bool fleshstuck;
7066                                                                                                                                                         fleshstuck=0;
7067                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
7068                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7069                                                                                                                                                                         fleshstuck=1;
7070                                                                                                                                                                 }
7071                                                                                                                                                         }
7072                                                                                                                                                         if(!fleshstuck){
7073                                                                                                                                                                 if(weapons.type[k]!=staff){
7074                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
7075                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
7076                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
7077                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
7078                                                                                                                                                                 }
7079                                                                                                                                                         }
7080                                                                                                                                                         if(fleshstuck){
7081                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
7082                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
7083                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
7084                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
7085                                                                                                                                                         }
7086
7087                                                                                                                                                         player[i].weaponactive=0;
7088                                                                                                                                                         if(weapons.owner[k]!=-1){
7089                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
7090                                                                                                                                                                 else player[i].victim->num_weapons=1;
7091
7092                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
7093                                                                                                                                                                 player[i].victim->skeleton.free=1;
7094                                                                                                                                                                 player[i].victim->skeleton.broken=0;
7095
7096                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
7097                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
7098                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
7099                                                                                                                                                                 }
7100
7101                                                                                                                                                                 XYZ relative;
7102                                                                                                                                                                 relative=0;
7103                                                                                                                                                                 relative.y=10;
7104                                                                                                                                                                 Normalise(&relative);
7105                                                                                                                                                                 XYZ footvel,footpoint;
7106                                                                                                                                                                 footvel=0;
7107                                                                                                                                                                 footpoint=weapons.position[k];
7108                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
7109                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7110                                                                                                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
7111                                                                                                                                                                                 weapons.bloody[k]=2;
7112                                                                                                                                                                                 weapons.blooddrip[k]=5;
7113                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
7114                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
7115                                                                                                                                                                                 player[i].victim->DoDamage(2000);
7116                                                                                                                                                                         }
7117                                                                                                                                                                 }
7118                                                                                                                                                                 if(player[i].victim->num_weapons>0){
7119                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
7120                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
7121                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
7122                                                                                                                                                                 }
7123
7124                                                                                                                                                                 player[i].victim->weaponactive=-1;
7125
7126                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
7127                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
7128                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
7129                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
7130                                                                                                                                                         }
7131                                                                                                                                                         weapons.owner[k]=i;
7132                                                                                                                                                         if(player[i].num_weapons>0){
7133                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7134                                                                                                                                                         }
7135                                                                                                                                                         player[i].num_weapons++;
7136                                                                                                                                                         player[i].weaponids[0]=k;
7137                                                                                                                                                 }
7138                                                                                                                                         }
7139                                                                                                                                 }
7140                                                                                                         }
7141                                                                                         }
7142                                                                                 }
7143                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7144                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
7145                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
7146                                                                                                         if(numplayers>1)
7147                                                                                                                 for(j=0;j<numplayers;j++){
7148                                                                                                                         if(i!=j)
7149                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
7150                                                                                                                                         if(hostile)
7151                                                                                                                                                 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&findDistancefast(&player[i].coords,&player[j].coords)<100&&findDistancefast(&player[i].coords,&player[j].coords)>1.5&&!player[j].skeleton.free&&-1==checkcollide(DoRotation(player[j].skeleton.joints[player[j].skeleton.jointlabels[head]].position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
7152                                                                                                                                                         if(!player[i].isFlip()){
7153                                                                                                                                                                 player[i].throwtogglekeydown=1;
7154                                                                                                                                                                 player[i].victim=&player[j];
7155                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
7156                                                                                                                                                                 player[i].target=0;
7157                                                                                                                                                                 player[i].targetframe=0;
7158                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
7159                                                                                                                                                                 Normalise(&rotatetarget);
7160                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
7161                                                                                                                                                                 player[i].targetrotation*=360/6.28;
7162                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7163
7164                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
7165                                                                                                                                                         }
7166                                                                                                                                                         if(player[i].isFlip()){
7167                                                                                                                                                                 if(player[i].weaponactive!=-1){
7168                                                                                                                                                                         player[i].throwtogglekeydown=1;
7169                                                                                                                                                                         player[i].victim=&player[j];
7170                                                                                                                                                                         XYZ aim;
7171                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
7172                                                                                                                                                                         aim=player[i].victim->coords+DoRotation(player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].position,0,player[i].victim->rotation,0)*player[i].victim->scale+player[i].victim->velocity*findDistance(&player[i].victim->coords,&player[i].coords)/50-(player[i].coords+DoRotation(player[i].skeleton.joints[player[i].skeleton.jointlabels[righthand]].position,0,player[i].rotation,0)*player[i].scale);
7173                                                                                                                                                                         Normalise(&aim);
7174
7175                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
7176
7177                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
7178                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
7179                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
7180                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
7181                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
7182                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
7183                                                                                                                                                                         player[i].num_weapons--;
7184                                                                                                                                                                         if(player[i].num_weapons){
7185                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7186                                                                                                                                                                         }
7187                                                                                                                                                                         player[i].weaponactive=-1;
7188                                                                                                                                                                 }
7189                                                                                                                                                         }
7190                                                                                                                                                 }
7191                                                                                                                 }
7192                                                                                         }
7193                                                                                 }
7194                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7195                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
7196                                                                                         {
7197                                                                                                 player[i].throwtogglekeydown=1;
7198                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
7199                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
7200                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
7201                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
7202                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
7203                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
7204                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
7205                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
7206                                                                                                 player[i].num_weapons--;
7207                                                                                                 if(player[i].num_weapons){
7208                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7209                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7210                                                                                                 }
7211
7212                                                                                                 player[i].weaponactive=-1;
7213                                                                                                 for(j=0;j<numplayers;j++){
7214                                                                                                         player[j].wentforweapon=0;
7215                                                                                                 }
7216                                                                                         }
7217                                                                                 }
7218
7219                                                                         }
7220
7221                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
7222                                                                                 if((player[i].drawkeydown&&!player[i].drawtogglekeydown)||(player[i].num_weapons==2&&player[i].weaponactive==-1&&player[i].isIdle())||(player[0].dead&&player[i].weaponactive!=-1&&i!=0)){
7223                                                                                         //Setenvironment(1-environment);
7224                                                                                         bool isgood;
7225                                                                                         isgood=1;
7226                                                                                         if(player[i].weaponactive!=-1){
7227                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
7228                                                                                         }
7229                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
7230                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7231                                                                                                         player[i].targetanimation=drawrightanim;
7232                                                                                                         player[i].targetframe=0;
7233                                                                                                         player[i].target=0;
7234                                                                                                         player[i].drawtogglekeydown=1;
7235                                                                                                 }
7236                                                                                                 if((player[i].isIdle()||(player[i].aitype!=playercontrolled&&player[0].weaponactive!=-1&&player[i].isRun()))&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==sword){
7237                                                                                                         player[i].targetanimation=drawleftanim;
7238                                                                                                         player[i].targetframe=0;
7239                                                                                                         player[i].target=0;
7240                                                                                                         player[i].drawtogglekeydown=1;
7241                                                                                                 }
7242                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7243                                                                                                         player[i].targetanimation=crouchdrawrightanim;
7244                                                                                                         player[i].targetframe=0;
7245                                                                                                         player[i].target=0;
7246                                                                                                         player[i].drawtogglekeydown=1;
7247                                                                                                 }
7248                                                                                         }
7249                                                                                 }
7250                                                                                 if(player[i].isCrouch()&&weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&bloodtoggle&&player[i].onterrain&&player[i].num_weapons&&player[i].weaponactive!=-1&&player[i].attackkeydown){
7251                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
7252                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
7253                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
7254                                                                                                 player[i].targetframe=0;
7255                                                                                                 player[i].target=0;
7256                                                                                                 player[i].hasvictim=0;
7257                                                                                                 //player[i].attacktogglekeydown=1;
7258                                                                                         }
7259                                                                                 }
7260
7261                                                                                 if(!player[i].drawkeydown){
7262                                                                                         player[i].drawtogglekeydown=0;
7263                                                                                 }
7264
7265                                                                                 if(i==0){
7266                                                                                         absflatfacing=0;
7267                                                                                         absflatfacing.z=-1;
7268
7269                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7270                                                                                 }
7271                                                                                 else absflatfacing=flatfacing;
7272
7273                                                                                 if(indialogue!=-1){
7274                                                                                         player[i].forwardkeydown=0;
7275                                                                                         player[i].leftkeydown=0;
7276                                                                                         player[i].backkeydown=0;
7277                                                                                         player[i].rightkeydown=0;
7278                                                                                         player[i].jumpkeydown=0;
7279                                                                                         player[i].crouchkeydown=0;
7280                                                                                         player[i].drawkeydown=0;
7281                                                                                         player[i].throwkeydown=0;
7282                                                                                 }
7283                                                                                 movekey=0;
7284                                                                                 //Do controls
7285                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
7286                                                                                         if(!player[i].forwardkeydown){
7287                                                                                                 player[i].forwardstogglekeydown=0;
7288                                                                                         }
7289                                                                                         if(player[i].crouchkeydown){
7290                                                                                                 //Crouch
7291                                                                                                 target=-2;
7292                                                                                                 if(i==0){
7293                                                                                                         player[i].superruntoggle=1;
7294                                                                                                         if(numplayers>1)
7295                                                                                                                 for(j=0;j<numplayers;j++){
7296                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
7297                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
7298                                                                                                                                         player[i].superruntoggle=0;
7299                                                                                                                                 }
7300                                                                                                                         }
7301                                                                                                                 }
7302                                                                                                 }
7303
7304                                                                                                 if(numplayers>1)
7305                                                                                                         for(j=0;j<numplayers;j++){
7306                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7307                                                                                                                         if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim||player[j].targetanimation==upunchanim||player[j].targetanimation==wolfslapanim||((player[j].targetanimation==swordslashanim||player[j].targetanimation==knifeslashstartanim||player[j].targetanimation==staffhitanim||player[j].targetanimation==staffspinhitanim)&&findDistancefast(&player[j].coords,&player[i].coords)<2))){
7308                                                                                                                                 if(target>=0)target=-1;
7309                                                                                                                                 else target=j;
7310                                                                                                                         }
7311                                                                                                                 }
7312                                                                                                         }
7313                                                                                                         if(target>=0)player[target].Reverse();
7314                                                                                                         player[i].lowreversaldelay=.5;
7315
7316                                                                                                         if(player[i].isIdle()){
7317                                                                                                                 player[i].targetanimation=player[i].getCrouch();
7318                                                                                                                 player[i].target=0;
7319                                                                                                                 player[i].targetframe=0;
7320                                                                                                                 player[i].transspeed=10;
7321                                                                                                         }
7322                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
7323                                                                                                                 player[i].targetanimation=rollanim;
7324                                                                                                                 player[i].target=0;
7325                                                                                                                 player[i].targetframe=0;
7326                                                                                                                 player[i].transspeed=20;
7327                                                                                                         }
7328                                                                                         }
7329                                                                                         if(!player[i].crouchkeydown){
7330                                                                                                 //Uncrouch
7331                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7332                                                                                                 target=-2;
7333                                                                                                 if(player[i].isCrouch()){
7334                                                                                                         if(numplayers>1)
7335                                                                                                                 for(j=0;j<numplayers;j++){
7336                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
7337                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
7338                                                                                                                                         if(target>=0)target=-1;
7339                                                                                                                                         else target=j;
7340                                                                                                                                 }
7341                                                                                                                         }
7342                                                                                                                 }
7343                                                                                                                 if(target>=0)player[target].Reverse();
7344                                                                                                                 player[i].highreversaldelay=.5;
7345
7346                                                                                                                 if(player[i].isCrouch()){
7347                                                                                                                         if(!player[i].wasCrouch()){
7348                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
7349                                                                                                                                 player[i].currentframe=0;
7350                                                                                                                         }
7351                                                                                                                         player[i].target=0;
7352                                                                                                                         player[i].targetanimation=player[i].getIdle();
7353                                                                                                                         player[i].targetframe=0;
7354                                                                                                                         player[i].transspeed=10;
7355                                                                                                                 }
7356                                                                                                 }
7357                                                                                                 if(player[i].targetanimation==sneakanim){
7358                                                                                                         player[i].targetanimation=player[i].getIdle();
7359                                                                                                         player[i].target=0;
7360                                                                                                         player[i].targetframe=0;
7361                                                                                                         player[i].transspeed=10;
7362                                                                                                 }
7363                                                                                         }
7364                                                                                         if(player[i].forwardkeydown){
7365                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
7366                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
7367                                                                                                         else player[i].targetanimation=player[i].getRun();
7368                                                                                                         player[i].target=0;
7369                                                                                                         player[i].targetframe=0;
7370                                                                                                 }
7371                                                                                                 if(player[i].isCrouch()){
7372                                                                                                         player[i].targetanimation=sneakanim;
7373                                                                                                         if(player[i].wasCrouch())player[i].target=0;
7374                                                                                                         player[i].targetframe=0;
7375                                                                                                 }
7376                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7377                                                                                                         player[i].targetanimation=climbanim;
7378                                                                                                         player[i].target=0;
7379                                                                                                         player[i].targetframe=1;
7380                                                                                                         player[i].jumpclimb=1;
7381                                                                                                 }
7382                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7383                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
7384                                                                                                 }
7385                                                                                                 player[i].forwardstogglekeydown=1;
7386                                                                                                 movekey=1;
7387                                                                                         }
7388                                                                                         if (player[i].rightkeydown){
7389                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
7390                                                                                                         player[i].targetanimation=player[i].getRun();
7391                                                                                                         player[i].target=0;
7392                                                                                                         player[i].targetframe=0;
7393                                                                                                 }
7394                                                                                                 if(player[i].isCrouch()){
7395                                                                                                         player[i].targetanimation=sneakanim;
7396                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
7397                                                                                                         player[i].targetframe=0;
7398                                                                                                 }
7399                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7400                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7401                                                                                                 }
7402                                                                                                 player[i].targetrotation-=90;
7403                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7404                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
7405                                                                                                 movekey=1;
7406                                                                                         }
7407                                                                                         if ( player[i].leftkeydown){
7408                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
7409                                                                                                         player[i].targetanimation=player[i].getRun();
7410                                                                                                         player[i].target=0;
7411                                                                                                         player[i].targetframe=0;
7412                                                                                                 }
7413                                                                                                 if(player[i].isCrouch()){
7414                                                                                                         player[i].targetanimation=sneakanim;
7415                                                                                                         if(player[i].wasCrouch())player[i].target=0;
7416                                                                                                         player[i].targetframe=0;
7417                                                                                                 }
7418                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7419                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7420                                                                                                 }
7421                                                                                                 player[i].targetrotation+=90;
7422                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7423                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
7424                                                                                                 movekey=1;
7425                                                                                         }
7426                                                                                         if(player[i].backkeydown){
7427                                                                                                 if(player[i].isIdle()||(player[i].isStop()&&player[i].targetrotation==player[i].rotation)||(player[i].isLanding()&&player[i].targetframe>0&&!player[i].jumpkeydown)||(player[i].isLandhard()&&player[i].targetframe>0&&!player[i].jumpkeydown&&player[i].crouchkeydown)){
7428                                                                                                         player[i].targetanimation=player[i].getRun();
7429                                                                                                         player[i].target=0;
7430                                                                                                         player[i].targetframe=0;
7431                                                                                                 }
7432                                                                                                 if(player[i].isCrouch()){
7433                                                                                                         player[i].targetanimation=sneakanim;
7434                                                                                                         if(player[i].wasCrouch())player[i].target=0;
7435                                                                                                         player[i].targetframe=0;
7436                                                                                                 }
7437                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7438                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
7439                                                                                                 }
7440                                                                                                 if(player[i].targetanimation==hanganim){
7441                                                                                                         player[i].currentanimation=jumpdownanim;
7442                                                                                                         player[i].targetanimation=jumpdownanim;
7443                                                                                                         player[i].target=0;
7444                                                                                                         player[i].currentframe=0;
7445                                                                                                         player[i].targetframe=1;
7446                                                                                                         player[i].velocity=0;
7447                                                                                                         player[i].velocity.y+=gravity;
7448                                                                                                         player[i].coords.y-=1.4;
7449                                                                                                         player[i].grabdelay=1;
7450                                                                                                 }
7451                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7452                                                                                                         player[i].targetrotation+=180;
7453                                                                                                 movekey=1;
7454                                                                                         }
7455                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7456                                                                                                 if((((player[i].isLanding()&&player[i].targetframe>=3)||player[i].isRun()||player[i].targetanimation==walkanim||player[i].isCrouch()||player[i].targetanimation==sneakanim)&&player[i].jumppower>1)&&((player[i].targetanimation!=rabbitrunninganim&&player[i].targetanimation!=wolfrunninganim)||i!=0)){
7457                                                                                                         player[i].jumpstart=0;
7458                                                                                                         player[i].targetanimation=jumpupanim;
7459                                                                                                         player[i].target=0;
7460                                                                                                         player[i].targetframe=0;
7461                                                                                                         player[i].rotation=player[i].targetrotation;
7462                                                                                                         player[i].transspeed=20;
7463                                                                                                         player[i].FootLand(0,1);
7464                                                                                                         player[i].FootLand(1,1);
7465
7466                                                                                                         facing=0;
7467                                                                                                         facing.z=-1;
7468                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7469
7470                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7471                                                                                                         if(!movekey)player[i].velocity=0;
7472
7473                                                                                                         //Dodge sweep?
7474                                                                                                         target=-2;
7475                                                                                                         if(numplayers>1)
7476                                                                                                                 for(j=0;j<numplayers;j++){
7477                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7478                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
7479                                                                                                                                         if(target>=0)target=-1;
7480                                                                                                                                         else target=j;
7481                                                                                                                                 }
7482                                                                                                                         }
7483                                                                                                                 }
7484                                                                                                                 if(target>=0)player[i].velocity.y=1;
7485                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7486                                                                                                                         player[i].velocity.y=7;
7487                                                                                                                         player[i].crouchtogglekeydown=1;
7488                                                                                                                 }
7489                                                                                                                 else player[i].velocity.y=5;
7490
7491                                                                                                                 if(mousejump&&i==0&&debugmode){
7492                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
7493                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7494                                                                                                                 }
7495
7496                                                                                                                 player[i].coords.y+=.2;
7497                                                                                                                 player[i].jumppower-=1;
7498
7499                                                                                                                 static float gLoc[3];
7500                                                                                                                 static float vel[3];
7501                                                                                                                 gLoc[0]=player[i].coords.x;
7502                                                                                                                 gLoc[1]=player[i].coords.y;
7503                                                                                                                 gLoc[2]=player[i].coords.z;
7504                                                                                                                 vel[0]=player[i].velocity.x;
7505                                                                                                                 vel[1]=player[i].velocity.y;
7506                                                                                                                 vel[2]=player[i].velocity.z;
7507
7508                                                                                                                 if(i==0){
7509                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
7510                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
7511                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
7512                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
7513                                                                                                                 }
7514
7515                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
7516                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
7517                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
7518                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
7519                                                                                                 }
7520                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
7521                                                                                                         player[i].targetanimation=player[i].getLanding();
7522                                                                                                         player[i].landhard=0;
7523                                                                                                         player[i].target=0;
7524                                                                                                         player[i].targetframe=2;
7525                                                                                                         player[i].jumpstart=1;
7526                                                                                                         player[i].tempdeltav=deltav;
7527                                                                                                 }
7528                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
7529                                                                                                         if(player[i].jumppower>multiplier*6){
7530                                                                                                                 player[i].velocity.y+=multiplier*6;
7531                                                                                                                 player[i].jumppower-=multiplier*6;
7532                                                                                                         }
7533                                                                                                         if(player[i].jumppower<=multiplier*6){
7534                                                                                                                 player[i].velocity.y+=player[i].jumppower;
7535                                                                                                                 player[i].jumppower=0;
7536                                                                                                         }
7537                                                                                                 }
7538                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7539                                                                                         }
7540
7541                                                                                         if(!movekey){
7542                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
7543                                                                                                         player[i].targetanimation=player[i].getStop();
7544                                                                                                         player[i].target=0;
7545                                                                                                         player[i].targetframe=0;
7546                                                                                                 }
7547                                                                                                 if(player[i].targetanimation==sneakanim){
7548                                                                                                         player[i].targetanimation=player[i].getCrouch();
7549                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
7550                                                                                                         player[i].targetframe=0;
7551                                                                                                 }
7552                                                                                         }
7553                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
7554                                                                                                 player[i].targetanimation=player[i].getStop();
7555                                                                                                 player[i].target=0;
7556                                                                                                 player[i].targetframe=0;
7557                                                                                         }
7558                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
7559                                                                                                 player[i].targetanimation=player[i].getStop();
7560                                                                                                 player[i].target=0;
7561                                                                                                 player[i].targetframe=0;
7562                                                                                         }
7563                                                                                 }
7564                                                                 }
7565                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
7566                                                         }
7567
7568                                                         //Rotation
7569                                                         for(k=0;k<numplayers;k++){
7570                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
7571                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
7572                                                                         else player[k].rotation+=360;
7573                                                                 }
7574
7575                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
7576                                                                         player[k].targetanimation=player[k].getStop();
7577                                                                         player[k].targetframe=0;
7578                                                                         player[k].target=0;
7579                                                                 }
7580
7581                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
7582                                                                         player[k].targettilt=0;
7583                                                                 }
7584                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
7585                                                                         player[k].targettilt=0;
7586                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
7587                                                                         player[k].jumppower+=multiplier*7;
7588                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
7589                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
7590                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
7591                                                                 }
7592
7593                                                                 if(player[k].isRun()){
7594                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7595                                                                 }
7596
7597                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
7598                                                                 else if(player[k].tilt>player[k].targettilt){
7599                                                                         player[k].tilt-=multiplier*150;
7600                                                                 }
7601                                                                 else if(player[k].tilt<player[k].targettilt){
7602                                                                         player[k].tilt+=multiplier*150;
7603                                                                 }
7604
7605                                                                 player[k].grabdelay-=multiplier;
7606                                                         }
7607
7608                                                         for(k=0;k<numplayers;k++){
7609                                                                 player[k].DoAnimations();
7610                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
7611                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
7612                                                         }
7613
7614                                                         objects.DoStuff();
7615                                                         
7616                                                         for(j=numenvsounds-1;j>=0;j--){
7617                                                                 envsoundlife[j]-=multiplier;
7618                                                                 if(envsoundlife[j]<0){
7619                                                                         numenvsounds--;
7620                                                                         envsoundlife[j]=envsoundlife[numenvsounds];
7621                                                                         envsound[j]=envsound[numenvsounds];
7622                                                                 }
7623                                                         }
7624                                                         if(slomo) OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7625                                                         else OPENAL_SetFrequency(OPENAL_ALL, 22050);
7626
7627                                                         if(tutoriallevel==1){
7628                                                                 XYZ temp;
7629                                                                 XYZ temp2;
7630                                                                 XYZ temp3;
7631                                                                 XYZ oldtemp;
7632                                                                 XYZ oldtemp2;
7633                                                                 temp.x=1011;
7634                                                                 temp.y=84;
7635                                                                 temp.z=491;
7636                                                                 temp2.x=1025;
7637                                                                 temp2.y=75;
7638                                                                 temp2.z=447;
7639                                                                 temp3.x=1038;
7640                                                                 temp3.y=76;
7641                                                                 temp3.z=453;
7642                                                                 oldtemp=temp;
7643                                                                 oldtemp2=temp2;
7644                                                                 if(tutorialstage>=51)
7645                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7646                                                                                 OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7647                                                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7648
7649                                                                                 PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
7650                                                                                 OPENAL_SetPaused(channels[stream_music3], false);
7651                                                                                 OPENAL_SetVolume(channels[stream_music3], 256);
7652
7653                                                                                 gameon=0;
7654                                                                                 mainmenu=5;
7655
7656                                                                                 fireSound();
7657
7658                                                                                 flash();
7659                                                                         }
7660                                                                         if(tutorialstage<51)
7661                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7662                                                                                         float gLoc[3];
7663                                                                                         float vel[3];
7664                                                                                         gLoc[0]=player[0].coords.x;
7665                                                                                         gLoc[1]=player[0].coords.y;
7666                                                                                         gLoc[2]=player[0].coords.z;
7667                                                                                         vel[0]=0;
7668                                                                                         vel[1]=0;
7669                                                                                         vel[2]=0;
7670                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7671                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7672                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
7673                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
7674
7675                                                                                         player[0].coords=(oldtemp+oldtemp2)/2;
7676
7677                                                                                         flash();
7678                                                                                 }
7679                                                                                 if(tutorialstage>=14&&tutorialstage<50)
7680                                                                                         if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7681                                                                                                 float gLoc[3];
7682                                                                                                 float vel[3];
7683                                                                                                 gLoc[0]=player[1].coords.x;
7684                                                                                                 gLoc[1]=player[1].coords.y;
7685                                                                                                 gLoc[2]=player[1].coords.z;
7686                                                                                                 vel[0]=0;
7687                                                                                                 vel[1]=0;
7688                                                                                                 vel[2]=0;
7689                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7690                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7691                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7692                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7693
7694                                                                                                 for(int i=0;i<player[1].skeleton.num_joints;i++){
7695                                                                                                         if(Random()%2==0){
7696                                                                                                                 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7697                                                                                                                 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7698                                                                                                                 if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
7699                                                                                                                 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7700                                                                                                                 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7701                                                                                                         }
7702                                                                                                 }
7703
7704                                                                                                 player[1].coords=(oldtemp+oldtemp2)/2;
7705                                                                                                 for(int i=0;i<player[1].skeleton.num_joints;i++){
7706                                                                                                         player[1].skeleton.joints[i].velocity=0;
7707                                                                                                         if(Random()%2==0){
7708                                                                                                                 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7709                                                                                                                 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7710                                                                                                                 if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
7711                                                                                                                 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7712                                                                                                                 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7713                                                                                                         }
7714                                                                                                 }
7715                                                                                         }
7716                                                         }
7717
7718
7719                                                         //3d sound
7720                                                         static float gLoc[3];
7721                                                         gLoc[0]=viewer.x;
7722                                                         gLoc[1]=viewer.y;
7723                                                         gLoc[2]=viewer.z;
7724                                                         static float vel[3];
7725                                                         vel[0]=(viewer.x-oldviewer.x)/multiplier;
7726                                                         vel[1]=(viewer.y-oldviewer.y)/multiplier;
7727                                                         vel[2]=(viewer.z-oldviewer.z)/multiplier;
7728
7729                                                         //Set orientation with forward and up vectors
7730                                                         static XYZ upvector;
7731                                                         upvector=0;
7732                                                         upvector.z=-1;
7733
7734                                                         upvector=DoRotation(upvector,-rotation2+90,0,0);
7735                                                         upvector=DoRotation(upvector,0,0-rotation,0);
7736
7737                                                         facing=0;
7738                                                         facing.z=-1;
7739
7740                                                         facing=DoRotation(facing,-rotation2,0,0);
7741                                                         facing=DoRotation(facing,0,0-rotation,0);
7742
7743
7744                                                         static float ori[6];
7745                                                         ori[0] = -facing.x;
7746                                                         ori[1] = facing.y;
7747                                                         ori[2] = -facing.z;
7748                                                         ori[3] = -upvector.x;
7749                                                         ori[4] = upvector.y;
7750                                                         ori[5] = -upvector.z;
7751
7752                                                         OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7753                                                         OPENAL_Update();
7754
7755                                                         oldviewer=viewer;
7756                 }
7757         }
7758
7759         if(Input::isKeyDown(SDLK_F1)&&!freezetogglekeydown){
7760                 Screenshot();
7761                 freezetogglekeydown=1;
7762         }
7763 }
7764
7765 void    Game::TickOnce(){
7766         if(mainmenu)
7767                 rotation+=multiplier*5;
7768         else
7769                 if(directing||indialogue==-1) {
7770                         rotation+=deltah*.7;
7771                         if(!invertmouse)rotation2+=deltav*.7;
7772                         if(invertmouse)rotation2-=deltav*.7;
7773                         if(rotation2>90)rotation2=90;
7774                         if(rotation2<-70)rotation2=-70;
7775                 }
7776 }
7777
7778 void    Game::TickOnceAfter(){
7779         static XYZ colviewer;
7780         static XYZ coltarget;
7781         static XYZ target;
7782         static XYZ col;
7783         static float brotate;
7784         static XYZ facing;
7785         static int i,j;
7786         static float changedelay;
7787         static bool alldead;
7788         static float unseendelay;
7789         static float cameraspeed;
7790
7791         if(!mainmenu){
7792
7793                 if(environment==snowyenvironment)music1=stream_music1snow;
7794                 if(environment==grassyenvironment)music1=stream_music1grass;
7795                 if(environment==desertenvironment)music1=stream_music1desert;
7796
7797                 realthreat=0;
7798
7799                 musictype=music1;
7800                 for(i=0;i<numplayers;i++){
7801                         if((player[i].aitype==attacktypecutoff||player[i].aitype==getweapontype||player[i].aitype==gethelptype||player[i].aitype==searchtype)&&!player[i].dead/*&&player[i].surprised<=0*/&&(player[i].targetanimation!=sneakattackedanim&&player[i].targetanimation!=knifesneakattackedanim&&player[i].targetanimation!=swordsneakattackedanim)){
7802                                 musictype=stream_music2;
7803                                 realthreat=1;
7804                         }
7805                 }
7806                 if(player[0].dead)musictype=stream_music3;
7807
7808
7809                 if(musictype==stream_music2){
7810                         unseendelay=1;
7811                 }
7812
7813                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
7814                         unseendelay-=multiplier;
7815                         if(unseendelay>0){
7816                                 musictype=stream_music2;
7817                         }
7818                 }
7819
7820
7821                 if(loading==2){
7822                         musictype=stream_music3;
7823                         musicvolume[2]=512;
7824                         musicvolume[0]=0;
7825                         musicvolume[1]=0;
7826                         musicvolume[3]=0;
7827                 }
7828
7829                 if(musictoggle){
7830                         if(musictype!=oldmusictype&&musictype==stream_music2){
7831                                 static float gLoc[3];
7832                                 static float vel[3];
7833                                 gLoc[0]=cameraloc.x;
7834                                 gLoc[1]=cameraloc.y;
7835                                 gLoc[2]=cameraloc.z;
7836                                 vel[0]=0;
7837                                 vel[1]=0;
7838                                 vel[2]=0;
7839                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
7840                                 OPENAL_SetVolume(channels[alarmsound], 512);
7841                                 OPENAL_SetPaused(channels[alarmsound], false);
7842
7843                         }
7844                 }
7845                 musicselected=musictype;
7846
7847                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
7848                 else musicvolume[0]-=multiplier*450;
7849                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
7850                 else musicvolume[1]-=multiplier*450;
7851                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
7852                 else musicvolume[2]-=multiplier*450;
7853
7854                 for(i=0;i<3;i++){
7855                         if(musicvolume[i]<0)musicvolume[i]=0;
7856                         if(musicvolume[i]>512)musicvolume[i]=512;
7857                 }
7858
7859                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
7860
7861                 if(musictoggle){
7862                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
7863                                 PlayStreamEx( music1, samp[music1], NULL, true);
7864                                 OPENAL_SetPaused(channels[music1], false);
7865                         }
7866                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
7867                                 PlayStreamEx( stream_music2, samp[stream_music2], NULL, true);
7868                                 OPENAL_SetPaused(channels[stream_music2], false);
7869                         }
7870                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
7871                                 PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
7872                                 OPENAL_SetPaused(channels[stream_music3], false);
7873                         }
7874                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
7875                                 OPENAL_SetPaused(channels[music1], true);
7876                         }
7877                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
7878                                 OPENAL_SetPaused(channels[stream_music2], true);
7879                         }
7880                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
7881                                 OPENAL_SetPaused(channels[stream_music3], true);
7882                         }
7883
7884                         if(musicvolume[0]!=oldmusicvolume[0]){
7885                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
7886                         }
7887                         if(musicvolume[1]!=oldmusicvolume[1]){
7888                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
7889                         }
7890                         if(musicvolume[2]!=oldmusicvolume[2]){
7891                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
7892                         }
7893
7894                         for(i=0;i<3;i++){
7895                                 oldmusicvolume[i]=musicvolume[i];
7896                         }
7897                 } else {
7898                         OPENAL_SetPaused(channels[music1], true);
7899                         OPENAL_SetPaused(channels[stream_music2], true);
7900                         OPENAL_SetPaused(channels[stream_music3], true);
7901
7902                         for(i=0;i<4;i++){
7903                                 oldmusicvolume[i]=0;
7904                                 musicvolume[i]=0;
7905                         }
7906                 }
7907
7908                 killhotspot=2;
7909                 for(i=0;i<numhotspots;i++){
7910                         if(hotspottype[i]>10&&hotspottype[i]<20){
7911                                 if(player[hotspottype[i]-10].dead==0){
7912                                         killhotspot=0;
7913                                 }
7914                                 else if(killhotspot==2)
7915                                         killhotspot=1;
7916                         }
7917                 }
7918                 if(killhotspot==2)killhotspot=0;
7919
7920
7921                 winhotspot=0;
7922                 for(i=0;i<numhotspots;i++){
7923                         if(hotspottype[i]==-1){
7924                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7925                                         winhotspot=1;
7926                         }
7927                 }
7928
7929                 int numalarmed=0;
7930                 for(i=1;i<numplayers;i++){
7931                         if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
7932                 }
7933                 if(numalarmed>maxalarmed)maxalarmed=numalarmed;
7934
7935                 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7936                         if(player[0].dead&&changedelay<=0){
7937                                 changedelay=1;
7938                                 targetlevel=whichlevel;
7939                         }
7940                         alldead=1;
7941                         for(i=1;i<numplayers;i++){
7942                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
7943                         }
7944
7945
7946                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7947                                 changedelay=1;
7948                                 targetlevel=whichlevel+1;
7949                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
7950                         }
7951                         if(winhotspot||windialogue){
7952                                 changedelay=0.1;
7953                                 targetlevel=whichlevel+1;
7954                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
7955                         }
7956
7957
7958                         if(killhotspot){
7959                                 changedelay=1;
7960                                 targetlevel=whichlevel+1;
7961                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
7962                         }
7963
7964                         if(changedelay>0&&!player[0].dead&&!won){
7965                                 //high scores, awards, win
7966                                 if(campaign){
7967                                         accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7968                                         scoreadded=1;
7969                                 }
7970                                 else
7971                                 {
7972                                         accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7973                                 }
7974                                 won=1;
7975                         }
7976                 }
7977
7978                 if(!winfreeze){
7979
7980                         if(leveltime<1){
7981                                 loading=0;
7982                                 changedelay=.1;
7983                                 alldead=0;
7984                                 winhotspot=0;
7985                                 killhotspot=0;
7986                         }
7987
7988                         if(!editorenabled&&gameon&&!mainmenu){
7989                                 if(changedelay!=-999)changedelay-=multiplier/7;
7990                                 if(player[0].dead)targetlevel=whichlevel;
7991                                 if(loading==2&&!campaign){
7992                                         flash();
7993
7994                                         fireSound(firestartsound);
7995
7996                                         if(!player[0].dead&&targetlevel!=whichlevel){
7997                                                 startbonustotal=bonustotal;
7998                                         }
7999                                         if(player[0].dead) Loadlevel(whichlevel);
8000                                         else Loadlevel(targetlevel);
8001
8002                                         fireSound();
8003
8004                                         loading=3;
8005                                 }
8006                                 if(loading==2&&targetlevel==whichlevel){
8007                                         flash();
8008                                         loadtime=0;
8009
8010                                         fireSound(firestartsound);
8011
8012                                         for(i=0;i<255;i++){
8013                                                 mapname[i]='\0';
8014                                         }
8015                                         mapname[0]=':';
8016                                         mapname[1]='D';
8017                                         mapname[2]='a';
8018                                         mapname[3]='t';
8019                                         mapname[4]='a';
8020                                         mapname[5]=':';
8021                                         mapname[6]='M';
8022                                         mapname[7]='a';
8023                                         mapname[8]='p';
8024                                         mapname[9]='s';
8025                                         mapname[10]=':';
8026                                         strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]);
8027                                         Loadlevel(mapname);
8028
8029                                         fireSound();
8030
8031                                         loading=3;
8032                                 }
8033                                 if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
8034                                 if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
8035                         {
8036                                                 if(whichlevel!=-2&&!loading&&!player[0].dead){
8037                                                         winfreeze=1;
8038                                                         changedelay=-999;
8039                                                 }
8040                                                 if(player[0].dead)loading=1;
8041                                         }
8042                                 }
8043                         }
8044
8045                         if(campaign)
8046                                 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
8047                                         if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
8048                                                 endgame=1;
8049                                         }
8050                                 }
8051                                 else if(mainmenu==0&&winfreeze){
8052                                         if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
8053                                                 stealthloading=1;
8054                                         else stealthloading=0;
8055
8056                                         if(!stealthloading){
8057                                                 float gLoc[3]={0,0,0};
8058                                                 float vel[3]={0,0,0};
8059                                                 fireSound(firestartsound);
8060
8061                                                 flash();
8062                                         }
8063
8064                                         startbonustotal=0;
8065
8066                                         ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
8067                                         ipstream.ignore(256,':');
8068                                         ipstream >> campaignnumlevels;
8069                                         for(i=0;i<campaignnumlevels;i++){
8070                                                 ipstream.ignore(256,':');
8071                                                 ipstream.ignore(256,':');
8072                                                 ipstream.ignore(256,' ');
8073                                                 ipstream >> campaignmapname[i];
8074                                                 ipstream.ignore(256,':');
8075                                                 ipstream >> campaigndescription[i];
8076                                                 for(j=0;j<256;j++){
8077                                                         if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
8078                                                 }
8079                                                 ipstream.ignore(256,':');
8080                                                 ipstream >> campaignchoosenext[i];
8081                                                 ipstream.ignore(256,':');
8082                                                 ipstream >> campaignnumnext[i];
8083                                                 for(j=0;j<campaignnumnext[i];j++){
8084                                                         ipstream.ignore(256,':');
8085                                                         ipstream >> campaignnextlevel[i][j];
8086                                                         campaignnextlevel[i][j]-=1;
8087                                                 }
8088                                                 ipstream.ignore(256,':');
8089                                                 ipstream >> campaignlocationx[i];
8090                                                 ipstream.ignore(256,':');
8091                                                 ipstream >> campaignlocationy[i];
8092                                         }
8093                                         ipstream.close();
8094
8095                                         for(i=0;i<campaignnumlevels;i++){
8096                                                 levelvisible[i]=0;
8097                                                 levelhighlight[i]=0;
8098                                         }
8099
8100
8101                                         for(i=0;i<campaignnumlevels;i++){
8102                                                 levelvisible[i]=0;
8103                                                 levelhighlight[i]=0;
8104                                         }
8105
8106                                         levelorder[0]=0;
8107                                         levelvisible[0]=1;
8108                                         for(i=0;i<accountactive->getCampaignChoicesMade();i++){
8109                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
8110                                                 levelvisible[levelorder[i+1]]=1;
8111                                         }
8112                                         int whichlevelstart;
8113                                         whichlevelstart=accountactive->getCampaignChoicesMade()-1;
8114                                         if(whichlevelstart<0){
8115                                                 campaignchoicenum=1;
8116                                                 campaignchoicewhich[0]=0;
8117                                         }
8118                                         else
8119                                         {
8120                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
8121                                                 for(i=0;i<campaignchoicenum;i++){
8122                                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
8123                                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
8124                                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
8125                                                 }
8126                                         }
8127
8128                                         loading=2;
8129                                         loadtime=0;
8130                                         targetlevel=7;
8131                                         //if(firstload)TickOnceAfter();
8132                                         if(!firstload)LoadStuff();
8133                                         //else {
8134                                         for(i=0;i<255;i++){
8135                                                 mapname[i]='\0';
8136                                         }
8137                                         mapname[0]=':';
8138                                         mapname[1]='D';
8139                                         mapname[2]='a';
8140                                         mapname[3]='t';
8141                                         mapname[4]='a';
8142                                         mapname[5]=':';
8143                                         mapname[6]='M';
8144                                         mapname[7]='a';
8145                                         mapname[8]='p';
8146                                         mapname[9]='s';
8147                                         mapname[10]=':';
8148
8149                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
8150                                         whichchoice=0;
8151                                         visibleloading=1;
8152                                         stillloading=1;
8153                                         Loadlevel(mapname);
8154                                         campaign=1;
8155                                         mainmenu=0;
8156                                         gameon=1;
8157                                         OPENAL_SetPaused(channels[stream_music3], true);
8158
8159                                         stealthloading=0;
8160                                 }
8161
8162                                 if(loading==3)loading=0;
8163
8164                         }
8165
8166                         oldmusictype=musictype;
8167         }
8168
8169         facing=0;
8170         facing.z=-1;
8171
8172         facing=DoRotation(facing,-rotation2,0,0);
8173         facing=DoRotation(facing,0,0-rotation,0);
8174         viewerfacing=facing;
8175
8176         brotate=0;
8177         if(!cameramode){
8178                 if((animation[player[0].targetanimation].attack!=3&&animation[player[0].currentanimation].attack!=3)||player[0].skeleton.free)target=player[0].coords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
8179                 else target=player[0].oldcoords+player[0].currentoffset*(1-player[0].target)*player[0].scale+player[0].targetoffset*player[0].target*player[0].scale-player[0].facing*.05;
8180                 target.y+=.1;
8181                 if(player[0].skeleton.free){
8182                         for(i=0;i<player[0].skeleton.num_joints;i++){
8183                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
8184                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
8185                         }
8186                         target.y+=.1;
8187                 }
8188                 if(player[0].skeleton.free!=2&&!autocam){
8189                         cameraspeed=20;
8190                         if(findLengthfast(&player[0].velocity)>400){
8191                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8192                         }
8193                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8194                         coltarget=target-cameraloc;
8195                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8196                         else {
8197                                 Normalise(&coltarget);
8198                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8199                                 else cameraloc=cameraloc+coltarget*multiplier*8;
8200                         }
8201                         if(editorenabled)cameraloc=target;
8202                         cameradist+=multiplier*5;
8203                         if(cameradist>2.3)cameradist=2.3;
8204                         viewer=cameraloc-facing*cameradist;
8205                         colviewer=viewer;
8206                         coltarget=cameraloc;
8207                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8208                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8209                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8210                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8211                                         colviewer=viewer;
8212                                         coltarget=cameraloc;
8213                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8214                                 }
8215                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8216                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8217                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8218                                                 colviewer=viewer;
8219                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8220                                                         viewer=colviewer;
8221                                                 }
8222                                         }
8223                                         cameradist=findDistance(&viewer,&target);
8224                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
8225                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
8226                                         }
8227                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8228                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8229                                         }
8230                 }
8231                 if(player[0].skeleton.free!=2&&autocam){
8232                         cameraspeed=20;
8233                         if(findLengthfast(&player[0].velocity)>400){
8234                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8235                         }
8236                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8237                         cameradist+=multiplier*5;
8238                         if(cameradist>3.3)cameradist=3.3;
8239                         coltarget=target-cameraloc;
8240                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8241                         else if(findLengthfast(&coltarget)>1)
8242                         {
8243                                 Normalise(&coltarget);
8244                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8245                                 else cameraloc=cameraloc+coltarget*multiplier*8;
8246                         }
8247                         if(editorenabled)cameraloc=target;
8248                         viewer=cameraloc;
8249                         colviewer=viewer;
8250                         coltarget=cameraloc;
8251                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8252                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8253                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8254                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8255                                         colviewer=viewer;
8256                                         coltarget=cameraloc;
8257                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8258                                 }
8259                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8260                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8261                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8262                                                 colviewer=viewer;
8263                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8264                                                         viewer=colviewer;
8265                                                 }
8266                                         }
8267                                         cameradist=findDistance(&viewer,&target);
8268                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
8269                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
8270                                         }
8271                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8272                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8273                                         }
8274                 }
8275                 if(camerashake>.8)camerashake=.8;
8276                 //if(woozy>10)woozy=10;
8277                 //woozy+=multiplier;
8278                 woozy+=multiplier;
8279                 if(player[0].dead)camerashake=0;
8280                 if(player[0].dead)woozy=0;
8281                 camerashake-=multiplier*2;
8282                 blackout-=multiplier*2;
8283                 //if(player[0].isCrouch())woozy-=multiplier*8;
8284                 if(camerashake<0)camerashake=0;
8285                 if(blackout<0)blackout=0;
8286                 //if(woozy<0)woozy=0;
8287                 if(camerashake){
8288                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
8289                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
8290                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
8291                 }
8292         }
8293 }