2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
32 #include "openal_wrapper.h"
38 // Added more evilness needed for MSVC
40 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
41 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
45 extern float multiplier;
47 extern int environment;
48 extern float texscale;
49 extern Terrain terrain;
50 extern OPENAL_SAMPLE *samp[100];
51 extern int channels[100];
52 extern Sprites sprites;
53 extern int kTextureSize;
54 extern float screenwidth,screenheight;
57 extern float texdetail;
58 extern Objects objects;
60 extern float slomodelay;
61 extern bool floatjump;
63 extern Animation animation[animation_count];
65 extern float texdetail;
66 extern GLubyte bloodText[512*512*3];
67 extern GLubyte wolfbloodText[512*512*3];
68 extern float terraindetail;
69 extern float camerashake;
71 extern float blackout;
72 extern bool cellophane;
73 extern bool musictoggle;
74 extern int difficulty;
75 extern Weapons weapons;
76 extern Person player[maxplayers];
77 extern int numplayers;
78 extern int bloodtoggle;
79 extern bool invertmouse;
81 extern float precipdelay;
82 extern XYZ viewerfacing;
83 extern bool ambientsound;
84 extern bool mousejump;
85 extern float viewdistance;
87 extern bool autoslomo;
88 extern bool keyboardfrozen;
89 extern int netdatanew;
90 extern bool loadingstuff;
91 extern char mapname[256];
92 extern XYZ windvector;
93 extern bool debugmode;
96 extern int oldmainmenu;
97 extern bool visibleloading;
98 extern int loadscreencolor;
99 extern float flashamount,flashr,flashg,flashb;
100 extern int flashdelay;
101 extern XYZ envsound[30];
102 extern float envsoundvol[30];
103 extern int numenvsounds;
104 extern float envsoundlife[30];
105 extern float usermousesensitivity;
106 extern bool ismotionblur;
108 extern bool trilinear;
109 extern bool damageeffects;
110 extern bool showpoints;
111 extern bool showdamagebar; // (des)activate the damage bar
112 extern bool texttoggle;
113 extern bool alwaysblur;
114 extern float gamespeed;
117 extern bool immediate;
118 extern bool velocityblur;
121 extern float bonusvalue;
122 extern float bonustotal;
123 extern float bonustime;
124 extern float startbonustotal;
125 extern float tintr,tintg,tintb;
126 extern float bonusnum[100];
127 extern bool skyboxtexture;
128 extern float skyboxr;
129 extern float skyboxg;
130 extern float skyboxb;
131 extern float skyboxlightr;
132 extern float skyboxlightg;
133 extern float skyboxlightb;
134 extern float fadestart;
135 extern float slomospeed;
136 extern float slomofreq;
137 extern int tutoriallevel;
138 extern float smoketex;
139 extern float tutorialstagetime;
140 extern int tutorialstage;
141 extern float tutorialmaxtime;
142 extern float tutorialsuccess;
143 extern bool againbonus;
144 extern bool reversaltrain;
145 extern bool canattack;
146 extern bool cananger;
147 extern float damagedealt;
148 extern float damagetaken;
150 extern int editoractive;
151 extern int editorpathtype;
153 extern float hostiletime;
155 extern bool gamestarted;
157 extern int numhotspots;
158 extern int winhotspot;
159 extern int windialogue;
160 extern int killhotspot;
161 extern XYZ hotspot[40];
162 extern int hotspottype[40];
163 extern float hotspotsize[40];
164 extern char hotspottext[40][256];
165 extern int currenthotspot;
167 extern int kBitsPerPixel;
170 extern bool stillloading;
171 extern bool winfreeze;
174 extern int numflipfail;
176 extern int numstaffattack;
177 extern int numswordattack;
178 extern int numknifeattack;
179 extern int numunarmedattack;
180 extern int numescaped;
181 extern int numflipped;
182 extern int numwallflipped;
183 extern int numthrowkill;
184 extern int numafterkill;
185 extern int numreversals;
186 extern int numattacks;
187 extern int maxalarmed;
188 extern int numresponded;
190 extern int numdialogues;
191 extern int numdialogueboxes[max_dialogues];
192 extern int dialoguetype[max_dialogues];
193 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
194 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
195 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
196 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
197 extern char dialoguename[max_dialogues][max_dialoguelength][64];
198 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
199 extern XYZ participantlocation[max_dialogues][10];
200 extern int participantfocus[max_dialogues][max_dialoguelength];
201 extern int participantaction[max_dialogues][max_dialoguelength];
202 extern float participantrotation[max_dialogues][10];
203 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
204 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
205 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
206 extern int indialogue;
207 extern int whichdialogue;
208 extern int directing;
209 extern float dialoguetime;
210 extern int dialoguegonethrough[20];
212 extern bool campaign;
214 extern float oldgamespeed;
216 extern float accountcampaignhighscore[10];
217 extern float accountcampaignfasttime[10];
218 extern float accountcampaignscore[10];
219 extern float accountcampaigntime[10];
221 extern int accountcampaignchoicesmade[10];
222 extern int accountcampaignchoices[10][5000];
224 static const char *rabbitskin[] = {
225 ":Data:Textures:Fur3.jpg",
226 ":Data:Textures:Fur.jpg",
227 ":Data:Textures:Fur2.jpg",
228 ":Data:Textures:Lynx.jpg",
229 ":Data:Textures:Otter.jpg",
230 ":Data:Textures:Opal.jpg",
231 ":Data:Textures:Sable.jpg",
232 ":Data:Textures:Chocolate.jpg",
233 ":Data:Textures:BW2.jpg",
234 ":Data:Textures:WB2.jpg"
237 static const char *wolfskin[] = {
238 ":Data:Textures:Wolf.jpg",
239 ":Data:Textures:Darkwolf.jpg",
240 ":Data:Textures:Snowwolf.jpg"
243 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
244 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
246 static const char **creatureskin[] = {rabbitskin, wolfskin};
248 /* Return true if PFX is a prefix of STR (case-insensitive). */
249 static bool stripfx(const char *str, const char *pfx)
251 return !strncasecmp(str, pfx, strlen(pfx));
254 extern OPENAL_STREAM * strm[20];
255 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
256 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
259 static const char *cmd_names[] = {
260 #define DECLARE_COMMAND(cmd) #cmd " ",
261 #include "ConsoleCmds.h"
262 #undef DECLARE_COMMAND
265 typedef void (*console_handler)(Game *game, const char *args);
267 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
268 #include "ConsoleCmds.h"
269 #undef DECLARE_COMMAND
271 static console_handler cmd_handlers[] = {
272 #define DECLARE_COMMAND(cmd) ch_##cmd,
273 #include "ConsoleCmds.h"
274 #undef DECLARE_COMMAND
277 static void ch_quit(Game *game, const char *args)
282 static void ch_map(Game *game, const char *args)
285 snprintf(buf, 63, ":Data:Maps:%s", args);
286 game->Loadlevel(buf);
287 game->whichlevel = -2;
291 static void ch_save(Game *game, const char *args)
294 int i, j, k, l, m, templength;
295 float headprop, bodyprop, armprop, legprop;
296 snprintf(buf, 63, ":Data:Maps:%s", args);
302 tfile=fopen( ConvertFileName(buf), "wb" );
303 fpackf(tfile, "Bi", mapvers);
304 fpackf(tfile, "Bi", maptype);
305 fpackf(tfile, "Bi", hostile);
306 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
307 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
308 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
309 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);
310 if(player[0].num_weapons>0&&player[0].num_weapons<5)
311 for(j=0;j<player[0].num_weapons;j++){
312 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
315 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
316 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
317 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
318 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
320 fpackf(tfile, "Bi", player[0].numclothes);
322 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
324 fpackf(tfile, "Bi", numdialogues);
326 for(k=0;k<numdialogues;k++){
327 fpackf(tfile, "Bi", numdialogueboxes[k]);
328 fpackf(tfile, "Bi", dialoguetype[k]);
330 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
331 fpackf(tfile, "Bf", participantrotation[k][l]);
334 for(l=0;l<numdialogueboxes[k];l++){
335 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
336 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
337 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
338 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
339 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
341 templength=strlen(dialoguetext[k][l]);
342 fpackf(tfile, "Bi",(templength));
343 for(m=0;m<templength;m++){
344 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
345 if(dialoguetext[k][l][m]=='\0')break;
348 templength=strlen(dialoguename[k][l]);
349 fpackf(tfile, "Bi",templength);
350 for(m=0;m<templength;m++){
351 fpackf(tfile, "Bb", dialoguename[k][l][m]);
352 if(dialoguename[k][l][m]=='\0')break;
355 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
356 fpackf(tfile, "Bi", participantfocus[k][l]);
357 fpackf(tfile, "Bi", participantaction[k][l]);
360 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
362 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
366 if(player[0].numclothes)
367 for(k=0;k<player[0].numclothes;k++){
368 templength=strlen(player[0].clothes[k]);
369 fpackf(tfile, "Bi", templength);
370 for(l=0;l<templength;l++)
371 fpackf(tfile, "Bb", player[0].clothes[k][l]);
372 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
375 fpackf(tfile, "Bi", environment);
377 fpackf(tfile, "Bi", objects.numobjects);
379 if(objects.numobjects)
380 for(k=0;k<objects.numobjects;k++){
381 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]);
384 fpackf(tfile, "Bi", numhotspots);
386 for(i=0;i<numhotspots;i++){
387 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
388 templength=strlen(hotspottext[i]);
389 fpackf(tfile, "Bi",templength);
390 for(l=0;l<templength;l++)
391 fpackf(tfile, "Bb", hotspottext[i][l]);
394 fpackf(tfile, "Bi", numplayers);
395 if(numplayers>1&&numplayers<maxplayers)
396 for(j=1;j<numplayers;j++){
397 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);
398 if(player[j].num_weapons>0&&player[j].num_weapons<5)
399 for(k=0;k<player[j].num_weapons;k++){
400 fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
402 if(player[j].numwaypoints<30){
403 fpackf(tfile, "Bi", player[j].numwaypoints);
404 for(k=0;k<player[j].numwaypoints;k++){
405 fpackf(tfile, "Bf", player[j].waypoints[k].x);
406 fpackf(tfile, "Bf", player[j].waypoints[k].y);
407 fpackf(tfile, "Bf", player[j].waypoints[k].z);
408 fpackf(tfile, "Bi", player[j].waypointtype[k]);
410 fpackf(tfile, "Bi", player[j].waypoint);
413 player[j].numwaypoints=0;
414 player[j].waypoint=0;
415 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
418 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
419 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
420 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
421 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
423 if(player[j].creature==wolftype){
424 headprop=player[j].proportionhead.x/1.1;
425 bodyprop=player[j].proportionbody.x/1.1;
426 armprop=player[j].proportionarms.x/1.1;
427 legprop=player[j].proportionlegs.x/1.1;
430 if(player[j].creature==rabbittype){
431 headprop=player[j].proportionhead.x/1.2;
432 bodyprop=player[j].proportionbody.x/1.05;
433 armprop=player[j].proportionarms.x/1.00;
434 legprop=player[j].proportionlegs.x/1.1;
437 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
441 fpackf(tfile, "Bi", player[j].numclothes);
442 if(player[j].numclothes)
443 for(k=0;k<player[j].numclothes;k++){
445 templength=strlen(player[j].clothes[k]);
446 fpackf(tfile, "Bi", templength);
447 for(l=0;l<templength;l++)
448 fpackf(tfile, "Bb", player[j].clothes[k][l]);
449 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
453 fpackf(tfile, "Bi", game->numpathpoints);
454 if(game->numpathpoints)
455 for(j=0;j<game->numpathpoints;j++){
456 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
457 for(k=0;k<game->numpathpointconnect[j];k++){
458 fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
462 fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
467 static void ch_cellar(Game *game, const char *args)
469 game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
472 static void ch_tint(Game *game, const char *args)
474 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
477 static void ch_tintr(Game *game, const char *args)
482 static void ch_tintg(Game *game, const char *args)
487 static void ch_tintb(Game *game, const char *args)
492 static void ch_speed(Game *game, const char *args)
494 player[0].speedmult = atof(args);
497 static void ch_strength(Game *game, const char *args)
499 player[0].power = atof(args);
502 static void ch_power(Game *game, const char *args)
504 player[0].power = atof(args);
507 static void ch_size(Game *game, const char *args)
509 player[0].scale = atof(args) * .2;
512 static int find_closest()
515 float closestdist = 1.0/0.0;
517 for (int i = 1; i < numplayers; i++) {
519 distance = findDistancefast(&player[i].coords,&player[0].coords);
520 if (distance < closestdist) {
521 closestdist = distance;
528 static void ch_sizenear(Game *game, const char *args)
530 int closest = find_closest();
533 player[closest].scale = atof(args) * .2;
536 static void set_proportion(int pnum, const char *args)
538 float headprop,bodyprop,armprop,legprop;
540 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
542 if(player[pnum].creature==wolftype){
543 player[pnum].proportionhead=1.1*headprop;
544 player[pnum].proportionbody=1.1*bodyprop;
545 player[pnum].proportionarms=1.1*armprop;
546 player[pnum].proportionlegs=1.1*legprop;
549 if(player[pnum].creature==rabbittype){
550 player[pnum].proportionhead=1.2*headprop;
551 player[pnum].proportionbody=1.05*bodyprop;
552 player[pnum].proportionarms=1.00*armprop;
553 player[pnum].proportionlegs=1.1*legprop;
554 player[pnum].proportionlegs.y=1.05*legprop;
558 static void ch_proportion(Game *game, const char *args)
560 set_proportion(0, args);
563 static void ch_proportionnear(Game *game, const char *args)
565 int closest = find_closest();
567 set_proportion(closest, args);
570 static void set_protection(int pnum, const char *args)
572 float head, high, low;
573 sscanf(args, "%f%f%f", &head, &high, &low);
575 player[pnum].protectionhead = head;
576 player[pnum].protectionhigh = high;
577 player[pnum].protectionlow = low;
580 static void ch_protection(Game *game, const char *args)
582 set_protection(0, args);
585 static void ch_protectionnear(Game *game, const char *args)
587 int closest = find_closest();
589 set_protection(closest, args);
592 static void set_armor(int pnum, const char *args)
594 float head, high, low;
595 sscanf(args, "%f%f%f", &head, &high, &low);
597 player[pnum].armorhead = head;
598 player[pnum].armorhigh = high;
599 player[pnum].armorlow = low;
602 static void ch_armor(Game *game, const char *args)
607 static void ch_armornear(Game *game, const char *args)
609 int closest = find_closest();
611 set_armor(closest, args);
614 static void ch_protectionreset(Game *game, const char *args)
616 set_protection(0, "1 1 1");
617 set_armor(0, "1 1 1");
620 static void set_metal(int pnum, const char *args)
622 float head, high, low;
623 sscanf(args, "%f%f%f", &head, &high, &low);
625 player[pnum].metalhead = head;
626 player[pnum].metalhigh = high;
627 player[pnum].metallow = low;
630 static void ch_metal(Game *game, const char *args)
635 static void set_noclothes(int pnum, Game *game, const char *args)
637 player[pnum].numclothes = 0;
638 game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
639 &player[pnum].skeleton.drawmodel.textureptr,1,
640 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
643 static void ch_noclothes(Game *game, const char *args)
645 set_noclothes(0, game, args);
648 static void ch_noclothesnear(Game *game, const char *args)
650 int closest = find_closest();
652 set_noclothes(closest, game, args);
656 static void set_clothes(int pnum, Game *game, const char *args)
659 snprintf(buf, 63, ":Data:Textures:%s.png", args);
661 if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
664 player[pnum].DoMipmaps(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize);
665 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
666 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
667 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
668 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
669 player[pnum].numclothes++;
672 static void ch_clothes(Game *game, const char *args)
674 set_clothes(0, game, args);
677 static void ch_clothesnear(Game *game, const char *args)
679 int closest = find_closest();
681 set_clothes(closest, game, args);
684 static void ch_belt(Game *game, const char *args)
686 player[0].skeleton.clothes = !player[0].skeleton.clothes;
690 static void ch_cellophane(Game *game, const char *args)
692 cellophane = !cellophane;
693 float mul = cellophane ? 0 : 1;
695 for (int i = 0; i < numplayers; i++) {
696 player[i].proportionhead.z = player[i].proportionhead.x * mul;
697 player[i].proportionbody.z = player[i].proportionbody.x * mul;
698 player[i].proportionarms.z = player[i].proportionarms.x * mul;
699 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
703 static void ch_funnybunny(Game *game, const char *args)
705 player[0].skeleton.id=0;
706 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
707 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
708 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
709 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
710 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
711 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
712 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
713 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
714 player[0].creature=rabbittype;
716 player[0].headless=0;
717 player[0].damagetolerance=200;
718 set_proportion(0, "1 1 1 1");
721 static void ch_wolfie(Game *game, const char *args)
723 player[0].skeleton.id=0;
724 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
725 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
726 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
727 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
728 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
729 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
730 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
731 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
732 player[0].creature=wolftype;
733 player[0].damagetolerance=300;
734 set_proportion(0, "1 1 1 1");
737 static void ch_wolfieisgod(Game *game, const char *args)
739 ch_wolfie(game, args);
742 static void ch_wolf(Game *game, const char *args)
744 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
745 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
748 static void ch_snowwolf(Game *game, const char *args)
750 game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
751 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
754 static void ch_darkwolf(Game *game, const char *args)
756 game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
757 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
760 static void ch_lizardwolf(Game *game, const char *args)
762 game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
763 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
766 static void ch_white(Game *game, const char *args)
768 game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
769 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
772 static void ch_brown(Game *game, const char *args)
774 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
775 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
778 static void ch_black(Game *game, const char *args)
780 game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
781 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
784 static void ch_sizemin(Game *game, const char *args)
787 for (i = 1; i < numplayers; i++)
788 if (player[i].scale < 0.8 * 0.2)
789 player[i].scale = 0.8 * 0.2;
792 static void ch_tutorial(Game *game, const char *args)
794 tutoriallevel = atoi(args);
797 static void ch_hostile(Game *game, const char *args)
799 hostile = atoi(args);
802 static void ch_indemo(Game *game, const char *args)
805 hotspot[numhotspots]=player[0].coords;
806 hotspotsize[numhotspots]=0;
807 hotspottype[numhotspots]=-111;
808 strcpy(hotspottext[numhotspots],"mapname");
812 static void ch_notindemo(Game *game, const char *args)
818 static void ch_type(Game *game, const char *args)
820 int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]);
821 for (i = 0; i < n; i++)
822 if (stripfx(args, editortypenames[i]))
829 static void ch_path(Game *game, const char *args)
831 int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
832 for (i = 0; i < n; i++)
833 if (stripfx(args, pathtypenames[i]))
840 static void ch_hs(Game *game, const char *args)
842 hotspot[numhotspots]=player[0].coords;
846 sscanf(args, "%f%d %n", &size, &type, &shift);
848 hotspotsize[numhotspots] = size;
849 hotspottype[numhotspots] = type;
851 strcpy(hotspottext[numhotspots], args + shift);
852 strcat(hotspottext[numhotspots], "\n");
857 static void ch_dialogue(Game *game, const char *args)
860 char buf1[32], buf2[64];
862 sscanf(args, "%d %31s", &dlg, buf1);
863 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
865 dialoguetype[numdialogues] = dlg;
867 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
868 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
870 ifstream ipstream(ConvertFileName(buf2));
871 ipstream.ignore(256,':');
872 ipstream >> numdialogueboxes[numdialogues];
873 for(i=0;i<numdialogueboxes[numdialogues];i++){
874 ipstream.ignore(256,':');
875 ipstream.ignore(256,':');
876 ipstream.ignore(256,' ');
877 ipstream >> dialogueboxlocation[numdialogues][i];
878 ipstream.ignore(256,':');
879 ipstream >> dialogueboxcolor[numdialogues][i][0];
880 ipstream >> dialogueboxcolor[numdialogues][i][1];
881 ipstream >> dialogueboxcolor[numdialogues][i][2];
882 ipstream.ignore(256,':');
883 ipstream.getline(dialoguename[numdialogues][i],64);
884 ipstream.ignore(256,':');
885 ipstream.ignore(256,' ');
886 ipstream.getline(dialoguetext[numdialogues][i],128);
888 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
890 ipstream.ignore(256,':');
891 ipstream >> dialogueboxsound[numdialogues][i];
894 for(i=0;i<numdialogueboxes[numdialogues];i++){
895 for(j=0;j<numplayers;j++){
896 participantfacing[numdialogues][i][j]=player[j].facing;
903 whichdialogue=numdialogues;
908 static void ch_fixdialogue(Game *game, const char *args)
910 char buf1[32], buf2[64];
913 sscanf(args, "%d %31s", &whichdi, buf1);
914 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
916 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
917 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
919 ifstream ipstream(ConvertFileName(buf2));
920 ipstream.ignore(256,':');
921 ipstream >> numdialogueboxes[whichdi];
922 for(i=0;i<numdialogueboxes[whichdi];i++){
923 ipstream.ignore(256,':');
924 ipstream.ignore(256,':');
925 ipstream.ignore(256,' ');
926 ipstream >> dialogueboxlocation[whichdi][i];
927 ipstream.ignore(256,':');
928 ipstream >> dialogueboxcolor[whichdi][i][0];
929 ipstream >> dialogueboxcolor[whichdi][i][1];
930 ipstream >> dialogueboxcolor[whichdi][i][2];
931 ipstream.ignore(256,':');
932 ipstream.getline(dialoguename[whichdi][i],64);
933 ipstream.ignore(256,':');
934 ipstream.ignore(256,' ');
935 ipstream.getline(dialoguetext[whichdi][i],128);
937 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
939 ipstream.ignore(256,':');
940 ipstream >> dialogueboxsound[whichdi][i];
946 static void ch_fixtype(Game *game, const char *args)
949 sscanf(args, "%d", &dlg);
950 dialoguetype[0] = dlg;
953 static void ch_fixrotation(Game *game, const char *args)
955 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
958 static void ch_ddialogue(Game *game, const char *args)
964 static void ch_dhs(Game *game, const char *args)
970 static void ch_immobile(Game *game, const char *args)
972 player[0].immobile = 1;
975 static void ch_allimmobile(Game *game, const char *args)
977 for (int i = 1; i < numplayers; i++)
978 player[i].immobile = 1;
981 static void ch_mobile(Game *game, const char *args)
983 player[0].immobile = 0;
986 static void ch_default(Game *game, const char *args)
988 player[0].armorhead=1;
989 player[0].armorhigh=1;
990 player[0].armorlow=1;
991 player[0].protectionhead=1;
992 player[0].protectionhigh=1;
993 player[0].protectionlow=1;
994 player[0].metalhead=1;
995 player[0].metalhigh=1;
996 player[0].metallow=1;
998 player[0].speedmult=1;
1001 if(player[0].creature==wolftype){
1002 player[0].proportionhead=1.1;
1003 player[0].proportionbody=1.1;
1004 player[0].proportionarms=1.1;
1005 player[0].proportionlegs=1.1;
1008 if(player[0].creature==rabbittype){
1009 player[0].proportionhead=1.2;
1010 player[0].proportionbody=1.05;
1011 player[0].proportionarms=1.00;
1012 player[0].proportionlegs=1.1;
1013 player[0].proportionlegs.y=1.05;
1016 player[0].numclothes=0;
1017 game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
1018 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
1019 &player[0].skeleton.skinsize);
1021 editoractive=typeactive;
1022 player[0].immobile=0;
1025 static void ch_play(Game *game, const char *args)
1028 sscanf(args, "%d", &dlg);
1029 whichdialogue = dlg;
1031 if (whichdialogue >= numdialogues)
1034 for(i=0;i<numdialogueboxes[whichdialogue];i++){
1035 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1036 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1037 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1038 player[participantfocus[whichdialogue][i]].velocity=0;
1039 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1040 player[participantfocus[whichdialogue][i]].targetframe=0;
1049 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
1050 temppos=temppos-viewer;
1051 Normalise(&temppos);
1061 whichsoundplay=rabbitchitter;
1062 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
1063 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
1064 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
1065 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
1066 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
1067 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
1068 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
1069 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
1070 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
1071 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
1072 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
1073 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
1074 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
1075 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
1076 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
1077 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
1078 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
1079 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
1080 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
1081 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
1082 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
1083 OPENAL_SetVolume(channels[whichsoundplay], 256);
1084 OPENAL_SetPaused(channels[whichsoundplay], false);
1087 static void ch_mapkilleveryone(Game *game, const char *args)
1089 maptype = mapkilleveryone;
1092 static void ch_mapkillmost(Game *game, const char *args)
1094 maptype = mapkillmost;
1097 static void ch_mapkillsomeone(Game *game, const char *args)
1099 maptype = mapkillsomeone;
1102 static void ch_mapgosomewhere(Game *game, const char *args)
1104 maptype = mapgosomewhere;
1107 static void ch_viewdistance(Game *game, const char *args)
1109 viewdistance = atof(args)*100;
1112 static void ch_fadestart(Game *game, const char *args)
1114 fadestart = atof(args);
1117 static void ch_slomo(Game *game, const char *args)
1119 slomospeed = atof(args);
1124 static void ch_slofreq(Game *game, const char *args)
1126 slomofreq = atof(args);
1129 static void ch_skytint(Game *game, const char *args)
1131 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1133 skyboxlightr=skyboxr;
1134 skyboxlightg=skyboxg;
1135 skyboxlightb=skyboxb;
1137 game->SetUpLighting();
1139 terrain.DoShadows();
1140 objects.DoShadows();
1143 static void ch_skylight(Game *game, const char *args)
1145 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1147 game->SetUpLighting();
1149 terrain.DoShadows();
1150 objects.DoShadows();
1153 static void ch_skybox(Game *game, const char *args)
1155 skyboxtexture = !skyboxtexture;
1157 game->SetUpLighting();
1159 terrain.DoShadows();
1160 objects.DoShadows();
1163 static void cmd_dispatch(Game *game, const char *cmd)
1165 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1167 for (i = 0; i < n_cmds; i++)
1168 if (stripfx(cmd, cmd_names[i]))
1170 cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
1175 PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true);
1176 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1177 OPENAL_SetPaused(channels[consolesuccesssound], false);
1181 PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true);
1182 OPENAL_SetVolume(channels[consolefailsound], 256);
1183 OPENAL_SetPaused(channels[consolefailsound], false);
1187 /********************> Tick() <*****/
1188 extern void ScreenShot(const char * fname);
1189 void Screenshot (void)
1192 time_t t = time(NULL);
1193 struct tm *tme = localtime(&t);
1194 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);
1197 mkdir("Screenshots");
1199 mkdir("Screenshots", S_IRWXU);
1207 void Game::SetUpLighting(){
1208 if(environment==snowyenvironment){
1212 light.ambient[0]=.4;
1213 light.ambient[1]=.4;
1214 light.ambient[2]=.44;
1216 if(environment==desertenvironment){
1220 light.ambient[0]=.4;
1221 light.ambient[1]=.35;
1222 light.ambient[2]=.3;
1225 if(environment==grassyenvironment){
1229 light.ambient[0]=.4;
1230 light.ambient[1]=.4;
1231 light.ambient[2]=.44;
1237 light.ambient[0]=.4;
1238 light.ambient[1]=.4;
1239 light.ambient[2]=.4;
1242 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1243 light.color[0]*=(skyboxlightr+average)/2;
1244 light.color[1]*=(skyboxlightg+average)/2;
1245 light.color[2]*=(skyboxlightb+average)/2;
1246 light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
1247 light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
1248 light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
1252 light.ambient[2]=0; */
1255 int Game::findPathDist(int start,int end){
1256 int i,j,k,smallestcount,count,connected;
1257 int last,last2,last3,last4;
1267 while(last!=end&&count<30){
1269 for(j=0;j<numpathpoints;j++){
1270 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1273 if(numpathpointconnect[j])
1274 for(k=0;k<numpathpointconnect[j];k++){
1275 if(pathpointconnect[j][k]==last)connected=1;
1278 if(numpathpointconnect[last])
1279 for(k=0;k<numpathpointconnect[last];k++){
1280 if(pathpointconnect[last][k]==j)connected=1;
1283 if(closest==-1||Random()%2==0){
1294 if(count<smallestcount)smallestcount=count;
1296 return smallestcount;
1299 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1300 static XYZ colpoint,colviewer,coltarget;
1301 static float minx,minz,maxx,maxz,miny,maxy;
1310 if(minx>endpoint.x)minx=endpoint.x;
1312 if(miny>endpoint.y)miny=endpoint.y;
1314 if(minz>endpoint.z)minz=endpoint.z;
1317 if(maxx<endpoint.x)maxx=endpoint.x;
1319 if(maxy<endpoint.y)maxy=endpoint.y;
1321 if(maxz<endpoint.z)maxz=endpoint.z;
1330 for(i=0;i<objects.numobjects;i++){
1331 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){
1332 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
1333 colviewer=startpoint;
1335 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1340 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1345 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1346 static XYZ colpoint,colviewer,coltarget;
1347 static float minx,minz,maxx,maxz,miny,maxy;
1356 if(minx>endpoint.x)minx=endpoint.x;
1358 if(miny>endpoint.y)miny=endpoint.y;
1360 if(minz>endpoint.z)minz=endpoint.z;
1363 if(maxx<endpoint.x)maxx=endpoint.x;
1365 if(maxy<endpoint.y)maxy=endpoint.y;
1367 if(maxz<endpoint.z)maxz=endpoint.z;
1377 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){
1378 if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
1379 colviewer=startpoint;
1381 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1386 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1391 void Game::Setenvironment(int which)
1395 LOG(" Setting environment...");
1397 float temptexdetail;
1400 OPENAL_SetPaused(channels[music1snow], true);
1401 OPENAL_SetPaused(channels[music1grass], true);
1402 OPENAL_SetPaused(channels[music1desert], true);
1403 OPENAL_SetPaused(channels[wind], true);
1404 OPENAL_SetPaused(channels[desertambient], true);
1406 OPENAL_SetPaused(channels[stream_music1snow], true);
1407 OPENAL_SetPaused(channels[stream_music1grass], true);
1408 OPENAL_SetPaused(channels[stream_music1desert], true);
1409 OPENAL_SetPaused(channels[stream_wind], true);
1410 OPENAL_SetPaused(channels[stream_desertambient], true);
1413 if(environment==snowyenvironment){
1417 //PlaySoundEx( wind, samp[wind], NULL, true);
1418 PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
1419 OPENAL_SetPaused(channels[stream_wind], false);
1420 OPENAL_SetVolume(channels[stream_wind], 256);
1423 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1424 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1425 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1426 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1428 OPENAL_Sample_Free(samp[footstepsound]);
1429 OPENAL_Sample_Free(samp[footstepsound2]);
1430 OPENAL_Sample_Free(samp[footstepsound3]);
1431 OPENAL_Sample_Free(samp[footstepsound4]);
1432 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
1433 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
1434 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
1435 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
1436 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
1437 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
1438 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
1439 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
1441 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1443 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1445 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1450 temptexdetail=texdetail;
1451 if(texdetail>1)texdetail=4;
1452 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1453 ":Data:Textures:Skybox(snow):Left.jpg",
1454 ":Data:Textures:Skybox(snow):Back.jpg",
1455 ":Data:Textures:Skybox(snow):Right.jpg",
1456 ":Data:Textures:Skybox(snow):Up.jpg",
1457 ":Data:Textures:Skybox(snow):Down.jpg",
1458 ":Data:Textures:Skybox(snow):Cloud.jpg",
1459 ":Data:Textures:Skybox(snow):Reflect.jpg");
1464 texdetail=temptexdetail;
1466 if(environment==desertenvironment){
1469 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1470 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1471 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1472 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1476 //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
1477 PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
1478 OPENAL_SetPaused(channels[stream_desertambient], false);
1479 OPENAL_SetVolume(channels[stream_desertambient], 256);
1482 OPENAL_Sample_Free(samp[footstepsound]);
1483 OPENAL_Sample_Free(samp[footstepsound2]);
1484 OPENAL_Sample_Free(samp[footstepsound3]);
1485 OPENAL_Sample_Free(samp[footstepsound4]);
1486 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
1487 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
1488 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
1489 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
1490 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
1491 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
1492 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
1493 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
1495 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1497 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1499 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1503 temptexdetail=texdetail;
1504 if(texdetail>1)texdetail=4;
1505 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1506 ":Data:Textures:Skybox(sand):Left.jpg",
1507 ":Data:Textures:Skybox(sand):Back.jpg",
1508 ":Data:Textures:Skybox(sand):Right.jpg",
1509 ":Data:Textures:Skybox(sand):Up.jpg",
1510 ":Data:Textures:Skybox(sand):Down.jpg",
1511 ":Data:Textures:Skybox(sand):Cloud.jpg",
1512 ":Data:Textures:Skybox(sand):Reflect.jpg");
1517 texdetail=temptexdetail;
1519 if(environment==grassyenvironment){
1522 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1523 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1524 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1525 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1528 PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
1529 OPENAL_SetPaused(channels[stream_wind], false);
1530 OPENAL_SetVolume(channels[stream_wind], 100);
1533 OPENAL_Sample_Free(samp[footstepsound]);
1534 OPENAL_Sample_Free(samp[footstepsound2]);
1535 OPENAL_Sample_Free(samp[footstepsound3]);
1536 OPENAL_Sample_Free(samp[footstepsound4]);
1537 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass1.ogg"), OPENAL_HW3D, 0, 0);
1538 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass2.ogg"), OPENAL_HW3D, 0, 0);
1539 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
1540 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
1541 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
1542 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
1543 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
1544 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
1546 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1548 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1550 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1554 temptexdetail=texdetail;
1555 if(texdetail>1)texdetail=4;
1556 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1557 ":Data:Textures:Skybox(grass):Left.jpg",
1558 ":Data:Textures:Skybox(grass):Back.jpg",
1559 ":Data:Textures:Skybox(grass):Right.jpg",
1560 ":Data:Textures:Skybox(grass):Up.jpg",
1561 ":Data:Textures:Skybox(grass):Down.jpg",
1562 ":Data:Textures:Skybox(grass):Cloud.jpg",
1563 ":Data:Textures:Skybox(grass):Reflect.jpg");
1567 texdetail=temptexdetail;
1569 temptexdetail=texdetail;
1571 terrain.load(":Data:Textures:heightmap.png");
1573 texdetail=temptexdetail;
1577 void Game::Loadlevel(int which){
1580 if(which==0)Loadlevel((char *)":Data:Maps:map1");
1581 else if(which==1)Loadlevel((char *)":Data:Maps:map2");
1582 else if(which==2)Loadlevel((char *)":Data:Maps:map3");
1583 else if(which==3)Loadlevel((char *)":Data:Maps:map4");
1584 else if(which==4)Loadlevel((char *)":Data:Maps:map5");
1585 else if(which==5)Loadlevel((char *)":Data:Maps:map6");
1586 else if(which==6)Loadlevel((char *)":Data:Maps:map7");
1587 else if(which==7)Loadlevel((char *)":Data:Maps:map8");
1588 else if(which==8)Loadlevel((char *)":Data:Maps:map9");
1589 else if(which==9)Loadlevel((char *)":Data:Maps:map10");
1590 else if(which==10)Loadlevel((char *)":Data:Maps:map11");
1591 else if(which==11)Loadlevel((char *)":Data:Maps:map12");
1592 else if(which==12)Loadlevel((char *)":Data:Maps:map13");
1593 else if(which==13)Loadlevel((char *)":Data:Maps:map14");
1594 else if(which==14)Loadlevel((char *)":Data:Maps:map15");
1595 else if(which==15)Loadlevel((char *)":Data:Maps:map16");
1596 else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
1597 else Loadlevel((char *)":Data:Maps:mapsave");
1602 /*char * Game::MD5_string (unsigned char *string){
1606 strcpy(temp2,(const char *)string);
1607 strcat((char *)temp2,(const char *)"Lugaru");
1608 sprintf (temp, "%d",strlen((char *)temp2));
1609 strcat((char *)temp2,temp);
1612 unsigned int len = strlen ( (char *)temp2);
1614 context.update ((unsigned char *)temp2, len);
1615 context.finalize ();
1617 return context.hex_digest();
1622 void Game::Loadlevel(char *name){
1624 static int oldlevel;
1629 float headprop,legprop,armprop,bodyprop;
1633 LOG(std::string("Loading level...") + name);
1635 if(!gameon)visibleloading=1;
1637 if(stealthloading)visibleloading=0;
1639 if(!stillloading)loadtime=0;
1644 if(tutoriallevel!=-1)tutoriallevel=0;
1645 else tutoriallevel=1;
1647 if(tutoriallevel==1)tutorialstage=0;
1648 if(tutorialstage==0){
1649 tutorialstagetime=0;
1656 OPENAL_SetPaused(channels[whooshsound], true);
1657 OPENAL_SetPaused(channels[stream_firesound], true);
1659 // Change the map filename into something that is os specific
1660 char *FixedFN = ConvertFileName(name);
1664 tfile=fopen( FixedFN, "rb" );
1667 OPENAL_SetPaused(channels[stream_firesound], true);
1678 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
1684 dialoguegonethrough[i]=0;
1693 if(accountactive)difficulty=accountactive->getDifficulty();
1695 if(difficulty!=2)minimap=1;
1732 bonustotal=startbonustotal;
1738 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1739 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1740 OPENAL_SetPaused(channels[consolesuccesssound], false);
1747 terrain.numdecals=0;
1748 sprites.numsprites=0;
1749 for(i=0;i<objects.numobjects;i++)
1751 objects.model[i].numdecals=0;
1754 j=objects.numobjects;
1757 objects.DeleteObject(0);
1758 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1761 for(i=0;i<subdivision;i++)
1763 for(j=0;j<subdivision;j++)
1765 terrain.patchobjectnum[i][j]=0;
1768 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1771 weapons.numweapons=0;
1773 funpackf(tfile, "Bi", &mapvers);
1774 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1776 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1777 else maptype=mapkilleveryone;
1778 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1780 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1786 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1794 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1797 skyboxlightr=skyboxr;
1798 skyboxlightg=skyboxg;
1799 skyboxlightb=skyboxb;
1801 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);
1802 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1803 player[0].originalcoords=player[0].coords;
1804 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1806 for(j=0;j<player[0].num_weapons;j++)
1808 player[0].weaponids[j]=weapons.numweapons;
1809 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1810 weapons.owner[weapons.numweapons]=0;
1811 weapons.numweapons++;
1815 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1817 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1818 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1819 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1820 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1822 funpackf(tfile, "Bi", &player[0].numclothes);
1826 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1830 player[0].whichskin=0;
1831 player[0].creature=rabbittype;
1834 for(i=0;i<max_dialogues;i++)
1836 for(j=0;j<max_dialoguelength;j++)
1840 dialoguetext[i][j][k]='\0';
1844 dialoguename[i][j][k]='\0';
1849 player[0].lastattack=-1;
1850 player[0].lastattack2=-1;
1851 player[0].lastattack3=-1;
1855 funpackf(tfile, "Bi", &numdialogues);
1858 for(k=0;k<numdialogues;k++)
1860 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1861 funpackf(tfile, "Bi", &dialoguetype[k]);
1864 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1865 funpackf(tfile, "Bf", &participantrotation[k][l]);
1867 if(numdialogueboxes)
1869 for(l=0;l<numdialogueboxes[k];l++)
1871 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1872 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1873 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1874 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1875 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1879 funpackf(tfile, "Bi",&templength);
1880 if(templength>128||templength<=0)templength=128;
1881 for(m=0;m<templength;m++){
1882 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1883 if(dialoguetext[k][l][m]=='\0')break;
1886 funpackf(tfile, "Bi",&templength);
1887 if(templength>64||templength<=0)templength=64;
1888 for(m=0;m<templength;m++){
1889 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1890 if(dialoguename[k][l][m]=='\0'){
1894 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1895 funpackf(tfile, "Bi", &participantfocus[k][l]);
1896 funpackf(tfile, "Bi", &participantaction[k][l]);
1899 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1901 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1907 else numdialogues=0;
1909 if(player[0].numclothes)
1911 for(k=0;k<player[0].numclothes;k++)
1913 funpackf(tfile, "Bi", &templength);
1914 for(l=0;l<templength;l++)
1915 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1916 player[0].clothes[k][templength]='\0';
1917 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1921 funpackf(tfile, "Bi", &environment);
1923 funpackf(tfile, "Bi", &objects.numobjects);
1924 if(objects.numobjects)
1926 for(i=0;i<objects.numobjects;i++)
1928 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]);
1929 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1935 funpackf(tfile, "Bi", &numhotspots);
1938 for(i=0;i<numhotspots;i++)
1940 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1941 funpackf(tfile, "Bi", &templength);
1943 for(l=0;l<templength;l++)
1944 funpackf(tfile, "Bb", &hotspottext[i][l]);
1945 hotspottext[i][templength]='\0';
1946 if(hotspottype[i]==-111)indemo=1;
1952 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1957 for(i=0;i<objects.numobjects;i++)
1959 objects.center+=objects.position[i];
1961 objects.center/=objects.numobjects;
1964 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1966 float maxdistance=0;
1969 for(i=0;i<objects.numobjects;i++)
1971 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1972 if(tempdist>maxdistance)
1975 maxdistance=tempdist;
1978 objects.radius=fast_sqrt(maxdistance);
1981 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1982 //mapcenter=objects.center;
1983 //mapradius=objects.radius;
1985 funpackf(tfile, "Bi", &numplayers);
1986 int howmanyremoved=0;
1987 bool removeanother=0;
1988 if(numplayers>1&&numplayers<maxplayers)
1990 for(i=1;i<numplayers;i++)
1992 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1995 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);
1996 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1997 else player[i-howmanyremoved].howactive=typeactive;
1998 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1999 else player[i-howmanyremoved].scale=-1;
2000 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
2001 else player[i-howmanyremoved].immobile=0;
2002 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
2003 else player[i-howmanyremoved].rotation=0;
2004 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
2005 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
2011 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
2013 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
2015 player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
2016 funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
2017 weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
2018 weapons.numweapons++;
2021 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
2022 //player[i-howmanyremoved].numwaypoints=10;
2023 for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
2025 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
2026 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
2027 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
2028 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
2029 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
2032 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
2033 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
2035 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
2036 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
2037 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
2038 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
2040 if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
2048 if(player[i-howmanyremoved].creature==wolftype)
2050 player[i-howmanyremoved].proportionhead=1.1*headprop;
2051 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
2052 player[i-howmanyremoved].proportionarms=1.1*armprop;
2053 player[i-howmanyremoved].proportionlegs=1.1*legprop;
2056 if(player[i-howmanyremoved].creature==rabbittype)
2058 player[i-howmanyremoved].proportionhead=1.2*headprop;
2059 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
2060 player[i-howmanyremoved].proportionarms=1.00*armprop;
2061 player[i-howmanyremoved].proportionlegs=1.1*legprop;
2062 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
2065 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
2066 if(player[i-howmanyremoved].numclothes)
2068 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
2071 funpackf(tfile, "Bi", &templength);
2072 for(l=0;l<templength;l++)
2073 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
2074 player[i-howmanyremoved].clothes[k][templength]='\0';
2075 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
2081 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2083 numplayers-=howmanyremoved;
2084 funpackf(tfile, "Bi", &numpathpoints);
2085 if(numpathpoints>30||numpathpoints<0)
2089 for(j=0;j<numpathpoints;j++)
2091 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
2092 for(k=0;k<numpathpointconnect[j];k++){
2093 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
2097 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2099 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
2102 if(environment!=oldenvironment)Setenvironment(environment);
2103 oldenvironment=environment;
2107 j=objects.numobjects;
2108 objects.numobjects=0;
2111 //if(objects.type[i]!=spiketype)
2112 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
2113 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2116 //if(skyboxtexture){
2117 terrain.DoShadows();
2118 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2119 objects.DoShadows();
2120 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2122 else terrain.DoLighting();
2128 oldlevel=whichlevel;
2131 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
2132 for(i=0;i<numplayers;i++)
2134 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2138 if(i==0||player[i].scale<0)player[i].scale=.2;
2139 player[i].skeleton.free=0;
2140 player[i].skeleton.id=i;
2141 //if(Random()%2==0)player[i].creature=wolftype;
2142 //else player[i].creature=rabbittype;
2143 if(i==0&&mapvers<9)player[i].creature=rabbittype;
2144 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);
2147 if(player[i].creature!=wolftype){
2148 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);
2149 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
2151 if(player[i].creature==wolftype){
2152 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);
2158 texsize=512*512*3/texdetail/texdetail;
2159 //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
2160 //player[i].skeleton.skinText.resize(texsize);
2162 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2164 if(player[i].numclothes)
2166 for(j=0;j<player[i].numclothes;j++)
2168 tintr=player[i].clothestintr[j];
2169 tintg=player[i].clothestintg[j];
2170 tintb=player[i].clothestintb[j];
2171 AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2173 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
2176 player[i].currentanimation=bounceidleanim;
2177 player[i].targetanimation=bounceidleanim;
2178 player[i].currentframe=0;
2179 player[i].targetframe=1;
2181 player[i].speed=1+(float)(Random()%100)/1000;
2182 if(difficulty==0)player[i].speed-=.2;
2183 if(difficulty==1)player[i].speed-=.1;
2185 player[i].velocity=0;
2186 player[i].oldcoords=player[i].coords;
2187 player[i].realoldcoords=player[i].coords;
2190 player[i].skeleton.id=i;
2191 player[i].updatedelay=0;
2192 player[i].normalsupdatedelay=0;
2194 player[i].aitype=passivetype;
2195 player[i].aitarget=0;
2196 player[i].madskills=0;
2200 player[i].proportionhead=1.2;
2201 player[i].proportionbody=1.05;
2202 player[i].proportionarms=1.00;
2203 player[i].proportionlegs=1.1;
2204 player[i].proportionlegs.y=1.05;
2206 player[i].headless=0;
2207 player[i].currentoffset=0;
2208 player[i].targetoffset=0;
2209 /*player[i].armorhead=1;
2210 player[i].armorhigh=1;
2211 player[i].armorlow=1;
2212 player[i].protectionhead=1;
2213 player[i].protectionhigh=1;
2214 player[i].protectionlow=1;
2215 player[i].metalhead=1;
2216 player[i].metalhigh=1;
2217 player[i].metallow=1;
2219 player[i].speedmult=1;*/
2221 player[i].damagetolerance=200;
2223 if(player[i].creature==wolftype)
2225 /*player[i].proportionhead=1.1;
2226 player[i].proportionbody=1.1;
2227 player[i].proportionarms=1.1;
2228 player[i].proportionlegs=1.1;
2229 player[i].proportionlegs.y=1.1;*/
2230 if(i==0||player[i].scale<0)player[i].scale=.23;
2232 player[i].damagetolerance=300;
2235 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2238 player[i].proportionhead.z=0;
2239 player[i].proportionbody.z=0;
2240 player[i].proportionarms.z=0;
2241 player[i].proportionlegs.z=0;
2244 player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
2246 player[i].headmorphness=0;
2247 player[i].targetheadmorphness=1;
2248 player[i].headmorphstart=0;
2249 player[i].headmorphend=0;
2251 player[i].pausetime=0;
2254 player[i].jumppower=5;
2256 player[i].permanentdamage=0;
2257 player[i].superpermanentdamage=0;
2259 player[i].forwardkeydown=0;
2260 player[i].leftkeydown=0;
2261 player[i].backkeydown=0;
2262 player[i].rightkeydown=0;
2263 player[i].jumpkeydown=0;
2264 player[i].crouchkeydown=0;
2265 player[i].throwkeydown=0;
2267 player[i].collided=-10;
2269 player[i].bloodloss=0;
2270 player[i].weaponactive=-1;
2271 player[i].weaponstuck=-1;
2272 player[i].bleeding=0;
2273 player[i].deathbleeding=0;
2274 player[i].stunned=0;
2275 player[i].hasvictim=0;
2276 player[i].wentforweapon=0;
2279 player[0].aitype=playercontrolled;
2280 player[0].weaponactive=-1;
2284 //player[0].speedmult=1/.9;
2285 player[0].power=1/.9;
2290 //player[0].speedmult=1/.8;
2291 player[0].power=1/.8;
2294 //player[0].weaponstuck=1;
2296 if(difficulty==1)player[0].damagetolerance=250;
2297 if(difficulty==0)player[0].damagetolerance=300;
2298 if(difficulty==0)player[0].armorhead*=1.5;
2299 if(difficulty==0)player[0].armorhigh*=1.5;
2300 if(difficulty==0)player[0].armorlow*=1.5;
2301 cameraloc=player[0].coords;
2303 rotation=player[0].rotation;
2305 hawkcoords=player[0].coords;
2308 if(visibleloading){loadscreencolor=4; LoadingScreen();}
2309 //weapons.numweapons=numplayers;
2310 for(i=0;i<weapons.numweapons;i++)
2312 weapons.bloody[i]=0;
2313 weapons.blooddrip[i]=0;
2314 weapons.blooddripdelay[i]=0;
2315 weapons.onfire[i]=0;
2316 weapons.flamedelay[i]=0;
2317 weapons.damage[i]=0;
2318 //weapons.type[i]=sword;
2319 if(weapons.type[i]==sword){
2320 weapons.mass[i]=1.5;
2321 weapons.tipmass[i]=1;
2322 weapons.length[i]=.8;
2324 if(weapons.type[i]==staff){
2326 weapons.tipmass[i]=1;
2327 weapons.length[i]=1.5;
2329 if(weapons.type[i]==knife){
2331 weapons.tipmass[i]=1.2;
2332 weapons.length[i]=.25;
2334 weapons.position[i]=-1000;
2335 weapons.tippoint[i]=-1000;
2338 LOG("Starting background music...");
2340 OPENAL_StopSound(OPENAL_ALL);
2341 if(environment==snowyenvironment)
2345 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
2346 OPENAL_SetPaused(channels[stream_wind], false);
2347 OPENAL_SetVolume(channels[stream_wind], 256);
2350 else if(environment==desertenvironment)
2354 //PlaySoundEx(desertambient,
2355 // samp[desertambient], NULL, true);
2356 PlayStreamEx(stream_desertambient,
2357 strm[stream_desertambient], NULL, true);
2358 OPENAL_SetPaused(channels[stream_desertambient], false);
2359 OPENAL_SetVolume(channels[stream_desertambient], 256);
2362 else if(environment==grassyenvironment)
2366 //PlaySoundEx(wind, samp[wind], NULL, true);
2367 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
2368 OPENAL_SetPaused(channels[stream_wind], false);
2369 OPENAL_SetVolume(channels[stream_wind], 100);
2372 oldmusicvolume[0]=0;
2373 oldmusicvolume[1]=0;
2374 oldmusicvolume[2]=0;
2375 oldmusicvolume[3]=0;
2389 static int i,k,j,l,m;
2390 static XYZ facing,flatfacing,absflatfacing;
2391 static XYZ rotatetarget;
2393 static float oldtargetrotation;
2394 static int target, numgood;
2395 static XYZ tempcoords1,tempcoords2;
2398 static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
2399 static int whichhit;
2400 static bool oldjumpkeydown;
2404 float headprop,bodyprop,armprop,legprop;
2407 displaytime[i]+=multiplier;
2412 if (Input::isKeyDown(SDLK_F6) && !freezetogglekeydown) {
2413 if (Input::isKeyDown(SDLK_LSHIFT)) {
2416 stereoreverse=false;
2419 if (stereoreverse) {
2420 printf("Stereo reversed\n");
2422 printf("Stereo unreversed\n");
2424 freezetogglekeydown=1;
2427 if (Input::isKeyDown(SDLK_F7)) {
2428 if (Input::isKeyDown(SDLK_LSHIFT)) {
2429 stereoseparation -= 0.001;
2431 stereoseparation -= 0.010;
2434 printf("Stereo decreased increased to %f\n", stereoseparation);
2437 if (Input::isKeyDown(SDLK_F8)) {
2438 if (Input::isKeyDown(SDLK_LSHIFT)) {
2439 stereoseparation += 0.001;
2441 stereoseparation += 0.010;
2444 printf("Stereo separation increased to %f\n", stereoseparation);
2449 if(mainmenu&&endgame==1)mainmenu=10;
2450 if( (Input::isKeyDown(SDLK_ESCAPE)||(mainmenu==0&&((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))
2451 && !mainmenutogglekeydown
2452 && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)
2455 if(mainmenu==1||mainmenu==2||mainmenu==0){
2456 if(mainmenu==0&&!winfreeze)mainmenu=2;
2457 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
2458 else if(mainmenu==0&&winfreeze){
2461 else if(mainmenu==1||mainmenu==2)mainmenu=0;
2462 if(mainmenu&&musictoggle){
2463 if(mainmenu==1||mainmenu==2||mainmenu==100){
2464 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2465 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2466 OPENAL_SetPaused(channels[stream_music3], false);
2467 OPENAL_SetVolume(channels[stream_music3], 256);
2468 OPENAL_SetPaused(channels[music1], true);
2472 OPENAL_SetPaused(channels[stream_music3], true);
2473 OPENAL_SetPaused(channels[music1], false);
2481 if(newdetail>2)newdetail=detail;
2482 if(newdetail<0)newdetail=detail;
2483 if(newscreenwidth<0)newscreenwidth=screenwidth;
2484 if(newscreenheight<0)newscreenheight=screenheight;
2486 SaveSettings(*this);
2488 if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
2493 if(mainmenu==3&&gameon)mainmenu=2;
2494 if(mainmenu==3&&!gameon)mainmenu=1;
2495 if(mainmenu==5&&gameon)mainmenu=2;
2496 if(mainmenu==5&&!gameon)mainmenu=1;
2497 if(mainmenu==4)mainmenu=3;
2498 if(mainmenu==6)mainmenu=5;
2499 if(mainmenu==7)mainmenu=1;
2500 if(mainmenu==9)mainmenu=5;
2501 if(mainmenu==11)mainmenu=5;
2502 if(mainmenu==13)mainmenu=12;
2503 if(mainmenu==10)mainmenu=5;
2509 mainmenutogglekeydown=1;
2511 if(!Input::isKeyDown(SDLK_ESCAPE)){
2512 mainmenutogglekeydown=0;
2516 /*static bool minimaptogglekeydown;
2517 if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown){
2519 minimaptogglekeydown=1;
2521 if(!Input::isKeyDown(SDLK_TAB)){
2522 minimaptogglekeydown=0;
2526 static bool minimaptogglekeydown;
2527 if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
2528 if(tutorialstage!=51)
2529 tutorialstagetime=tutorialmaxtime;
2530 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
2531 OPENAL_SetVolume(channels[consolefailsound], 128);
2532 OPENAL_SetPaused(channels[consolefailsound], false);
2533 minimaptogglekeydown=1;
2535 if(!Input::isKeyDown(SDLK_TAB)){
2536 minimaptogglekeydown=0;
2541 if(mainmenu==1||mainmenu==2){
2542 if(Button()&&!oldbutton&&selected==1){
2544 fireSound(firestartsound);
2560 OPENAL_SetPaused(channels[stream_music3], true);
2561 OPENAL_SetPaused(channels[music1], false);
2565 if(Button()&&!oldbutton&&selected==2){
2574 if(newdetail>2)newdetail=detail;
2575 if(newdetail<0)newdetail=detail;
2576 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2577 if(newscreenwidth<0)newscreenwidth=screenwidth;
2578 if(newscreenheight>3000)newscreenheight=screenheight;
2579 if(newscreenheight<0)newscreenheight=screenheight;
2582 if(Button()&&!oldbutton&&selected==3){
2590 OPENAL_SetPaused(channels[stream_music3], true);
2600 if(Button()&&!oldbutton&&selected!=-1){
2603 if(Button()&&!oldbutton&&selected==0){
2605 extern SDL_Rect **resolutions;
2606 bool isCustomResolution = true;
2608 for (int i = 0; (!found) && (resolutions[i]); i++)
2610 if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2611 isCustomResolution = false;
2613 if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2616 if (resolutions[i] != NULL)
2618 newscreenwidth = (int) resolutions[i]->w;
2619 newscreenheight = (int) resolutions[i]->h;
2621 else if (isCustomResolution)
2623 if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2625 newscreenwidth = (int) resolutions[0]->w;
2626 newscreenheight = (int) resolutions[0]->h;
2630 newscreenwidth = screenwidth;
2631 newscreenheight = screenheight;
2636 newscreenwidth = (int) resolutions[0]->w;
2637 newscreenheight = (int) resolutions[0]->h;
2645 newscreenwidth = (int) resolutions[0]->w;
2646 newscreenheight = (int) resolutions[0]->h;
2651 if(Button()&&!oldbutton&&selected==1){
2653 if(newdetail>2)newdetail=0;
2655 if(Button()&&!oldbutton&&selected==2){
2657 if(bloodtoggle>2)bloodtoggle=0;
2659 if(Button()&&!oldbutton&&selected==3){
2661 if(difficulty>2)difficulty=0;
2663 if(Button()&&!oldbutton&&selected==4){
2664 ismotionblur=1-ismotionblur;
2666 if(Button()&&!oldbutton&&selected==5){
2669 if(Button()&&!oldbutton&&selected==6){
2670 musictoggle=1-musictoggle;
2673 OPENAL_SetPaused(channels[music1], true);
2674 OPENAL_SetPaused(channels[stream_music2], true);
2675 OPENAL_SetPaused(channels[stream_music3], true);
2678 oldmusicvolume[i]=0;
2684 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2685 OPENAL_SetPaused(channels[stream_music3], false);
2686 OPENAL_SetVolume(channels[stream_music3], 256);
2689 if(Button()&&!oldbutton&&selected==9){
2690 invertmouse=1-invertmouse;
2692 if(Button()&&!oldbutton&&selected==10){
2693 usermousesensitivity+=.2;
2694 if(usermousesensitivity>2)usermousesensitivity=.2;
2696 if(Button()&&!oldbutton&&selected==11){
2698 if(volume>1.0001f)volume=0;
2699 OPENAL_SetSFXMasterVolume((int)(volume*255));
2701 if(Button()&&!oldbutton&&selected==7){
2712 if(Button() && !oldbutton && selected == 12) {
2715 newstereomode = stereomode;
2719 if(Button() && !oldbutton && selected == 13) {
2720 showdamagebar=!showdamagebar;
2722 if(Button()&&!oldbutton&&selected==8){
2727 if(newdetail>2)newdetail=detail;
2728 if(newdetail<0)newdetail=detail;
2729 if(newscreenwidth<0)newscreenwidth=screenwidth;
2730 if(newscreenheight<0)newscreenheight=screenheight;
2733 SaveSettings(*this);
2734 if(mainmenu==3&&gameon)mainmenu=2;
2735 if(mainmenu==3&&!gameon)mainmenu=1;
2739 if(Button()&&!oldbutton&&selected!=-1&&!waiting){
2741 if(selected<9&&keyselect==-1)
2750 if(newdetail>2)newdetail=detail;
2751 if(newdetail<0)newdetail=detail;
2752 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2753 if(newscreenwidth<0)newscreenwidth=screenwidth;
2754 if(newscreenheight>3000)newscreenheight=screenheight;
2755 if(newscreenheight<0)newscreenheight=screenheight;
2763 accountactive->endGame();
2767 if(Button()&&!oldbutton&&selected==1){
2777 if(firstload)TickOnceAfter();
2778 if(!firstload)LoadStuff();
2785 OPENAL_SetPaused(channels[stream_music3], true);
2787 if(Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){//selected>=7&&(selected-7<=campaignnumchoices)){
2797 if(firstload) TickOnceAfter();
2813 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
2814 whichchoice=selected-7-accountactive->getCampaignChoicesMade();
2818 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2822 OPENAL_SetPaused(channels[stream_music3], true);
2824 if(Button()&&!oldbutton&&selected==4){
2829 if(mainmenu==5&&gameon)mainmenu=2;
2830 if(mainmenu==5&&!gameon)mainmenu=1;
2832 if(Button()&&!oldbutton&&selected==5){
2839 if(Button()&&!oldbutton&&selected==3){
2846 if(Button()&&!oldbutton&&selected==2){
2855 if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
2864 targetlevel=selected;
2865 if(firstload)TickOnceAfter();
2866 if(!firstload)LoadStuff();
2868 Loadlevel(selected);
2874 OPENAL_SetPaused(channels[stream_music3], true);
2876 if(Button()&&!oldbutton&&selected==numchallengelevels){
2885 if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
2894 targetlevel=selected;
2897 Loadlevel(selected);
2904 OPENAL_SetPaused(channels[stream_music3], true);
2906 if(Button()&&!oldbutton&&selected==numchallengelevels){
2916 if(Button()&&!oldbutton&&selected==3){
2926 if(Button()&&!oldbutton) {
2931 accountactive = Account::destroy(accountactive);
2933 } else if(selected==2) {
2941 if(Button()&&!oldbutton) {
2944 if(selected==0&&Account::getNbAccounts()<8){
2946 } else if (selected<Account::getNbAccounts()+1) {
2947 accountactive=Account::get(selected-1);
2950 } else if (selected==Account::getNbAccounts()+1) {
2956 displaytext[0][j]=' ';
2966 if(Button()&&!oldbutton&&selected>-1){
2970 accountactive->setDifficulty(selected);
2979 if(Button()&&!oldbutton&&selected==0) {
2980 newstereomode = (StereoMode)(newstereomode + 1);
2981 while(!CanInitStereo(newstereomode)) {
2982 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
2983 newstereomode = (StereoMode)(newstereomode + 1);
2984 if ( newstereomode >= stereoCount ) {
2985 newstereomode = stereoNone;
2990 if(Input::isKeyDown(MOUSEBUTTON1)&&!oldbutton&&selected==1) {
2991 stereoseparation+=0.001;
2993 if(Input::isKeyDown(MOUSEBUTTON2)&&!oldbutton&&selected==1) {
2994 stereoseparation-=0.001;
2997 if(Button()&&!oldbutton&&selected==2) {
2998 stereoreverse =! stereoreverse;
3001 if(Button()&&!oldbutton&&selected==3) {
3004 stereomode = newstereomode;
3005 InitStereo(stereomode);
3012 if(Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1;
3015 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
3018 if(newdetail>2)newdetail=detail;
3019 if(newdetail<0)newdetail=detail;
3020 if(newscreenwidth<0)newscreenwidth=screenwidth;
3021 if(newscreenheight<0)newscreenheight=screenheight;
3023 SaveSettings(*this);
3027 if(mainmenu==1||mainmenu==2){
3028 if(loaddistrib>4)transition+=multiplier/8;
3036 OPENAL_SetFrequency(channels[stream_music3], 22050);
3039 inputText(displaytext[0],&displayselected,&displaychars[0]);
3040 if(!waiting) { // the input as finished
3041 if(displaychars[0]){ // with enter
3042 accountactive = Account::add(string(displaytext[0]));
3048 fireSound(firestartsound);
3051 displaytext[0][i]=' ';
3056 } else { // with escape or empty
3057 mainmenutogglekeydown=1;
3062 displayblinkdelay-=multiplier;
3063 if(displayblinkdelay<=0){
3064 displayblinkdelay=.3;
3065 displayblink=1-displayblink;
3071 if(hostile==1)hostiletime+=multiplier;
3073 if(!winfreeze)leveltime+=multiplier;
3074 if(Input::isKeyDown(SDLK_ESCAPE)){
3081 if(Input::isKeyDown(chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3083 chattogglekeydown=1;
3086 if(!Input::isKeyDown(chatkey)){
3087 chattogglekeydown=0;
3091 inputText(displaytext[0],&displayselected,&displaychars[0]);
3093 if(displaychars[0]){
3094 for(int j=0;j<255;j++){
3095 displaytext[0][j]=' ';
3103 displayblinkdelay-=multiplier;
3104 if(displayblinkdelay<=0){
3105 displayblinkdelay=.3;
3106 displayblink=1-displayblink;
3110 if(chatting)keyboardfrozen=1;
3112 if(Input::isKeyDown(SDLK_v)&&!freezetogglekeydown&&debugmode){
3115 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3117 freezetogglekeydown=1;
3120 if(!Input::isKeyDown(SDLK_v)&&!Input::isKeyDown(SDLK_F1)){
3121 freezetogglekeydown=0;
3124 if(Input::isKeyDown(SDLK_BACKQUOTE)&&!consoletogglekeydown&&debugmode){
3127 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3132 consoletogglekeydown=1;
3135 if(!Input::isKeyDown(SDLK_BACKQUOTE)){
3136 consoletogglekeydown=0;
3139 if(console)freeze=1;
3141 if(console&&!Input::isKeyDown(SDLK_LMETA)){
3142 inputText(consoletext[0],&consoleselected,&consolechars[0]);
3145 cmd_dispatch(this, consoletext[0]);
3146 if(consolechars[0]>0){
3150 consoletext[k][j]=consoletext[k-1][j];
3152 consolechars[k]=consolechars[k-1];
3155 consoletext[0][j]=' ';
3162 consoleblinkdelay-=multiplier;
3163 if(consoleblinkdelay<=0){
3164 consoleblinkdelay=.3;
3165 consoleblink=1-consoleblink;
3169 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
3172 if(newdetail>2)newdetail=detail;
3173 if(newdetail<0)newdetail=detail;
3174 if(newscreenwidth<0)newscreenwidth=screenwidth;
3175 if(newscreenheight<0)newscreenheight=screenheight;
3177 SaveSettings(*this);
3181 static int oldwinfreeze;
3182 if(winfreeze&&!oldwinfreeze){
3183 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3184 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3185 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3186 OPENAL_SetPaused(channels[consolesuccesssound], false);
3188 if(winfreeze==0)oldwinfreeze=winfreeze;
3189 else oldwinfreeze++;
3191 if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))&&!oldjumpkeydown&&!campaign){
3192 if(winfreeze)winfreeze=0;
3195 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
3201 if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))){
3204 if(!Input::isKeyDown(jumpkey)&&!Input::isKeyDown(SDLK_SPACE))oldjumpkeydown=0;
3206 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
3208 static bool oldbuttondialogue;
3210 if(indialogue!=-1)talkdelay=1;
3211 talkdelay-=multiplier;
3214 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
3215 for(i=0;i<numdialogues;i++){
3216 int realdialoguetype;
3218 if(dialoguetype[i]>49){
3219 realdialoguetype=dialoguetype[i]-50;
3222 else if(dialoguetype[i]>39){
3223 realdialoguetype=dialoguetype[i]-40;
3226 else if(dialoguetype[i]>29){
3227 realdialoguetype=dialoguetype[i]-30;
3230 else if(dialoguetype[i]>19){
3231 realdialoguetype=dialoguetype[i]-20;
3234 else if(dialoguetype[i]>9){
3235 realdialoguetype=dialoguetype[i]-10;
3239 realdialoguetype=dialoguetype[i];
3242 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(Input::isKeyDown(attackkey)&&!oldbuttondialogue))){
3243 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
3245 for(j=0;j<numdialogueboxes[whichdialogue];j++){
3246 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
3247 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
3248 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
3249 player[participantfocus[whichdialogue][j]].velocity=0;
3250 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
3251 player[participantfocus[whichdialogue][j]].targetframe=0;
3256 dialoguegonethrough[i]++;
3257 if(dialogueboxsound[whichdialogue][indialogue]!=0){
3258 static float gLoc[3];
3259 static float vel[3];
3261 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
3262 temppos=temppos-viewer;
3263 Normalise(&temppos);
3268 gLoc[2]=temppos.z;vel[0]=0;
3272 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
3273 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
3274 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
3275 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
3276 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
3277 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
3278 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
3279 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
3280 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
3281 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
3282 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
3283 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
3284 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
3285 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
3286 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
3287 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
3288 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
3289 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
3290 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
3291 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
3292 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
3293 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
3294 OPENAL_SetVolume(channels[whichsoundplay], 256);
3295 OPENAL_SetPaused(channels[whichsoundplay], false);
3297 if(Input::isKeyDown(attackkey))oldbuttondialogue=1;
3302 windvar+=multiplier;
3303 smoketex+=multiplier;
3304 tutorialstagetime+=multiplier;
3306 static float hotspotvisual[40];
3310 for(i=0;i<numhotspots;i++)
3311 hotspotvisual[i]-=multiplier/320;
3313 for(i=0;i<numhotspots;i++){
3314 //if(hotspottype[i]<=10)
3315 while(hotspotvisual[i]<0){
3317 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
3318 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
3319 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
3320 hotspotsprite+=hotspot[i];
3321 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
3322 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
3326 for(i=0;i<numhotspots;i++){
3327 if(hotspottype[i]<=10&&hotspottype[i]>0){
3328 hotspot[i]=player[hotspottype[i]].coords;
3334 if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
3337 if(tutorialstage<=1){
3342 if(tutorialstage==1){
3344 } else if(tutorialstage==2){
3346 } else if(tutorialstage==3){
3347 tutorialmaxtime=600;
3348 } else if(tutorialstage==4){
3349 tutorialmaxtime=1000;
3350 } else if(tutorialstage==5){
3351 tutorialmaxtime=600;
3352 } else if(tutorialstage==6){
3353 tutorialmaxtime=600;
3354 } else if(tutorialstage==7){
3355 tutorialmaxtime=600;
3356 } else if(tutorialstage==8){
3357 tutorialmaxtime=600;
3358 } else if(tutorialstage==9){
3359 tutorialmaxtime=600;
3360 } else if(tutorialstage==10){
3362 } else if(tutorialstage==11){
3363 tutorialmaxtime=1000;
3364 } else if(tutorialstage==12){
3365 tutorialmaxtime=1000;
3366 } else if(tutorialstage==13){
3368 } else if(tutorialstage==14){
3380 player[1].coords=(temp+temp2)/2;
3384 gLoc[0]=player[1].coords.x;
3385 gLoc[1]=player[1].coords.y;
3386 gLoc[2]=player[1].coords.z;
3390 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3391 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3392 OPENAL_SetVolume(channels[fireendsound], 256);
3393 OPENAL_SetPaused(channels[fireendsound], false);
3395 for(i=0;i<player[1].skeleton.num_joints;i++){
3397 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
3398 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
3399 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;
3400 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
3401 sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3405 } else if(tutorialstage==15){
3406 tutorialmaxtime=500;
3407 } else if(tutorialstage==16){
3408 tutorialmaxtime=500;
3409 } else if(tutorialstage==17){
3410 tutorialmaxtime=500;
3411 } else if(tutorialstage==18){
3412 tutorialmaxtime=500;
3413 } else if(tutorialstage==19){
3415 //tutorialmaxtime=500;
3416 } else if(tutorialstage==20){
3417 tutorialmaxtime=500;
3418 } else if(tutorialstage==21){
3419 tutorialmaxtime=500;
3425 } else if(tutorialstage==22){
3426 tutorialmaxtime=500;
3427 } else if(tutorialstage==23){
3428 tutorialmaxtime=500;
3429 } else if(tutorialstage==24){
3430 tutorialmaxtime=500;
3431 } else if(tutorialstage==25){
3432 tutorialmaxtime=500;
3433 } else if(tutorialstage==26){
3435 } else if(tutorialstage==27){
3439 player[1].aitype=attacktypecutoff;
3440 } else if(tutorialstage==28){
3441 tutorialmaxtime=400;
3442 } else if(tutorialstage==29){
3443 tutorialmaxtime=400;
3444 player[0].escapednum=0;
3445 } else if(tutorialstage==30){
3449 player[1].aitype=passivetype;
3450 } else if(tutorialstage==31){
3452 } else if(tutorialstage==32){
3454 } else if(tutorialstage==33){
3455 tutorialmaxtime=400;
3458 player[1].aitype=attacktypecutoff;
3459 } else if(tutorialstage==34){
3460 tutorialmaxtime=400;
3461 } else if(tutorialstage==35){
3462 tutorialmaxtime=400;
3463 } else if(tutorialstage==36){
3467 player[1].aitype=passivetype;
3468 } else if(tutorialstage==37){
3474 player[1].aitype=attacktypecutoff;
3475 } else if(tutorialstage==38){
3479 player[1].aitype=passivetype;
3480 } else if(tutorialstage==39){
3491 weapons.owner[weapons.numweapons]=-1;
3492 weapons.type[weapons.numweapons]=knife;
3493 weapons.damage[weapons.numweapons]=0;
3494 weapons.mass[weapons.numweapons]=1;
3495 weapons.tipmass[weapons.numweapons]=1.2;
3496 weapons.length[weapons.numweapons]=.25;
3497 weapons.position[weapons.numweapons]=(temp+temp2)/2;
3498 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
3500 weapons.velocity[weapons.numweapons]=0.1;
3501 weapons.tipvelocity[weapons.numweapons]=0.1;
3502 weapons.missed[weapons.numweapons]=1;
3503 weapons.hitsomething[weapons.numweapons]=0;
3504 weapons.freetime[weapons.numweapons]=0;
3505 weapons.firstfree[weapons.numweapons]=1;
3506 weapons.physics[weapons.numweapons]=1;
3508 weapons.numweapons++;
3509 } else if(tutorialstage==40){
3510 tutorialmaxtime=300;
3511 } else if(tutorialstage==41){
3512 tutorialmaxtime=300;
3513 } else if(tutorialstage==42){
3515 } else if(tutorialstage==43){
3516 tutorialmaxtime=300;
3517 } else if(tutorialstage==44){
3519 player[0].weaponactive=-1;
3520 player[0].num_weapons=0;
3521 player[1].weaponactive=0;
3522 player[1].num_weapons=1;
3523 player[1].weaponids[0]=0;
3527 player[1].aitype=attacktypecutoff;
3529 tutorialmaxtime=300;
3530 } else if(tutorialstage==45){
3532 player[0].weaponactive=-1;
3533 player[0].num_weapons=0;
3534 player[1].weaponactive=0;
3535 player[1].num_weapons=1;
3536 player[1].weaponids[0]=0;
3538 tutorialmaxtime=300;
3539 } else if(tutorialstage==46){
3541 player[0].weaponactive=-1;
3542 player[0].num_weapons=0;
3543 player[1].weaponactive=0;
3544 player[1].num_weapons=1;
3545 player[1].weaponids[0]=0;
3547 weapons.type[0]=sword;
3549 tutorialmaxtime=300;
3550 } else if(tutorialstage==47){
3562 weapons.owner[weapons.numweapons]=-1;
3563 weapons.type[weapons.numweapons]=sword;
3564 weapons.damage[weapons.numweapons]=0;
3565 weapons.mass[weapons.numweapons]=1;
3566 weapons.tipmass[weapons.numweapons]=1.2;
3567 weapons.length[weapons.numweapons]=.25;
3568 weapons.position[weapons.numweapons]=(temp+temp2)/2;
3569 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
3571 weapons.velocity[weapons.numweapons]=0.1;
3572 weapons.tipvelocity[weapons.numweapons]=0.1;
3573 weapons.missed[weapons.numweapons]=1;
3574 weapons.hitsomething[weapons.numweapons]=0;
3575 weapons.freetime[weapons.numweapons]=0;
3576 weapons.firstfree[weapons.numweapons]=1;
3577 weapons.physics[weapons.numweapons]=1;
3581 player[0].weaponactive=0;
3582 player[0].num_weapons=1;
3583 player[0].weaponids[0]=1;
3584 player[1].weaponactive=0;
3585 player[1].num_weapons=1;
3586 player[1].weaponids[0]=0;
3588 weapons.numweapons++;
3589 } else if(tutorialstage==48){
3592 player[1].aitype=passivetype;
3598 player[0].weaponactive=0;
3599 player[0].num_weapons=1;
3600 player[0].weaponids[0]=1;
3601 player[1].weaponactive=0;
3602 player[1].num_weapons=1;
3603 player[1].weaponids[0]=0;
3605 if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
3606 else weapons.type[0]=staff;
3608 weapons.numweapons++;
3609 } else if(tutorialstage==49){
3612 player[1].aitype=passivetype;
3614 tutorialmaxtime=200;
3616 weapons.position[1]=1000;
3617 weapons.tippoint[1]=1000;
3619 weapons.numweapons=1;
3621 player[1].weaponactive=-1;
3622 player[1].num_weapons=0;
3623 player[0].weaponactive=0;
3624 player[0].num_weapons=1;
3625 player[0].weaponids[0]=0;
3627 weapons.type[0]=knife;
3629 weapons.numweapons++;
3630 } else if(tutorialstage==50){
3636 gLoc[0]=player[1].coords.x;
3637 gLoc[1]=player[1].coords.y;
3638 gLoc[2]=player[1].coords.z;
3642 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3643 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3644 OPENAL_SetVolume(channels[fireendsound], 256);
3645 OPENAL_SetPaused(channels[fireendsound], false);
3647 for(i=0;i<player[1].skeleton.num_joints;i++){
3649 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
3650 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
3651 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;
3652 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
3653 sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3657 player[1].num_weapons=0;
3658 player[1].weaponstuck=-1;
3659 player[1].weaponactive=-1;
3661 weapons.numweapons=0;
3663 weapons.owner[0]=-1;
3664 weapons.velocity[0]=0.1;
3665 weapons.tipvelocity[0]=-0.1;
3666 weapons.missed[0]=1;
3667 weapons.hitsomething[0]=0;
3668 weapons.freetime[0]=0;
3669 weapons.firstfree[0]=1;
3670 weapons.physics[0]=1;
3671 } else if(tutorialstage==51){
3672 tutorialmaxtime=80000;
3674 if(tutorialstage<=51)tutorialstagetime=0;
3678 if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
3679 if(tutorialstage==3){
3680 if(deltah||deltav)tutorialsuccess+=multiplier;
3682 if(tutorialstage==4){
3683 if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
3685 if(tutorialstage==5){
3686 if(player[0].jumpkeydown)tutorialsuccess=1;
3688 if(tutorialstage==6){
3689 if(player[0].isCrouch())tutorialsuccess=1;
3691 if(tutorialstage==7){
3692 if(player[0].targetanimation==rollanim)tutorialsuccess=1;
3694 if(tutorialstage==8){
3695 if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
3697 if(tutorialstage==9){
3698 if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
3700 if(tutorialstage==11){
3701 if(player[0].isWallJump())tutorialsuccess=1;
3703 if(tutorialstage==12){
3704 if(player[0].targetanimation==flipanim)tutorialsuccess=1;
3706 if(tutorialstage==15){
3707 if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
3709 if(tutorialstage==16){
3710 if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
3712 if(tutorialstage==17){
3713 if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
3715 if(tutorialstage==18){
3716 if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
3718 if(tutorialstage==19){
3719 if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
3721 if(tutorialstage==20){
3722 if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
3724 if(tutorialstage==21){
3725 if(bonus==cannon)tutorialsuccess=1;
3727 if(tutorialstage==22){
3728 if(bonus==spinecrusher)tutorialsuccess=1;
3730 if(tutorialstage==23){
3731 if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
3733 if(tutorialstage==24){
3734 if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
3736 if(tutorialstage==25){
3737 if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
3739 if(tutorialstage==28){
3740 if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
3742 if(tutorialstage==29){
3743 if(player[0].escapednum==2){
3747 player[1].aitype=passivetype;
3750 if(tutorialstage==33){
3751 if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3753 if(tutorialstage==34){
3754 if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3756 if(tutorialstage==35){
3757 if(animation[player[0].targetanimation].attack==reversal){
3761 player[1].aitype=passivetype;
3764 if(tutorialstage==40){
3765 if(player[0].num_weapons>0)tutorialsuccess=1;
3767 if(tutorialstage==41){
3768 if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
3770 if(tutorialstage==43){
3771 if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
3773 if(tutorialstage==44){
3774 if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3776 if(tutorialstage==45){
3777 if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3779 if(tutorialstage==46){
3780 if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
3782 if(tutorialstage==49){
3783 if(player[1].weaponstuck!=-1)tutorialsuccess=1;
3785 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
3788 if(tutorialstagetime==tutorialmaxtime-3){
3789 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3790 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3791 OPENAL_SetPaused(channels[consolesuccesssound], false);
3794 if(tutorialsuccess>=1){
3795 if(tutorialstage==34||tutorialstage==35)
3796 tutorialstagetime=tutorialmaxtime-1;
3801 if(tutorialstage<14||tutorialstage>=50){
3802 player[1].coords.y=300;
3803 player[1].velocity=0;
3807 if(tutoriallevel!=1){
3808 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
3809 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3810 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3811 OPENAL_SetPaused(channels[consolesuccesssound], false);
3816 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3817 OPENAL_SetVolume(channels[fireendsound], 256);
3818 OPENAL_SetPaused(channels[fireendsound], false);
3821 if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
3822 else bonusnum[bonus]+=0.15;
3823 if(tutoriallevel)bonusvalue=0;
3824 bonusvalue/=bonusnum[bonus];
3825 bonustotal+=bonusvalue;
3827 bonustime+=multiplier;
3829 if(environment==snowyenvironment){
3830 precipdelay-=multiplier;
3831 while(precipdelay<0){
3833 if(!detail)precipdelay+=.04;
3834 XYZ footvel,footpoint;
3837 footpoint=viewer+viewerfacing*6;
3838 footpoint.y+=((float)abs(Random()%1200))/100-6;
3839 footpoint.x+=((float)abs(Random()%1200))/100-6;
3840 footpoint.z+=((float)abs(Random()%1200))/100-6;
3841 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
3844 for(k=0;k<numplayers;k++){
3845 if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
3846 if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
3848 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){
3849 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3850 else if(player[k].rotation>player[k].targetrotation){
3851 player[k].rotation-=multiplier*player[k].turnspeed;
3853 else if(player[k].rotation<player[k].targetrotation){
3854 player[k].rotation+=multiplier*player[k].turnspeed;
3859 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))){
3860 player[k].turnspeed*=2;
3861 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3862 else if(player[k].rotation>player[k].targetrotation){
3863 player[k].rotation-=multiplier*player[k].turnspeed;
3865 else if(player[k].rotation<player[k].targetrotation){
3866 player[k].rotation+=multiplier*player[k].turnspeed;
3868 player[k].turnspeed/=2;
3871 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3872 player[k].turnspeed*=4;
3873 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
3874 else if(player[k].rotation>player[k].targetrotation){
3875 player[k].rotation-=multiplier*player[k].turnspeed;
3877 else if(player[k].rotation<player[k].targetrotation){
3878 player[k].rotation+=multiplier*player[k].turnspeed;
3880 player[k].turnspeed/=4;
3883 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/ player[k].DoStuff();
3884 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
3886 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
3887 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
3890 if(player[k].collide<-.3)player[k].collide=-.3;
3891 if(player[k].collide>1)player[k].collide=1;
3892 player[k].collide-=multiplier*30;
3894 if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
3895 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3897 if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
3898 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3899 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3900 if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
3901 lowpoint=player[k].coords;
3902 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
3903 else lowpoint.y+=1.3;
3904 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){
3905 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3907 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
3908 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
3910 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3911 flatfacing=lowpoint-player[k].coords;
3912 player[k].coords=lowpoint;
3913 player[k].coords.y-=1.3;
3914 player[k].collide=1;
3916 if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
3917 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3918 tempcoords1=lowpoint;
3919 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3920 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3922 player[k].targetanimation=walljumpleftanim;
3923 player[k].targetframe=0;
3926 gLoc[0]=player[k].coords.x;
3927 gLoc[1]=player[k].coords.y;
3928 gLoc[2]=player[k].coords.z;
3932 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3933 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3934 OPENAL_SetVolume(channels[movewhooshsound], 256);
3935 OPENAL_SetPaused(channels[movewhooshsound], false);
3936 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3938 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3939 player[k].rotation=-asin(0-lowpointtarget.x);
3940 player[k].rotation*=360/6.28;
3941 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3942 player[k].targetrotation=player[k].rotation;
3943 player[k].lowrotation=player[k].rotation;
3944 if(k==0)numwallflipped++;
3948 lowpoint=tempcoords1;
3949 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3950 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3951 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3953 player[k].targetanimation=walljumprightanim;
3954 player[k].targetframe=0;
3957 gLoc[0]=player[k].coords.x;
3958 gLoc[1]=player[k].coords.y;
3959 gLoc[2]=player[k].coords.z;
3963 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3964 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3965 OPENAL_SetVolume(channels[movewhooshsound], 256);
3966 OPENAL_SetPaused(channels[movewhooshsound], false);
3967 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
3969 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3970 player[k].rotation=-asin(0-lowpointtarget.x);
3971 player[k].rotation*=360/6.28;
3972 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3973 player[k].targetrotation=player[k].rotation;
3974 player[k].lowrotation=player[k].rotation;
3975 if(k==0)numwallflipped++;
3979 lowpoint=tempcoords1;
3980 lowpointtarget=lowpoint+player[k].facing*2;
3981 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3982 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
3984 player[k].targetanimation=walljumpbackanim;
3985 player[k].targetframe=0;
3988 gLoc[0]=player[k].coords.x;
3989 gLoc[1]=player[k].coords.y;
3990 gLoc[2]=player[k].coords.z;
3994 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
3995 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
3996 OPENAL_SetVolume(channels[movewhooshsound], 256);
3997 OPENAL_SetPaused(channels[movewhooshsound], false);
3998 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
4000 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4001 player[k].rotation=-asin(0-lowpointtarget.x);
4002 player[k].rotation*=360/6.28;
4003 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
4004 player[k].targetrotation=player[k].rotation;
4005 player[k].lowrotation=player[k].rotation;
4006 if(k==0)numwallflipped++;
4010 lowpoint=tempcoords1;
4011 lowpointtarget=lowpoint-player[k].facing*2;
4012 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4013 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
4015 player[k].targetanimation=walljumpfrontanim;
4016 player[k].targetframe=0;
4019 gLoc[0]=player[k].coords.x;
4020 gLoc[1]=player[k].coords.y;
4021 gLoc[2]=player[k].coords.z;
4025 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
4026 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
4027 OPENAL_SetVolume(channels[movewhooshsound], 256);
4028 OPENAL_SetPaused(channels[movewhooshsound], false);
4029 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
4031 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4032 player[k].rotation=-asin(0-lowpointtarget.x);
4033 player[k].rotation*=360/6.28;
4034 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
4035 player[k].rotation+=180;
4036 player[k].targetrotation=player[k].rotation;
4037 player[k].lowrotation=player[k].rotation;
4038 if(k==0)numwallflipped++;
4046 else if(objects.type[i]==rocktype){
4047 lowpoint2=player[k].coords;
4048 lowpoint=player[k].coords;
4050 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
4051 player[k].coords=colpoint;
4052 player[k].collide=1;
4055 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
4056 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
4058 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
4060 player[k].targetframe=0;
4061 player[k].onterrain=1;
4063 if(player[k].id==0){
4064 OPENAL_SetPaused(channels[whooshsound], true);
4065 OPENAL_SetVolume(channels[whooshsound], 0);
4068 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
4069 if(player[k].isFlip())player[k].jumppower=-4;
4070 player[k].targetanimation=player[k].getLanding();
4073 gLoc[0]=player[k].coords.x;
4074 gLoc[1]=player[k].coords.y;
4075 gLoc[2]=player[k].coords.z;
4076 vel[0]=player[k].velocity.x;
4077 vel[1]=player[k].velocity.y;
4078 vel[2]=player[k].velocity.z;
4079 PlaySoundEx( landsound, samp[landsound], NULL, true);
4080 OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
4081 OPENAL_SetVolume(channels[landsound], 128);
4082 OPENAL_SetPaused(channels[landsound], false);
4084 envsound[numenvsounds]=player[k].coords;
4085 envsoundvol[numenvsounds]=16;
4086 envsoundlife[numenvsounds]=.4;
4095 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
4096 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
4097 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
4098 lowpoint=player[k].coords;
4100 if(objects.type[i]!=rocktype)
4101 if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
4102 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
4103 player[k].coords=lowpoint;
4104 player[k].coords.y-=1.35;
4105 player[k].collide=1;
4107 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)){
4108 lowpoint=player[k].coords;
4109 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
4110 lowpoint=player[k].coords;
4114 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
4115 lowpointtarget=lowpoint+facing*1.4;
4116 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4118 lowpoint=player[k].coords;
4120 lowpointtarget=lowpoint+facing*1.4;
4122 lowpointtarget2=lowpointtarget;
4124 lowpointtarget3=lowpointtarget;
4126 lowpointtarget4=lowpointtarget;
4128 lowpointtarget5=lowpointtarget;
4130 lowpointtarget6=lowpointtarget;
4132 lowpointtarget7=lowpoint;
4134 lowpointtarget2.x+=.1;
4136 lowpointtarget3.z+=.1;
4138 lowpointtarget4.x-=.1;
4140 lowpointtarget5.z-=.1;
4142 lowpointtarget6.y+=45/13;
4143 lowpointtarget6+=facing*.6;
4144 lowpointtarget7.y+=90/13;
4145 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4146 if(objects.friction[i]>.5)
4149 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
4150 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
4151 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
4152 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)
4154 lowpoint=player[k].coords;
4155 lowpoint.y+=(float)j/13;
4156 lowpointtarget=lowpoint+facing*1.4;
4157 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
4161 /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
4164 if(j<=25&&player[k].targetanimation==jumpdownanim){
4167 if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
4168 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
4169 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)*/){
4170 lowpoint=player[k].coords;
4171 lowpoint.y+=(float)j/13;
4172 lowpointtarget=lowpoint+facing*1.3;
4173 flatfacing=player[k].coords;
4174 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
4175 player[k].coords.y=lowpointtarget.y-.07;
4176 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
4178 if(j>10||!player[k].isRun()){
4179 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
4180 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
4184 gLoc[0]=player[k].coords.x;
4185 gLoc[1]=player[k].coords.y;
4186 gLoc[2]=player[k].coords.z;
4187 vel[0]=player[k].velocity.x;
4188 vel[1]=player[k].velocity.y;
4189 vel[2]=player[k].velocity.z;
4190 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
4191 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
4192 OPENAL_SetVolume(channels[jumpsound], 128);
4193 OPENAL_SetPaused(channels[jumpsound], false);
4195 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4196 player[k].rotation=-asin(0-lowpointtarget.x);
4197 player[k].rotation*=360/6.28;
4198 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
4199 player[k].targetrotation=player[k].rotation;
4200 player[k].lowrotation=player[k].rotation;
4202 //player[k].velocity=lowpointtarget*.03;
4203 player[k].velocity=0;
4205 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
4206 //player[k].currentanimation=climbanim;
4207 player[k].targetanimation=climbanim;
4208 player[k].jumppower=0;
4209 player[k].jumpclimb=1;
4211 player[k].transspeed=6;
4214 //player[k].currentframe=1;
4215 player[k].targetframe=1;
4217 //player[k].currentframe=0;
4218 player[k].targetframe=0;
4219 //player[k].currentanimation=hanganim;
4220 player[k].targetanimation=hanganim;
4221 player[k].jumppower=0;
4235 if(player[k].collide<=0){
4236 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()){
4237 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)){
4238 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
4239 player[k].targetanimation=jumpdownanim;
4240 player[k].targetframe=0;
4245 gLoc[0]=player[k].coords.x;
4246 gLoc[1]=player[k].coords.y;
4247 gLoc[2]=player[k].coords.z;
4248 vel[0]=player[k].velocity.x;
4249 vel[1]=player[k].velocity.y;
4250 vel[2]=player[k].velocity.z;
4252 PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
4253 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4254 OPENAL_SetVolume(channels[whooshsound], 128);
4255 OPENAL_SetPaused(channels[whooshsound], false);
4258 player[k].velocity.y+=gravity;
4263 player[k].realoldcoords=player[k].coords;
4266 static XYZ oldviewer;
4269 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
4270 player[0].leftkeydown=Input::isKeyDown(leftkey);
4271 player[0].backkeydown=Input::isKeyDown(backkey);
4272 player[0].rightkeydown=Input::isKeyDown(rightkey);
4273 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
4274 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
4275 player[0].drawkeydown=Input::isKeyDown(drawkey);
4276 player[0].throwkeydown=Input::isKeyDown(throwkey);
4280 player[0].forwardkeydown=0;
4281 player[0].leftkeydown=0;
4282 player[0].backkeydown=0;
4283 player[0].rightkeydown=0;
4284 player[0].jumpkeydown=0;
4285 player[0].crouchkeydown=0;
4286 player[0].drawkeydown=0;
4287 player[0].throwkeydown=0;
4290 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
4293 static bool endkeydown;
4300 facing=DoRotation(facing,-rotation2,0,0);
4301 facing=DoRotation(facing,0,0-rotation,0);
4306 flatfacing=DoRotation(flatfacing,0,-rotation,0);
4308 if(Input::isKeyDown(forwardkey))viewer+=facing*multiplier*4;
4309 if(Input::isKeyDown(backkey))viewer-=facing*multiplier*4;
4310 if(Input::isKeyDown(leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
4311 if(Input::isKeyDown(rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
4312 if(Input::isKeyDown(jumpkey))viewer.y+=multiplier*4;
4313 if(Input::isKeyDown(crouchkey))viewer.y-=multiplier*4;
4314 if(!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
4315 ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
4316 ||Input::isKeyDown(SDLK_MINUS))){
4318 if(Input::isKeyDown(SDLK_1))whichend=1;
4319 if(Input::isKeyDown(SDLK_2))whichend=2;
4320 if(Input::isKeyDown(SDLK_3))whichend=3;
4321 if(Input::isKeyDown(SDLK_4))whichend=4;
4322 if(Input::isKeyDown(SDLK_5))whichend=5;
4323 if(Input::isKeyDown(SDLK_6))whichend=6;
4324 if(Input::isKeyDown(SDLK_7))whichend=7;
4325 if(Input::isKeyDown(SDLK_8))whichend=8;
4326 if(Input::isKeyDown(SDLK_9))whichend=9;
4327 if(Input::isKeyDown(SDLK_0))whichend=0;
4328 if(Input::isKeyDown(SDLK_MINUS))whichend=-1;
4330 participantfocus[whichdialogue][indialogue]=whichend;
4331 participantlocation[whichdialogue][whichend]=player[whichend].coords;
4332 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
4335 participantfocus[whichdialogue][indialogue]=-1;
4337 if(player[participantfocus[whichdialogue][indialogue]].dead){
4342 dialoguecamera[whichdialogue][indialogue]=viewer;
4343 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
4344 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
4346 if(indialogue<numdialogueboxes[whichdialogue]){
4347 if(dialogueboxsound[whichdialogue][indialogue]!=0){
4348 static float gLoc[3];
4349 static float vel[3];
4351 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4352 temppos=temppos-viewer;
4353 Normalise(&temppos);
4358 gLoc[2]=temppos.z;vel[0]=0;
4362 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
4363 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4364 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4365 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4366 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4367 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4368 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4369 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4370 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4371 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4372 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4373 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4374 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4375 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4376 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4377 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4378 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4379 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4380 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4381 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4382 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4383 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4384 OPENAL_SetVolume(channels[whichsoundplay], 256);
4385 OPENAL_SetPaused(channels[whichsoundplay], false);
4389 for(j=0;j<numplayers;j++){
4390 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
4395 if((Input::isKeyDown(SDLK_KP1)||Input::isKeyDown(SDLK_KP2)||Input::isKeyDown(SDLK_KP3)||Input::isKeyDown(SDLK_KP4)||Input::isKeyDown(SDLK_KP5)
4396 ||Input::isKeyDown(SDLK_KP6)||Input::isKeyDown(SDLK_KP7)||Input::isKeyDown(SDLK_KP8)||Input::isKeyDown(SDLK_KP9)||Input::isKeyDown(SDLK_KP0)
4399 if(Input::isKeyDown(SDLK_KP1))whichend=1;
4400 if(Input::isKeyDown(SDLK_KP2))whichend=2;
4401 if(Input::isKeyDown(SDLK_KP3))whichend=3;
4402 if(Input::isKeyDown(SDLK_KP4))whichend=4;
4403 if(Input::isKeyDown(SDLK_KP5))whichend=5;
4404 if(Input::isKeyDown(SDLK_KP6))whichend=6;
4405 if(Input::isKeyDown(SDLK_KP7))whichend=7;
4406 if(Input::isKeyDown(SDLK_KP8))whichend=8;
4407 if(Input::isKeyDown(SDLK_KP9))whichend=9;
4408 if(Input::isKeyDown(SDLK_KP0))whichend=0;
4409 participantfacing[whichdialogue][indialogue][whichend]=facing;
4411 if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
4412 &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
4413 &&!Input::isKeyDown(SDLK_MINUS)){
4416 if(indialogue>=numdialogueboxes[whichdialogue]){
4423 OPENAL_SetPaused(channels[whooshsound], true);
4424 viewer=dialoguecamera[whichdialogue][indialogue];
4425 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
4426 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
4428 rotation=dialoguecamerarotation[whichdialogue][indialogue];
4429 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
4430 if(dialoguetime>0.5)
4431 if((!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
4432 ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
4433 ||Input::isKeyDown(SDLK_MINUS)))||(Input::isKeyDown(attackkey)&&!oldbuttondialogue)){
4436 if(indialogue<numdialogueboxes[whichdialogue]){
4437 if(dialogueboxsound[whichdialogue][indialogue]!=0){
4438 static float gLoc[3];
4439 static float vel[3];
4441 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4442 temppos=temppos-viewer;
4443 Normalise(&temppos);
4448 gLoc[2]=temppos.z;vel[0]=0;
4452 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
4453 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4454 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4455 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4456 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4457 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4458 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4459 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4460 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4461 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4462 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4463 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4464 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4465 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4466 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4467 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4468 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4469 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4470 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4471 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4472 if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
4473 if(dialogueboxsound[whichdialogue][indialogue]!=-5){
4474 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4475 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4476 OPENAL_SetVolume(channels[whichsoundplay], 256);
4477 OPENAL_SetPaused(channels[whichsoundplay], false);
4479 if(dialogueboxsound[whichdialogue][indialogue]==-5){
4480 hotspot[numhotspots]=player[0].coords;
4481 hotspotsize[numhotspots]=10;
4482 hotspottype[numhotspots]=-1;
4486 if(dialogueboxsound[whichdialogue][indialogue]==-6){
4490 if(player[participantfocus[whichdialogue][indialogue]].dead){
4498 if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
4499 &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
4500 &&!Input::isKeyDown(SDLK_MINUS)){
4503 if(indialogue>=numdialogueboxes[whichdialogue]){
4507 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
4510 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
4513 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
4515 for(i=1;i<numplayers;i++){
4516 player[i].aitype = attacktypecutoff;
4523 if(!Input::isKeyDown(attackkey))oldbuttondialogue=0;
4524 else oldbuttondialogue=1;
4526 static float keyrefreshdelay=0,bigrefreshdelay=0;
4528 if(!player[0].jumpkeydown){
4529 player[0].jumptogglekeydown=0;
4531 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
4534 dialoguetime+=multiplier;
4535 skybox.cloudmove+=multiplier;
4536 hawkrotation+=multiplier*25;
4538 realhawkcoords.x=25;
4539 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
4540 hawkcalldelay-=multiplier/2;
4542 if(hawkcalldelay<=0)
4544 static float gLoc[3];
4545 static float vel[3];
4546 gLoc[0]=realhawkcoords.x;
4547 gLoc[1]=realhawkcoords.y;
4548 gLoc[2]=realhawkcoords.z;
4552 PlaySoundEx( hawksound, samp[hawksound], NULL, true);
4553 OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
4554 OPENAL_SetVolume(channels[hawksound], 128);
4555 OPENAL_SetPaused(channels[hawksound], false);
4557 hawkcalldelay=16+abs(Random()%8);
4559 static float temptexdetail;
4562 if(Input::isKeyDown(SDLK_h)&&debugmode){
4563 player[0].damagetolerance=200000;
4566 player[0].permanentdamage=0;
4567 player[0].superpermanentdamage=0;
4570 if(Input::isKeyDown(SDLK_j)&&!envtogglekeydown&&debugmode){
4572 if(environment>2)environment=0;
4573 Setenvironment(environment);
4579 if(!Input::isKeyDown(SDLK_j)){
4583 if(Input::isKeyDown(SDLK_c)&&!cameratogglekeydown&&debugmode){
4584 cameramode=1-cameramode;
4585 cameratogglekeydown=1;
4588 if(!Input::isKeyDown(SDLK_c)){
4589 cameratogglekeydown=0;
4592 if(Input::isKeyDown(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
4593 if(player[0].num_weapons>0){
4594 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
4595 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
4596 else weapons.type[player[0].weaponids[0]]=sword;
4597 if(weapons.type[player[0].weaponids[0]]==sword){
4598 weapons.mass[player[0].weaponids[0]]=1.5;
4599 weapons.tipmass[player[0].weaponids[0]]=1;
4600 weapons.length[player[0].weaponids[0]]=.8;
4602 if(weapons.type[player[0].weaponids[0]]==staff){
4603 weapons.mass[player[0].weaponids[0]]=2;
4604 weapons.tipmass[player[0].weaponids[0]]=1;
4605 weapons.length[player[0].weaponids[0]]=1.5;
4608 if(weapons.type[player[0].weaponids[0]]==knife){
4609 weapons.mass[player[0].weaponids[0]]=1;
4610 weapons.tipmass[player[0].weaponids[0]]=1.2;
4611 weapons.length[player[0].weaponids[0]]=.25;
4614 detailtogglekeydown=1;
4617 if(Input::isKeyDown(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
4619 float closestdist=-1;
4622 for(i=1;i<numplayers;i++){
4623 distance=findDistancefast(&player[i].coords,&player[0].coords);
4624 if(closestdist==-1||distance<closestdist){
4625 closestdist=distance;
4630 if(player[closest].num_weapons)
4632 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
4633 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
4634 else weapons.type[player[closest].weaponids[0]]=sword;
4635 if(weapons.type[player[closest].weaponids[0]]==sword){
4636 weapons.mass[player[closest].weaponids[0]]=1.5;
4637 weapons.tipmass[player[closest].weaponids[0]]=1;
4638 weapons.length[player[closest].weaponids[0]]=.8;
4640 if(weapons.type[player[0].weaponids[0]]==staff){
4641 weapons.mass[player[0].weaponids[0]]=2;
4642 weapons.tipmass[player[0].weaponids[0]]=1;
4643 weapons.length[player[0].weaponids[0]]=1.5;
4645 if(weapons.type[player[closest].weaponids[0]]==knife){
4646 weapons.mass[player[closest].weaponids[0]]=1;
4647 weapons.tipmass[player[closest].weaponids[0]]=1.2;
4648 weapons.length[player[closest].weaponids[0]]=.25;
4651 if(!player[closest].num_weapons)
4653 player[closest].weaponids[0]=weapons.numweapons;
4654 weapons.owner[weapons.numweapons]=closest;
4655 weapons.type[weapons.numweapons]=knife;
4656 weapons.damage[weapons.numweapons]=0;
4657 weapons.numweapons++;
4658 player[closest].num_weapons=1;
4659 if(weapons.type[player[closest].weaponids[0]]==sword){
4660 weapons.mass[player[closest].weaponids[0]]=1.5;
4661 weapons.tipmass[player[closest].weaponids[0]]=1;
4662 weapons.length[player[closest].weaponids[0]]=.8;
4664 if(weapons.type[player[closest].weaponids[0]]==knife){
4665 weapons.mass[player[closest].weaponids[0]]=1;
4666 weapons.tipmass[player[closest].weaponids[0]]=1.2;
4667 weapons.length[player[closest].weaponids[0]]=.25;
4671 detailtogglekeydown=1;
4674 if(Input::isKeyDown(SDLK_u)&&debugmode){
4676 float closestdist=-1;
4679 for(i=1;i<numplayers;i++){
4680 distance=findDistancefast(&player[i].coords,&player[0].coords);
4681 if(closestdist==-1||distance<closestdist){
4682 closestdist=distance;
4687 player[closest].rotation+=multiplier*50;
4688 player[closest].targetrotation=player[closest].rotation;
4692 if(Input::isKeyDown(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4694 float closestdist=-1;
4697 for(i=1;i<numplayers;i++){
4698 distance=findDistancefast(&player[i].coords,&player[0].coords);
4699 if(closestdist==-1||distance<closestdist){
4700 closestdist=distance;
4704 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
4707 player[closest].whichskin++;
4708 if(player[closest].whichskin>9)player[closest].whichskin=0;
4709 if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
4711 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
4712 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4715 if(player[closest].numclothes){
4716 for(i=0;i<player[closest].numclothes;i++){
4717 tintr=player[closest].clothestintr[i];
4718 tintg=player[closest].clothestintg[i];
4719 tintb=player[closest].clothestintb[i];
4720 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4722 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
4725 detailtogglekeydown=1;
4728 if(Input::isKeyDown(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4730 float closestdist=-1;
4733 for(i=1;i<numplayers;i++){
4734 distance=findDistancefast(&player[i].coords,&player[0].coords);
4735 if(closestdist==-1||distance<closestdist){
4736 closestdist=distance;
4741 if(player[closest].creature==wolftype){
4742 headprop=player[closest].proportionhead.x/1.1;
4743 bodyprop=player[closest].proportionbody.x/1.1;
4744 armprop=player[closest].proportionarms.x/1.1;
4745 legprop=player[closest].proportionlegs.x/1.1;
4748 if(player[closest].creature==rabbittype){
4749 headprop=player[closest].proportionhead.x/1.2;
4750 bodyprop=player[closest].proportionbody.x/1.05;
4751 armprop=player[closest].proportionarms.x/1.00;
4752 legprop=player[closest].proportionlegs.x/1.1;
4756 if(player[closest].creature==rabbittype){
4757 player[closest].skeleton.id=closest;
4758 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);
4759 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
4760 player[closest].whichskin=0;
4761 player[closest].creature=wolftype;
4763 player[closest].proportionhead=1.1;
4764 player[closest].proportionbody=1.1;
4765 player[closest].proportionarms=1.1;
4766 player[closest].proportionlegs=1.1;
4767 player[closest].proportionlegs.y=1.1;
4768 player[closest].scale=.23*5*player[0].scale;
4770 player[closest].damagetolerance=300;
4774 player[closest].skeleton.id=closest;
4775 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);
4776 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
4777 player[closest].whichskin=0;
4778 player[closest].creature=rabbittype;
4780 player[closest].proportionhead=1.2;
4781 player[closest].proportionbody=1.05;
4782 player[closest].proportionarms=1.00;
4783 player[closest].proportionlegs=1.1;
4784 player[closest].proportionlegs.y=1.05;
4785 player[closest].scale=.2*5*player[0].scale;
4787 player[closest].damagetolerance=200;
4790 if(player[closest].creature==wolftype){
4791 player[closest].proportionhead=1.1*headprop;
4792 player[closest].proportionbody=1.1*bodyprop;
4793 player[closest].proportionarms=1.1*armprop;
4794 player[closest].proportionlegs=1.1*legprop;
4797 if(player[closest].creature==rabbittype){
4798 player[closest].proportionhead=1.2*headprop;
4799 player[closest].proportionbody=1.05*bodyprop;
4800 player[closest].proportionarms=1.00*armprop;
4801 player[closest].proportionlegs=1.1*legprop;
4802 player[closest].proportionlegs.y=1.05*legprop;
4806 detailtogglekeydown=1;
4809 if(!Input::isKeyDown(SDLK_x)){
4810 detailtogglekeydown=0;
4813 if(Input::isKeyDown(SDLK_b)&&!slomotogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
4816 slomotogglekeydown=1;
4820 if(((Input::isKeyDown(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
4822 float closestdist=-1;
4824 XYZ flatfacing2,flatvelocity2;
4827 for(i=1;i<numplayers;i++){
4828 distance=findDistancefast(&player[i].coords,&player[0].coords);
4829 if(distance<144&&!player[i].headless)
4830 if(closestdist==-1||distance<closestdist){
4831 closestdist=distance;
4833 blah = player[i].coords;
4838 XYZ headspurtdirection;
4839 int i = player[closest].skeleton.jointlabels[head];
4840 for(k=0;k<player[closest].skeleton.num_joints; k++){
4841 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4842 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4843 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;
4844 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4845 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4846 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4847 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4848 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
4849 Normalise(&headspurtdirection);
4850 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
4851 flatvelocity2+=headspurtdirection*8;
4852 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
4854 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
4864 PlaySoundEx( splattersound, samp[splattersound], NULL, true);
4865 OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
4866 OPENAL_SetVolume(channels[splattersound], 256);
4867 OPENAL_SetPaused(channels[splattersound], false);
4869 PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
4870 OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
4871 OPENAL_SetVolume(channels[breaksound2], 100);
4872 OPENAL_SetPaused(channels[breaksound2], false);
4874 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
4875 player[closest].RagDoll(0);
4876 player[closest].dead=2;
4877 player[closest].headless=1;
4878 player[closest].DoBloodBig(3,165);
4883 explodetogglekeydown=1;
4886 if(((Input::isKeyDown(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
4888 float closestdist=-1;
4890 XYZ flatfacing2,flatvelocity2;
4893 for(i=1;i<numplayers;i++){
4894 distance=findDistancefast(&player[i].coords,&player[0].coords);
4896 if(closestdist==-1||distance<closestdist){
4897 closestdist=distance;
4899 blah=player[i].coords;
4913 PlaySoundEx( splattersound, samp[splattersound], NULL, true);
4914 OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
4915 OPENAL_SetVolume(channels[splattersound], 256);
4916 OPENAL_SetPaused(channels[splattersound], false);
4918 PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
4919 OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
4920 OPENAL_SetVolume(channels[breaksound2], 600);
4921 OPENAL_SetPaused(channels[breaksound2], false);
4923 for(i=0;i<player[closest].skeleton.num_joints; i++){
4924 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4925 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4926 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;
4927 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4928 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4929 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4930 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4931 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
4932 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
4933 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
4936 for(i=0;i<player[closest].skeleton.num_joints; i++){
4937 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4938 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4939 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;
4940 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4941 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4942 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4943 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4944 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
4945 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
4948 for(i=0;i<player[closest].skeleton.num_joints; i++){
4949 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4950 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4951 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;
4952 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4953 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4954 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4955 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4956 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
4957 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
4960 for(i=0;i<player[closest].skeleton.num_joints; i++){
4961 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
4962 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
4963 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;
4964 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
4965 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
4966 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
4967 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
4968 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
4969 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
4973 for(j=0;j<numplayers; j++){
4975 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
4976 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
4977 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
4978 player[j].skeleton.longdead=0;
4979 player[j].RagDoll(0);
4980 for(i=0;i<player[j].skeleton.num_joints; i++){
4981 temppos=player[j].skeleton.joints[i].position+player[j].coords;
4982 if(findDistancefast(&temppos,&player[closest].coords)<25){
4983 flatvelocity2=temppos-player[closest].coords;
4984 Normalise(&flatvelocity2);
4985 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
4992 player[closest].DoDamage(10000);
4993 player[closest].RagDoll(0);
4994 player[closest].dead=2;
4995 player[closest].coords=20;
4996 player[closest].skeleton.free=2;
5002 explodetogglekeydown=1;
5005 if(!Input::isKeyDown(SDLK_i)){
5006 explodetogglekeydown=0;
5009 if(!Input::isKeyDown(SDLK_b)&&!Input::isKeyDown(SDLK_f)&&!Input::isKeyDown(SDLK_k)&&!Input::isKeyDown(SDLK_s)){
5010 slomotogglekeydown=0;
5014 if(Input::isKeyDown(SDLK_f)&&!slomotogglekeydown&&debugmode){
5015 player[0].onfire=1-player[0].onfire;
5016 if(player[0].onfire){
5017 player[0].CatchFire();
5019 if(!player[0].onfire){
5022 gLoc[0]=player[0].coords.x;
5023 gLoc[1]=player[0].coords.y;
5024 gLoc[2]=player[0].coords.z;
5028 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5029 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5030 OPENAL_SetVolume(channels[fireendsound], 256);
5031 OPENAL_SetPaused(channels[fireendsound], false);
5032 OPENAL_SetPaused(channels[stream_firesound], true);
5034 slomotogglekeydown=1;
5037 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)){
5039 float closestdist=-1;
5042 for(i=1;i<numplayers;i++){
5043 distance=findDistancefast(&player[i].coords,&player[0].coords);
5044 if(closestdist==-1||distance<closestdist){
5045 closestdist=distance;
5049 if(closestdist>0&&closest>=0){
5050 //player[closest]=player[numplayers-1];
5051 //player[closest].skeleton=player[numplayers-1].skeleton;
5054 drawmodetogglekeydown=1;
5057 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)){
5059 float closestdist=-1;
5062 for(i=1;i<max_objects;i++){
5063 distance=findDistancefast(&objects.position[i],&player[0].coords);
5064 if(closestdist==-1||distance<closestdist){
5065 closestdist=distance;
5069 if(closestdist>0&&closest>=0){
5070 objects.position[closest].y-=500;
5072 drawmodetogglekeydown=1;
5075 if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&editorenabled&&debugmode){
5077 //if(drawmode>2)drawmode=0;
5078 if(objects.numobjects<max_objects-1){
5080 boxcoords.x=player[0].coords.x;
5081 boxcoords.z=player[0].coords.z;
5082 boxcoords.y=player[0].coords.y-3;
5083 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
5084 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
5085 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
5086 float temprotat,temprotat2;
5087 temprotat=editorrotation;
5088 temprotat2=editorrotation2;
5089 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
5090 if(temprotat2<0)temprotat2=Random()%360;
5092 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
5093 if(editortype==treetrunktype)
5094 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
5097 drawmodetogglekeydown=1;
5100 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
5101 if(numplayers<maxplayers-1){
5102 player[numplayers].scale=.2*5*player[0].scale;
5103 player[numplayers].creature=rabbittype;
5104 player[numplayers].howactive=editoractive;
5105 player[numplayers].skeleton.id=numplayers;
5106 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);
5108 //texsize=512*512*3/texdetail/texdetail;
5109 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
5110 //player[numplayers].skeleton.skinText.resize(texsize);
5112 k=abs(Random()%2)+1;
5114 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
5115 player[numplayers].whichskin=0;
5118 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
5119 player[numplayers].whichskin=1;
5122 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
5123 player[numplayers].whichskin=2;
5126 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
5127 player[numplayers].power=1;
5128 player[numplayers].speedmult=1;
5129 player[numplayers].currentanimation=bounceidleanim;
5130 player[numplayers].targetanimation=bounceidleanim;
5131 player[numplayers].currentframe=0;
5132 player[numplayers].targetframe=1;
5133 player[numplayers].target=0;
5134 player[numplayers].bled=0;
5135 player[numplayers].speed=1+(float)(Random()%100)/1000;
5137 player[numplayers].targetrotation=player[0].targetrotation;
5138 player[numplayers].rotation=player[0].rotation;
5140 player[numplayers].velocity=0;
5141 player[numplayers].coords=player[0].coords;
5142 player[numplayers].oldcoords=player[numplayers].coords;
5143 player[numplayers].realoldcoords=player[numplayers].coords;
5145 player[numplayers].id=numplayers;
5146 player[numplayers].skeleton.id=numplayers;
5147 player[numplayers].updatedelay=0;
5148 player[numplayers].normalsupdatedelay=0;
5150 player[numplayers].aitype=passivetype;
5151 player[numplayers].aitarget=0;
5153 if(player[0].creature==wolftype){
5154 headprop=player[0].proportionhead.x/1.1;
5155 bodyprop=player[0].proportionbody.x/1.1;
5156 armprop=player[0].proportionarms.x/1.1;
5157 legprop=player[0].proportionlegs.x/1.1;
5160 if(player[0].creature==rabbittype){
5161 headprop=player[0].proportionhead.x/1.2;
5162 bodyprop=player[0].proportionbody.x/1.05;
5163 armprop=player[0].proportionarms.x/1.00;
5164 legprop=player[0].proportionlegs.x/1.1;
5167 if(player[numplayers].creature==wolftype){
5168 player[numplayers].proportionhead=1.1*headprop;
5169 player[numplayers].proportionbody=1.1*bodyprop;
5170 player[numplayers].proportionarms=1.1*armprop;
5171 player[numplayers].proportionlegs=1.1*legprop;
5174 if(player[numplayers].creature==rabbittype){
5175 player[numplayers].proportionhead=1.2*headprop;
5176 player[numplayers].proportionbody=1.05*bodyprop;
5177 player[numplayers].proportionarms=1.00*armprop;
5178 player[numplayers].proportionlegs=1.1*legprop;
5179 player[numplayers].proportionlegs.y=1.05*legprop;
5182 player[numplayers].headless=0;
5183 player[numplayers].onfire=0;
5186 player[numplayers].proportionhead.z=0;
5187 player[numplayers].proportionbody.z=0;
5188 player[numplayers].proportionarms.z=0;
5189 player[numplayers].proportionlegs.z=0;
5192 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
5194 player[numplayers].damagetolerance=200;
5196 player[numplayers].protectionhead=player[0].protectionhead;
5197 player[numplayers].protectionhigh=player[0].protectionhigh;
5198 player[numplayers].protectionlow=player[0].protectionlow;
5199 player[numplayers].armorhead=player[0].armorhead;
5200 player[numplayers].armorhigh=player[0].armorhigh;
5201 player[numplayers].armorlow=player[0].armorlow;
5202 player[numplayers].metalhead=player[0].metalhead;
5203 player[numplayers].metalhigh=player[0].metalhigh;
5204 player[numplayers].metallow=player[0].metallow;
5206 player[numplayers].immobile=player[0].immobile;
5208 player[numplayers].numclothes=player[0].numclothes;
5209 if(player[numplayers].numclothes)
5210 for(i=0;i<player[numplayers].numclothes;i++){
5211 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
5212 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
5213 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
5214 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
5215 tintr=player[numplayers].clothestintr[i];
5216 tintg=player[numplayers].clothestintg[i];
5217 tintb=player[numplayers].clothestintb[i];
5218 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
5220 if(player[numplayers].numclothes){
5221 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
5224 player[numplayers].power=player[0].power;
5225 player[numplayers].speedmult=player[0].speedmult;
5227 player[numplayers].damage=0;
5228 player[numplayers].permanentdamage=0;
5229 player[numplayers].superpermanentdamage=0;
5230 player[numplayers].deathbleeding=0;
5231 player[numplayers].bleeding=0;
5232 player[numplayers].numwaypoints=0;
5233 player[numplayers].waypoint=0;
5234 player[numplayers].jumppath=0;
5235 player[numplayers].weaponstuck=-1;
5236 player[numplayers].weaponactive=-1;
5237 player[numplayers].num_weapons=0;
5238 player[numplayers].bloodloss=0;
5239 player[numplayers].dead=0;
5241 player[numplayers].loaded=1;
5245 drawmodetogglekeydown=1;
5248 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&editorenabled){
5249 if(player[numplayers-1].numwaypoints<90){
5250 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
5251 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
5252 player[numplayers-1].numwaypoints++;
5254 drawmodetogglekeydown=1;
5257 if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
5258 if(numpathpoints<30){
5259 bool connected,alreadyconnected;
5262 for(i=0;i<numpathpoints;i++){
5263 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
5265 for(j=0;j<numpathpointconnect[pathpointselected];j++){
5266 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
5268 if(!alreadyconnected){
5269 numpathpointconnect[pathpointselected]++;
5271 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
5277 pathpoint[numpathpoints-1]=player[0].coords;
5278 numpathpointconnect[numpathpoints-1]=0;
5279 if(numpathpoints>1&&pathpointselected!=-1){
5280 numpathpointconnect[pathpointselected]++;
5281 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
5283 pathpointselected=numpathpoints-1;
5286 drawmodetogglekeydown=1;
5289 if(Input::isKeyDown(SDLK_PERIOD)&&!drawmodetogglekeydown&&editorenabled){
5290 pathpointselected++;
5291 if(pathpointselected>=numpathpoints)pathpointselected=-1;
5292 drawmodetogglekeydown=1;
5294 if(Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
5295 pathpointselected--;
5296 if(pathpointselected<=-2)
5297 pathpointselected=numpathpoints-1;
5298 drawmodetogglekeydown=1;
5300 if(Input::isKeyDown(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
5301 if(pathpointselected!=-1){
5303 pathpoint[pathpointselected]=pathpoint[numpathpoints];
5304 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
5305 for(i=0;i<numpathpointconnect[pathpointselected];i++){
5306 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
5308 for(i=0;i<numpathpoints;i++){
5309 for(j=0;j<numpathpointconnect[i];j++){
5310 if(pathpointconnect[i][j]==pathpointselected){
5311 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
5312 numpathpointconnect[i]--;
5314 if(pathpointconnect[i][j]==numpathpoints){
5315 pathpointconnect[i][j]=pathpointselected;
5319 pathpointselected=numpathpoints-1;
5321 drawmodetogglekeydown=1;
5324 if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
5325 editorenabled=1-editorenabled;
5327 player[0].damagetolerance=100000;
5329 player[0].damagetolerance=200;
5331 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
5332 player[0].permanentdamage=0;
5333 player[0].superpermanentdamage=0;
5334 player[0].bloodloss=0;
5335 player[0].deathbleeding=0;
5336 drawmodetogglekeydown=1;
5339 if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5341 if(editortype==treeleavestype||editortype==10)editortype--;
5342 if(editortype<0)editortype=firetype;
5343 drawmodetogglekeydown=1;
5346 if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5348 if(editortype==treeleavestype||editortype==10)editortype++;
5349 if(editortype>firetype)editortype=0;
5350 drawmodetogglekeydown=1;
5353 if(Input::isKeyDown(SDLK_LEFT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5354 editorrotation-=multiplier*100;
5355 if(editorrotation<-.01)editorrotation=-.01;
5356 drawmodetogglekeydown=1;
5359 if(Input::isKeyDown(SDLK_RIGHT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
5360 editorrotation+=multiplier*100;
5361 drawmodetogglekeydown=1;
5364 if(Input::isKeyDown(SDLK_UP)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
5365 editorsize+=multiplier;
5366 drawmodetogglekeydown=1;
5369 if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
5370 editorsize-=multiplier;
5371 if(editorsize<.1)editorsize=.1;
5372 drawmodetogglekeydown=1;
5376 if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
5377 mapradius-=multiplier*10;
5380 if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
5381 mapradius+=multiplier*10;
5383 if(Input::isKeyDown(SDLK_UP)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
5384 editorrotation2+=multiplier*100;
5387 if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
5388 editorrotation2-=multiplier*100;
5389 if(editorrotation2<-.01)editorrotation2=-.01;
5391 if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)){
5393 float closestdist=-1;
5395 for(i=0;i<objects.numobjects;i++){
5396 distance=findDistancefast(&objects.position[i],&player[0].coords);
5397 if(closestdist==-1||distance<closestdist){
5398 closestdist=distance;
5402 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
5403 drawmodetogglekeydown=1;
5407 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)){
5408 drawmodetogglekeydown=0;
5411 if(Input::isKeyDown(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
5412 //if(!player[0].skeleton.free)player[0].damage+=500;
5413 player[0].RagDoll(0);
5414 //player[0].spurt=1;
5415 //player[0].DoDamage(1000);
5419 gLoc[0]=player[0].coords.x;
5420 gLoc[1]=player[0].coords.y;
5421 gLoc[2]=player[0].coords.z;
5422 vel[0]=player[0].velocity.x;
5423 vel[1]=player[0].velocity.y;
5424 vel[2]=player[0].velocity.z;
5425 PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
5426 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
5427 OPENAL_SetVolume(channels[whooshsound], 128);
5428 OPENAL_SetPaused(channels[whooshsound], false);
5429 //OPENAL_SetPaused(channels[whooshsound], true);
5431 texturesizetogglekeydown=1;
5434 if(Input::isKeyDown(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
5437 float closestdist=-1;
5439 for(i=0;i<objects.numobjects;i++){
5440 if(objects.type[i]==treeleavestype){
5441 objects.scale[i]*=.9;
5444 texturesizetogglekeydown=1;
5447 static XYZ relative;
5448 static int randattack;
5450 static bool playerrealattackkeydown=0;
5452 if(!Input::isKeyDown(MOUSEBUTTON1)&&!Input::isKeyDown(MOUSEBUTTON2))oldbutton=0;
5453 if(!Input::isKeyDown(attackkey))oldattackkey=0;
5454 if(oldattackkey)player[0].attackkeydown=0;
5455 if(oldattackkey)playerrealattackkeydown=0;
5456 if(!oldattackkey)playerrealattackkeydown=Input::isKeyDown(attackkey);
5457 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);
5458 if(Input::isKeyDown(attackkey)&&!oldattackkey&&!player[0].backkeydown){
5459 for(k=0;k<numplayers;k++){
5460 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
5461 player[k].Reverse();
5465 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
5467 for(k=0;k<numplayers;k++){
5468 if(indialogue!=-1)player[k].attackkeydown=0;
5469 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
5470 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
5471 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)){
5472 player[k].jumppower-=2;
5474 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)){
5475 for(i=0;i<numplayers;i++){
5477 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
5478 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
5479 player[k].targetanimation=dodgebackanim;
5481 player[k].targetframe=0;
5482 rotatetarget=player[i].coords-player[k].coords;
5483 Normalise(&rotatetarget);
5484 player[k].targetrotation=-asin(0-rotatetarget.x);
5485 player[k].targetrotation*=360/6.28;
5486 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5488 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
5491 if(player[k].targetanimation!=dodgebackanim){
5492 if(k==0)numflipped++;
5493 player[k].targetanimation=backhandspringanim;
5495 player[k].targetframe=0;
5496 player[k].targetrotation=-rotation+180;
5497 if(player[k].leftkeydown)player[k].targetrotation-=45;
5498 if(player[k].rightkeydown)player[k].targetrotation+=45;
5499 player[k].rotation=player[k].targetrotation;
5500 player[k].jumppower-=2;
5503 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())){
5504 player[k].hasvictim=0;
5506 for(i=0;i<numplayers;i++){
5508 if(!player[k].hasvictim)
5509 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
5510 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){
5511 player[k].victim=&player[i];
5512 player[k].hasvictim=1;
5513 if(player[k].aitype==playercontrolled){
5514 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;
5515 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;
5516 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;
5517 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;
5518 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;
5519 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;
5520 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;
5521 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;
5522 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;
5523 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;
5526 if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
5527 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
5528 else randattack=abs(Random()%5);
5529 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
5530 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
5531 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
5532 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
5533 else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
5535 if(player[k].weaponactive!=-1){
5536 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;
5537 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;
5538 //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;
5539 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;
5540 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;
5541 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;
5542 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;
5543 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;
5547 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
5549 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)){
5550 if(player[k].weaponactive==-1){
5551 player[i].targetanimation=sneakattackedanim;
5552 player[i].currentanimation=sneakattackedanim;
5553 player[k].currentanimation=sneakattackanim;
5554 player[k].targetanimation=sneakattackanim;
5555 player[k].oldcoords=player[k].coords;
5556 player[k].coords=player[i].coords;
5558 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
5559 player[i].targetanimation=knifesneakattackedanim;
5560 player[i].currentanimation=knifesneakattackedanim;
5561 player[k].currentanimation=knifesneakattackanim;
5562 player[k].targetanimation=knifesneakattackanim;
5563 player[i].oldcoords=player[i].coords;
5564 player[i].coords=player[k].coords;
5566 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
5567 player[i].targetanimation=swordsneakattackedanim;
5568 player[i].currentanimation=swordsneakattackedanim;
5569 player[k].currentanimation=swordsneakattackanim;
5570 player[k].targetanimation=swordsneakattackanim;
5571 player[i].oldcoords=player[i].coords;
5572 player[i].coords=player[k].coords;
5574 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
5575 player[k].victim=&player[i];
5576 player[k].hasvictim=1;
5577 player[i].targettilt2=0;
5578 player[i].targetframe=1;
5579 player[i].currentframe=0;
5581 player[i].velocity=0;
5582 player[k].targettilt2=player[i].targettilt2;
5583 player[k].currentframe=player[i].currentframe;
5584 player[k].targetframe=player[i].targetframe;
5585 player[k].target=player[i].target;
5586 player[k].velocity=0;
5587 player[k].targetrotation=player[i].rotation;
5588 player[k].rotation=player[i].rotation;
5589 player[i].targetrotation=player[i].rotation;
5592 if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
5594 player[k].targetframe=0;
5596 //player[k].velocity=0;
5598 rotatetarget=player[i].coords-player[k].coords;
5599 Normalise(&rotatetarget);
5600 player[k].targetrotation=-asin(0-rotatetarget.x);
5601 player[k].targetrotation*=360/6.28;
5602 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5604 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5606 player[k].lastattack3=player[k].lastattack2;
5607 player[k].lastattack2=player[k].lastattack;
5608 player[k].lastattack=player[k].targetanimation;
5609 //player[k].targettilt2=0;
5613 if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
5614 rotatetarget=player[i].coords-player[k].coords;
5615 Normalise(&rotatetarget);
5616 player[k].targetrotation=-asin(0-rotatetarget.x);
5617 player[k].targetrotation*=360/6.28;
5618 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5619 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5621 player[k].victim=&player[i];
5622 player[k].hasvictim=1;
5623 player[i].targetanimation=knifefollowedanim;
5624 player[i].currentanimation=knifefollowedanim;
5625 player[i].targettilt2=0;
5626 player[i].targettilt2=player[k].targettilt2;
5627 player[i].targetframe=1;
5628 player[i].currentframe=0;
5630 player[i].velocity=0;
5631 player[k].currentanimation=knifefollowanim;
5632 player[k].targetanimation=knifefollowanim;
5633 player[k].targettilt2=player[i].targettilt2;
5634 player[k].currentframe=player[i].currentframe;
5635 player[k].targetframe=player[i].targetframe;
5636 player[k].target=player[i].target;
5637 player[k].velocity=0;
5638 player[k].oldcoords=player[k].coords;
5639 player[i].coords=player[k].coords;
5640 player[i].targetrotation=player[k].targetrotation;
5641 player[i].rotation=player[k].targetrotation;
5642 player[k].rotation=player[k].targetrotation;
5643 player[i].rotation=player[k].targetrotation;
5648 if(player[k].weaponactive!=-1){
5649 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
5652 for(i=0;i<numplayers;i++){
5654 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
5655 if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
5656 if(player[i].skeleton.free)
5657 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)))){
5658 player[k].victim=&player[i];
5659 player[k].hasvictim=1;
5660 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
5661 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;
5662 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;
5663 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;
5665 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){
5666 player[k].targetanimation=killanim;
5667 for(j=0;j<terrain.numdecals;j++){
5668 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
5669 terrain.DeleteDecal(j);
5672 for(l=0;l<objects.numobjects;l++){
5673 if(objects.model[l].type==decalstype)
5674 for(j=0;j<objects.model[l].numdecals;j++){
5675 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
5676 objects.model[l].DeleteDecal(j);
5681 if(!player[i].dead||musictype!=2)
5682 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)){
5683 player[k].targetanimation=dropkickanim;
5684 for(j=0;j<terrain.numdecals;j++){
5685 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
5686 terrain.DeleteDecal(j);
5689 for(l=0;l<objects.numobjects;l++){
5690 if(objects.model[l].type==decalstype)
5691 for(j=0;j<objects.model[l].numdecals;j++){
5692 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
5693 objects.model[l].DeleteDecal(j);
5699 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)){
5701 player[k].targetframe=0;
5703 //player[k].velocity=0;
5705 rotatetarget=player[i].coords-player[k].coords;
5706 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
5707 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;
5709 Normalise(&rotatetarget);
5710 player[k].targetrotation=-asin(0-rotatetarget.x);
5711 player[k].targetrotation*=360/6.28;
5712 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
5714 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
5715 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
5718 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
5719 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
5721 player[k].lastattack3=player[k].lastattack2;
5722 player[k].lastattack2=player[k].lastattack;
5723 player[k].lastattack=player[k].targetanimation;
5725 if(player[k].targetanimation==swordgroundstabanim){
5726 player[k].targetrotation+=30;
5728 //player[k].targettilt2=0;
5734 if(!player[k].hasvictim){
5735 for(i=0;i<numplayers;i++){
5736 if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
5737 player[k].victim=&player[i];
5738 player[k].hasvictim=1;
5740 if(player[k].hasvictim&&!player[i].skeleton.free)
5741 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
5742 player[k].victim=&player[i];
5746 if(player[k].aitype==playercontrolled)
5747 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)){
5749 player[k].targetanimation=rabbitkickanim;
5750 player[k].targetframe=0;
5753 if(animation[player[k].targetanimation].attack&&k==0){
5756 if(player[k].weaponactive!=-1){
5757 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
5760 if(player[k].weaponactive!=-1){
5761 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
5764 if(player[k].weaponactive!=-1){
5765 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
5767 if(armedstaff)numstaffattack++;
5768 else if(armedsword)numswordattack++;
5769 else if(armedknife)numknifeattack++;
5770 else numunarmedattack++;
5777 static float collisionradius;
5779 for(k=0;k<numplayers;k++){
5780 for(i=k;i<numplayers;i++){
5783 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))
5784 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))
5785 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
5786 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
5787 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)
5788 if(player[i].coords.y>player[k].coords.y-3)
5789 if(player[i].coords.y<player[k].coords.y+3)
5790 if(player[i].coords.x>player[k].coords.x-3)
5791 if(player[i].coords.x<player[k].coords.x+3)
5792 if(player[i].coords.z>player[k].coords.z-3)
5793 if(player[i].coords.z<player[k].coords.z+3){
5794 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)){
5795 if(player[i].onfire||player[k].onfire){
5796 if(!player[i].onfire)player[i].CatchFire();
5797 if(!player[k].onfire)player[k].CatchFire();
5801 tempcoords1=player[i].coords;
5802 tempcoords2=player[k].coords;
5803 if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
5804 if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
5805 collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
5806 if(player[0].hasvictim)
5807 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
5808 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
5810 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)){
5811 player[k].coords.y=player[i].coords.y;
5812 player[i].velocity=player[k].velocity;
5813 player[i].skeleton.free=0;
5814 player[i].rotation=0;
5815 player[i].RagDoll(0);
5816 player[i].DoDamage(20);
5817 if(k==0)camerashake+=.3;
5818 player[i].skeleton.longdead=0;
5819 player[k].lastcollide=1;
5822 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)){
5823 player[i].coords.y=player[k].coords.y;
5824 player[k].velocity=player[i].velocity;
5825 player[k].skeleton.free=0;
5826 player[k].rotation=0;
5827 player[k].RagDoll(0);
5828 player[k].DoDamage(20);
5829 if(i==0)camerashake+=.3;
5830 player[k].skeleton.longdead=0;
5831 player[i].lastcollide=1;
5834 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)){
5835 rotatetarget=player[k].velocity-player[i].velocity;
5836 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))
5837 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))){
5839 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)){
5840 static float gLoc[3];
5841 static float vel[3];
5842 gLoc[0]=player[i].coords.x;
5843 gLoc[1]=player[i].coords.y;
5844 gLoc[2]=player[i].coords.z;
5845 vel[0]=player[i].velocity.x;
5846 vel[1]=player[i].velocity.y;
5847 vel[2]=player[i].velocity.z;
5848 if(tutoriallevel!=1){
5849 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
5850 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
5851 OPENAL_SetVolume(channels[heavyimpactsound], 256);
5852 OPENAL_SetPaused(channels[heavyimpactsound], false);
5854 //player[i].velocity=player[k].velocity;
5855 //player[k].velocity=player[i].velocity;
5857 player[i].RagDoll(0);
5858 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
5863 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
5864 player[k].RagDoll(0);
5865 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
5870 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
5872 //if(player[i].skeleton.oldfree){
5873 for(j=0;j<player[i].skeleton.num_joints;j++){
5874 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
5877 //if(player[k].skeleton.oldfree){
5878 for(j=0;j<player[k].skeleton.num_joints;j++){
5879 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
5885 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)){
5887 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
5888 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)){
5889 rotatetarget=player[k].coords-player[i].coords;
5890 Normalise(&rotatetarget);
5891 player[k].coords=(player[k].coords+player[i].coords)/2;
5892 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);
5893 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
5894 if(player[k].howactive==typeactive||hostile)
5895 if(player[k].isIdle()){
5896 if(player[k].howactive<typesleeping){
5897 player[k].targetanimation=player[k].getStop();
5898 player[k].targetframe=0;
5901 else if(player[k].howactive==typesleeping)
5903 player[k].targetanimation=getupfromfrontanim;
5904 player[k].targetframe=0;
5907 if(!editorenabled)player[k].howactive=typeactive;
5909 if(player[i].howactive==typeactive||hostile)
5910 if(player[i].isIdle()){
5911 if(player[i].howactive<typesleeping){
5912 player[i].targetanimation=player[i].getStop();
5913 player[i].targetframe=0;
5918 player[i].targetanimation=getupfromfrontanim;
5919 player[i].targetframe=0;
5922 if(!editorenabled)player[i].howactive=typeactive;
5926 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){
5927 player[i].velocity=player[k].velocity;
5928 player[k].velocity=player[k].velocity*-.5;
5929 //player[i].velocity.y-=10;
5930 player[k].velocity.y=player[i].velocity.y;
5931 player[i].DoDamage(20);
5932 player[i].RagDoll(0);
5933 player[k].lastcollide=1;
5940 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){
5941 player[k].velocity=player[i].velocity;
5942 player[i].velocity=player[i].velocity*-.3;
5943 //player[k].velocity.y-=10;
5944 player[i].velocity.y=player[k].velocity.y;
5945 player[k].DoDamage(20);
5946 player[k].RagDoll(0);
5947 player[i].lastcollide=1;
5958 player[i].CheckKick();
5959 player[k].CheckKick();
5965 for(k=0;k<numplayers;k++){
5966 for(i=k;i<numplayers;i++){
5968 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))){
5969 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)){
5970 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)){
5971 player[i].victim=&player[k];
5972 player[i].targetanimation=jumpreversedanim;
5973 player[i].currentanimation=jumpreversedanim;
5974 player[k].currentanimation=jumpreversalanim;
5975 player[k].targetanimation=jumpreversalanim;
5976 player[i].targettilt2=0;
5977 player[i].currentframe=0;
5978 player[i].targetframe=1;
5979 player[k].currentframe=0;
5980 player[k].targetframe=1;
5981 if(player[i].coords.y<player[k].coords.y+1){
5982 player[i].targetanimation=rabbitkickreversedanim;
5983 player[i].currentanimation=rabbitkickreversedanim;
5984 player[k].currentanimation=rabbitkickreversalanim;
5985 player[k].targetanimation=rabbitkickreversalanim;
5986 player[k].currentframe=1;
5987 player[k].targetframe=2;
5988 player[i].currentframe=1;
5989 player[i].targetframe=2;
5991 player[k].targettilt2=0;
5993 player[i].velocity=0;
5994 player[k].velocity=0;
5995 player[k].oldcoords=player[k].coords;
5996 player[i].coords=player[k].coords;
5997 player[k].targetrotation=player[i].targetrotation;
5998 player[k].rotation=player[i].targetrotation;
5999 player[k].victim=&player[i];
6000 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
6002 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)){
6003 player[k].victim=&player[i];
6004 player[k].targetanimation=jumpreversedanim;
6005 player[k].currentanimation=jumpreversedanim;
6006 player[i].currentanimation=jumpreversalanim;
6007 player[i].targetanimation=jumpreversalanim;
6008 player[k].targettilt2=0;
6009 player[i].targettilt2=0;
6010 player[k].currentframe=0;
6011 player[k].targetframe=1;
6012 player[i].currentframe=0;
6013 player[i].targetframe=1;
6014 if(player[k].coords.y<player[i].coords.y+1){
6015 player[k].targetanimation=rabbitkickreversedanim;
6016 player[k].currentanimation=rabbitkickreversedanim;
6017 player[i].currentanimation=rabbitkickreversalanim;
6018 player[i].targetanimation=rabbitkickreversalanim;
6019 player[k].currentframe=1;
6020 player[k].targetframe=2;
6021 player[i].currentframe=1;
6022 player[i].targetframe=2;
6025 player[k].velocity=0;
6026 player[i].velocity=0;
6027 player[i].oldcoords=player[i].coords;
6028 player[k].coords=player[i].coords;
6029 player[i].targetrotation=player[k].targetrotation;
6030 player[i].rotation=player[k].targetrotation;
6031 player[i].victim=&player[k];
6032 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
6039 for(k=0;k<numplayers;k++)
6040 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6044 if(!Input::isKeyDown(SDLK_n)){
6045 texturesizetogglekeydown=0;
6048 for(k=0;k<numplayers;k++){
6049 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6050 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6051 player[k].DoDamage(1000);
6056 static bool respawnkeydown;
6057 if(!editorenabled&&(whichlevel!=-2&&(Input::isKeyDown(SDLK_z)&&Input::isKeyDown(SDLK_LMETA)&&debugmode&&!editorenabled)||(Input::isKeyDown(jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
6058 targetlevel=whichlevel;
6062 if(!Input::isKeyDown(jumpkey))respawnkeydown=0;
6063 if(Input::isKeyDown(jumpkey))respawnkeydown=1;
6068 if(whichlevel!=-2&&Input::isKeyDown(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!slomotogglekeydown&&debugmode&&!editorenabled){
6070 if(targetlevel>numchallengelevels-1)targetlevel=0;
6073 slomotogglekeydown=1;
6075 static bool movekey;
6076 static bool connected;
6078 for(int i=0;i<numplayers;i++){
6079 if(!player[i].skeleton.free){
6080 oldtargetrotation=player[i].targetrotation;
6081 if(i==0&&indialogue==-1){
6082 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){
6083 if(!cameramode)player[0].targetrotation=-rotation+180;
6084 if(cameramode)player[0].targetrotation=0;
6090 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6091 if(cameramode){facing=flatfacing;}
6093 facing=DoRotation(facing,-rotation2,0,0);
6094 facing=DoRotation(facing,0,0-rotation,0);
6097 player[0].lookrotation=-rotation;
6099 player[i].targetheadrotation=rotation;
6100 player[i].targetheadrotation2=rotation2;
6102 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6103 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){
6104 player[i].targetrotation=-player[i].lookrotation+180;
6110 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6112 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6113 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6115 player[i].targetheadrotation=player[i].lookrotation;
6116 player[i].targetheadrotation2=player[i].lookrotation2;
6119 rotatetarget=participantfacing[whichdialogue][indialogue][i];
6120 Normalise(&rotatetarget);
6121 player[i].targetheadrotation=-asin(0-rotatetarget.x);
6122 player[i].targetheadrotation*=360/6.28;
6123 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
6125 player[i].targetheadrotation*=-1;
6126 player[i].targetheadrotation+=180;
6127 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
6135 player[i].avoidsomething=0;
6137 for(j=0;j<objects.numobjects;j++){
6138 if(objects.onfire[j]){
6139 if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
6141 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
6142 player[i].collided=0;
6143 player[i].avoidcollided=1;
6144 if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
6145 player[i].avoidwhere=objects.position[j];
6151 //Add avoidwhere to players
6153 for(j=0;j<numplayers;j++){
6154 if(player[j].onfire){
6155 if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
6157 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
6158 player[i].collided=0;
6159 player[i].avoidcollided=1;
6160 if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
6161 player[i].avoidwhere=objects.position[j];
6167 if(player[i].collided>.8)player[i].avoidcollided=0;
6168 if(player[i].aitype!=playercontrolled&&indialogue==-1){
6169 player[i].jumpclimb=0;
6171 if(editorenabled)player[i].stunned=1;
6174 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
6175 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;
6177 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
6178 player[i].forwardkeydown=0;
6179 player[i].leftkeydown=0;
6180 player[i].backkeydown=0;
6181 player[i].rightkeydown=0;
6182 player[i].crouchkeydown=0;
6183 player[i].attackkeydown=0;
6184 player[i].jumpkeydown=0;
6185 player[i].throwkeydown=0;
6188 if(player[i].aitype==pathfindtype){
6189 if(player[i].finalpathfindpoint==-1){
6190 float closestdistance;
6196 for(j=0;j<numpathpoints;j++){
6197 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
6198 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
6200 player[i].finaltarget=pathpoint[j];
6203 player[i].finalpathfindpoint=closest;
6204 for(j=0;j<numpathpoints;j++){
6205 if(numpathpointconnect[j])
6206 for(k=0;k<numpathpointconnect[j];k++){
6207 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
6208 if(tempdist*tempdist<closestdistance){
6209 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
6210 closestdistance=tempdist*tempdist;
6212 player[i].finaltarget=colpoint;
6217 player[i].finalpathfindpoint=closest;
6220 if(player[i].targetpathfindpoint==-1){
6221 float closestdistance;
6227 if(player[i].lastpathfindpoint==-1){
6228 for(j=0;j<numpathpoints;j++){
6229 if(j!=player[i].lastpathfindpoint)
6230 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
6231 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
6235 player[i].targetpathfindpoint=closest;
6236 for(j=0;j<numpathpoints;j++){
6237 if(j!=player[i].lastpathfindpoint)
6238 if(numpathpointconnect[j])
6239 for(k=0;k<numpathpointconnect[j];k++){
6240 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
6241 if(tempdist*tempdist<closestdistance){
6242 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
6243 //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
6244 closestdistance=tempdist*tempdist;
6251 player[i].targetpathfindpoint=closest;
6255 for(j=0;j<numpathpoints;j++){
6256 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
6259 if(numpathpointconnect[j])
6260 for(k=0;k<numpathpointconnect[j];k++){
6261 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
6264 if(numpathpointconnect[player[i].lastpathfindpoint])
6265 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
6266 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
6269 tempdist=findPathDist(j,player[i].finalpathfindpoint);
6270 if(closest==-1||tempdist<closestdistance){
6271 closestdistance=tempdist;
6277 player[i].targetpathfindpoint=closest;
6280 player[i].losupdatedelay-=multiplier;
6282 rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
6283 Normalise(&rotatetarget);
6284 player[i].targetrotation=-asin(0-rotatetarget.x);
6285 player[i].targetrotation*=360/6.28;
6286 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6287 player[i].lookrotation=player[i].targetrotation;
6288 //player[i].aiupdatedelay=.05;
6290 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
6291 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
6292 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
6293 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
6294 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
6295 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
6296 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
6297 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
6298 player[i].targetpathfindpoint=-1;
6300 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){
6301 player[i].aitype=passivetype;
6304 player[i].forwardkeydown=1;
6305 player[i].leftkeydown=0;
6306 player[i].backkeydown=0;
6307 player[i].rightkeydown=0;
6308 player[i].crouchkeydown=0;
6309 player[i].attackkeydown=0;
6310 player[i].throwkeydown=0;
6312 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6314 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6315 if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6317 if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
6318 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))
6319 player[i].aitype=attacktypecutoff;
6320 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
6321 player[i].aitype=attacktypecutoff;
6323 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
6324 player[i].losupdatedelay=.2;
6325 for(j=0;j<numplayers;j++){
6326 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
6327 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
6328 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
6329 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
6330 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
6331 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)){
6332 player[i].aitype=searchtype;
6333 player[i].lastchecktime=12;
6334 player[i].lastseen=player[j].coords;
6335 player[i].lastseentime=12;
6341 if(player[i].aitype==attacktypecutoff&&musictype!=2){
6342 if(player[i].creature!=wolftype){
6343 player[i].stunned=.6;
6344 player[i].surprised=.6;
6349 if(player[i].aitype!=passivetype&&leveltime>.5){
6350 player[i].howactive=typeactive;
6353 if(player[i].aitype==passivetype){
6354 player[i].aiupdatedelay-=multiplier;
6355 player[i].losupdatedelay-=multiplier;
6356 player[i].lastseentime+=multiplier;
6357 player[i].pausetime-=multiplier;
6358 if(player[i].lastseentime>1)player[i].lastseentime=1;
6360 if(player[i].aiupdatedelay<0){
6361 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
6362 rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
6363 Normalise(&rotatetarget);
6364 player[i].targetrotation=-asin(0-rotatetarget.x);
6365 player[i].targetrotation*=360/6.28;
6366 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6367 player[i].lookrotation=player[i].targetrotation;
6368 player[i].aiupdatedelay=.05;
6370 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
6371 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
6372 player[i].waypoint++;
6373 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
6378 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
6379 else player[i].forwardkeydown=0;
6380 player[i].leftkeydown=0;
6381 player[i].backkeydown=0;
6382 player[i].rightkeydown=0;
6383 player[i].crouchkeydown=0;
6384 player[i].attackkeydown=0;
6385 player[i].throwkeydown=0;
6387 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6388 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6390 XYZ leftpos,rightpos;
6391 float leftdist,rightdist;
6392 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6393 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6394 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6395 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6396 if(leftdist<rightdist)player[i].targetrotation+=90;
6397 else player[i].targetrotation-=90;
6401 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6402 if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6406 if(player[i].howactive<typesleeping)
6407 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
6408 for(j=0;j<numenvsounds;j++){
6409 if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
6410 player[i].aitype=attacktypecutoff;
6414 if(player[i].howactive==typesleeping)
6415 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
6416 for(j=0;j<numenvsounds;j++){
6417 if(envsoundvol[j]>14)
6418 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
6419 player[i].aitype=attacktypecutoff;
6423 if(player[i].aitype!=passivetype){
6424 if(player[i].howactive==typesleeping){
6425 player[i].targetanimation=getupfromfrontanim;
6426 player[i].targetframe=0;
6430 player[i].howactive=typeactive;
6434 if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
6435 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
6436 player[i].aitype=attacktypecutoff;
6437 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
6438 player[i].aitype=attacktypecutoff;
6440 if(player[i].creature==wolftype){
6442 float smelldistance;
6444 for(j=0;j<numplayers;j++){
6445 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
6446 if(j==0&&player[j].num_weapons>0){
6447 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
6448 if(player[j].num_weapons==2)
6449 if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
6454 windsmell=windvector;
6455 Normalise(&windsmell);
6456 windsmell=windsmell*2+player[j].coords;
6457 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
6458 player[i].aitype=attacktypecutoff;
6463 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
6464 player[i].losupdatedelay=.2;
6465 for(j=0;j<numplayers;j++){
6466 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
6467 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
6468 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
6469 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
6470 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)){
6471 player[i].lastseentime-=.2;
6472 if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
6473 else player[i].lastseentime-=.6;
6475 if(player[i].lastseentime<=0){
6476 player[i].aitype=searchtype;
6477 player[i].lastchecktime=12;
6478 player[i].lastseen=player[j].coords;
6479 player[i].lastseentime=12;
6485 if(player[i].aitype==attacktypecutoff&&musictype!=2){
6486 if(player[i].creature!=wolftype){
6487 player[i].stunned=.6;
6488 player[i].surprised=.6;
6490 if(player[i].creature==wolftype){
6491 player[i].stunned=.47;
6492 player[i].surprised=.47;
6498 if(player[i].aitype==searchtype){
6499 player[i].aiupdatedelay-=multiplier;
6500 player[i].losupdatedelay-=multiplier;
6501 if(!player[i].pause)player[i].lastseentime-=multiplier;
6502 player[i].lastchecktime-=multiplier;
6504 if(player[i].isRun()&&!player[i].onground){
6505 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
6506 test2=player[i].coords+player[i].facing;
6508 test=player[i].coords+player[i].facing;
6510 j=checkcollide(test2,test,player[i].laststanding);
6511 if(j==-1)j=checkcollide(test2,test);
6513 player[i].velocity=0;
6514 player[i].targetanimation=player[i].getStop();
6515 player[i].targetframe=0;
6517 player[i].targetrotation+=180;
6518 player[i].stunned=.5;
6519 //player[i].aitype=passivetype;
6520 player[i].aitype=pathfindtype;
6521 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6522 player[i].finalpathfindpoint=-1;
6523 player[i].targetpathfindpoint=-1;
6524 player[i].lastpathfindpoint=-1;
6525 player[i].lastpathfindpoint2=-1;
6526 player[i].lastpathfindpoint3=-1;
6527 player[i].lastpathfindpoint4=-1;
6529 else player[i].laststanding=j;
6532 if(player[i].aiupdatedelay<0){
6533 rotatetarget=player[i].lastseen-player[i].coords;
6534 Normalise(&rotatetarget);
6535 player[i].targetrotation=-asin(0-rotatetarget.x);
6536 player[i].targetrotation*=360/6.28;
6537 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6538 player[i].lookrotation=player[i].targetrotation;
6539 player[i].aiupdatedelay=.05;
6540 player[i].forwardkeydown=1;
6542 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
6543 player[i].forwardkeydown=0;
6544 player[i].aiupdatedelay=1;
6545 player[i].lastseen.x+=(float(Random()%100)-50)/25;
6546 player[i].lastseen.z+=(float(Random()%100)-50)/25;
6547 player[i].lastchecktime=3;
6550 player[i].leftkeydown=0;
6551 player[i].backkeydown=0;
6552 player[i].rightkeydown=0;
6553 player[i].crouchkeydown=0;
6554 player[i].attackkeydown=0;
6555 player[i].throwkeydown=0;
6557 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6558 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6560 XYZ leftpos,rightpos;
6561 float leftdist,rightdist;
6562 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6563 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6564 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6565 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6566 if(leftdist<rightdist)player[i].targetrotation+=90;
6567 else player[i].targetrotation-=90;
6571 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6572 if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6574 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
6575 for(j=0;j<numenvsounds;j++){
6576 if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
6577 player[i].aitype=attacktypecutoff;
6581 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
6582 player[i].losupdatedelay=.2;
6583 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
6584 {player[i].aitype=attacktypecutoff;
6585 player[i].lastseentime=1;}
6586 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
6587 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
6588 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
6589 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)){
6590 player[i].aitype=attacktypecutoff;
6591 player[i].lastseentime=1;
6594 if(player[i].lastseentime<0){
6595 //player[i].aitype=passivetype;
6597 player[i].aitype=pathfindtype;
6598 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6599 player[i].finalpathfindpoint=-1;
6600 player[i].targetpathfindpoint=-1;
6601 player[i].lastpathfindpoint=-1;
6602 player[i].lastpathfindpoint2=-1;
6603 player[i].lastpathfindpoint3=-1;
6604 player[i].lastpathfindpoint4=-1;
6608 if(player[i].aitype!=gethelptype){
6609 player[i].runninghowlong=0;
6612 if(player[i].aitype==gethelptype){
6613 player[i].runninghowlong+=multiplier;
6614 player[i].aiupdatedelay-=multiplier;
6616 if(player[i].aiupdatedelay<0||player[i].ally==0){
6617 player[i].aiupdatedelay=.2;
6625 if(!player[i].ally){
6626 for(j=0;j<numplayers;j++){
6627 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
6628 distance=findDistancefast(&player[i].coords,&player[j].coords);
6629 if(closestdist==-1||distance<closestdist){
6630 closestdist=distance;
6636 if(closest!=-1)player[i].ally=closest;
6637 else player[i].ally=0;
6638 player[i].lastseen=player[0].coords;
6639 player[i].lastseentime=12;
6643 player[i].lastchecktime=12;
6644 //player[i].lastseentime-=.5;
6646 facing=player[i].coords;
6647 flatfacing=player[player[i].ally].coords;
6648 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
6649 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
6650 if(-1!=checkcollide(facing,flatfacing))
6651 player[i].lastseentime-=.1;
6653 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
6654 player[i].aitype=searchtype;
6655 player[i].lastseentime=12;
6658 if(player[i].ally>0){
6659 rotatetarget=player[player[i].ally].coords-player[i].coords;
6660 Normalise(&rotatetarget);
6661 player[i].targetrotation=-asin(0-rotatetarget.x);
6662 player[i].targetrotation*=360/6.28;
6663 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6664 player[i].lookrotation=player[i].targetrotation;
6665 player[i].aiupdatedelay=.05;
6666 player[i].forwardkeydown=1;
6668 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
6669 player[i].aitype=searchtype;
6670 player[i].lastseentime=12;
6671 player[player[i].ally].aitype=searchtype;
6672 if(player[player[i].ally].lastseentime<player[i].lastseentime){
6673 player[player[i].ally].lastseen=player[i].lastseen;
6674 player[player[i].ally].lastseentime=player[i].lastseentime;
6675 player[player[i].ally].lastchecktime=player[i].lastchecktime;
6679 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6680 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6682 XYZ leftpos,rightpos;
6683 float leftdist,rightdist;
6684 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6685 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6686 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6687 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6688 if(leftdist<rightdist)player[i].targetrotation+=90;
6689 else player[i].targetrotation-=90;
6694 player[i].leftkeydown=0;
6695 player[i].backkeydown=0;
6696 player[i].rightkeydown=0;
6697 player[i].crouchkeydown=0;
6698 player[i].attackkeydown=0;
6700 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6701 if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6704 if(player[i].aitype==getweapontype){
6705 player[i].aiupdatedelay-=multiplier;
6706 player[i].lastchecktime-=multiplier;
6708 if(player[i].aiupdatedelay<0){
6709 player[i].aiupdatedelay=.2;
6717 if(player[i].ally<0){
6718 for(j=0;j<weapons.numweapons;j++){
6719 if(weapons.owner[j]==-1){
6720 distance=findDistancefast(&player[i].coords,&weapons.position[j]);
6721 if(closestdist==-1||distance<closestdist){
6722 closestdist=distance;
6728 if(closest!=-1)player[i].ally=closest;
6729 else player[i].ally=-1;
6732 player[i].lastseentime=12;
6734 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
6735 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
6736 player[i].aitype=attacktypecutoff;
6737 player[i].lastseentime=1;
6740 if(player[i].ally>=0){
6741 if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
6742 player[i].aitype=attacktypecutoff;
6743 player[i].lastseentime=1;
6745 rotatetarget=weapons.position[player[i].ally]-player[i].coords;
6746 Normalise(&rotatetarget);
6747 player[i].targetrotation=-asin(0-rotatetarget.x);
6748 player[i].targetrotation*=360/6.28;
6749 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6750 player[i].lookrotation=player[i].targetrotation;
6751 player[i].aiupdatedelay=.05;
6752 player[i].forwardkeydown=1;
6755 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
6756 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6758 XYZ leftpos,rightpos;
6759 float leftdist,rightdist;
6760 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
6761 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
6762 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
6763 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
6764 if(leftdist<rightdist)player[i].targetrotation+=90;
6765 else player[i].targetrotation-=90;
6768 /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
6769 if(abs(Random()%6)){
6770 player[i].crouchkeydown=1;
6771 if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
6772 if(player[i].isRun()){
6773 player[i].targetframe=0;
6775 player[i].targetanimation=sneakanim;
6778 else player[i].forwardkeydown=0;
6780 else player[i].crouchkeydown=0;
6782 else player[i].crouchkeydown=0;*/
6785 player[i].leftkeydown=0;
6786 player[i].backkeydown=0;
6787 player[i].rightkeydown=0;
6788 player[i].attackkeydown=0;
6789 player[i].throwkeydown=1;
6790 player[i].crouchkeydown=0;
6791 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
6792 player[i].drawkeydown=0;
6794 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
6795 if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
6798 if(player[i].aitype==attacktypecutoff){
6799 player[i].aiupdatedelay-=multiplier;
6800 if(player[i].damage<player[i].damagetolerance*2/3)
6801 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)){
6802 player[i].attackkeydown=0;
6803 if(player[i].isIdle())player[i].crouchkeydown=1;
6804 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
6805 if(weapons.type[player[0].weaponids[0]]==knife){
6806 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
6807 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
6808 else player[i].targetanimation=rollanim;
6810 player[i].targetframe=0;
6811 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
6812 player[i].wentforweapon=0;
6814 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
6815 player[i].targetanimation=flipanim;
6817 player[i].targetframe=0;
6821 player[i].forwardkeydown=0;
6822 player[i].aiupdatedelay=.02;
6824 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
6825 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
6826 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
6828 if(player[i].wentforweapon<3)
6829 for(j=0;j<weapons.numweapons;j++){
6830 if(player[i].creature!=wolftype)
6831 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){
6832 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
6833 player[i].wentforweapon++;
6834 player[i].lastchecktime=6;
6835 player[i].aitype=getweapontype;
6840 if(player[i].damage<player[i].damagetolerance/2)
6841 if(animation[player[i].targetanimation].height!=highheight)
6842 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)))){
6843 player[i].crouchkeydown=1;
6845 if(player[i].isRun()&&!player[i].onground){
6846 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
6847 test2=player[i].coords+player[i].facing;
6849 test=player[i].coords+player[i].facing;
6851 j=checkcollide(test2,test,player[i].laststanding);
6852 if(j==-1)j=checkcollide(test2,test);
6854 player[i].velocity=0;
6855 player[i].targetanimation=player[i].getStop();
6856 player[i].targetframe=0;
6858 player[i].targetrotation+=180;
6859 player[i].stunned=.5;
6860 //player[i].aitype=passivetype;
6861 player[i].aitype=pathfindtype;
6862 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6863 player[i].finalpathfindpoint=-1;
6864 player[i].targetpathfindpoint=-1;
6865 player[i].lastpathfindpoint=-1;
6866 player[i].lastpathfindpoint2=-1;
6867 player[i].lastpathfindpoint3=-1;
6868 player[i].lastpathfindpoint4=-1;
6870 else player[i].laststanding=j;
6873 if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
6874 player[i].aitype=pathfindtype;
6875 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6876 player[i].finalpathfindpoint=-1;
6877 player[i].targetpathfindpoint=-1;
6878 player[i].lastpathfindpoint=-1;
6879 player[i].lastpathfindpoint2=-1;
6880 player[i].lastpathfindpoint3=-1;
6881 player[i].lastpathfindpoint4=-1;
6883 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){
6884 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
6885 else player[i].drawkeydown=0;
6886 player[i].rabbitkickenabled=Random()%2;
6887 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
6888 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
6889 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;
6890 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
6891 Normalise(&rotatetarget);
6892 player[i].targetrotation=-asin(0-rotatetarget.x);
6893 player[i].targetrotation*=360/6.28;
6894 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
6895 player[i].lookrotation=player[i].targetrotation;
6896 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
6898 oldkey=player[i].forwardkeydown;
6899 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
6900 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;
6901 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
6902 else player[i].forwardkeydown=0;
6904 player[i].forwardkeydown=0;
6905 if(Random()%10==0)player[i].forwardkeydown=1;
6906 if(Random()%100==0){
6907 player[i].aitype=pathfindtype;
6908 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
6909 player[i].finalpathfindpoint=-1;
6910 player[i].targetpathfindpoint=-1;
6911 player[i].lastpathfindpoint=-1;
6912 player[i].lastpathfindpoint2=-1;
6913 player[i].lastpathfindpoint3=-1;
6914 player[i].lastpathfindpoint4=-1;
6917 player[i].leftkeydown=0;
6918 player[i].backkeydown=0;
6919 player[i].rightkeydown=0;
6920 player[i].crouchkeydown=0;
6921 player[i].throwkeydown=0;
6923 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
6924 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
6925 else player[i].attackkeydown=0;
6926 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
6928 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
6930 for(j=0;j<numplayers;j++){
6931 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)){
6932 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))))){
6933 if(target>=0)target=-1;
6938 if(target>=0)player[target].Reverse();
6941 if(player[i].collided<1)player[i].jumpkeydown=0;
6942 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;
6943 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
6944 player[0].jumpkeydown=0;
6945 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
6946 if(player[i].jumpkeydown)player[i].attackkeydown=0;
6947 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
6949 if(tutoriallevel==1){
6950 if(!canattack)player[i].attackkeydown=0;
6954 facing=player[i].coords;
6955 flatfacing=player[0].coords;
6956 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
6957 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
6958 if(player[i].occluded>=2)
6959 if(-1!=checkcollide(facing,flatfacing)){
6960 if(!player[i].pause)player[i].lastseentime-=.2;
6961 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
6962 player[i].aitype=searchtype;
6963 player[i].lastchecktime=12;
6964 player[i].lastseen=player[0].coords;
6965 player[i].lastseentime=12;
6968 else player[i].lastseentime=1;
6971 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
6972 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
6973 test=player[0].coords;
6975 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
6978 // NOTE: Ask about logic of this call : NOTE
6979 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
6980 player[i].stunned>0 ||
6981 (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
6983 if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
6984 player[i].targetrotation=player[i].rotation;
6985 player[i].forwardkeydown=0;
6986 player[i].leftkeydown=0;
6987 player[i].backkeydown=0;
6988 player[i].rightkeydown=0;
6989 player[i].jumpkeydown=0;
6990 player[i].attackkeydown=0;
6991 player[i].crouchkeydown=0;
6992 player[i].throwkeydown=0;
6999 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
7002 if(player[i].aitype==attacktypecutoff){
7003 rotatetarget=player[0].coords-player[i].coords;
7004 Normalise(&rotatetarget);
7005 player[i].targetheadrotation=-asin(0-rotatetarget.x);
7006 player[i].targetheadrotation*=360/6.28;
7007 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
7009 player[i].targetheadrotation*=-1;
7010 player[i].targetheadrotation+=180;
7011 //player[i].targetheadrotation2=0;
7012 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
7014 else if(player[i].howactive>=typesleeping){
7015 player[i].targetheadrotation=player[i].targetrotation;
7016 player[i].targetheadrotation2=0;
7019 if(player[i].interestdelay<=0){
7020 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
7021 player[i].headtarget=player[i].coords;
7022 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
7023 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
7024 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
7025 player[i].headtarget+=player[i].facing*1.5;
7027 rotatetarget=player[i].headtarget-player[i].coords;
7028 Normalise(&rotatetarget);
7029 player[i].targetheadrotation=-asin(0-rotatetarget.x);
7030 player[i].targetheadrotation*=360/6.28;
7031 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
7033 player[i].targetheadrotation*=-1;
7034 player[i].targetheadrotation+=180;
7035 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
7037 //if(whichlevel==2)player[i].jumpkeydown=0;
7039 if(animation[player[i].targetanimation].attack==reversed){
7040 //player[i].targetrotation=player[i].rotation;
7041 player[i].forwardkeydown=0;
7042 player[i].leftkeydown=0;
7043 player[i].backkeydown=0;
7044 player[i].rightkeydown=0;
7045 player[i].jumpkeydown=0;
7046 player[i].attackkeydown=0;
7047 //player[i].crouchkeydown=0;
7048 player[i].throwkeydown=0;
7052 player[i].forwardkeydown=0;
7053 player[i].leftkeydown=0;
7054 player[i].backkeydown=0;
7055 player[i].rightkeydown=0;
7056 player[i].jumpkeydown=0;
7057 player[i].crouchkeydown=0;
7058 player[i].drawkeydown=0;
7059 player[i].throwkeydown=0;
7062 if(player[i].collided<-.3)player[i].collided=-.3;
7063 if(player[i].collided>1)player[i].collided=1;
7064 player[i].collided-=multiplier*4;
7065 player[i].whichdirectiondelay-=multiplier;
7066 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
7067 player[i].avoidcollided=-.3;
7068 player[i].whichdirection=abs(Random()%2);
7069 player[i].whichdirectiondelay=.4;
7071 if(player[i].avoidcollided>1)player[i].avoidcollided=1;
7072 player[i].avoidcollided-=multiplier/4;
7073 if(!player[i].skeleton.free)player[i].stunned-=multiplier;
7074 if(!player[i].skeleton.free)player[i].surprised-=multiplier;
7075 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;
7077 if(!player[i].throwkeydown){
7078 player[i].throwtogglekeydown=0;
7080 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
7081 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)){
7082 for(j=0;j<weapons.numweapons;j++){
7083 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)
7084 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
7085 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
7086 if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
7087 player[i].throwtogglekeydown=1;
7088 player[i].targetanimation=crouchremoveknifeanim;
7090 player[i].targetframe=0;
7091 rotatetarget=weapons.position[j]-player[i].coords;
7092 Normalise(&rotatetarget);
7093 player[i].targetrotation=-asin(0-rotatetarget.x);
7094 player[i].targetrotation*=360/6.28;
7095 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7096 player[i].hasvictim=0;
7098 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7099 player[i].throwtogglekeydown=1;
7100 player[i].hasvictim=0;
7102 //for(i=0;i<weapons.numweapons;i++){
7103 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))
7104 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
7105 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
7108 gLoc[0]=player[i].coords.x;
7109 gLoc[1]=player[i].coords.y;
7110 gLoc[2]=player[i].coords.z;
7111 vel[0]=player[i].velocity.x;
7112 vel[1]=player[i].velocity.y;
7113 vel[2]=player[i].velocity.z;
7114 if(weapons.type[j]!=staff){
7115 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
7116 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
7117 OPENAL_SetVolume(channels[knifedrawsound], 128);
7118 OPENAL_SetPaused(channels[knifedrawsound], false);
7121 player[i].weaponactive=0;
7122 weapons.owner[j]=player[i].id;
7123 if(player[i].num_weapons>0){
7124 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7126 player[i].num_weapons++;
7127 player[i].weaponids[0]=j;
7133 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){
7134 if(!player[i].isFlip()){
7135 player[i].throwtogglekeydown=1;
7136 player[i].targetanimation=removeknifeanim;
7138 player[i].targetframe=0;
7139 rotatetarget=weapons.position[j]-player[i].coords;
7140 Normalise(&rotatetarget);
7141 player[i].targetrotation=-asin(0-rotatetarget.x);
7142 player[i].targetrotation*=360/6.28;
7143 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7145 if(player[i].isFlip()){
7146 player[i].throwtogglekeydown=1;
7147 player[i].hasvictim=0;
7149 for(k=0;k<weapons.numweapons;k++){
7150 if(player[i].weaponactive==-1)
7151 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))
7152 if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
7155 gLoc[0]=player[i].coords.x;
7156 gLoc[1]=player[i].coords.y;
7157 gLoc[2]=player[i].coords.z;
7158 vel[0]=player[i].velocity.x;
7159 vel[1]=player[i].velocity.y;
7160 vel[2]=player[i].velocity.z;
7161 if(weapons.type[k]!=staff){
7162 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
7163 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
7164 OPENAL_SetVolume(channels[knifedrawsound], 128);
7165 OPENAL_SetPaused(channels[knifedrawsound], false);
7168 player[i].weaponactive=0;
7169 weapons.owner[k]=player[i].id;
7170 if(player[i].num_weapons>0){
7171 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7173 player[i].num_weapons++;
7174 player[i].weaponids[0]=k;
7181 if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7183 for(j=0;j<numplayers;j++){
7184 if(player[i].weaponactive==-1)
7186 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)){
7187 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
7188 player[i].throwtogglekeydown=1;
7189 player[i].victim=&player[j];
7190 player[i].hasvictim=1;
7191 player[i].targetanimation=crouchremoveknifeanim;
7193 player[i].targetframe=0;
7194 rotatetarget=player[j].coords-player[i].coords;
7195 Normalise(&rotatetarget);
7196 player[i].targetrotation=-asin(0-rotatetarget.x);
7197 player[i].targetrotation*=360/6.28;
7198 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7200 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7201 player[i].throwtogglekeydown=1;
7202 player[i].victim=&player[j];
7203 player[i].hasvictim=1;
7204 int k = player[j].weaponids[0];
7205 if(player[i].hasvictim){
7208 gLoc[0]=player[i].coords.x;
7209 gLoc[1]=player[i].coords.y;
7210 gLoc[2]=player[i].coords.z;
7211 vel[0]=player[i].velocity.x;
7212 vel[1]=player[i].velocity.y;
7213 vel[2]=player[i].velocity.z;
7216 if(player[i].victim->weaponstuck!=-1){
7217 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7222 if(weapons.type[k]!=staff){
7223 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
7224 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
7225 OPENAL_SetVolume(channels[knifedrawsound], 128);
7226 OPENAL_SetPaused(channels[knifedrawsound], false);
7230 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
7231 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
7232 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
7233 OPENAL_SetPaused(channels[fleshstabremovesound], false);
7236 player[i].weaponactive=0;
7237 if(weapons.owner[k]!=-1){
7238 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
7239 else player[i].victim->num_weapons=1;
7241 player[i].victim->skeleton.longdead=0;
7242 player[i].victim->skeleton.free=1;
7243 player[i].victim->skeleton.broken=0;
7245 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
7246 player[i].victim->skeleton.joints[l].velchange=0;
7247 player[i].victim->skeleton.joints[l].locked=0;
7253 Normalise(&relative);
7254 XYZ footvel,footpoint;
7256 footpoint=weapons.position[k];
7257 if(player[i].victim->weaponstuck!=-1){
7258 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7259 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
7260 weapons.bloody[k]=2;
7261 weapons.blooddrip[k]=5;
7262 player[i].victim->weaponstuck=-1;
7263 player[i].victim->bloodloss+=2000;
7264 player[i].victim->DoDamage(2000);
7267 if(player[i].victim->num_weapons>0){
7268 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
7269 if(player[i].victim->weaponids[0]==k)
7270 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
7273 player[i].victim->weaponactive=-1;
7275 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
7276 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
7277 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
7278 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
7281 if(player[i].num_weapons>0){
7282 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7284 player[i].num_weapons++;
7285 player[i].weaponids[0]=k;
7292 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7293 if(weapons.type[player[i].weaponids[0]]==knife){
7294 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
7296 for(j=0;j<numplayers;j++){
7298 if(tutoriallevel!=1||tutorialstage==49)
7300 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)){
7301 if(!player[i].isFlip()){
7302 player[i].throwtogglekeydown=1;
7303 player[i].victim=&player[j];
7304 player[i].targetanimation=knifethrowanim;
7306 player[i].targetframe=0;
7307 rotatetarget=player[j].coords-player[i].coords;
7308 Normalise(&rotatetarget);
7309 player[i].targetrotation=-asin(0-rotatetarget.x);
7310 player[i].targetrotation*=360/6.28;
7311 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
7313 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
7315 if(player[i].isFlip()){
7316 if(player[i].weaponactive!=-1){
7317 player[i].throwtogglekeydown=1;
7318 player[i].victim=&player[j];
7320 weapons.owner[player[i].weaponids[0]]=-1;
7321 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);
7324 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
7326 weapons.velocity[player[i].weaponids[0]]=aim*50;
7327 weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
7328 weapons.missed[player[i].weaponids[0]]=0;
7329 weapons.freetime[player[i].weaponids[0]]=0;
7330 weapons.firstfree[player[i].weaponids[0]]=1;
7331 weapons.physics[player[i].weaponids[0]]=0;
7332 player[i].num_weapons--;
7333 if(player[i].num_weapons){
7334 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7336 player[i].weaponactive=-1;
7343 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7344 if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
7346 player[i].throwtogglekeydown=1;
7347 weapons.owner[player[i].weaponids[0]]=-1;
7348 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
7349 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
7350 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
7351 weapons.missed[player[i].weaponids[0]]=1;
7352 weapons.freetime[player[i].weaponids[0]]=0;
7353 weapons.firstfree[player[i].weaponids[0]]=1;
7354 weapons.physics[player[i].weaponids[0]]=1;
7355 player[i].num_weapons--;
7356 if(player[i].num_weapons){
7357 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7358 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7361 player[i].weaponactive=-1;
7362 for(j=0;j<numplayers;j++){
7363 player[j].wentforweapon=0;
7370 if(i==0||!player[0].dead||player[i].weaponactive!=-1)
7371 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)){
7372 //Setenvironment(1-environment);
7375 if(player[i].weaponactive!=-1){
7376 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
7378 if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
7379 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7380 player[i].targetanimation=drawrightanim;
7381 player[i].targetframe=0;
7383 player[i].drawtogglekeydown=1;
7385 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){
7386 player[i].targetanimation=drawleftanim;
7387 player[i].targetframe=0;
7389 player[i].drawtogglekeydown=1;
7391 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7392 player[i].targetanimation=crouchdrawrightanim;
7393 player[i].targetframe=0;
7395 player[i].drawtogglekeydown=1;
7399 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){
7400 if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
7401 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
7402 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
7403 player[i].targetframe=0;
7405 player[i].hasvictim=0;
7406 //player[i].attacktogglekeydown=1;
7410 if(!player[i].drawkeydown){
7411 player[i].drawtogglekeydown=0;
7418 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7420 else absflatfacing=flatfacing;
7423 player[i].forwardkeydown=0;
7424 player[i].leftkeydown=0;
7425 player[i].backkeydown=0;
7426 player[i].rightkeydown=0;
7427 player[i].jumpkeydown=0;
7428 player[i].crouchkeydown=0;
7429 player[i].drawkeydown=0;
7430 player[i].throwkeydown=0;
7434 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
7435 if(!player[i].forwardkeydown){
7436 player[i].forwardstogglekeydown=0;
7438 if(player[i].crouchkeydown){
7442 player[i].superruntoggle=1;
7444 for(j=0;j<numplayers;j++){
7445 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
7446 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
7447 player[i].superruntoggle=0;
7454 for(j=0;j<numplayers;j++){
7455 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7456 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))){
7457 if(target>=0)target=-1;
7462 if(target>=0)player[target].Reverse();
7463 player[i].lowreversaldelay=.5;
7465 if(player[i].isIdle()){
7466 player[i].targetanimation=player[i].getCrouch();
7468 player[i].targetframe=0;
7469 player[i].transspeed=10;
7471 if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
7472 player[i].targetanimation=rollanim;
7474 player[i].targetframe=0;
7475 player[i].transspeed=20;
7478 if(!player[i].crouchkeydown){
7480 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7482 if(player[i].isCrouch()){
7484 for(j=0;j<numplayers;j++){
7485 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
7486 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
7487 if(target>=0)target=-1;
7492 if(target>=0)player[target].Reverse();
7493 player[i].highreversaldelay=.5;
7495 if(player[i].isCrouch()){
7496 if(!player[i].wasCrouch()){
7497 player[i].currentanimation=player[i].getCrouch();
7498 player[i].currentframe=0;
7501 player[i].targetanimation=player[i].getIdle();
7502 player[i].targetframe=0;
7503 player[i].transspeed=10;
7506 if(player[i].targetanimation==sneakanim){
7507 player[i].targetanimation=player[i].getIdle();
7509 player[i].targetframe=0;
7510 player[i].transspeed=10;
7513 if(player[i].forwardkeydown){
7514 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)){
7515 if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
7516 else player[i].targetanimation=player[i].getRun();
7518 player[i].targetframe=0;
7520 if(player[i].isCrouch()){
7521 player[i].targetanimation=sneakanim;
7522 if(player[i].wasCrouch())player[i].target=0;
7523 player[i].targetframe=0;
7525 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7526 player[i].targetanimation=climbanim;
7528 player[i].targetframe=1;
7529 player[i].jumpclimb=1;
7531 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7532 player[i].velocity+=absflatfacing*5*multiplier;
7534 player[i].forwardstogglekeydown=1;
7537 if (player[i].rightkeydown){
7538 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)){
7539 player[i].targetanimation=player[i].getRun();
7541 player[i].targetframe=0;
7543 if(player[i].isCrouch()){
7544 player[i].targetanimation=sneakanim;
7545 if(player[i].wasCrouch()) player[i].target=0;
7546 player[i].targetframe=0;
7548 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7549 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7551 player[i].targetrotation-=90;
7552 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7553 if(player[i].backkeydown)player[i].targetrotation-=45;
7556 if ( player[i].leftkeydown){
7557 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)){
7558 player[i].targetanimation=player[i].getRun();
7560 player[i].targetframe=0;
7562 if(player[i].isCrouch()){
7563 player[i].targetanimation=sneakanim;
7564 if(player[i].wasCrouch())player[i].target=0;
7565 player[i].targetframe=0;
7567 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7568 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7570 player[i].targetrotation+=90;
7571 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7572 if(player[i].backkeydown)player[i].targetrotation+=45;
7575 if(player[i].backkeydown){
7576 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)){
7577 player[i].targetanimation=player[i].getRun();
7579 player[i].targetframe=0;
7581 if(player[i].isCrouch()){
7582 player[i].targetanimation=sneakanim;
7583 if(player[i].wasCrouch())player[i].target=0;
7584 player[i].targetframe=0;
7586 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7587 player[i].velocity-=absflatfacing*5*multiplier;
7589 if(player[i].targetanimation==hanganim){
7590 player[i].currentanimation=jumpdownanim;
7591 player[i].targetanimation=jumpdownanim;
7593 player[i].currentframe=0;
7594 player[i].targetframe=1;
7595 player[i].velocity=0;
7596 player[i].velocity.y+=gravity;
7597 player[i].coords.y-=1.4;
7598 player[i].grabdelay=1;
7600 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7601 player[i].targetrotation+=180;
7604 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7605 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)){
7606 player[i].jumpstart=0;
7607 player[i].targetanimation=jumpupanim;
7609 player[i].targetframe=0;
7610 player[i].rotation=player[i].targetrotation;
7611 player[i].transspeed=20;
7612 player[i].FootLand(0,1);
7613 player[i].FootLand(1,1);
7617 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7619 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7620 if(!movekey)player[i].velocity=0;
7625 for(j=0;j<numplayers;j++){
7626 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7627 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
7628 if(target>=0)target=-1;
7633 if(target>=0)player[i].velocity.y=1;
7634 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7635 player[i].velocity.y=7;
7636 player[i].crouchtogglekeydown=1;
7638 else player[i].velocity.y=5;
7640 if(mousejump&&i==0&&debugmode){
7641 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7642 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7645 player[i].coords.y+=.2;
7646 player[i].jumppower-=1;
7648 static float gLoc[3];
7649 static float vel[3];
7650 gLoc[0]=player[i].coords.x;
7651 gLoc[1]=player[i].coords.y;
7652 gLoc[2]=player[i].coords.z;
7653 vel[0]=player[i].velocity.x;
7654 vel[1]=player[i].velocity.y;
7655 vel[2]=player[i].velocity.z;
7658 PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
7659 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
7660 OPENAL_SetVolume(channels[whooshsound], 128);
7661 OPENAL_SetPaused(channels[whooshsound], false);
7664 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
7665 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
7666 OPENAL_SetVolume(channels[jumpsound], 128);
7667 OPENAL_SetPaused(channels[jumpsound], false);
7669 if((player[i].isIdle())&&player[i].jumppower>1){
7670 player[i].targetanimation=player[i].getLanding();
7671 player[i].landhard=0;
7673 player[i].targetframe=2;
7674 player[i].jumpstart=1;
7675 player[i].tempdeltav=deltav;
7677 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
7678 if(player[i].jumppower>multiplier*6){
7679 player[i].velocity.y+=multiplier*6;
7680 player[i].jumppower-=multiplier*6;
7682 if(player[i].jumppower<=multiplier*6){
7683 player[i].velocity.y+=player[i].jumppower;
7684 player[i].jumppower=0;
7687 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7691 if(player[i].isRun()||player[i].targetanimation==walkanim){
7692 player[i].targetanimation=player[i].getStop();
7694 player[i].targetframe=0;
7696 if(player[i].targetanimation==sneakanim){
7697 player[i].targetanimation=player[i].getCrouch();
7698 if(player[i].currentanimation==sneakanim)player[i].target=0;
7699 player[i].targetframe=0;
7702 if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
7703 player[i].targetanimation=player[i].getStop();
7705 player[i].targetframe=0;
7707 if(player[i].isRun()&&(player[i].aitype==passivetype)){
7708 player[i].targetanimation=player[i].getStop();
7710 player[i].targetframe=0;
7714 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
7718 for(k=0;k<numplayers;k++){
7719 if(abs(player[k].rotation-player[k].targetrotation)>180){
7720 if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
7721 else player[k].rotation+=360;
7724 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
7725 player[k].targetanimation=player[k].getStop();
7726 player[k].targetframe=0;
7730 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
7731 player[k].targettilt=0;
7733 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
7734 player[k].targettilt=0;
7735 if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
7736 player[k].jumppower+=multiplier*7;
7737 if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
7738 //*(1-(player[k].damage/player[k].damagetolerance))
7739 if(player[k].jumppower>5)player[k].jumppower=5;
7742 if(player[k].isRun()){
7743 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7746 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
7747 else if(player[k].tilt>player[k].targettilt){
7748 player[k].tilt-=multiplier*150;
7750 else if(player[k].tilt<player[k].targettilt){
7751 player[k].tilt+=multiplier*150;
7754 player[k].grabdelay-=multiplier;
7757 for(k=0;k<numplayers;k++){
7758 player[k].DoAnimations();
7759 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
7760 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
7766 for(j=numenvsounds-1;j>=0;j--){
7767 envsoundlife[j]-=multiplier;
7768 if(envsoundlife[j]<0){
7770 envsoundlife[j]=envsoundlife[numenvsounds];
7771 envsound[j]=envsound[numenvsounds];
7774 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
7775 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7777 if(tutoriallevel==1){
7794 if(tutorialstage>=51)
7795 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7796 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7797 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7799 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
7800 OPENAL_SetPaused(channels[stream_music3], false);
7801 OPENAL_SetVolume(channels[stream_music3], 256);
7806 float gLoc[3]={0,0,0};
7807 float vel[3]={0,0,0};
7808 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
7809 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7810 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7811 OPENAL_SetVolume(channels[fireendsound], 256);
7812 OPENAL_SetPaused(channels[fireendsound], false);
7813 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
7817 if(tutorialstage<51)
7818 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7821 gLoc[0]=player[0].coords.x;
7822 gLoc[1]=player[0].coords.y;
7823 gLoc[2]=player[0].coords.z;
7827 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7828 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7829 OPENAL_SetVolume(channels[fireendsound], 256);
7830 OPENAL_SetPaused(channels[fireendsound], false);
7832 player[0].coords=(oldtemp+oldtemp2)/2;
7836 if(tutorialstage>=14&&tutorialstage<50)
7837 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7840 gLoc[0]=player[1].coords.x;
7841 gLoc[1]=player[1].coords.y;
7842 gLoc[2]=player[1].coords.z;
7846 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7847 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7848 OPENAL_SetVolume(channels[fireendsound], 256);
7849 OPENAL_SetPaused(channels[fireendsound], false);
7851 for(int i=0;i<player[1].skeleton.num_joints;i++){
7853 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7854 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7855 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;
7856 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7857 sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7861 player[1].coords=(oldtemp+oldtemp2)/2;
7862 for(int i=0;i<player[1].skeleton.num_joints;i++){
7863 player[1].skeleton.joints[i].velocity=0;
7865 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7866 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7867 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;
7868 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7869 sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7877 static float gLoc[3];
7881 static float vel[3];
7882 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7883 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7884 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7886 //Set orientation with forward and up vectors
7887 static XYZ upvector;
7891 upvector=DoRotation(upvector,-rotation2+90,0,0);
7892 upvector=DoRotation(upvector,0,0-rotation,0);
7897 facing=DoRotation(facing,-rotation2,0,0);
7898 facing=DoRotation(facing,0,0-rotation,0);
7901 static float ori[6];
7905 ori[3] = -upvector.x;
7906 ori[4] = upvector.y;
7907 ori[5] = -upvector.z;
7909 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7916 if(Input::isKeyDown(SDLK_F1)&&!freezetogglekeydown){
7918 freezetogglekeydown=1;
7922 void Game::TickOnce(){
7924 if(directing||indialogue==-1){
7925 rotation+=deltah*.7;
7926 if(!invertmouse)rotation2+=deltav*.7;
7927 if(invertmouse)rotation2-=deltav*.7;
7928 if(rotation2>90)rotation2=90;
7929 if(rotation2<-70)rotation2=-70;
7931 if(mainmenu)rotation+=multiplier*5;
7934 void Game::TickOnceAfter(){
7935 static XYZ colviewer;
7936 static XYZ coltarget;
7939 static float brotate;
7942 static float changedelay;
7943 static bool alldead;
7944 static float unseendelay;
7945 static float cameraspeed;
7949 if(environment==snowyenvironment)music1=stream_music1snow;
7950 if(environment==grassyenvironment)music1=stream_music1grass;
7951 if(environment==desertenvironment)music1=stream_music1desert;
7956 for(i=0;i<numplayers;i++){
7957 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)){
7958 musictype=stream_music2;
7962 if(player[0].dead)musictype=stream_music3;
7965 if(musictype==stream_music2){
7969 if(oldmusictype==stream_music2&&musictype!=stream_music2){
7970 unseendelay-=multiplier;
7972 musictype=stream_music2;
7978 musictype=stream_music3;
7986 if(musictype!=oldmusictype&&musictype==stream_music2){
7987 static float gLoc[3];
7988 static float vel[3];
7989 gLoc[0]=cameraloc.x;
7990 gLoc[1]=cameraloc.y;
7991 gLoc[2]=cameraloc.z;
7995 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
7996 OPENAL_SetVolume(channels[alarmsound], 512);
7997 OPENAL_SetPaused(channels[alarmsound], false);
8001 musicselected=musictype;
8003 if(musicselected==music1)musicvolume[0]+=multiplier*450;
8004 else musicvolume[0]-=multiplier*450;
8005 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
8006 else musicvolume[1]-=multiplier*450;
8007 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
8008 else musicvolume[2]-=multiplier*450;
8011 if(musicvolume[i]<0)musicvolume[i]=0;
8012 if(musicvolume[i]>512)musicvolume[i]=512;
8015 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
8018 if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
8019 PlayStreamEx( music1, strm[music1], NULL, true);
8020 OPENAL_SetPaused(channels[music1], false);
8022 if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
8023 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
8024 OPENAL_SetPaused(channels[stream_music2], false);
8026 if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
8027 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
8028 OPENAL_SetPaused(channels[stream_music3], false);
8033 OPENAL_SetPaused(channels[music1], true);
8034 OPENAL_SetPaused(channels[stream_music2], true);
8035 OPENAL_SetPaused(channels[stream_music3], true);
8038 oldmusicvolume[i]=0;
8044 if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
8045 OPENAL_SetPaused(channels[music1], true);
8047 if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
8048 OPENAL_SetPaused(channels[stream_music2], true);
8050 if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
8051 OPENAL_SetPaused(channels[stream_music3], true);
8054 if(musicvolume[0]!=oldmusicvolume[0]){
8055 OPENAL_SetVolume(channels[music1], musicvolume[0]);
8057 if(musicvolume[1]!=oldmusicvolume[1]){
8058 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
8060 if(musicvolume[2]!=oldmusicvolume[2]){
8061 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
8065 oldmusicvolume[i]=musicvolume[i];
8071 for(i=0;i<numhotspots;i++){
8072 if(hotspottype[i]>10&&hotspottype[i]<20){
8073 if(player[hotspottype[i]-10].dead==0){
8076 else if(killhotspot==2)
8080 if(killhotspot==2)killhotspot=0;
8085 for(i=0;i<numhotspots;i++){
8086 if(hotspottype[i]==-1){
8087 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
8094 for(i=1;i<numplayers;i++){
8095 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
8097 if(numalarmed>maxalarmed)maxalarmed=numalarmed;
8099 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
8100 if(player[0].dead&&changedelay<=0){
8102 targetlevel=whichlevel;
8106 for(i=1;i<numplayers;i++){
8107 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
8111 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
8113 targetlevel=whichlevel+1;
8114 if(targetlevel>numchallengelevels-1)targetlevel=0;
8116 if(winhotspot||windialogue){
8118 targetlevel=whichlevel+1;
8119 if(targetlevel>numchallengelevels-1)targetlevel=0;
8125 targetlevel=whichlevel+1;
8126 if(targetlevel>numchallengelevels-1)targetlevel=0;
8129 if(changedelay>0&&!player[0].dead&&!won){
8130 //high scores, awards, win
8133 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
8134 /*accountcampaignchoices[accountactive][accountactive->getCampaignChoicesMade()]=whichchoice;
8135 accountactive->getCampaignChoicesMade()++;
8136 accountcampaignscore[accountactive]+=bonustotal;
8137 accountcampaigntime[accountactive]+=leveltime;
8138 if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])
8139 accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];*/
8145 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
8160 if(!editorenabled&&gameon&&!mainmenu){
8161 if(changedelay!=-999)changedelay-=multiplier/7;
8162 if(player[0].dead)targetlevel=whichlevel;
8163 if(loading==2&&!campaign){
8166 fireSound(firestartsound);
8168 if(!player[0].dead&&targetlevel!=whichlevel){
8169 startbonustotal=bonustotal;
8171 if(!player[0].dead)Loadlevel(targetlevel);
8172 if(player[0].dead)Loadlevel(whichlevel);
8178 if(loading==2&&targetlevel==whichlevel){
8182 float gLoc[3]={0,0,0};
8183 float vel[3]={0,0,0};
8184 fireSound(firestartsound);
8200 strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]);
8207 if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
8208 if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
8210 if(whichlevel!=-2&&!loading&&!player[0].dead){
8214 if(player[0].dead)loading=1;
8220 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
8221 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
8225 else if(mainmenu==0&&winfreeze){
8226 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
8228 else stealthloading=0;
8230 if(!stealthloading){
8231 float gLoc[3]={0,0,0};
8232 float vel[3]={0,0,0};
8233 fireSound(firestartsound);
8240 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
8241 ipstream.ignore(256,':');
8242 ipstream >> campaignnumlevels;
8243 for(i=0;i<campaignnumlevels;i++){
8244 ipstream.ignore(256,':');
8245 ipstream.ignore(256,':');
8246 ipstream.ignore(256,' ');
8247 ipstream >> campaignmapname[i];
8248 ipstream.ignore(256,':');
8249 ipstream >> campaigndescription[i];
8251 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
8253 ipstream.ignore(256,':');
8254 ipstream >> campaignchoosenext[i];
8255 ipstream.ignore(256,':');
8256 ipstream >> campaignnumnext[i];
8257 if(campaignnumnext[i])
8258 for(j=0;j<campaignnumnext[i];j++){
8259 ipstream.ignore(256,':');
8260 ipstream >> campaignnextlevel[i][j];
8261 campaignnextlevel[i][j]-=1;
8263 ipstream.ignore(256,':');
8264 ipstream >> campaignlocationx[i];
8265 ipstream.ignore(256,':');
8266 ipstream >> campaignlocationy[i];
8270 for(i=0;i<campaignnumlevels;i++){
8272 levelhighlight[i]=0;
8276 for(i=0;i<campaignnumlevels;i++){
8278 levelhighlight[i]=0;
8283 if(accountactive->getCampaignChoicesMade())
8284 for(i=0;i<accountactive->getCampaignChoicesMade();i++){
8285 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
8286 levelvisible[levelorder[i+1]]=1;
8288 int whichlevelstart;
8289 whichlevelstart=accountactive->getCampaignChoicesMade()-1;
8290 if(whichlevelstart<0){
8291 campaignchoicenum=1;
8292 campaignchoicewhich[0]=0;
8296 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
8297 if(campaignchoicenum)
8298 for(i=0;i<campaignchoicenum;i++){
8299 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
8300 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
8301 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
8308 //if(firstload)TickOnceAfter();
8309 if(!firstload)LoadStuff();
8326 strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
8334 OPENAL_SetPaused(channels[stream_music3], true);
8339 if(loading==3)loading=0;
8343 oldmusictype=musictype;
8349 facing=DoRotation(facing,-rotation2,0,0);
8350 facing=DoRotation(facing,0,0-rotation,0);
8351 viewerfacing=facing;
8355 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;
8356 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;
8358 if(player[0].skeleton.free){
8359 for(i=0;i<player[0].skeleton.num_joints;i++){
8360 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
8361 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
8365 if(player[0].skeleton.free!=2&&!autocam){
8367 if(findLengthfast(&player[0].velocity)>400){
8368 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8370 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8371 coltarget=target-cameraloc;
8372 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8374 Normalise(&coltarget);
8375 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8376 else cameraloc=cameraloc+coltarget*multiplier*8;
8378 if(editorenabled)cameraloc=target;
8379 cameradist+=multiplier*5;
8380 if(cameradist>2.3)cameradist=2.3;
8381 viewer=cameraloc-facing*cameradist;
8383 coltarget=cameraloc;
8384 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8385 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8386 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8387 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8389 coltarget=cameraloc;
8390 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8392 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8393 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8394 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8396 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8400 cameradist=findDistance(&viewer,&target);
8401 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
8402 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
8404 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8405 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8408 if(player[0].skeleton.free!=2&&autocam){
8410 if(findLengthfast(&player[0].velocity)>400){
8411 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8413 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8414 cameradist+=multiplier*5;
8415 if(cameradist>3.3)cameradist=3.3;
8416 coltarget=target-cameraloc;
8417 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8418 else if(findLengthfast(&coltarget)>1)
8420 Normalise(&coltarget);
8421 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8422 else cameraloc=cameraloc+coltarget*multiplier*8;
8424 if(editorenabled)cameraloc=target;
8427 coltarget=cameraloc;
8428 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8429 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8430 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8431 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8433 coltarget=cameraloc;
8434 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8436 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8437 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8438 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8440 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8444 cameradist=findDistance(&viewer,&target);
8445 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
8446 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
8448 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8449 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8452 if(camerashake>.8)camerashake=.8;
8453 //if(woozy>10)woozy=10;
8454 //woozy+=multiplier;
8456 if(player[0].dead)camerashake=0;
8457 if(player[0].dead)woozy=0;
8458 camerashake-=multiplier*2;
8459 blackout-=multiplier*2;
8460 //if(player[0].isCrouch())woozy-=multiplier*8;
8461 if(camerashake<0)camerashake=0;
8462 if(blackout<0)blackout=0;
8463 //if(woozy<0)woozy=0;
8465 viewer.x+=(float)(Random()%100)*.0005*camerashake;
8466 viewer.y+=(float)(Random()%100)*.0005*camerashake;
8467 viewer.z+=(float)(Random()%100)*.0005*camerashake;