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>
33 #include "openal_wrapper.h"
36 #include "Animation.h"
44 // Added more evilness needed for MSVC
46 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
47 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
51 extern float multiplier;
53 extern int environment;
54 extern Terrain terrain;
55 extern float screenwidth,screenheight;
58 extern float texdetail;
59 extern Objects objects;
61 extern float slomodelay;
62 extern bool floatjump;
65 extern float camerashake;
67 extern float blackout;
68 extern bool cellophane;
69 extern bool musictoggle;
70 extern int difficulty;
71 extern int bloodtoggle;
72 extern bool invertmouse;
74 extern float precipdelay;
75 extern XYZ viewerfacing;
76 extern bool ambientsound;
77 extern bool mousejump;
78 extern float viewdistance;
80 extern bool keyboardfrozen;
81 extern bool loadingstuff;
82 extern XYZ windvector;
83 extern bool debugmode;
84 static int leveltheme;
86 extern bool visibleloading;
87 extern XYZ envsound[30];
88 extern float envsoundvol[30];
89 extern int numenvsounds;
90 extern float envsoundlife[30];
91 extern float usermousesensitivity;
92 extern bool ismotionblur;
93 extern bool showdamagebar; // (des)activate the damage bar
95 extern float tintr,tintg,tintb;
96 extern bool skyboxtexture;
100 extern float skyboxlightr;
101 extern float skyboxlightg;
102 extern float skyboxlightb;
103 extern float fadestart;
104 extern float slomospeed;
105 extern float slomofreq;
106 extern int tutoriallevel;
107 extern float smoketex;
108 extern float tutorialstagetime;
109 extern int tutorialstage;
110 extern float tutorialmaxtime;
111 extern float tutorialsuccess;
112 extern bool againbonus;
113 extern bool reversaltrain;
114 extern bool canattack;
115 extern bool cananger;
116 extern float damagedealt;
118 extern int editoractive;
119 extern int editorpathtype;
121 extern float hostiletime;
123 extern bool gamestarted;
125 extern int numhotspots;
126 extern int killhotspot;
127 extern XYZ hotspot[40];
128 extern int hotspottype[40];
129 extern float hotspotsize[40];
130 extern char hotspottext[40][256];
131 extern int currenthotspot;
135 extern bool stillloading;
136 extern bool winfreeze;
138 extern bool campaign;
140 static const char *rabbitskin[] = {
141 ":Data:Textures:Fur3.jpg",
142 ":Data:Textures:Fur.jpg",
143 ":Data:Textures:Fur2.jpg",
144 ":Data:Textures:Lynx.jpg",
145 ":Data:Textures:Otter.jpg",
146 ":Data:Textures:Opal.jpg",
147 ":Data:Textures:Sable.jpg",
148 ":Data:Textures:Chocolate.jpg",
149 ":Data:Textures:BW2.jpg",
150 ":Data:Textures:WB2.jpg"
153 static const char *wolfskin[] = {
154 ":Data:Textures:Wolf.jpg",
155 ":Data:Textures:Darkwolf.jpg",
156 ":Data:Textures:Snowwolf.jpg"
159 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
160 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
162 static const char **creatureskin[] = {rabbitskin, wolfskin};
164 /* Return true if PFX is a prefix of STR (case-insensitive). */
165 static bool stripfx(const char *str, const char *pfx)
167 return !strncasecmp(str, pfx, strlen(pfx));
170 static const char *cmd_names[] = {
171 #define DECLARE_COMMAND(cmd) #cmd,
172 #include "ConsoleCmds.h"
173 #undef DECLARE_COMMAND
176 typedef void (*console_handler)(const char *args);
178 #define DECLARE_COMMAND(cmd) static void ch_##cmd(const char *args);
179 #include "ConsoleCmds.h"
180 #undef DECLARE_COMMAND
182 static console_handler cmd_handlers[] = {
183 #define DECLARE_COMMAND(cmd) ch_##cmd,
184 #include "ConsoleCmds.h"
185 #undef DECLARE_COMMAND
190 // added utility functions -sf17k =============================================================
192 //TODO: this is incorrect but I'm afraid to change it and break something,
193 //probably causes quirky behavior that I might want to preserve
194 inline float roughDirection(XYZ vec){
196 float angle=-asin(-vec.x)*180/M_PI;
201 inline float roughDirectionTo(XYZ start, XYZ end){
202 return roughDirection(end-start);
205 //TODO: gotta be a better way
206 inline float pitch(XYZ vec){
208 return -asin(vec.y)*180/M_PI;
210 inline float pitchTo(XYZ start, XYZ end){
211 return pitch(end-start);
214 inline float sq(float n) { return n*n; }
216 inline float stepTowardf(float from, float to, float by){
217 if(fabs(from-to)<by) return to;
218 else if(from>to) return from-by;
222 void playdialogueboxsound(){
224 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
225 temppos=temppos-viewer;
230 switch(dialogueboxsound[whichdialogue][indialogue]){
231 case -6: sound=alarmsound; break;
232 case -4: sound=consolefailsound; break;
233 case -3: sound=consolesuccesssound; break;
234 case -2: sound=firestartsound; break;
235 case -1: sound=fireendsound; break;
236 case 1: sound=rabbitchitter; break;
237 case 2: sound=rabbitchitter2; break;
238 case 3: sound=rabbitpainsound; break;
239 case 4: sound=rabbitpain1sound; break;
240 case 5: sound=rabbitattacksound; break;
241 case 6: sound=rabbitattack2sound; break;
242 case 7: sound=rabbitattack3sound; break;
243 case 8: sound=rabbitattack4sound; break;
244 case 9: sound=growlsound; break;
245 case 10: sound=growl2sound; break;
246 case 11: sound=snarlsound; break;
247 case 12: sound=snarl2sound; break;
248 case 13: sound=barksound; break;
249 case 14: sound=bark2sound; break;
250 case 15: sound=bark3sound; break;
251 case 16: sound=barkgrowlsound; break;
255 emit_sound_at(sound, temppos);
258 // end added utility functions ================================================================
262 static void ch_quit(const char *args)
267 static void ch_map(const char *args)
274 static void ch_save(const char *args){
276 snprintf(buf, 63, ":Data:Maps:%s", args);
281 tfile=fopen( ConvertFileName(buf), "wb" );
282 fpackf(tfile, "Bi", mapvers);
283 fpackf(tfile, "Bi", maptype);
284 fpackf(tfile, "Bi", hostile);
285 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
286 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
287 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
288 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
289 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
290 if(player[0].num_weapons>0&&player[0].num_weapons<5)
291 for(int j=0;j<player[0].num_weapons;j++)
292 fpackf(tfile, "Bi", weapons[player[0].weaponids[j]].getType());
294 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
295 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
296 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
297 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
299 fpackf(tfile, "Bi", player[0].numclothes);
301 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
303 fpackf(tfile, "Bi", numdialogues);
305 for(int k=0;k<numdialogues;k++){
306 fpackf(tfile, "Bi", numdialogueboxes[k]);
307 fpackf(tfile, "Bi", dialoguetype[k]);
308 for(int l=0;l<10;l++){
309 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
310 fpackf(tfile, "Bf", participantrotation[k][l]);
312 for(int l=0;l<numdialogueboxes[k];l++){
313 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
314 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
315 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
316 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
317 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
319 int templength=strlen(dialoguetext[k][l]);
320 fpackf(tfile, "Bi",(templength));
321 for(int m=0;m<templength;m++){
322 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
323 if(dialoguetext[k][l][m]=='\0')
327 templength=strlen(dialoguename[k][l]);
328 fpackf(tfile, "Bi",templength);
329 for(int m=0;m<templength;m++){
330 fpackf(tfile, "Bb", dialoguename[k][l][m]);
331 if(dialoguename[k][l][m]=='\0')
335 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
336 fpackf(tfile, "Bi", participantfocus[k][l]);
337 fpackf(tfile, "Bi", participantaction[k][l]);
339 for(int m=0;m<10;m++)
340 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
342 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
346 for(int k=0;k<player[0].numclothes;k++){
347 int templength=strlen(player[0].clothes[k]);
348 fpackf(tfile, "Bi", templength);
349 for(int l=0;l<templength;l++)
350 fpackf(tfile, "Bb", player[0].clothes[k][l]);
351 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
354 fpackf(tfile, "Bi", environment);
356 fpackf(tfile, "Bi", objects.numobjects);
358 for(int k=0;k<objects.numobjects;k++)
359 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
360 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
362 fpackf(tfile, "Bi", numhotspots);
363 for(int i=0;i<numhotspots;i++){
364 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
365 int templength=strlen(hotspottext[i]);
366 fpackf(tfile, "Bi",templength);
367 for(int l=0;l<templength;l++)
368 fpackf(tfile, "Bb", hotspottext[i][l]);
371 fpackf(tfile, "Bi", numplayers);
372 if(numplayers<maxplayers)
373 for(int j=1;j<numplayers;j++){
374 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
375 player[j].coords.x, player[j].coords.y, player[j].coords.z,
376 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
377 if(player[j].num_weapons<5)
378 for(int k=0;k<player[j].num_weapons;k++)
379 fpackf(tfile, "Bi", weapons[player[j].weaponids[k]].getType());
380 if(player[j].numwaypoints<30){
381 fpackf(tfile, "Bi", player[j].numwaypoints);
382 for(int k=0;k<player[j].numwaypoints;k++){
383 fpackf(tfile, "Bf", player[j].waypoints[k].x);
384 fpackf(tfile, "Bf", player[j].waypoints[k].y);
385 fpackf(tfile, "Bf", player[j].waypoints[k].z);
386 fpackf(tfile, "Bi", player[j].waypointtype[k]);
388 fpackf(tfile, "Bi", player[j].waypoint);
390 player[j].numwaypoints=0;
391 player[j].waypoint=0;
392 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
395 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
396 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
397 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
398 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
400 float headprop, bodyprop, armprop, legprop;
401 if(player[j].creature==wolftype){
402 headprop=player[j].proportionhead.x/1.1;
403 bodyprop=player[j].proportionbody.x/1.1;
404 armprop=player[j].proportionarms.x/1.1;
405 legprop=player[j].proportionlegs.x/1.1;
406 }else if(player[j].creature==rabbittype){
407 headprop=player[j].proportionhead.x/1.2;
408 bodyprop=player[j].proportionbody.x/1.05;
409 armprop=player[j].proportionarms.x/1.00;
410 legprop=player[j].proportionlegs.x/1.1;
413 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
415 fpackf(tfile, "Bi", player[j].numclothes);
416 if(player[j].numclothes)
417 for(int k=0;k<player[j].numclothes;k++){
419 templength=strlen(player[j].clothes[k]);
420 fpackf(tfile, "Bi", templength);
421 for(int l=0;l<templength;l++)
422 fpackf(tfile, "Bb", player[j].clothes[k][l]);
423 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
427 fpackf(tfile, "Bi", numpathpoints);
428 for(int j=0;j<numpathpoints;j++){
429 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
430 for(int k=0;k<numpathpointconnect[j];k++)
431 fpackf(tfile, "Bi", pathpointconnect[j][k]);
434 fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
439 static void ch_cellar(const char *args)
441 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
444 static void ch_tint(const char *args)
446 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
449 static void ch_tintr(const char *args)
454 static void ch_tintg(const char *args)
459 static void ch_tintb(const char *args)
464 static void ch_speed(const char *args)
466 player[0].speedmult = atof(args);
469 static void ch_strength(const char *args)
471 player[0].power = atof(args);
474 static void ch_power(const char *args)
476 player[0].power = atof(args);
479 static void ch_size(const char *args)
481 player[0].scale = atof(args) * .2;
484 static int find_closest()
487 float closestdist = std::numeric_limits<float>::max();
489 for (int i = 1; i < numplayers; i++) {
491 distance = findDistancefast(&player[i].coords,&player[0].coords);
492 if (distance < closestdist) {
493 closestdist = distance;
500 static void ch_sizenear(const char *args)
502 int closest = find_closest();
505 player[closest].scale = atof(args) * .2;
508 static void set_proportion(int pnum, const char *args)
510 float headprop,bodyprop,armprop,legprop;
512 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
514 if(player[pnum].creature==wolftype){
515 player[pnum].proportionhead=1.1*headprop;
516 player[pnum].proportionbody=1.1*bodyprop;
517 player[pnum].proportionarms=1.1*armprop;
518 player[pnum].proportionlegs=1.1*legprop;
519 } else if(player[pnum].creature==rabbittype){
520 player[pnum].proportionhead=1.2*headprop;
521 player[pnum].proportionbody=1.05*bodyprop;
522 player[pnum].proportionarms=1.00*armprop;
523 player[pnum].proportionlegs=1.1*legprop;
524 player[pnum].proportionlegs.y=1.05*legprop;
528 static void ch_proportion(const char *args)
530 set_proportion(0, args);
533 static void ch_proportionnear(const char *args)
535 int closest = find_closest();
537 set_proportion(closest, args);
540 static void set_protection(int pnum, const char *args)
542 float head, high, low;
543 sscanf(args, "%f%f%f", &head, &high, &low);
545 player[pnum].protectionhead = head;
546 player[pnum].protectionhigh = high;
547 player[pnum].protectionlow = low;
550 static void ch_protection(const char *args)
552 set_protection(0, args);
555 static void ch_protectionnear(const char *args)
557 int closest = find_closest();
559 set_protection(closest, args);
562 static void set_armor(int pnum, const char *args)
564 float head, high, low;
565 sscanf(args, "%f%f%f", &head, &high, &low);
567 player[pnum].armorhead = head;
568 player[pnum].armorhigh = high;
569 player[pnum].armorlow = low;
572 static void ch_armor(const char *args)
577 static void ch_armornear(const char *args)
579 int closest = find_closest();
581 set_armor(closest, args);
584 static void ch_protectionreset(const char *args)
586 set_protection(0, "1 1 1");
587 set_armor(0, "1 1 1");
590 static void set_metal(int pnum, const char *args)
592 float head, high, low;
593 sscanf(args, "%f%f%f", &head, &high, &low);
595 player[pnum].metalhead = head;
596 player[pnum].metalhigh = high;
597 player[pnum].metallow = low;
600 static void ch_metal(const char *args)
605 static void set_noclothes(int pnum, const char *args)
607 player[pnum].numclothes = 0;
608 LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
609 &player[pnum].skeleton.drawmodel.textureptr,1,
610 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
613 static void ch_noclothes(const char *args)
615 set_noclothes(0, args);
618 static void ch_noclothesnear(const char *args)
620 int closest = find_closest();
622 set_noclothes(closest, args);
626 static void set_clothes(int pnum, const char *args)
629 snprintf(buf, 63, ":Data:Textures:%s.png", args);
631 if (!AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
634 player[pnum].DoMipmaps();
635 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
636 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
637 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
638 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
639 player[pnum].numclothes++;
642 static void ch_clothes(const char *args)
644 set_clothes(0, args);
647 static void ch_clothesnear(const char *args)
649 int closest = find_closest();
651 set_clothes(closest, args);
654 static void ch_belt(const char *args)
656 player[0].skeleton.clothes = !player[0].skeleton.clothes;
660 static void ch_cellophane(const char *args)
662 cellophane = !cellophane;
663 float mul = cellophane ? 0 : 1;
665 for (int i = 0; i < numplayers; i++) {
666 player[i].proportionhead.z = player[i].proportionhead.x * mul;
667 player[i].proportionbody.z = player[i].proportionbody.x * mul;
668 player[i].proportionarms.z = player[i].proportionarms.x * mul;
669 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
673 static void ch_funnybunny(const char *args)
675 player[0].skeleton.id=0;
676 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
677 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
678 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
679 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
680 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
681 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
682 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
683 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
684 player[0].creature=rabbittype;
686 player[0].headless=0;
687 player[0].damagetolerance=200;
688 set_proportion(0, "1 1 1 1");
691 static void ch_wolfie(const char *args)
693 player[0].skeleton.id=0;
694 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
695 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
696 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
697 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
698 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
699 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
700 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
701 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
702 player[0].creature=wolftype;
703 player[0].damagetolerance=300;
704 set_proportion(0, "1 1 1 1");
707 static void ch_wolfieisgod(const char *args)
712 static void ch_wolf(const char *args)
714 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
715 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
718 static void ch_snowwolf(const char *args)
720 LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
721 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
724 static void ch_darkwolf(const char *args)
726 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
727 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
730 static void ch_lizardwolf(const char *args)
732 LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
733 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
736 static void ch_white(const char *args)
738 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
739 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
742 static void ch_brown(const char *args)
744 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
745 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
748 static void ch_black(const char *args)
750 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
751 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
754 static void ch_sizemin(const char *args)
756 for (int i = 1; i < numplayers; i++)
757 if (player[i].scale < 0.8 * 0.2)
758 player[i].scale = 0.8 * 0.2;
761 static void ch_tutorial(const char *args)
763 tutoriallevel = atoi(args);
766 static void ch_hostile(const char *args)
768 hostile = atoi(args);
771 static void ch_indemo(const char *args)
774 hotspot[numhotspots]=player[0].coords;
775 hotspotsize[numhotspots]=0;
776 hotspottype[numhotspots]=-111;
777 strcpy(hotspottext[numhotspots],"mapname");
781 static void ch_notindemo(const char *args)
787 static void ch_type(const char *args)
789 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
790 for (int i = 0; i < n; i++)
791 if (stripfx(args, editortypenames[i])) {
797 static void ch_path(const char *args)
799 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
800 for (int i = 0; i < n; i++)
801 if (stripfx(args, pathtypenames[i])) {
807 static void ch_hs(const char *args)
809 hotspot[numhotspots]=player[0].coords;
813 sscanf(args, "%f%d %n", &size, &type, &shift);
815 hotspotsize[numhotspots] = size;
816 hotspottype[numhotspots] = type;
818 strcpy(hotspottext[numhotspots], args + shift);
819 strcat(hotspottext[numhotspots], "\n");
824 static void ch_dialogue(const char *args)
827 char buf1[32], buf2[64];
829 sscanf(args, "%d %31s", &dlg, buf1);
830 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
832 dialoguetype[numdialogues] = dlg;
834 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
835 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
837 ifstream ipstream(ConvertFileName(buf2));
838 ipstream.ignore(256,':');
839 ipstream >> numdialogueboxes[numdialogues];
840 for(int i=0;i<numdialogueboxes[numdialogues];i++){
841 ipstream.ignore(256,':');
842 ipstream.ignore(256,':');
843 ipstream.ignore(256,' ');
844 ipstream >> dialogueboxlocation[numdialogues][i];
845 ipstream.ignore(256,':');
846 ipstream >> dialogueboxcolor[numdialogues][i][0];
847 ipstream >> dialogueboxcolor[numdialogues][i][1];
848 ipstream >> dialogueboxcolor[numdialogues][i][2];
849 ipstream.ignore(256,':');
850 ipstream.getline(dialoguename[numdialogues][i],64);
851 ipstream.ignore(256,':');
852 ipstream.ignore(256,' ');
853 ipstream.getline(dialoguetext[numdialogues][i],128);
854 for(int j=0;j<128;j++){
855 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
857 ipstream.ignore(256,':');
858 ipstream >> dialogueboxsound[numdialogues][i];
861 for(int i=0;i<numdialogueboxes[numdialogues];i++){
862 for(int j=0;j<numplayers;j++){
863 participantfacing[numdialogues][i][j]=player[j].facing;
870 whichdialogue=numdialogues;
875 static void ch_fixdialogue(const char *args)
877 char buf1[32], buf2[64];
880 sscanf(args, "%d %31s", &whichdi, buf1);
881 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
883 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
884 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
886 ifstream ipstream(ConvertFileName(buf2));
887 ipstream.ignore(256,':');
888 ipstream >> numdialogueboxes[whichdi];
889 for(int i=0;i<numdialogueboxes[whichdi];i++){
890 ipstream.ignore(256,':');
891 ipstream.ignore(256,':');
892 ipstream.ignore(256,' ');
893 ipstream >> dialogueboxlocation[whichdi][i];
894 ipstream.ignore(256,':');
895 ipstream >> dialogueboxcolor[whichdi][i][0];
896 ipstream >> dialogueboxcolor[whichdi][i][1];
897 ipstream >> dialogueboxcolor[whichdi][i][2];
898 ipstream.ignore(256,':');
899 ipstream.getline(dialoguename[whichdi][i],64);
900 ipstream.ignore(256,':');
901 ipstream.ignore(256,' ');
902 ipstream.getline(dialoguetext[whichdi][i],128);
903 for(int j=0;j<128;j++){
904 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
906 ipstream.ignore(256,':');
907 ipstream >> dialogueboxsound[whichdi][i];
913 static void ch_fixtype(const char *args)
916 sscanf(args, "%d", &dlg);
917 dialoguetype[0] = dlg;
920 static void ch_fixrotation(const char *args)
922 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
925 static void ch_ddialogue(const char *args)
931 static void ch_dhs(const char *args)
937 static void ch_immobile(const char *args)
939 player[0].immobile = 1;
942 static void ch_allimmobile(const char *args)
944 for (int i = 1; i < numplayers; i++)
945 player[i].immobile = 1;
948 static void ch_mobile(const char *args)
950 player[0].immobile = 0;
953 static void ch_default(const char *args)
955 player[0].armorhead=1;
956 player[0].armorhigh=1;
957 player[0].armorlow=1;
958 player[0].protectionhead=1;
959 player[0].protectionhigh=1;
960 player[0].protectionlow=1;
961 player[0].metalhead=1;
962 player[0].metalhigh=1;
963 player[0].metallow=1;
965 player[0].speedmult=1;
968 if(player[0].creature==wolftype){
969 player[0].proportionhead=1.1;
970 player[0].proportionbody=1.1;
971 player[0].proportionarms=1.1;
972 player[0].proportionlegs=1.1;
973 } else if(player[0].creature==rabbittype){
974 player[0].proportionhead=1.2;
975 player[0].proportionbody=1.05;
976 player[0].proportionarms=1.00;
977 player[0].proportionlegs=1.1;
978 player[0].proportionlegs.y=1.05;
981 player[0].numclothes=0;
982 LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
983 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
984 &player[0].skeleton.skinsize);
986 editoractive=typeactive;
987 player[0].immobile=0;
990 static void ch_play(const char *args)
993 sscanf(args, "%d", &dlg);
996 if (whichdialogue >= numdialogues)
999 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1000 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1001 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1002 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1003 player[participantfocus[whichdialogue][i]].velocity=0;
1004 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1005 player[participantfocus[whichdialogue][i]].targetframe=0;
1011 playdialogueboxsound();
1014 static void ch_mapkilleveryone(const char *args)
1016 maptype = mapkilleveryone;
1019 static void ch_mapkillmost(const char *args)
1021 maptype = mapkillmost;
1024 static void ch_mapkillsomeone(const char *args)
1026 maptype = mapkillsomeone;
1029 static void ch_mapgosomewhere(const char *args)
1031 maptype = mapgosomewhere;
1034 static void ch_viewdistance(const char *args)
1036 viewdistance = atof(args)*100;
1039 static void ch_fadestart(const char *args)
1041 fadestart = atof(args);
1044 static void ch_slomo(const char *args)
1046 slomospeed = atof(args);
1051 static void ch_slofreq(const char *args)
1053 slomofreq = atof(args);
1056 static void ch_skytint(const char *args)
1058 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1060 skyboxlightr=skyboxr;
1061 skyboxlightg=skyboxg;
1062 skyboxlightb=skyboxb;
1066 terrain.DoShadows();
1067 objects.DoShadows();
1070 static void ch_skylight(const char *args)
1072 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1076 terrain.DoShadows();
1077 objects.DoShadows();
1080 static void ch_skybox(const char *args)
1082 skyboxtexture = !skyboxtexture;
1086 terrain.DoShadows();
1087 objects.DoShadows();
1090 static void cmd_dispatch(const string cmd)
1092 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1094 for (i = 0; i < n_cmds; i++)
1095 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1097 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1098 cmd_handlers[i](cmd.substr(cmd.find(' ')+1).c_str());
1101 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1104 /********************> Tick() <*****/
1105 extern bool save_image(const char * fname);
1106 void Screenshot (void)
1109 time_t t = time(NULL);
1110 struct tm *tme = localtime(&t);
1111 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);
1114 mkdir("Screenshots");
1116 mkdir("Screenshots", S_IRWXU);
1122 void Game::SetUpLighting(){
1123 if(environment==snowyenvironment)
1124 light.setColors(.65,.65,.7,.4,.4,.44);
1125 if(environment==desertenvironment)
1126 light.setColors(.95,.95,.95,.4,.35,.3);
1127 if(environment==grassyenvironment)
1128 light.setColors(.95,.95,1,.4,.4,.44);
1130 light.setColors(1,1,1,.4,.4,.4);
1132 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1133 light.color[0]*=(skyboxlightr+average)/2;
1134 light.color[1]*=(skyboxlightg+average)/2;
1135 light.color[2]*=(skyboxlightb+average)/2;
1136 light.ambient[0]*=(skyboxlightr+average)/2;
1137 light.ambient[1]*=(skyboxlightg+average)/2;
1138 light.ambient[2]*=(skyboxlightb+average)/2;
1141 int Game::findPathDist(int start,int end){
1142 int smallestcount,count,connected;
1143 int last,last2,last3,last4;
1147 for(int i=0;i<50;i++){
1153 while(last!=end&&count<30){
1155 for(int j=0;j<numpathpoints;j++){
1156 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1159 if(numpathpointconnect[j])
1160 for(int k=0;k<numpathpointconnect[j];k++){
1161 if(pathpointconnect[j][k]==last)connected=1;
1164 if(numpathpointconnect[last])
1165 for(int k=0;k<numpathpointconnect[last];k++){
1166 if(pathpointconnect[last][k]==j)connected=1;
1169 if(closest==-1||Random()%2==0){
1180 if(count<smallestcount)smallestcount=count;
1182 return smallestcount;
1185 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1186 static XYZ colpoint,colviewer,coltarget;
1187 static float minx,minz,maxx,maxz,miny,maxy;
1189 minx=min(startpoint.x,endpoint.x)-1;
1190 miny=min(startpoint.y,endpoint.y)-1;
1191 minz=min(startpoint.z,endpoint.z)-1;
1192 maxx=max(startpoint.x,endpoint.x)+1;
1193 maxy=max(startpoint.y,endpoint.y)+1;
1194 maxz=max(startpoint.z,endpoint.z)+1;
1196 for(int i=0;i<objects.numobjects;i++){
1197 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1198 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1199 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1200 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1201 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1202 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1203 if( objects.type[i]!=treeleavestype&&
1204 objects.type[i]!=bushtype&&
1205 objects.type[i]!=firetype){
1206 colviewer=startpoint;
1208 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1213 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1218 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1219 static XYZ colpoint,colviewer,coltarget;
1220 static float minx,minz,maxx,maxz,miny,maxy;
1221 static int i; //FIXME: see below
1223 minx=min(startpoint.x,endpoint.x)-1;
1224 miny=min(startpoint.y,endpoint.y)-1;
1225 minz=min(startpoint.z,endpoint.z)-1;
1226 maxx=max(startpoint.x,endpoint.x)+1;
1227 maxy=max(startpoint.y,endpoint.y)+1;
1228 maxz=max(startpoint.z,endpoint.z)+1;
1231 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1232 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1233 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1234 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1235 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1236 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1237 if( objects.type[what]!=treeleavestype&&
1238 objects.type[what]!=bushtype&&
1239 objects.type[what]!=firetype){
1240 colviewer=startpoint;
1243 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1248 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1253 void Game::Setenvironment(int which)
1257 LOG(" Setting environment...");
1259 float temptexdetail;
1262 pause_sound(stream_snowtheme);
1263 pause_sound(stream_grasstheme);
1264 pause_sound(stream_deserttheme);
1265 pause_sound(stream_wind);
1266 pause_sound(stream_desertambient);
1269 if(environment==snowyenvironment){
1273 emit_stream_np(stream_wind);
1275 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1276 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1277 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1278 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1280 footstepsound = footstepsn1;
1281 footstepsound2 = footstepsn2;
1282 footstepsound3 = footstepst1;
1283 footstepsound4 = footstepst2;
1285 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1287 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1289 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1294 temptexdetail=texdetail;
1295 if(texdetail>1)texdetail=4;
1296 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1297 ":Data:Textures:Skybox(snow):Left.jpg",
1298 ":Data:Textures:Skybox(snow):Back.jpg",
1299 ":Data:Textures:Skybox(snow):Right.jpg",
1300 ":Data:Textures:Skybox(snow):Up.jpg",
1301 ":Data:Textures:Skybox(snow):Down.jpg");
1306 texdetail=temptexdetail;
1307 } else if(environment==desertenvironment){
1310 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1311 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1312 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1313 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1317 emit_stream_np(stream_desertambient);
1319 footstepsound = footstepsn1;
1320 footstepsound2 = footstepsn2;
1321 footstepsound3 = footstepsn1;
1322 footstepsound4 = footstepsn2;
1324 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1326 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1328 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1332 temptexdetail=texdetail;
1333 if(texdetail>1)texdetail=4;
1334 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1335 ":Data:Textures:Skybox(sand):Left.jpg",
1336 ":Data:Textures:Skybox(sand):Back.jpg",
1337 ":Data:Textures:Skybox(sand):Right.jpg",
1338 ":Data:Textures:Skybox(sand):Up.jpg",
1339 ":Data:Textures:Skybox(sand):Down.jpg");
1344 texdetail=temptexdetail;
1345 } else if(environment==grassyenvironment){
1348 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1349 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1350 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1351 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1354 emit_stream_np(stream_wind, 100.);
1356 footstepsound = footstepgr1;
1357 footstepsound2 = footstepgr2;
1358 footstepsound3 = footstepst1;
1359 footstepsound4 = footstepst2;
1361 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1363 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1365 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1369 temptexdetail=texdetail;
1370 if(texdetail>1)texdetail=4;
1371 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1372 ":Data:Textures:Skybox(grass):Left.jpg",
1373 ":Data:Textures:Skybox(grass):Back.jpg",
1374 ":Data:Textures:Skybox(grass):Right.jpg",
1375 ":Data:Textures:Skybox(grass):Up.jpg",
1376 ":Data:Textures:Skybox(grass):Down.jpg");
1380 texdetail=temptexdetail;
1382 temptexdetail=texdetail;
1384 terrain.load(":Data:Textures:heightmap.png");
1386 texdetail=temptexdetail;
1389 void Game::Loadlevel(int which) {
1395 Loadlevel("tutorial");
1396 } else if(which >= 0 && which <= 15) {
1398 snprintf(buf, 32, "map%d", which + 1); // challenges
1401 Loadlevel("mapsave");
1404 void Game::Loadlevel(const char *name) {
1407 static const char *pfx = ":Data:Maps:";
1410 float headprop,legprop,armprop,bodyprop;
1414 LOG(std::string("Loading level...") + name);
1426 if(tutoriallevel!=-1)
1431 if(tutoriallevel==1)
1433 if(tutorialstage==0) {
1434 tutorialstagetime=0;
1438 pause_sound(whooshsound);
1439 pause_sound(stream_firesound);
1441 // Change the map filename into something that is os specific
1442 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1443 sprintf(buf, "%s%s", pfx, name);
1444 const char *FixedFN = ConvertFileName(buf);
1448 //~ char* buff=getcwd(NULL,0);
1449 //~ cout << buff << " " << FixedFN << endl;
1451 tfile=fopen( FixedFN, "rb" );
1453 pause_sound(stream_firesound);
1459 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1463 for(int i=0;i<20;i++)
1464 dialoguegonethrough[i]=0;
1473 difficulty=accountactive->getDifficulty();
1492 for(int i=0;i<100;i++)
1512 bonustotal=startbonustotal;
1517 emit_sound_np(consolesuccesssound);
1522 if(!stealthloading){
1523 terrain.numdecals=0;
1524 Sprite::deleteSprites();
1525 for(int i=0;i<objects.numobjects;i++)
1526 objects.model[i].numdecals=0;
1528 int j=objects.numobjects;
1529 for(int i=0;i<j;i++){
1530 objects.DeleteObject(0);
1535 for(int i=0;i<subdivision;i++)
1536 for(int j=0;j<subdivision;j++)
1537 terrain.patchobjectnum[i][j]=0;
1544 funpackf(tfile, "Bi", &mapvers);
1546 funpackf(tfile, "Bi", &indemo);
1550 funpackf(tfile, "Bi", &maptype);
1552 maptype=mapkilleveryone;
1554 funpackf(tfile, "Bi", &hostile);
1558 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1564 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1572 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1574 skyboxlightr=skyboxr;
1575 skyboxlightg=skyboxg;
1576 skyboxlightb=skyboxb;
1579 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);
1581 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1582 player[0].originalcoords=player[0].coords;
1583 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1584 for(int j=0;j<player[0].num_weapons;j++){
1585 player[0].weaponids[j]=weapons.size();
1587 funpackf(tfile, "Bi", &type);
1588 weapons.push_back(Weapon(type,0));
1594 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1595 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1596 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1597 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1599 funpackf(tfile, "Bi", &player[0].numclothes);
1602 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1604 player[0].whichskin=0;
1605 player[0].creature=rabbittype;
1608 player[0].lastattack=-1;
1609 player[0].lastattack2=-1;
1610 player[0].lastattack3=-1;
1614 funpackf(tfile, "Bi", &numdialogues);
1615 for(int k=0;k<numdialogues;k++){
1616 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1617 funpackf(tfile, "Bi", &dialoguetype[k]);
1618 for(int l=0;l<10;l++){
1619 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1620 funpackf(tfile, "Bf", &participantrotation[k][l]);
1622 for(int l=0;l<numdialogueboxes[k];l++){
1623 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1624 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1625 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1626 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1627 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1629 funpackf(tfile, "Bi",&templength);
1630 if(templength>128||templength<=0)
1633 for(m=0;m<templength;m++){
1634 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1635 if(dialoguetext[k][l][m]=='\0')
1638 dialoguetext[k][l][m] = 0;
1640 funpackf(tfile, "Bi",&templength);
1641 if(templength>64||templength<=0)templength=64;
1642 for(m=0;m<templength;m++){
1643 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1644 if(dialoguename[k][l][m]=='\0')
1647 dialoguename[k][l][m] = 0;
1648 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1649 funpackf(tfile, "Bi", &participantfocus[k][l]);
1650 funpackf(tfile, "Bi", &participantaction[k][l]);
1653 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1655 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1661 for(int k=0;k<player[0].numclothes;k++){
1662 funpackf(tfile, "Bi", &templength);
1663 for(int l=0;l<templength;l++)
1664 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1665 player[0].clothes[k][templength]='\0';
1666 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1669 funpackf(tfile, "Bi", &environment);
1671 funpackf(tfile, "Bi", &objects.numobjects);
1672 for(int i=0;i<objects.numobjects;i++){
1673 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]);
1674 if(objects.type[i]==treeleavestype)
1675 objects.scale[i]=objects.scale[i-1];
1679 funpackf(tfile, "Bi", &numhotspots);
1680 for(int i=0;i<numhotspots;i++){
1681 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1682 funpackf(tfile, "Bi", &templength);
1684 for(int l=0;l<templength;l++)
1685 funpackf(tfile, "Bb", &hotspottext[i][l]);
1686 hotspottext[i][templength]='\0';
1687 if(hotspottype[i]==-111)
1696 if(!stealthloading){
1698 for(int i=0;i<objects.numobjects;i++)
1699 objects.center+=objects.position[i];
1700 objects.center/=objects.numobjects;
1706 float maxdistance=0;
1708 //~ int whichclosest;
1709 for(int i=0;i<objects.numobjects;i++){
1710 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1711 if(tempdist>maxdistance){
1713 maxdistance=tempdist;
1716 objects.radius=fast_sqrt(maxdistance);
1721 //mapcenter=objects.center;
1722 //mapradius=objects.radius;
1724 funpackf(tfile, "Bi", &numplayers);
1725 int howmanyremoved=0;
1726 bool removeanother=0;
1727 if(numplayers>1&&numplayers<maxplayers){
1728 for(int i=1;i<numplayers;i++){
1733 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);
1735 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1737 player[i-howmanyremoved].howactive=typeactive;
1739 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1741 player[i-howmanyremoved].scale=-1;
1743 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1745 player[i-howmanyremoved].immobile=0;
1747 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1749 player[i-howmanyremoved].rotation=0;
1750 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1751 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1756 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1757 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1758 player[i-howmanyremoved].weaponids[j]=weapons.size();
1760 funpackf(tfile, "Bi", &type);
1761 weapons.push_back(Weapon(type,i));
1764 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1765 //player[i-howmanyremoved].numwaypoints=10;
1766 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1767 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1768 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1769 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1771 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1773 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1776 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1777 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1778 player[i-howmanyremoved].waypoint=0;
1780 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1781 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1782 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1783 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1786 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1793 if(player[i-howmanyremoved].creature==wolftype){
1794 player[i-howmanyremoved].proportionhead=1.1*headprop;
1795 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1796 player[i-howmanyremoved].proportionarms=1.1*armprop;
1797 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1800 if(player[i-howmanyremoved].creature==rabbittype){
1801 player[i-howmanyremoved].proportionhead=1.2*headprop;
1802 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1803 player[i-howmanyremoved].proportionarms=1.00*armprop;
1804 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1805 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1808 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1809 if(player[i-howmanyremoved].numclothes){
1810 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1812 funpackf(tfile, "Bi", &templength);
1813 for(int l=0;l<templength;l++)
1814 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1815 player[i-howmanyremoved].clothes[k][templength]='\0';
1816 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1825 numplayers-=howmanyremoved;
1826 funpackf(tfile, "Bi", &numpathpoints);
1827 if(numpathpoints>30||numpathpoints<0)
1829 for(int j=0;j<numpathpoints;j++){
1830 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1831 for(int k=0;k<numpathpointconnect[j];k++){
1832 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1838 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1841 if(environment!=oldenvironment)
1842 Setenvironment(environment);
1843 oldenvironment=environment;
1845 if(!stealthloading){
1846 int j=objects.numobjects;
1847 objects.numobjects=0;
1848 for(int i=0;i<j;i++){
1849 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1854 terrain.DoShadows();
1857 objects.DoShadows();
1864 if(numplayers>maxplayers-1)
1865 numplayers=maxplayers-1;
1866 for(int i=0;i<numplayers;i++){
1872 if(i==0||player[i].scale<0)
1874 player[i].skeleton.free=0;
1875 player[i].skeleton.id=i;
1877 player[i].creature=rabbittype;
1878 if(player[i].creature!=wolftype){
1879 player[i].skeleton.Load(
1880 (char *)":Data:Skeleton:Basic Figure",
1881 (char *)":Data:Skeleton:Basic Figurelow",
1882 (char *)":Data:Skeleton:Rabbitbelt",
1883 (char *)":Data:Models:Body.solid",
1884 (char *)":Data:Models:Body2.solid",
1885 (char *)":Data:Models:Body3.solid",
1886 (char *)":Data:Models:Body4.solid",
1887 (char *)":Data:Models:Body5.solid",
1888 (char *)":Data:Models:Body6.solid",
1889 (char *)":Data:Models:Body7.solid",
1890 (char *)":Data:Models:Bodylow.solid",
1891 (char *)":Data:Models:Belt.solid",0);
1893 if(player[i].creature!=wolftype){
1894 player[i].skeleton.Load(
1895 (char *)":Data:Skeleton:Basic Figure",
1896 (char *)":Data:Skeleton:Basic Figurelow",
1897 (char *)":Data:Skeleton:Rabbitbelt",
1898 (char *)":Data:Models:Body.solid",
1899 (char *)":Data:Models:Body2.solid",
1900 (char *)":Data:Models:Body3.solid",
1901 (char *)":Data:Models:Body4.solid",
1902 (char *)":Data:Models:Body5.solid",
1903 (char *)":Data:Models:Body6.solid",
1904 (char *)":Data:Models:Body7.solid",
1905 (char *)":Data:Models:Bodylow.solid",
1906 (char *)":Data:Models:Belt.solid",1);
1907 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1909 if(player[i].creature==wolftype){
1910 player[i].skeleton.Load(
1911 (char *)":Data:Skeleton:Basic Figure Wolf",
1912 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1913 (char *)":Data:Skeleton:Rabbitbelt",
1914 (char *)":Data:Models:Wolf.solid",
1915 (char *)":Data:Models:Wolf2.solid",
1916 (char *)":Data:Models:Wolf3.solid",
1917 (char *)":Data:Models:Wolf4.solid",
1918 (char *)":Data:Models:Wolf5.solid",
1919 (char *)":Data:Models:Wolf6.solid",
1920 (char *)":Data:Models:Wolf7.solid",
1921 (char *)":Data:Models:Wolflow.solid",
1922 (char *)":Data:Models:Belt.solid",0);
1928 //~ texsize=512*512*3/texdetail/texdetail;
1930 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1932 if(player[i].numclothes){
1933 for(int j=0;j<player[i].numclothes;j++){
1934 tintr=player[i].clothestintr[j];
1935 tintg=player[i].clothestintg[j];
1936 tintb=player[i].clothestintb[j];
1937 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1939 player[i].DoMipmaps();
1942 player[i].currentanimation=bounceidleanim;
1943 player[i].targetanimation=bounceidleanim;
1944 player[i].currentframe=0;
1945 player[i].targetframe=1;
1947 player[i].speed=1+(float)(Random()%100)/1000;
1949 player[i].speed-=.2;
1951 player[i].speed-=.1;
1953 player[i].velocity=0;
1954 player[i].oldcoords=player[i].coords;
1955 player[i].realoldcoords=player[i].coords;
1958 player[i].skeleton.id=i;
1959 player[i].updatedelay=0;
1960 player[i].normalsupdatedelay=0;
1962 player[i].aitype=passivetype;
1963 player[i].madskills=0;
1966 player[i].proportionhead=1.2;
1967 player[i].proportionbody=1.05;
1968 player[i].proportionarms=1.00;
1969 player[i].proportionlegs=1.1;
1970 player[i].proportionlegs.y=1.05;
1972 player[i].headless=0;
1973 player[i].currentoffset=0;
1974 player[i].targetoffset=0;
1976 player[i].damagetolerance=200;
1978 if(player[i].creature==wolftype){
1979 if(i==0||player[i].scale<0)
1980 player[i].scale=.23;
1981 player[i].damagetolerance=300;
1987 player[i].proportionhead.z=0;
1988 player[i].proportionbody.z=0;
1989 player[i].proportionarms.z=0;
1990 player[i].proportionlegs.z=0;
1993 player[i].tempanimation.Load((char *)"Tempanim",0,0);
1995 player[i].headmorphness=0;
1996 player[i].targetheadmorphness=1;
1997 player[i].headmorphstart=0;
1998 player[i].headmorphend=0;
2000 player[i].pausetime=0;
2003 player[i].jumppower=5;
2005 player[i].permanentdamage=0;
2006 player[i].superpermanentdamage=0;
2008 player[i].forwardkeydown=0;
2009 player[i].leftkeydown=0;
2010 player[i].backkeydown=0;
2011 player[i].rightkeydown=0;
2012 player[i].jumpkeydown=0;
2013 player[i].crouchkeydown=0;
2014 player[i].throwkeydown=0;
2016 player[i].collided=-10;
2018 player[i].bloodloss=0;
2019 player[i].weaponactive=-1;
2020 player[i].weaponstuck=-1;
2021 player[i].bleeding=0;
2022 player[i].deathbleeding=0;
2023 player[i].stunned=0;
2024 player[i].hasvictim=0;
2025 player[i].wentforweapon=0;
2028 player[0].aitype=playercontrolled;
2029 player[0].weaponactive=-1;
2032 player[0].power=1/.9;
2035 player[0].power=1/.8;
2038 player[0].damagetolerance=250;
2040 player[0].damagetolerance=300;
2042 player[0].armorhead*=1.5;
2044 player[0].armorhigh*=1.5;
2046 player[0].armorlow*=1.5;
2047 cameraloc=player[0].coords;
2049 rotation=player[0].rotation;
2051 hawkcoords=player[0].coords;
2056 //~ for(int i=0;i<weapons.size();i++){
2059 LOG("Starting background music...");
2061 OPENAL_StopSound(OPENAL_ALL);
2062 if(environment==snowyenvironment){
2064 emit_stream_np(stream_wind);
2065 }else if(environment==desertenvironment){
2067 emit_stream_np(stream_desertambient);
2068 }else if(environment==grassyenvironment){
2070 emit_stream_np(stream_wind, 100.);
2072 oldmusicvolume[0]=0;
2073 oldmusicvolume[1]=0;
2074 oldmusicvolume[2]=0;
2075 oldmusicvolume[3]=0;
2087 void Game::doTutorial(){
2088 if(tutorialstagetime>tutorialmaxtime){
2091 if(tutorialstage<=1){
2096 switch(tutorialstage){
2102 tutorialmaxtime=600;
2104 tutorialmaxtime=1000;
2106 tutorialmaxtime=600;
2108 tutorialmaxtime=600;
2110 tutorialmaxtime=600;
2112 tutorialmaxtime=600;
2114 tutorialmaxtime=600;
2118 tutorialmaxtime=1000;
2120 tutorialmaxtime=1000;
2135 player[1].coords=(temp+temp2)/2;
2137 emit_sound_at(fireendsound, player[1].coords);
2139 for(int i=0;i<player[1].skeleton.num_joints;i++){
2141 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2142 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2143 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;
2144 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2145 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2150 tutorialmaxtime=500;
2152 tutorialmaxtime=500;
2154 tutorialmaxtime=500;
2156 tutorialmaxtime=500;
2159 //tutorialmaxtime=500;
2161 tutorialmaxtime=500;
2163 tutorialmaxtime=500;
2170 tutorialmaxtime=500;
2172 tutorialmaxtime=500;
2174 tutorialmaxtime=500;
2176 tutorialmaxtime=500;
2183 player[1].aitype=attacktypecutoff;
2185 tutorialmaxtime=400;
2187 tutorialmaxtime=400;
2188 player[0].escapednum=0;
2193 player[1].aitype=passivetype;
2199 tutorialmaxtime=400;
2202 player[1].aitype=attacktypecutoff;
2204 tutorialmaxtime=400;
2206 tutorialmaxtime=400;
2211 player[1].aitype=passivetype;
2218 player[1].aitype=attacktypecutoff;
2223 player[1].aitype=passivetype;
2235 w.position=(temp+temp2)/2;
2236 w.tippoint=(temp+temp2)/2;
2246 weapons.push_back(w);
2249 tutorialmaxtime=300;
2251 tutorialmaxtime=300;
2255 tutorialmaxtime=300;
2258 player[0].weaponactive=-1;
2259 player[0].num_weapons=0;
2260 player[1].weaponactive=0;
2261 player[1].num_weapons=1;
2262 player[1].weaponids[0]=0;
2266 player[1].aitype=attacktypecutoff;
2268 tutorialmaxtime=300;
2271 player[0].weaponactive=-1;
2272 player[0].num_weapons=0;
2273 player[1].weaponactive=0;
2274 player[1].num_weapons=1;
2275 player[1].weaponids[0]=0;
2277 tutorialmaxtime=300;
2280 player[0].weaponactive=-1;
2281 player[0].num_weapons=0;
2282 player[1].weaponactive=0;
2283 player[1].num_weapons=1;
2284 player[1].weaponids[0]=0;
2286 weapons[0].setType(sword);
2288 tutorialmaxtime=300;
2302 w.position=(temp+temp2)/2;
2303 w.tippoint=(temp+temp2)/2;
2313 weapons.push_back(w);
2317 player[0].weaponactive=0;
2318 player[0].num_weapons=1;
2319 player[0].weaponids[0]=1;
2320 player[1].weaponactive=0;
2321 player[1].num_weapons=1;
2322 player[1].weaponids[0]=0;
2328 player[1].aitype=passivetype;
2334 player[0].weaponactive=0;
2335 player[0].num_weapons=1;
2336 player[0].weaponids[0]=1;
2337 player[1].weaponactive=0;
2338 player[1].num_weapons=1;
2339 player[1].weaponids[0]=0;
2341 if(player[0].weaponactive!=-1)
2342 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2344 weapons[0].setType(staff);
2348 player[1].aitype=passivetype;
2350 tutorialmaxtime=200;
2352 weapons[1].position=1000;
2353 weapons[1].tippoint=1000;
2355 weapons[0].setType(knife);
2358 player[1].weaponactive=-1;
2359 player[1].num_weapons=0;
2360 player[0].weaponactive=0;
2361 player[0].num_weapons=1;
2362 player[0].weaponids[0]=0;
2368 emit_sound_at(fireendsound, player[1].coords);
2370 for(int i=0;i<player[1].skeleton.num_joints;i++){
2372 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2373 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2374 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;
2375 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2376 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2380 player[1].num_weapons=0;
2381 player[1].weaponstuck=-1;
2382 player[1].weaponactive=-1;
2387 tutorialmaxtime=80000;
2388 break; default: break;
2390 if(tutorialstage<=51)tutorialstagetime=0;
2394 if(tutorialstagetime<tutorialmaxtime-3){
2395 switch(tutorialstage){
2396 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2397 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2398 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2399 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2400 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2401 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2402 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2403 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2404 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2405 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2406 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2407 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2408 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2409 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2410 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2411 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2412 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2413 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2414 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2415 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2416 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2418 if(player[0].escapednum==2) {
2422 player[1].aitype=passivetype;
2424 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2425 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2427 if(animation[player[0].targetanimation].attack==reversal){
2431 player[1].aitype=passivetype;
2433 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2434 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2435 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2436 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2437 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2438 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2439 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2440 break; default: break;
2442 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2445 if(tutorialstagetime==tutorialmaxtime-3){
2446 emit_sound_np(consolesuccesssound);
2449 if(tutorialsuccess>=1){
2450 if(tutorialstage==34||tutorialstage==35)
2451 tutorialstagetime=tutorialmaxtime-1;
2455 if(tutorialstage<14||tutorialstage>=50){
2456 player[1].coords.y=300;
2457 player[1].velocity=0;
2461 void Game::doDebugKeys(){
2462 float headprop,bodyprop,armprop,legprop;
2464 if(Input::isKeyPressed(SDLK_h)){
2465 player[0].damagetolerance=200000;
2468 player[0].permanentdamage=0;
2469 player[0].superpermanentdamage=0;
2472 if(Input::isKeyPressed(SDLK_j)){
2476 Setenvironment(environment);
2479 if(Input::isKeyPressed(SDLK_c)){
2480 cameramode=1-cameramode;
2483 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2484 if(player[0].num_weapons>0){
2485 if(weapons[player[0].weaponids[0]].getType()==sword)
2486 weapons[player[0].weaponids[0]].setType(staff);
2487 else if(weapons[player[0].weaponids[0]].getType()==staff)
2488 weapons[player[0].weaponids[0]].setType(knife);
2490 weapons[player[0].weaponids[0]].setType(sword);
2494 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2496 float closestdist=-1;
2499 for(int i=1;i<numplayers;i++){
2500 distance=findDistancefast(&player[i].coords,&player[0].coords);
2501 if(closestdist==-1||distance<closestdist){
2502 closestdist=distance;
2507 if(player[closest].num_weapons){
2508 if(weapons[player[closest].weaponids[0]].getType()==sword)
2509 weapons[player[closest].weaponids[0]].setType(staff);
2510 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2511 weapons[player[closest].weaponids[0]].setType(knife);
2513 weapons[player[closest].weaponids[0]].setType(sword);
2515 if(!player[closest].num_weapons){
2516 player[closest].weaponids[0]=weapons.size();
2518 weapons.push_back(Weapon(knife,closest));
2520 player[closest].num_weapons=1;
2525 if(Input::isKeyDown(SDLK_u)){
2527 float closestdist=-1;
2530 for(int i=1;i<numplayers;i++){
2531 distance=findDistancefast(&player[i].coords,&player[0].coords);
2532 if(closestdist==-1||distance<closestdist){
2533 closestdist=distance;
2537 player[closest].rotation+=multiplier*50;
2538 player[closest].targetrotation=player[closest].rotation;
2542 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2544 float closestdist=-1;
2547 for(int i=1;i<numplayers;i++){
2548 distance=findDistancefast(&player[i].coords,&player[0].coords);
2549 if(closestdist==-1||distance<closestdist){
2550 closestdist=distance;
2554 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2557 player[closest].whichskin++;
2558 if(player[closest].whichskin>9)
2559 player[closest].whichskin=0;
2560 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2561 player[closest].whichskin=0;
2563 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2564 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2567 if(player[closest].numclothes){
2568 for(int i=0;i<player[closest].numclothes;i++){
2569 tintr=player[closest].clothestintr[i];
2570 tintg=player[closest].clothestintg[i];
2571 tintb=player[closest].clothestintb[i];
2572 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2574 player[closest].DoMipmaps();
2578 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2580 float closestdist=-1;
2583 for(int i=1;i<numplayers;i++){
2584 distance=findDistancefast(&player[i].coords,&player[0].coords);
2585 if(closestdist==-1||distance<closestdist){
2586 closestdist=distance;
2591 if(player[closest].creature==wolftype){
2592 headprop=player[closest].proportionhead.x/1.1;
2593 bodyprop=player[closest].proportionbody.x/1.1;
2594 armprop=player[closest].proportionarms.x/1.1;
2595 legprop=player[closest].proportionlegs.x/1.1;
2598 if(player[closest].creature==rabbittype){
2599 headprop=player[closest].proportionhead.x/1.2;
2600 bodyprop=player[closest].proportionbody.x/1.05;
2601 armprop=player[closest].proportionarms.x/1.00;
2602 legprop=player[closest].proportionlegs.x/1.1;
2606 if(player[closest].creature==rabbittype){
2607 player[closest].skeleton.id=closest;
2608 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);
2609 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2610 player[closest].whichskin=0;
2611 player[closest].creature=wolftype;
2613 player[closest].proportionhead=1.1;
2614 player[closest].proportionbody=1.1;
2615 player[closest].proportionarms=1.1;
2616 player[closest].proportionlegs=1.1;
2617 player[closest].proportionlegs.y=1.1;
2618 player[closest].scale=.23*5*player[0].scale;
2620 player[closest].damagetolerance=300;
2624 player[closest].skeleton.id=closest;
2625 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);
2626 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2627 player[closest].whichskin=0;
2628 player[closest].creature=rabbittype;
2630 player[closest].proportionhead=1.2;
2631 player[closest].proportionbody=1.05;
2632 player[closest].proportionarms=1.00;
2633 player[closest].proportionlegs=1.1;
2634 player[closest].proportionlegs.y=1.05;
2635 player[closest].scale=.2*5*player[0].scale;
2637 player[closest].damagetolerance=200;
2640 if(player[closest].creature==wolftype){
2641 player[closest].proportionhead=1.1*headprop;
2642 player[closest].proportionbody=1.1*bodyprop;
2643 player[closest].proportionarms=1.1*armprop;
2644 player[closest].proportionlegs=1.1*legprop;
2647 if(player[closest].creature==rabbittype){
2648 player[closest].proportionhead=1.2*headprop;
2649 player[closest].proportionbody=1.05*bodyprop;
2650 player[closest].proportionarms=1.00*armprop;
2651 player[closest].proportionlegs=1.1*legprop;
2652 player[closest].proportionlegs.y=1.05*legprop;
2658 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2664 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2666 float closestdist=-1;
2668 XYZ flatfacing2,flatvelocity2;
2671 for(int i=1;i<numplayers;i++){
2672 distance=findDistancefast(&player[i].coords,&player[0].coords);
2673 if(distance<144&&!player[i].headless)
2674 if(closestdist==-1||distance<closestdist){
2675 closestdist=distance;
2677 blah = player[i].coords;
2682 XYZ headspurtdirection;
2683 //int i = player[closest].skeleton.jointlabels[head];
2684 Joint& headjoint= player[closest].getJointFor(head);
2685 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2686 if(!player[closest].skeleton.free)
2687 flatvelocity2=player[closest].velocity;
2688 if(player[closest].skeleton.free)
2689 flatvelocity2=headjoint.velocity;
2690 if(!player[closest].skeleton.free)
2691 flatfacing2=DoRotation(DoRotation(DoRotation(headjoint.position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].rotation,0)*player[closest].scale+player[closest].coords;
2692 if(player[closest].skeleton.free)
2693 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2694 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2695 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2696 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2697 headspurtdirection=headjoint.position-player[closest].getJointFor(neck).position;
2698 Normalise(&headspurtdirection);
2699 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2700 flatvelocity2+=headspurtdirection*8;
2701 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2703 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2705 emit_sound_at(splattersound, blah);
2706 emit_sound_at(breaksound2, blah, 100.);
2708 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2709 player[closest].RagDoll(0);
2710 player[closest].dead=2;
2711 player[closest].headless=1;
2712 player[closest].DoBloodBig(3,165);
2718 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2720 float closestdist=-1;
2722 XYZ flatfacing2,flatvelocity2;
2725 for(int i=1;i<numplayers;i++){
2726 distance=findDistancefast(&player[i].coords,&player[0].coords);
2728 if(closestdist==-1||distance<closestdist){
2729 closestdist=distance;
2731 blah=player[i].coords;
2736 emit_sound_at(splattersound, blah);
2738 emit_sound_at(breaksound2, blah);
2740 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2741 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2742 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2743 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;
2744 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2745 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2746 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2747 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2748 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2749 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2750 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2753 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2754 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2755 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2756 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;
2757 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2758 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2759 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2760 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2761 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2762 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2765 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2766 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2767 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2768 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;
2769 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2770 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2771 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2772 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2773 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2774 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2777 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2778 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2779 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2780 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;
2781 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2782 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2783 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2784 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2785 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2786 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2790 for(int j=0;j<numplayers; j++){
2792 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2793 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2794 if(player[j].skeleton.free==2)
2795 player[j].skeleton.free=1;
2796 player[j].skeleton.longdead=0;
2797 player[j].RagDoll(0);
2798 for(int i=0;i<player[j].skeleton.num_joints; i++){
2799 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2800 if(findDistancefast(&temppos,&player[closest].coords)<25){
2801 flatvelocity2=temppos-player[closest].coords;
2802 Normalise(&flatvelocity2);
2803 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2810 player[closest].DoDamage(10000);
2811 player[closest].RagDoll(0);
2812 player[closest].dead=2;
2813 player[closest].coords=20;
2814 player[closest].skeleton.free=2;
2821 if(Input::isKeyPressed(SDLK_f)){
2822 player[0].onfire=1-player[0].onfire;
2823 if(player[0].onfire){
2824 player[0].CatchFire();
2826 if(!player[0].onfire){
2827 emit_sound_at(fireendsound, player[0].coords);
2828 pause_sound(stream_firesound);
2832 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2833 //if(!player[0].skeleton.free)player[0].damage+=500;
2834 player[0].RagDoll(0);
2835 //player[0].spurt=1;
2836 //player[0].DoDamage(1000);
2838 emit_sound_at(whooshsound, player[0].coords, 128.);
2841 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2842 for(int i=0;i<objects.numobjects;i++){
2843 if(objects.type[i]==treeleavestype){
2844 objects.scale[i]*=.9;
2849 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2850 editorenabled=1-editorenabled;
2852 player[0].damagetolerance=100000;
2854 player[0].damagetolerance=200;
2856 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2857 player[0].permanentdamage=0;
2858 player[0].superpermanentdamage=0;
2859 player[0].bloodloss=0;
2860 player[0].deathbleeding=0;
2864 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2866 if(targetlevel>numchallengelevels-1)
2873 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2875 float closestdist=-1;
2878 for(int i=1;i<numplayers;i++){
2879 distance=findDistancefast(&player[i].coords,&player[0].coords);
2880 if(closestdist==-1||distance<closestdist){
2881 closestdist=distance;
2885 if(closestdist>0&&closest>=0){
2886 //player[closest]=player[numplayers-1];
2887 //player[closest].skeleton=player[numplayers-1].skeleton;
2892 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2894 float closestdist=-1;
2897 for(int i=1;i<max_objects;i++){
2898 distance=findDistancefast(&objects.position[i],&player[0].coords);
2899 if(closestdist==-1||distance<closestdist){
2900 closestdist=distance;
2904 if(closestdist>0&&closest>=0){
2905 objects.position[closest].y-=500;
2909 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2911 //if(drawmode>2)drawmode=0;
2912 if(objects.numobjects<max_objects-1){
2914 boxcoords.x=player[0].coords.x;
2915 boxcoords.z=player[0].coords.z;
2916 boxcoords.y=player[0].coords.y-3;
2917 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
2918 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
2919 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
2920 float temprotat,temprotat2;
2921 temprotat=editorrotation;
2922 temprotat2=editorrotation2;
2923 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
2924 if(temprotat2<0)temprotat2=Random()%360;
2926 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
2927 if(editortype==treetrunktype)
2928 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
2932 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
2933 if(numplayers<maxplayers-1){
2934 player[numplayers].scale=.2*5*player[0].scale;
2935 player[numplayers].creature=rabbittype;
2936 player[numplayers].howactive=editoractive;
2937 player[numplayers].skeleton.id=numplayers;
2938 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);
2940 //texsize=512*512*3/texdetail/texdetail;
2941 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
2942 //player[numplayers].skeleton.skinText.resize(texsize);
2944 int k=abs(Random()%2)+1;
2946 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2947 player[numplayers].whichskin=0;
2950 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2951 player[numplayers].whichskin=1;
2954 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2955 player[numplayers].whichskin=2;
2958 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
2959 player[numplayers].power=1;
2960 player[numplayers].speedmult=1;
2961 player[numplayers].currentanimation=bounceidleanim;
2962 player[numplayers].targetanimation=bounceidleanim;
2963 player[numplayers].currentframe=0;
2964 player[numplayers].targetframe=1;
2965 player[numplayers].target=0;
2966 player[numplayers].bled=0;
2967 player[numplayers].speed=1+(float)(Random()%100)/1000;
2969 player[numplayers].targetrotation=player[0].targetrotation;
2970 player[numplayers].rotation=player[0].rotation;
2972 player[numplayers].velocity=0;
2973 player[numplayers].coords=player[0].coords;
2974 player[numplayers].oldcoords=player[numplayers].coords;
2975 player[numplayers].realoldcoords=player[numplayers].coords;
2977 player[numplayers].id=numplayers;
2978 player[numplayers].skeleton.id=numplayers;
2979 player[numplayers].updatedelay=0;
2980 player[numplayers].normalsupdatedelay=0;
2982 player[numplayers].aitype=passivetype;
2984 if(player[0].creature==wolftype){
2985 headprop=player[0].proportionhead.x/1.1;
2986 bodyprop=player[0].proportionbody.x/1.1;
2987 armprop=player[0].proportionarms.x/1.1;
2988 legprop=player[0].proportionlegs.x/1.1;
2991 if(player[0].creature==rabbittype){
2992 headprop=player[0].proportionhead.x/1.2;
2993 bodyprop=player[0].proportionbody.x/1.05;
2994 armprop=player[0].proportionarms.x/1.00;
2995 legprop=player[0].proportionlegs.x/1.1;
2998 if(player[numplayers].creature==wolftype){
2999 player[numplayers].proportionhead=1.1*headprop;
3000 player[numplayers].proportionbody=1.1*bodyprop;
3001 player[numplayers].proportionarms=1.1*armprop;
3002 player[numplayers].proportionlegs=1.1*legprop;
3005 if(player[numplayers].creature==rabbittype){
3006 player[numplayers].proportionhead=1.2*headprop;
3007 player[numplayers].proportionbody=1.05*bodyprop;
3008 player[numplayers].proportionarms=1.00*armprop;
3009 player[numplayers].proportionlegs=1.1*legprop;
3010 player[numplayers].proportionlegs.y=1.05*legprop;
3013 player[numplayers].headless=0;
3014 player[numplayers].onfire=0;
3017 player[numplayers].proportionhead.z=0;
3018 player[numplayers].proportionbody.z=0;
3019 player[numplayers].proportionarms.z=0;
3020 player[numplayers].proportionlegs.z=0;
3023 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3025 player[numplayers].damagetolerance=200;
3027 player[numplayers].protectionhead=player[0].protectionhead;
3028 player[numplayers].protectionhigh=player[0].protectionhigh;
3029 player[numplayers].protectionlow=player[0].protectionlow;
3030 player[numplayers].armorhead=player[0].armorhead;
3031 player[numplayers].armorhigh=player[0].armorhigh;
3032 player[numplayers].armorlow=player[0].armorlow;
3033 player[numplayers].metalhead=player[0].metalhead;
3034 player[numplayers].metalhigh=player[0].metalhigh;
3035 player[numplayers].metallow=player[0].metallow;
3037 player[numplayers].immobile=player[0].immobile;
3039 player[numplayers].numclothes=player[0].numclothes;
3040 if(player[numplayers].numclothes)
3041 for(int i=0;i<player[numplayers].numclothes;i++){
3042 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3043 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3044 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3045 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3046 tintr=player[numplayers].clothestintr[i];
3047 tintg=player[numplayers].clothestintg[i];
3048 tintb=player[numplayers].clothestintb[i];
3049 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3051 if(player[numplayers].numclothes){
3052 player[numplayers].DoMipmaps();
3055 player[numplayers].power=player[0].power;
3056 player[numplayers].speedmult=player[0].speedmult;
3058 player[numplayers].damage=0;
3059 player[numplayers].permanentdamage=0;
3060 player[numplayers].superpermanentdamage=0;
3061 player[numplayers].deathbleeding=0;
3062 player[numplayers].bleeding=0;
3063 player[numplayers].numwaypoints=0;
3064 player[numplayers].waypoint=0;
3065 player[numplayers].jumppath=0;
3066 player[numplayers].weaponstuck=-1;
3067 player[numplayers].weaponactive=-1;
3068 player[numplayers].num_weapons=0;
3069 player[numplayers].bloodloss=0;
3070 player[numplayers].dead=0;
3072 player[numplayers].loaded=1;
3078 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3079 if(player[numplayers-1].numwaypoints<90){
3080 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3081 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3082 player[numplayers-1].numwaypoints++;
3086 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3087 if(numpathpoints<30){
3088 bool connected,alreadyconnected;
3091 for(int i=0;i<numpathpoints;i++){
3092 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3094 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3095 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3097 if(!alreadyconnected){
3098 numpathpointconnect[pathpointselected]++;
3100 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3106 pathpoint[numpathpoints-1]=player[0].coords;
3107 numpathpointconnect[numpathpoints-1]=0;
3108 if(numpathpoints>1&&pathpointselected!=-1){
3109 numpathpointconnect[pathpointselected]++;
3110 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3112 pathpointselected=numpathpoints-1;
3117 if(Input::isKeyPressed(SDLK_PERIOD)){
3118 pathpointselected++;
3119 if(pathpointselected>=numpathpoints)
3120 pathpointselected=-1;
3122 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3123 pathpointselected--;
3124 if(pathpointselected<=-2)
3125 pathpointselected=numpathpoints-1;
3127 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3128 if(pathpointselected!=-1){
3130 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3131 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3132 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3133 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3135 for(int i=0;i<numpathpoints;i++){
3136 for(int j=0;j<numpathpointconnect[i];j++){
3137 if(pathpointconnect[i][j]==pathpointselected){
3138 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3139 numpathpointconnect[i]--;
3141 if(pathpointconnect[i][j]==numpathpoints){
3142 pathpointconnect[i][j]=pathpointselected;
3146 pathpointselected=numpathpoints-1;
3150 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3152 if(editortype==treeleavestype||editortype==10)editortype--;
3153 if(editortype<0)editortype=firetype;
3156 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3158 if(editortype==treeleavestype||editortype==10)editortype++;
3159 if(editortype>firetype)editortype=0;
3162 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3163 editorrotation-=multiplier*100;
3164 if(editorrotation<-.01)editorrotation=-.01;
3167 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3168 editorrotation+=multiplier*100;
3171 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3172 editorsize+=multiplier;
3175 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3176 editorsize-=multiplier;
3177 if(editorsize<.1)editorsize=.1;
3181 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3182 mapradius-=multiplier*10;
3185 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3186 mapradius+=multiplier*10;
3188 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3189 editorrotation2+=multiplier*100;
3192 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3193 editorrotation2-=multiplier*100;
3194 if(editorrotation2<-.01)editorrotation2=-.01;
3196 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3198 float closestdist=-1;
3200 for(int i=0;i<objects.numobjects;i++){
3201 distance=findDistancefast(&objects.position[i],&player[0].coords);
3202 if(closestdist==-1||distance<closestdist){
3203 closestdist=distance;
3207 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3213 void Game::doJumpReversals(){
3214 for(int k=0;k<numplayers;k++)
3215 for(int i=k;i<numplayers;i++){
3217 if( player[k].skeleton.free==0&&
3218 player[i].skeleton.oldfree==0&&
3219 (player[i].targetanimation==jumpupanim||
3220 player[k].targetanimation==jumpupanim)&&
3221 (player[i].aitype==playercontrolled||
3222 player[k].aitype==playercontrolled)&&
3223 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3224 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3225 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3226 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3227 //TODO: refactor two huge similar ifs
3228 if(player[i].targetanimation==jumpupanim&&
3229 player[k].targetanimation!=getupfrombackanim&&
3230 player[k].targetanimation!=getupfromfrontanim&&
3231 animation[player[k].targetanimation].height==middleheight&&
3232 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3233 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3234 player[k].aitype!=playercontrolled)){
3235 player[i].victim=&player[k];
3236 player[i].velocity=0;
3237 player[i].currentanimation=jumpreversedanim;
3238 player[i].targetanimation=jumpreversedanim;
3239 player[i].currentframe=0;
3240 player[i].targetframe=1;
3241 player[i].targettilt2=0;
3242 player[k].victim=&player[i];
3243 player[k].velocity=0;
3244 player[k].currentanimation=jumpreversalanim;
3245 player[k].targetanimation=jumpreversalanim;
3246 player[k].currentframe=0;
3247 player[k].targetframe=1;
3248 player[k].targettilt2=0;
3249 if(player[i].coords.y<player[k].coords.y+1){
3250 player[i].currentanimation=rabbitkickreversedanim;
3251 player[i].targetanimation=rabbitkickreversedanim;
3252 player[i].currentframe=1;
3253 player[i].targetframe=2;
3254 player[k].currentanimation=rabbitkickreversalanim;
3255 player[k].targetanimation=rabbitkickreversalanim;
3256 player[k].currentframe=1;
3257 player[k].targetframe=2;
3260 player[k].oldcoords=player[k].coords;
3261 player[i].coords=player[k].coords;
3262 player[k].targetrotation=player[i].targetrotation;
3263 player[k].rotation=player[i].targetrotation;
3264 if(player[k].aitype==attacktypecutoff)
3265 player[k].stunned=.5;
3267 if(player[k].targetanimation==jumpupanim&&
3268 player[i].targetanimation!=getupfrombackanim&&
3269 player[i].targetanimation!=getupfromfrontanim&&
3270 animation[player[i].targetanimation].height==middleheight&&
3271 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3272 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3273 player[i].aitype!=playercontrolled)){
3274 player[k].victim=&player[i];
3275 player[k].velocity=0;
3276 player[k].currentanimation=jumpreversedanim;
3277 player[k].targetanimation=jumpreversedanim;
3278 player[k].currentframe=0;
3279 player[k].targetframe=1;
3280 player[k].targettilt2=0;
3281 player[i].victim=&player[k];
3282 player[i].velocity=0;
3283 player[i].currentanimation=jumpreversalanim;
3284 player[i].targetanimation=jumpreversalanim;
3285 player[i].currentframe=0;
3286 player[i].targetframe=1;
3287 player[i].targettilt2=0;
3288 if(player[k].coords.y<player[i].coords.y+1){
3289 player[k].targetanimation=rabbitkickreversedanim;
3290 player[k].currentanimation=rabbitkickreversedanim;
3291 player[i].currentanimation=rabbitkickreversalanim;
3292 player[i].targetanimation=rabbitkickreversalanim;
3293 player[k].currentframe=1;
3294 player[k].targetframe=2;
3295 player[i].currentframe=1;
3296 player[i].targetframe=2;
3299 player[i].oldcoords=player[i].coords;
3300 player[k].coords=player[i].coords;
3301 player[i].targetrotation=player[k].targetrotation;
3302 player[i].rotation=player[k].targetrotation;
3303 if(player[i].aitype==attacktypecutoff)
3304 player[i].stunned=.5;
3311 void Game::doAerialAcrobatics(){
3312 static XYZ facing,flatfacing;
3313 for(int k=0;k<numplayers;k++){
3314 player[k].turnspeed=500;
3316 if((player[k].isRun()&&
3317 ((player[k].targetrotation!=rabbitrunninganim&&
3318 player[k].targetrotation!=wolfrunninganim)||
3319 player[k].targetframe==4))||
3320 player[k].targetanimation==removeknifeanim||
3321 player[k].targetanimation==crouchremoveknifeanim||
3322 player[k].targetanimation==flipanim||
3323 player[k].targetanimation==fightsidestep||
3324 player[k].targetanimation==walkanim){
3325 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3329 if(player[k].isStop()||
3330 player[k].isLanding()||
3331 player[k].targetanimation==staggerbackhighanim||
3332 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3333 player[k].targetanimation==staggerbackhardanim||
3334 player[k].targetanimation==backhandspringanim||
3335 player[k].targetanimation==dodgebackanim||
3336 player[k].targetanimation==rollanim||
3337 (animation[player[k].targetanimation].attack&&
3338 player[k].targetanimation!=rabbitkickanim&&
3339 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3340 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3341 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3344 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3345 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3348 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3349 player[k].DoStuff();
3350 if(player[k].immobile&&k!=0)
3351 player[k].coords=player[k].realoldcoords;
3353 //if player's position has changed (?)
3354 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3355 !player[k].skeleton.free&&
3356 player[k].targetanimation!=climbanim&&
3357 player[k].targetanimation!=hanganim){
3358 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3362 if(player[k].collide<-.3)
3363 player[k].collide=-.3;
3364 if(player[k].collide>1)
3365 player[k].collide=1;
3366 player[k].collide-=multiplier*30;
3369 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3371 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3372 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3373 if(objects.type[i]!=rocktype||
3374 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3375 objects.position[i].y>player[k].coords.y){
3376 lowpoint=player[k].coords;
3377 if(player[k].targetanimation!=jumpupanim&&
3378 player[k].targetanimation!=jumpdownanim&&
3379 !player[k].isFlip())
3383 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3384 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3385 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3386 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3387 flatfacing=lowpoint-player[k].coords;
3388 player[k].coords=lowpoint;
3389 player[k].coords.y-=1.3;
3390 player[k].collide=1;
3393 //TODO: refactor four similar blocks
3394 if(player[k].aitype==playercontrolled&&
3395 (player[k].targetanimation==jumpupanim||
3396 player[k].targetanimation==jumpdownanim||
3397 player[k].isFlip())&&
3398 !player[k].jumptogglekeydown&&
3399 player[k].jumpkeydown){
3400 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3401 XYZ tempcoords1=lowpoint;
3402 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3403 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3404 player[k].setAnimation(walljumpleftanim);
3405 emit_sound_at(movewhooshsound, player[k].coords);
3407 pause_sound(whooshsound);
3409 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3410 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3411 if(lowpointtarget.z<0)
3412 player[k].rotation=180-player[k].rotation;
3413 player[k].targetrotation=player[k].rotation;
3414 player[k].lowrotation=player[k].rotation;
3420 lowpoint=tempcoords1;
3421 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3422 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3423 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3424 player[k].setAnimation(walljumprightanim);
3425 emit_sound_at(movewhooshsound, player[k].coords);
3426 if(k==0)pause_sound(whooshsound);
3428 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3429 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3430 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3431 player[k].targetrotation=player[k].rotation;
3432 player[k].lowrotation=player[k].rotation;
3433 if(k==0)numwallflipped++;
3437 lowpoint=tempcoords1;
3438 lowpointtarget=lowpoint+player[k].facing*2;
3439 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3440 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3441 player[k].setAnimation(walljumpbackanim);
3442 emit_sound_at(movewhooshsound, player[k].coords);
3443 if(k==0)pause_sound(whooshsound);
3445 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3446 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3447 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3448 player[k].targetrotation=player[k].rotation;
3449 player[k].lowrotation=player[k].rotation;
3450 if(k==0)numwallflipped++;
3454 lowpoint=tempcoords1;
3455 lowpointtarget=lowpoint-player[k].facing*2;
3456 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3457 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3458 player[k].setAnimation(walljumpfrontanim);
3459 emit_sound_at(movewhooshsound, player[k].coords);
3460 if(k==0)pause_sound(whooshsound);
3462 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3463 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3464 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3465 player[k].rotation+=180;
3466 player[k].targetrotation=player[k].rotation;
3467 player[k].lowrotation=player[k].rotation;
3468 if(k==0)numwallflipped++;
3476 else if(objects.type[i]==rocktype){
3477 lowpoint2=player[k].coords;
3478 lowpoint=player[k].coords;
3480 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3481 player[k].coords=colpoint;
3482 player[k].collide=1;
3485 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3486 //flipped into a rock
3487 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3488 player[k].RagDoll(0);
3490 if(player[k].targetanimation==jumpupanim){
3491 player[k].jumppower=-4;
3492 player[k].targetanimation=player[k].getIdle();
3495 player[k].targetframe=0;
3496 player[k].onterrain=1;
3498 if(player[k].id==0){
3499 pause_sound(whooshsound);
3500 OPENAL_SetVolume(channels[whooshsound], 0);
3504 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3505 if(player[k].isFlip())
3506 player[k].jumppower=-4;
3507 player[k].targetanimation=player[k].getLanding();
3508 emit_sound_at(landsound, player[k].coords, 128.);
3510 envsound[numenvsounds]=player[k].coords;
3511 envsoundvol[numenvsounds]=16;
3512 envsoundlife[numenvsounds]=.4;
3522 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3523 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3524 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3525 lowpoint=player[k].coords;
3527 if(objects.type[i]!=rocktype)
3528 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3529 if(player[k].targetanimation!=jumpupanim&&
3530 player[k].targetanimation!=jumpdownanim&&
3531 player[k].onterrain)
3532 player[k].avoidcollided=1;
3533 player[k].coords=lowpoint;
3534 player[k].coords.y-=1.35;
3535 player[k].collide=1;
3537 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3538 (player[k].currentanimation!=climbanim&&
3539 player[k].currentanimation!=hanganim&&
3540 !player[k].isWallJump()||
3541 player[k].targetanimation==jumpupanim||
3542 player[k].targetanimation==jumpdownanim)){
3543 lowpoint=player[k].coords;
3544 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3545 lowpoint=player[k].coords;
3549 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3550 lowpointtarget=lowpoint+facing*1.4;
3551 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3553 lowpoint=player[k].coords;
3555 lowpointtarget=lowpoint+facing*1.4;
3557 lowpointtarget2=lowpointtarget;
3559 lowpointtarget3=lowpointtarget;
3561 lowpointtarget4=lowpointtarget;
3563 lowpointtarget5=lowpointtarget;
3565 lowpointtarget6=lowpointtarget;
3567 lowpointtarget7=lowpoint;
3569 lowpointtarget2.x+=.1;
3571 lowpointtarget3.z+=.1;
3573 lowpointtarget4.x-=.1;
3575 lowpointtarget5.z-=.1;
3577 lowpointtarget6.y+=45/13;
3578 lowpointtarget6+=facing*.6;
3579 lowpointtarget7.y+=90/13;
3580 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3581 if(objects.friction[i]>.5)
3583 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3584 player[k].collided=1;
3585 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3586 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3587 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3588 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3589 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3590 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3591 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3592 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3593 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3594 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3595 for(int j=0;j<45;j++){
3596 lowpoint=player[k].coords;
3597 lowpoint.y+=(float)j/13;
3598 lowpointtarget=lowpoint+facing*1.4;
3599 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3600 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3601 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3603 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3604 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3605 lowpoint=player[k].coords;
3606 lowpoint.y+=(float)j/13;
3607 lowpointtarget=lowpoint+facing*1.3;
3608 flatfacing=player[k].coords;
3609 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3610 player[k].coords.y=lowpointtarget.y-.07;
3611 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3613 if(j>10||!player[k].isRun()){
3614 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3616 pause_sound(whooshsound);
3618 emit_sound_at(jumpsound, player[k].coords, 128.);
3620 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3621 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3622 if(lowpointtarget.z<0)
3623 player[k].rotation=180-player[k].rotation;
3624 player[k].targetrotation=player[k].rotation;
3625 player[k].lowrotation=player[k].rotation;
3627 //player[k].velocity=lowpointtarget*.03;
3628 player[k].velocity=0;
3631 if(player[k].targetanimation==jumpupanim){
3632 player[k].targetanimation=climbanim;
3633 player[k].jumppower=0;
3634 player[k].jumpclimb=1;
3636 player[k].transspeed=6;
3638 player[k].targetframe=1;
3641 player[k].setAnimation(hanganim);
3642 player[k].jumppower=0;
3654 if(player[k].collide<=0){
3656 if(!player[k].onterrain&&
3657 player[k].targetanimation!=jumpupanim&&
3658 player[k].targetanimation!=jumpdownanim&&
3659 player[k].targetanimation!=climbanim&&
3660 player[k].targetanimation!=hanganim&&
3661 !player[k].isWallJump()&&
3662 !player[k].isFlip()){
3663 if(player[k].currentanimation!=climbanim&&
3664 player[k].currentanimation!=tempanim&&
3665 player[k].targetanimation!=backhandspringanim&&
3666 (player[k].targetanimation!=rollanim||
3667 player[k].targetframe<2||
3668 player[k].targetframe>6)){
3669 //stagger off ledge (?)
3670 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3671 player[k].RagDoll(0);
3672 player[k].setAnimation(jumpdownanim);
3675 emit_sound_at(whooshsound, player[k].coords, 128.);
3678 player[k].velocity.y+=gravity;
3682 player[k].realoldcoords=player[k].coords;
3686 void Game::doAttacks(){
3687 static XYZ relative;
3688 static int randattack;
3689 static bool playerrealattackkeydown=0;
3691 if(!Input::isKeyDown(attackkey))
3694 player[0].attackkeydown=0;
3696 playerrealattackkeydown=0;
3698 playerrealattackkeydown=Input::isKeyDown(attackkey);
3699 if((player[0].parriedrecently<=0||
3700 player[0].weaponactive==-1)&&
3703 player[0].lastattack!=swordslashanim&&
3704 player[0].lastattack!=knifeslashstartanim&&
3705 player[0].lastattack!=staffhitanim&&
3706 player[0].lastattack!=staffspinhitanim)))
3707 player[0].attackkeydown=Input::isKeyDown(attackkey);
3708 if(Input::isKeyDown(attackkey)&&
3710 !player[0].backkeydown){
3711 for(int k=0;k<numplayers;k++){
3712 if((player[k].targetanimation==swordslashanim||
3713 player[k].targetanimation==staffhitanim||
3714 player[k].targetanimation==staffspinhitanim)&&
3715 player[0].currentanimation!=dodgebackanim&&
3716 !player[k].skeleton.free)
3717 player[k].Reverse();
3721 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3723 for(int k=0;k<numplayers;k++){
3724 if(indialogue!=-1)player[k].attackkeydown=0;
3725 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3726 if(player[k].aitype!=playercontrolled)
3727 player[k].victim=&player[0];
3728 //attack key pressed
3729 if(player[k].attackkeydown){
3731 if(player[k].backkeydown&&
3732 player[k].targetanimation!=backhandspringanim&&
3733 (player[k].isIdle()||
3734 player[k].isStop()||
3736 player[k].targetanimation==walkanim)){
3737 if(player[k].jumppower<=1){
3738 player[k].jumppower-=2;
3740 for(int i=0;i<numplayers;i++){
3742 if(player[i].targetanimation==swordslashanim||
3743 player[i].targetanimation==knifeslashstartanim||
3744 player[i].targetanimation==staffhitanim||
3745 player[i].targetanimation==staffspinhitanim)
3746 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3747 player[k].setAnimation(dodgebackanim);
3748 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3749 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3752 if(player[k].targetanimation!=dodgebackanim){
3753 if(k==0)numflipped++;
3754 player[k].setAnimation(backhandspringanim);
3755 player[k].targetrotation=-rotation+180;
3756 if(player[k].leftkeydown)
3757 player[k].targetrotation-=45;
3758 if(player[k].rightkeydown)
3759 player[k].targetrotation+=45;
3760 player[k].rotation=player[k].targetrotation;
3761 player[k].jumppower-=2;
3766 if(!animation[player[k].targetanimation].attack&&
3767 !player[k].backkeydown&&
3768 (player[k].isIdle()||
3770 player[k].targetanimation==walkanim||
3771 player[k].targetanimation==sneakanim||
3772 player[k].isCrouch())){
3773 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3774 //normal attacks (?)
3775 player[k].hasvictim=0;
3777 for(int i=0;i<numplayers;i++){
3778 if(i==k||!(k==0||i==0))continue;
3779 if(!player[k].hasvictim)
3780 if(animation[player[k].targetanimation].attack!=reversal){
3782 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3784 !player[i].skeleton.free&&
3785 player[i].howactive<typedead1&&
3786 player[i].targetanimation!=jumpreversedanim&&
3787 player[i].targetanimation!=rabbitkickreversedanim&&
3788 player[i].targetanimation!=rabbitkickanim&&
3789 player[k].targetanimation!=rabbitkickanim&&
3790 player[i].targetanimation!=getupfrombackanim&&
3791 (player[i].targetanimation!=staggerbackhighanim&&
3792 (player[i].targetanimation!=staggerbackhardanim||
3793 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3794 player[i].targetanimation!=jumpdownanim&&
3795 player[i].targetanimation!=jumpupanim&&
3796 player[i].targetanimation!=getupfromfrontanim){
3797 player[k].victim=&player[i];
3798 player[k].hasvictim=1;
3799 if(player[k].aitype==playercontrolled){ //human player
3801 if(distance<2.5*sq(player[k].scale*5)&&
3802 player[k].crouchkeydown&&
3803 animation[player[i].targetanimation].height!=lowheight)
3804 player[k].targetanimation=sweepanim;
3806 else if(distance<1.5*sq(player[k].scale*5)&&
3807 animation[player[i].targetanimation].height!=lowheight&&
3808 !player[k].forwardkeydown&&
3809 !player[k].leftkeydown&&
3810 !player[k].rightkeydown&&
3811 !player[k].crouchkeydown&&
3814 player[k].targetanimation=winduppunchanim;
3816 else if(distance<2.5*sq(player[k].scale*5)&&
3817 animation[player[i].targetanimation].height!=lowheight&&
3818 !player[k].forwardkeydown&&
3819 !player[k].leftkeydown&&
3820 !player[k].rightkeydown&&
3821 !player[k].crouchkeydown&&
3823 player[k].targetanimation=upunchanim;
3825 else if(distance<2.5*sq(player[k].scale*5)&&
3826 player[i].staggerdelay>0&&
3827 attackweapon==knife&&
3828 player[i].bloodloss>player[i].damagetolerance/2)
3829 player[k].targetanimation=knifefollowanim;
3831 else if(distance<2.5*sq(player[k].scale*5)&&
3832 animation[player[i].targetanimation].height!=lowheight&&
3833 !player[k].forwardkeydown&&
3834 !player[k].leftkeydown&&
3835 !player[k].rightkeydown&&
3836 !player[k].crouchkeydown&&
3837 attackweapon==knife&&
3838 player[k].weaponmissdelay<=0)
3839 player[k].targetanimation=knifeslashstartanim;
3841 else if(distance<4.5*sq(player[k].scale*5)&&
3842 animation[player[i].targetanimation].height!=lowheight&&
3843 !player[k].crouchkeydown&&
3844 attackweapon==sword&&
3845 player[k].weaponmissdelay<=0)
3846 player[k].targetanimation=swordslashanim;
3848 else if(distance<4.5*sq(player[k].scale*5)&&
3849 animation[player[i].targetanimation].height!=lowheight&&
3850 !player[k].crouchkeydown&&
3851 attackweapon==staff&&
3852 player[k].weaponmissdelay<=0&&
3853 !player[k].leftkeydown&&
3854 !player[k].rightkeydown&&
3855 !player[k].forwardkeydown)
3856 player[k].targetanimation=staffhitanim;
3858 else if(distance<4.5*sq(player[k].scale*5)&&
3859 animation[player[i].targetanimation].height!=lowheight&&
3860 !player[k].crouchkeydown&&
3861 attackweapon==staff&&
3862 player[k].weaponmissdelay<=0)
3863 player[k].targetanimation=staffspinhitanim;
3865 else if(distance<2.5*sq(player[k].scale*5)&&
3866 animation[player[i].targetanimation].height!=lowheight)
3867 player[k].targetanimation=spinkickanim;
3869 else if(distance<2.5*sq(player[k].scale*5)&&
3870 animation[player[i].targetanimation].height==lowheight&&
3871 animation[player[k].targetanimation].attack!=normalattack)
3872 player[k].targetanimation=lowkickanim;
3873 } else { //AI player
3874 if(distance<4.5*sq(player[k].scale*5)){
3875 randattack=abs(Random()%5);
3876 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3878 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3879 player[k].targetanimation=sweepanim;
3881 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3883 player[k].targetanimation=upunchanim;
3885 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3886 player[k].targetanimation=spinkickanim;
3888 else if(animation[player[i].targetanimation].height==lowheight)
3889 player[k].targetanimation=lowkickanim;
3893 if((tutoriallevel!=1||!attackweapon)&&
3894 distance<2.5*sq(player[k].scale*5)&&
3896 animation[player[i].targetanimation].height!=lowheight)
3897 player[k].targetanimation=sweepanim;
3899 else if(distance<2.5*sq(player[k].scale*5)&&
3900 attackweapon==knife&&
3901 player[k].weaponmissdelay<=0)
3902 player[k].targetanimation=knifeslashstartanim;
3904 else if(!(player[0].victim==&player[i]&&
3905 player[0].hasvictim&&
3906 player[0].targetanimation==swordslashanim)&&
3907 attackweapon==sword&&
3908 player[k].weaponmissdelay<=0)
3909 player[k].targetanimation=swordslashanim;
3911 else if(!(player[0].victim==&player[i]&&
3912 player[0].hasvictim&&
3913 player[0].targetanimation==swordslashanim)&&
3914 attackweapon==staff&&
3915 player[k].weaponmissdelay<=0&&
3917 player[k].targetanimation=staffhitanim;
3919 else if(!(player[0].victim==&player[i]&&
3920 player[0].hasvictim&&
3921 player[0].targetanimation==swordslashanim)&&
3922 attackweapon==staff&&
3923 player[k].weaponmissdelay<=0&&
3925 player[k].targetanimation=staffspinhitanim;
3927 else if((tutoriallevel!=1||!attackweapon)&&
3928 distance<2.5*sq(player[k].scale*5)&&
3930 animation[player[i].targetanimation].height!=lowheight)
3931 player[k].targetanimation=spinkickanim;
3933 else if(distance<2.5*sq(player[k].scale*5)&&
3934 animation[player[i].targetanimation].height==lowheight&&
3935 animation[player[k].targetanimation].attack!=normalattack)
3936 player[k].targetanimation=lowkickanim;
3940 //upunch becomes wolfslap
3941 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
3942 player[k].targetanimation=wolfslapanim;
3945 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
3946 player[i].howactive<typedead1&&
3947 distance<1.5*sq(player[k].scale*5)&&
3948 !player[i].skeleton.free&&
3949 player[i].targetanimation!=getupfrombackanim&&
3950 player[i].targetanimation!=getupfromfrontanim&&
3951 (player[i].stunned>0&&player[k].madskills||
3952 player[i].surprised>0||
3953 player[i].aitype==passivetype||
3954 attackweapon&&player[i].stunned>0)&&
3955 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
3958 player[k].currentanimation=sneakattackanim;
3959 player[k].targetanimation=sneakattackanim;
3960 player[i].currentanimation=sneakattackedanim;
3961 player[i].targetanimation=sneakattackedanim;
3962 player[k].oldcoords=player[k].coords;
3963 player[k].coords=player[i].coords;
3966 if(attackweapon==knife){
3967 player[k].currentanimation=knifesneakattackanim;
3968 player[k].targetanimation=knifesneakattackanim;
3969 player[i].currentanimation=knifesneakattackedanim;
3970 player[i].targetanimation=knifesneakattackedanim;
3971 player[i].oldcoords=player[i].coords;
3972 player[i].coords=player[k].coords;
3975 if(attackweapon==sword){
3976 player[k].currentanimation=swordsneakattackanim;
3977 player[k].targetanimation=swordsneakattackanim;
3978 player[i].currentanimation=swordsneakattackedanim;
3979 player[i].targetanimation=swordsneakattackedanim;
3980 player[i].oldcoords=player[i].coords;
3981 player[i].coords=player[k].coords;
3983 if(attackweapon!=staff){
3984 player[k].victim=&player[i];
3985 player[k].hasvictim=1;
3986 player[i].targettilt2=0;
3987 player[i].targetframe=1;
3988 player[i].currentframe=0;
3990 player[i].velocity=0;
3991 player[k].targettilt2=player[i].targettilt2;
3992 player[k].currentframe=player[i].currentframe;
3993 player[k].targetframe=player[i].targetframe;
3994 player[k].target=player[i].target;
3995 player[k].velocity=0;
3996 player[k].targetrotation=player[i].rotation;
3997 player[k].rotation=player[i].rotation;
3998 player[i].targetrotation=player[i].rotation;
4001 if(animation[player[k].targetanimation].attack==normalattack&&
4002 player[k].victim==&player[i]&&
4003 (!player[i].skeleton.free)){
4005 player[k].targetframe=0;
4008 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4009 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4010 player[k].lastattack3=player[k].lastattack2;
4011 player[k].lastattack2=player[k].lastattack;
4012 player[k].lastattack=player[k].targetanimation;
4014 if(player[k].targetanimation==knifefollowanim&&
4015 player[k].victim==&player[i]){
4017 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4018 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4019 player[k].victim=&player[i];
4020 player[k].hasvictim=1;
4021 player[i].targetanimation=knifefollowedanim;
4022 player[i].currentanimation=knifefollowedanim;
4023 player[i].targettilt2=0;
4024 player[i].targettilt2=player[k].targettilt2;
4025 player[i].targetframe=1;
4026 player[i].currentframe=0;
4028 player[i].velocity=0;
4029 player[k].currentanimation=knifefollowanim;
4030 player[k].targetanimation=knifefollowanim;
4031 player[k].targettilt2=player[i].targettilt2;
4032 player[k].currentframe=player[i].currentframe;
4033 player[k].targetframe=player[i].targetframe;
4034 player[k].target=player[i].target;
4035 player[k].velocity=0;
4036 player[k].oldcoords=player[k].coords;
4037 player[i].coords=player[k].coords;
4038 player[i].targetrotation=player[k].targetrotation;
4039 player[i].rotation=player[k].targetrotation;
4040 player[k].rotation=player[k].targetrotation;
4041 player[i].rotation=player[k].targetrotation;
4045 const bool hasstaff=attackweapon==staff;
4046 if(k==0&&numplayers>1)
4047 for(int i=0;i<numplayers;i++){
4049 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4050 animation[player[k].targetanimation].attack==neutral){
4051 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4052 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4053 if(player[i].skeleton.free)
4054 if(distance<3.5*sq(player[k].scale*5)&&
4056 player[i].skeleton.longdead>1000||
4060 (player[i].skeleton.longdead>2000||
4061 player[i].damage>player[i].damagetolerance/8||
4062 player[i].bloodloss>player[i].damagetolerance/2)&&
4063 distance<1.5*sq(player[k].scale*5)))){
4064 player[k].victim=&player[i];
4065 player[k].hasvictim=1;
4066 if(attackweapon&&tutoriallevel!=1){
4068 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4069 player[k].targetanimation=crouchstabanim;
4071 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4072 player[k].targetanimation=swordgroundstabanim;
4074 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4075 player[k].targetanimation=staffgroundsmashanim;
4078 player[k].crouchkeydown&&
4079 player[k].targetanimation!=crouchstabanim&&
4082 player[i].skeleton.free&&
4083 player[i].skeleton.longdead>1000){
4084 player[k].targetanimation=killanim;
4085 //TODO: refactor this out, what does it do?
4086 for(int j=0;j<terrain.numdecals;j++){
4087 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4088 terrain.decalalivetime[j]<2)
4089 terrain.DeleteDecal(j);
4091 for(int l=0;l<objects.numobjects;l++){
4092 if(objects.model[l].type==decalstype)
4093 for(int j=0;j<objects.model[l].numdecals;j++){
4094 if((objects.model[l].decaltype[j]==blooddecal||
4095 objects.model[l].decaltype[j]==blooddecalslow)&&
4096 objects.model[l].decalalivetime[j]<2)
4097 objects.model[l].DeleteDecal(j);
4101 if(!player[i].dead||musictype!=2)
4103 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4104 player[k].staggerdelay<=0&&
4106 player[i].skeleton.longdead<300&&
4107 player[k].lastattack!=spinkickanim&&
4108 player[i].skeleton.free)&&
4109 (!player[i].dead||musictype!=stream_fighttheme)){
4110 player[k].targetanimation=dropkickanim;
4111 for(int j=0;j<terrain.numdecals;j++){
4112 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4113 terrain.decalalivetime[j]<2){
4114 terrain.DeleteDecal(j);
4117 for(int l=0;l<objects.numobjects;l++){
4118 if(objects.model[l].type==decalstype)
4119 for(int j=0;j<objects.model[l].numdecals;j++){
4120 if((objects.model[l].decaltype[j]==blooddecal||
4121 objects.model[l].decaltype[j]==blooddecalslow)&&
4122 objects.model[l].decalalivetime[j]<2){
4123 objects.model[l].DeleteDecal(j);
4129 if(animation[player[k].targetanimation].attack==normalattack&&
4130 player[k].victim==&player[i]&&
4131 (!player[i].skeleton.free||
4132 player[k].targetanimation==killanim||
4133 player[k].targetanimation==crouchstabanim||
4134 player[k].targetanimation==swordgroundstabanim||
4135 player[k].targetanimation==staffgroundsmashanim||
4136 player[k].targetanimation==dropkickanim)){
4138 player[k].targetframe=0;
4141 XYZ targetpoint=player[i].coords;
4142 if(player[k].targetanimation==crouchstabanim||
4143 player[k].targetanimation==swordgroundstabanim||
4144 player[k].targetanimation==staffgroundsmashanim){
4145 targetpoint+=(player[i].getJointFor(abdomen).position+
4146 player[i].getJointFor(neck).position)/2*
4149 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4150 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4152 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4153 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4156 if(player[k].targetanimation==staffgroundsmashanim)
4157 player[k].targettilt2+=10;
4159 player[k].lastattack3=player[k].lastattack2;
4160 player[k].lastattack2=player[k].lastattack;
4161 player[k].lastattack=player[k].targetanimation;
4163 if(player[k].targetanimation==swordgroundstabanim){
4164 player[k].targetrotation+=30;
4169 if(!player[k].hasvictim){
4171 for(int i=0;i<numplayers;i++){
4172 if(i==k||!(i==0||k==0))continue;
4173 if(!player[i].skeleton.free){
4174 if(player[k].hasvictim){
4175 if(findDistancefast(&player[k].coords,&player[i].coords)<
4176 findDistancefast(&player[k].coords,&player[k].victim->coords))
4177 player[k].victim=&player[i];
4179 player[k].victim=&player[i];
4180 player[k].hasvictim=1;
4185 if(player[k].aitype==playercontrolled)
4187 if(player[k].attackkeydown&&
4189 player[k].wasRun()&&
4190 ((player[k].hasvictim&&
4191 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4192 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4193 !player[k].victim->skeleton.free&&
4194 player[k].victim->targetanimation!=getupfrombackanim&&
4195 player[k].victim->targetanimation!=getupfromfrontanim&&
4196 animation[player[k].victim->targetanimation].height!=lowheight&&
4197 player[k].aitype!=playercontrolled&& //wat???
4198 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4199 player[k].rabbitkickenabled)||
4200 player[k].jumpkeydown)){
4202 player[k].setAnimation(rabbitkickanim);
4205 if(animation[player[k].targetanimation].attack&&k==0){
4207 switch(attackweapon){
4208 case 0: numunarmedattack++; break;
4209 case knife: numknifeattack++; break;
4210 case sword: numswordattack++; break;
4211 case staff: numstaffattack++; break;
4220 void Game::doPlayerCollisions(){
4221 static XYZ rotatetarget;
4222 static float collisionradius;
4224 for(int k=0;k<numplayers;k++)
4225 for(int i=k+1;i<numplayers;i++){
4226 //neither player is part of a reversal
4227 if((animation[player[i].targetanimation].attack!=reversed&&
4228 animation[player[i].targetanimation].attack!=reversal&&
4229 animation[player[k].targetanimation].attack!=reversed&&
4230 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4231 if((animation[player[i].currentanimation].attack!=reversed&&
4232 animation[player[i].currentanimation].attack!=reversal&&
4233 animation[player[k].currentanimation].attack!=reversed&&
4234 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4235 //neither is sleeping
4236 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4237 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4238 //in same patch, neither is climbing
4239 if(player[i].whichpatchx==player[k].whichpatchx&&
4240 player[i].whichpatchz==player[k].whichpatchz&&
4241 player[k].skeleton.oldfree==player[k].skeleton.free&&
4242 player[i].skeleton.oldfree==player[i].skeleton.free&&
4243 player[i].targetanimation!=climbanim&&
4244 player[i].targetanimation!=hanganim&&
4245 player[k].targetanimation!=climbanim&&
4246 player[k].targetanimation!=hanganim)
4247 //players are close (bounding box test)
4248 if(player[i].coords.y>player[k].coords.y-3)
4249 if(player[i].coords.y<player[k].coords.y+3)
4250 if(player[i].coords.x>player[k].coords.x-3)
4251 if(player[i].coords.x<player[k].coords.x+3)
4252 if(player[i].coords.z>player[k].coords.z-3)
4253 if(player[i].coords.z<player[k].coords.z+3){
4254 //spread fire from player to player
4255 if(findDistancefast(&player[i].coords,&player[k].coords)
4256 <3*sq((player[i].scale+player[k].scale)*2.5)){
4257 if(player[i].onfire||player[k].onfire){
4258 if(!player[i].onfire)player[i].CatchFire();
4259 if(!player[k].onfire)player[k].CatchFire();
4263 XYZ tempcoords1=player[i].coords;
4264 XYZ tempcoords2=player[k].coords;
4265 if(!player[i].skeleton.oldfree)
4266 tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale;
4267 if(!player[k].skeleton.oldfree)
4268 tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale;
4269 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4270 if(player[0].hasvictim)
4271 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4273 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4274 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4275 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4276 //jump down on a dead body
4279 if(player[0].targetanimation==jumpdownanim&&
4280 !player[0].skeleton.oldfree&&
4281 !player[0].skeleton.free&&
4282 player[l].skeleton.oldfree&&
4283 player[l].skeleton.free&&
4285 player[0].lastcollide<=0&&
4286 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4287 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4288 player[0].coords.y=player[l].coords.y;
4289 player[l].velocity=player[0].velocity;
4290 player[l].skeleton.free=0;
4291 player[l].rotation=0;
4292 player[l].RagDoll(0);
4293 player[l].DoDamage(20);
4295 player[l].skeleton.longdead=0;
4296 player[0].lastcollide=1;
4300 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4301 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4302 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4303 rotatetarget=player[k].velocity-player[i].velocity;
4304 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4305 player[i].skeleton.free)&&
4306 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4307 player[k].skeleton.free))
4308 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4309 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4310 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4312 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4313 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4314 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4315 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4316 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4318 if( (i!=0||player[i].skeleton.free)&&
4319 (k!=0||player[k].skeleton.free)||
4320 (animation[player[i].targetanimation].height==highheight&&
4321 animation[player[k].targetanimation].height==highheight)){
4322 if(tutoriallevel!=1){
4323 emit_sound_at(heavyimpactsound, player[i].coords);
4326 player[i].RagDoll(0);
4327 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4328 award_bonus(0, aimbonus);
4330 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4331 player[k].RagDoll(0);
4332 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4333 award_bonus(0, aimbonus); // Huh, again?
4335 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4337 for(int j=0;j<player[i].skeleton.num_joints;j++){
4338 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4340 for(int j=0;j<player[k].skeleton.num_joints;j++){
4341 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4346 if( (animation[player[i].targetanimation].attack==neutral||
4347 animation[player[i].targetanimation].attack==normalattack)&&
4348 (animation[player[k].targetanimation].attack==neutral||
4349 animation[player[k].targetanimation].attack==normalattack)){
4351 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4352 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4353 rotatetarget=player[k].coords-player[i].coords;
4354 Normalise(&rotatetarget);
4355 player[k].coords=(player[k].coords+player[i].coords)/2;
4356 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4357 *sq((player[i].scale+player[k].scale)*2.5);
4358 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4359 if(player[k].howactive==typeactive||hostile)
4360 if(player[k].isIdle()){
4361 if(player[k].howactive<typesleeping)
4362 player[k].setAnimation(player[k].getStop());
4363 else if(player[k].howactive==typesleeping)
4364 player[k].setAnimation(getupfromfrontanim);
4366 player[k].howactive=typeactive;
4368 if(player[i].howactive==typeactive||hostile)
4369 if(player[i].isIdle()){
4370 if(player[i].howactive<typesleeping)
4371 player[i].setAnimation(player[k].getStop());
4373 player[i].setAnimation(getupfromfrontanim);
4375 player[i].howactive=typeactive;
4378 //jump down on player
4380 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4381 !player[i].isCrouch()&&
4382 player[i].targetanimation!=rollanim&&
4383 !player[k].skeleton.oldfree&&!
4384 player[k].skeleton.free&&
4385 player[k].lastcollide<=0&&
4386 player[k].velocity.y<-10){
4387 player[i].velocity=player[k].velocity;
4388 player[k].velocity=player[k].velocity*-.5;
4389 player[k].velocity.y=player[i].velocity.y;
4390 player[i].DoDamage(20);
4391 player[i].RagDoll(0);
4392 player[k].lastcollide=1;
4393 award_bonus(k, AboveBonus);
4395 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4396 !player[k].isCrouch()&&
4397 player[k].targetanimation!=rollanim&&
4398 !player[i].skeleton.oldfree&&
4399 !player[i].skeleton.free&&
4400 player[i].lastcollide<=0&&
4401 player[i].velocity.y<-10){
4402 player[k].velocity=player[i].velocity;
4403 player[i].velocity=player[i].velocity*-.3;
4404 player[i].velocity.y=player[k].velocity.y;
4405 player[k].DoDamage(20);
4406 player[k].RagDoll(0);
4407 player[i].lastcollide=1;
4408 award_bonus(i, AboveBonus);
4414 player[i].CheckKick();
4415 player[k].CheckKick();
4421 void Game::doAI(int i){
4422 static bool connected;
4423 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4424 player[i].jumpclimb=0;
4425 //disable movement in editor
4427 player[i].stunned=1;
4430 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4431 player[0].coords.y>player[i].coords.y+2&&
4432 !player[0].onterrain)
4436 if(player[i].aitype==pathfindtype){
4437 if(player[i].finalpathfindpoint==-1){
4438 float closestdistance;
4444 for(int j=0;j<numpathpoints;j++)
4445 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4446 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4448 player[i].finaltarget=pathpoint[j];
4450 player[i].finalpathfindpoint=closest;
4451 for(int j=0;j<numpathpoints;j++)
4452 for(int k=0;k<numpathpointconnect[j];k++){
4453 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4454 if(sq(tempdist)<closestdistance)
4455 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4456 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4457 closestdistance=sq(tempdist);
4459 player[i].finaltarget=colpoint;
4462 player[i].finalpathfindpoint=closest;
4465 if(player[i].targetpathfindpoint==-1){
4466 float closestdistance;
4472 if(player[i].lastpathfindpoint==-1){
4473 for(int j=0;j<numpathpoints;j++){
4474 if(j!=player[i].lastpathfindpoint)
4475 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4476 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4480 player[i].targetpathfindpoint=closest;
4481 for(int j=0;j<numpathpoints;j++)
4482 if(j!=player[i].lastpathfindpoint)
4483 for(int k=0;k<numpathpointconnect[j];k++){
4484 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4485 if(sq(tempdist)<closestdistance){
4486 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4487 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4488 closestdistance=sq(tempdist);
4493 player[i].targetpathfindpoint=closest;
4497 for(int j=0;j<numpathpoints;j++)
4498 if(j!=player[i].lastpathfindpoint&&
4499 j!=player[i].lastpathfindpoint2&&
4500 j!=player[i].lastpathfindpoint3&&
4501 j!=player[i].lastpathfindpoint4){
4503 if(numpathpointconnect[j])
4504 for(int k=0;k<numpathpointconnect[j];k++)
4505 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4508 if(numpathpointconnect[player[i].lastpathfindpoint])
4509 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4510 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4513 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4514 if(closest==-1||tempdist<closestdistance){
4515 closestdistance=tempdist;
4520 player[i].targetpathfindpoint=closest;
4523 player[i].losupdatedelay-=multiplier;
4525 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4526 player[i].lookrotation=player[i].targetrotation;
4528 //reached target point
4529 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4530 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4531 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4532 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4533 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4534 if(player[i].lastpathfindpoint2==-1)
4535 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4536 if(player[i].lastpathfindpoint3==-1)
4537 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4538 if(player[i].lastpathfindpoint4==-1)
4539 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4540 player[i].targetpathfindpoint=-1;
4542 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4543 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4544 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4545 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4546 player[i].aitype=passivetype;
4549 player[i].forwardkeydown=1;
4550 player[i].leftkeydown=0;
4551 player[i].backkeydown=0;
4552 player[i].rightkeydown=0;
4553 player[i].crouchkeydown=0;
4554 player[i].attackkeydown=0;
4555 player[i].throwkeydown=0;
4557 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4558 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4560 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4561 player[i].jumpkeydown=0;
4562 if((player[i].collided>.8&&player[i].jumppower>=5))
4563 player[i].jumpkeydown=1;
4565 if((tutoriallevel!=1||cananger)&&
4568 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4569 player[i].occluded<25){
4570 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4571 animation[player[0].targetanimation].height!=lowheight&&
4573 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4574 player[i].aitype=attacktypecutoff;
4575 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4576 animation[player[0].targetanimation].height==highheight&&
4578 player[i].aitype=attacktypecutoff;
4580 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4581 player[i].losupdatedelay=.2;
4582 for(int j=0;j<numplayers;j++)
4583 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4584 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4585 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4586 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4587 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4588 if(!player[j].isWallJump()&&-1==checkcollide(
4589 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)
4590 *player[i].scale+player[i].coords,
4591 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)
4592 *player[j].scale+player[j].coords)||
4593 (player[j].targetanimation==hanganim&&
4594 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4595 player[i].aitype=searchtype;
4596 player[i].lastchecktime=12;
4597 player[i].lastseen=player[j].coords;
4598 player[i].lastseentime=12;
4602 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4603 if(player[i].creature!=wolftype){
4604 player[i].stunned=.6;
4605 player[i].surprised=.6;
4609 if(player[i].aitype!=passivetype&&leveltime>.5)
4610 player[i].howactive=typeactive;
4612 if(player[i].aitype==passivetype){
4613 player[i].aiupdatedelay-=multiplier;
4614 player[i].losupdatedelay-=multiplier;
4615 player[i].lastseentime+=multiplier;
4616 player[i].pausetime-=multiplier;
4617 if(player[i].lastseentime>1)
4618 player[i].lastseentime=1;
4620 if(player[i].aiupdatedelay<0){
4621 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4622 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4623 player[i].lookrotation=player[i].targetrotation;
4624 player[i].aiupdatedelay=.05;
4626 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4627 if(player[i].waypointtype[player[i].waypoint]==wppause)
4628 player[i].pausetime=4;
4629 player[i].waypoint++;
4630 if(player[i].waypoint>player[i].numwaypoints-1)
4631 player[i].waypoint=0;
4636 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4637 player[i].forwardkeydown=1;
4639 player[i].forwardkeydown=0;
4640 player[i].leftkeydown=0;
4641 player[i].backkeydown=0;
4642 player[i].rightkeydown=0;
4643 player[i].crouchkeydown=0;
4644 player[i].attackkeydown=0;
4645 player[i].throwkeydown=0;
4647 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4648 if(!player[i].avoidsomething)
4649 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4651 XYZ leftpos,rightpos;
4652 float leftdist,rightdist;
4653 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4654 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4655 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4656 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4657 if(leftdist<rightdist)
4658 player[i].targetrotation+=90;
4660 player[i].targetrotation-=90;
4664 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4665 player[i].jumpkeydown=0;
4666 if((player[i].collided>.8&&player[i].jumppower>=5))
4667 player[i].jumpkeydown=1;
4672 if(player[i].howactive<=typesleeping)
4673 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4674 for(int j=0;j<numenvsounds;j++){
4675 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4676 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4677 2*(vol+vol*(player[i].creature==rabbittype)*3))
4678 player[i].aitype=attacktypecutoff;
4681 if(player[i].aitype!=passivetype){
4682 if(player[i].howactive==typesleeping)
4683 player[i].setAnimation(getupfromfrontanim);
4684 player[i].howactive=typeactive;
4688 if(player[i].howactive<typesleeping&&
4689 ((tutoriallevel!=1||cananger)&&hostile)&&
4691 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4692 player[i].occluded<25){
4693 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4694 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4695 player[i].aitype=attacktypecutoff;
4696 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4697 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4698 player[i].aitype=attacktypecutoff;
4701 if(player[i].creature==wolftype){
4703 for(int j=0;j<numplayers;j++){
4704 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4705 float smelldistance=50;
4706 if(j==0&&player[j].num_weapons>0){
4707 if(weapons[player[j].weaponids[0]].bloody)
4709 if(player[j].num_weapons==2)
4710 if(weapons[player[j].weaponids[1]].bloody)
4715 windsmell=windvector;
4716 Normalise(&windsmell);
4717 windsmell=windsmell*2+player[j].coords;
4718 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4719 player[i].aitype=attacktypecutoff;
4724 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4725 player[i].losupdatedelay=.2;
4726 for(int j=0;j<numplayers;j++){
4727 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4728 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4729 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4730 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4731 if((-1==checkcollide(
4732 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4733 player[i].scale+player[i].coords,
4734 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*
4735 player[j].scale+player[j].coords)&&
4736 !player[j].isWallJump())||
4737 (player[j].targetanimation==hanganim&&
4738 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4739 player[i].lastseentime-=.2;
4740 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4741 player[i].lastseentime-=.4;
4743 player[i].lastseentime-=.6;
4745 if(player[i].lastseentime<=0){
4746 player[i].aitype=searchtype;
4747 player[i].lastchecktime=12;
4748 player[i].lastseen=player[j].coords;
4749 player[i].lastseentime=12;
4756 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4757 if(player[i].creature!=wolftype){
4758 player[i].stunned=.6;
4759 player[i].surprised=.6;
4761 if(player[i].creature==wolftype){
4762 player[i].stunned=.47;
4763 player[i].surprised=.47;
4771 if(player[i].aitype==searchtype){
4772 player[i].aiupdatedelay-=multiplier;
4773 player[i].losupdatedelay-=multiplier;
4774 if(!player[i].pause)
4775 player[i].lastseentime-=multiplier;
4776 player[i].lastchecktime-=multiplier;
4778 if(player[i].isRun()&&!player[i].onground){
4779 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4780 XYZ test2=player[i].coords+player[i].facing;
4782 XYZ test=player[i].coords+player[i].facing;
4784 j=checkcollide(test2,test,player[i].laststanding);
4786 j=checkcollide(test2,test);
4788 player[i].velocity=0;
4789 player[i].setAnimation(player[i].getStop());
4790 player[i].targetrotation+=180;
4791 player[i].stunned=.5;
4792 //player[i].aitype=passivetype;
4793 player[i].aitype=pathfindtype;
4794 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4795 player[i].finalpathfindpoint=-1;
4796 player[i].targetpathfindpoint=-1;
4797 player[i].lastpathfindpoint=-1;
4798 player[i].lastpathfindpoint2=-1;
4799 player[i].lastpathfindpoint3=-1;
4800 player[i].lastpathfindpoint4=-1;
4802 else player[i].laststanding=j;
4805 //check out last seen location
4806 if(player[i].aiupdatedelay<0){
4807 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4808 player[i].lookrotation=player[i].targetrotation;
4809 player[i].aiupdatedelay=.05;
4810 player[i].forwardkeydown=1;
4812 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4813 player[i].forwardkeydown=0;
4814 player[i].aiupdatedelay=1;
4815 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4816 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4817 player[i].lastchecktime=3;
4820 player[i].leftkeydown=0;
4821 player[i].backkeydown=0;
4822 player[i].rightkeydown=0;
4823 player[i].crouchkeydown=0;
4824 player[i].attackkeydown=0;
4825 player[i].throwkeydown=0;
4827 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4828 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4830 XYZ leftpos,rightpos;
4831 float leftdist,rightdist;
4832 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4833 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4834 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4835 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4836 if(leftdist<rightdist)player[i].targetrotation+=90;
4837 else player[i].targetrotation-=90;
4841 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4842 player[i].jumpkeydown=0;
4843 if((player[i].collided>.8&&player[i].jumppower>=5))
4844 player[i].jumpkeydown=1;
4846 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4847 for(int k=0;k<numenvsounds;k++){
4848 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4849 player[i].aitype=attacktypecutoff;
4853 if(!player[0].dead&&
4854 player[i].losupdatedelay<0&&
4856 player[i].occluded<2&&
4857 ((tutoriallevel!=1||cananger)&&hostile)){
4858 player[i].losupdatedelay=.2;
4859 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4860 player[i].aitype=attacktypecutoff;
4861 player[i].lastseentime=1;
4863 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4864 //TODO: factor out canSeePlayer()
4865 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4866 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4868 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4869 player[i].scale+player[i].coords,
4870 DoRotation(player[0].getJointFor(head).position,0,player[0].rotation,0)*
4871 player[0].scale+player[0].coords)==-1)||
4872 (player[0].targetanimation==hanganim&&normaldotproduct(
4873 player[0].facing,player[i].coords-player[0].coords)<0)){
4874 /* //TODO: changed j to 0 on a whim, make sure this is correct
4875 (player[j].targetanimation==hanganim&&normaldotproduct(
4876 player[j].facing,player[i].coords-player[j].coords)<0)
4878 player[i].aitype=attacktypecutoff;
4879 player[i].lastseentime=1;
4883 if(player[i].lastseentime<0){
4884 //player[i].aitype=passivetype;
4886 player[i].aitype=pathfindtype;
4887 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4888 player[i].finalpathfindpoint=-1;
4889 player[i].targetpathfindpoint=-1;
4890 player[i].lastpathfindpoint=-1;
4891 player[i].lastpathfindpoint2=-1;
4892 player[i].lastpathfindpoint3=-1;
4893 player[i].lastpathfindpoint4=-1;
4897 if(player[i].aitype!=gethelptype)
4898 player[i].runninghowlong=0;
4900 //get help from buddies
4901 if(player[i].aitype==gethelptype) {
4902 player[i].runninghowlong+=multiplier;
4903 player[i].aiupdatedelay-=multiplier;
4905 if(player[i].aiupdatedelay<0||player[i].ally==0) {
4906 player[i].aiupdatedelay=.2;
4909 //TODO: factor out closest search somehow
4910 if(!player[i].ally) {
4912 float closestdist=-1;
4913 for(int k=0;k<numplayers;k++) {
4914 if(k!=i&&k!=0&&!player[k].dead&&
4915 player[k].howactive<typedead1&&
4916 !player[k].skeleton.free&&
4917 player[k].aitype==passivetype) {
4918 float distance=findDistancefast(&player[i].coords,&player[k].coords);
4919 if(closestdist==-1||distance<closestdist) {
4920 closestdist=distance;
4927 player[i].ally=closest;
4930 player[i].lastseen=player[0].coords;
4931 player[i].lastseentime=12;
4935 player[i].lastchecktime=12;
4937 XYZ facing=player[i].coords;
4938 XYZ flatfacing=player[player[i].ally].coords;
4939 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
4940 flatfacing.y+=player[player[i].ally].getJointFor(head).position.y*player[player[i].ally].scale;
4941 if(-1!=checkcollide(facing,flatfacing))
4942 player[i].lastseentime-=.1;
4944 //no available ally, run back to player
4945 if(player[i].ally<=0||
4946 player[player[i].ally].skeleton.free||
4947 player[player[i].ally].aitype!=passivetype||
4948 player[i].lastseentime<=0){
4949 player[i].aitype=searchtype;
4950 player[i].lastseentime=12;
4954 if(player[i].ally>0){
4955 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
4956 player[i].lookrotation=player[i].targetrotation;
4957 player[i].aiupdatedelay=.05;
4958 player[i].forwardkeydown=1;
4960 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
4961 player[i].aitype=searchtype;
4962 player[i].lastseentime=12;
4963 player[player[i].ally].aitype=searchtype;
4964 if(player[player[i].ally].lastseentime<player[i].lastseentime){
4965 player[player[i].ally].lastseen=player[i].lastseen;
4966 player[player[i].ally].lastseentime=player[i].lastseentime;
4967 player[player[i].ally].lastchecktime=player[i].lastchecktime;
4971 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4972 if(!player[i].avoidsomething)
4973 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4975 XYZ leftpos,rightpos;
4976 float leftdist,rightdist;
4977 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4978 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4979 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4980 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4981 if(leftdist<rightdist)
4982 player[i].targetrotation+=90;
4984 player[i].targetrotation-=90;
4989 player[i].leftkeydown=0;
4990 player[i].backkeydown=0;
4991 player[i].rightkeydown=0;
4992 player[i].crouchkeydown=0;
4993 player[i].attackkeydown=0;
4995 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4996 player[i].jumpkeydown=0;
4997 if(player[i].collided>.8&&player[i].jumppower>=5)
4998 player[i].jumpkeydown=1;
5001 //retreiving a weapon on the ground
5002 if(player[i].aitype==getweapontype){
5003 player[i].aiupdatedelay-=multiplier;
5004 player[i].lastchecktime-=multiplier;
5006 if(player[i].aiupdatedelay<0){
5007 player[i].aiupdatedelay=.2;
5010 if(player[i].ally<0){
5012 float closestdist=-1;
5013 for(int k=0;k<weapons.size();k++)
5014 if(weapons[k].owner==-1){
5015 float distance=findDistancefast(&player[i].coords,&weapons[k].position);
5016 if(closestdist==-1||distance<closestdist){
5017 closestdist=distance;
5023 player[i].ally=closest;
5028 player[i].lastseentime=12;
5030 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5031 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5032 player[i].aitype=attacktypecutoff;
5033 player[i].lastseentime=1;
5036 if(player[i].ally>=0){
5037 if(weapons[player[i].ally].owner!=-1||
5038 findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
5039 player[i].aitype=attacktypecutoff;
5040 player[i].lastseentime=1;
5042 //TODO: factor these out as moveToward()
5043 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5044 player[i].lookrotation=player[i].targetrotation;
5045 player[i].aiupdatedelay=.05;
5046 player[i].forwardkeydown=1;
5049 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5050 if(!player[i].avoidsomething)
5051 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5053 XYZ leftpos,rightpos;
5054 float leftdist,rightdist;
5055 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5056 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5057 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5058 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5059 if(leftdist<rightdist)
5060 player[i].targetrotation+=90;
5062 player[i].targetrotation-=90;
5067 player[i].leftkeydown=0;
5068 player[i].backkeydown=0;
5069 player[i].rightkeydown=0;
5070 player[i].attackkeydown=0;
5071 player[i].throwkeydown=1;
5072 player[i].crouchkeydown=0;
5073 if(player[i].targetanimation!=crouchremoveknifeanim&&
5074 player[i].targetanimation!=removeknifeanim)
5075 player[i].throwtogglekeydown=0;
5076 player[i].drawkeydown=0;
5078 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5079 player[i].jumpkeydown=0;
5080 if((player[i].collided>.8&&player[i].jumppower>=5))
5081 player[i].jumpkeydown=1;
5084 if(player[i].aitype==attacktypecutoff){
5085 player[i].aiupdatedelay-=multiplier;
5086 //dodge or reverse rabbit kicks, knife throws, flips
5087 if(player[i].damage<player[i].damagetolerance*2/3)
5088 if((player[0].targetanimation==rabbitkickanim||
5089 player[0].targetanimation==knifethrowanim||
5090 (player[0].isFlip()&&
5091 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5092 !player[0].skeleton.free&&
5093 (player[i].aiupdatedelay<.1)){
5094 player[i].attackkeydown=0;
5095 if(player[i].isIdle())
5096 player[i].crouchkeydown=1;
5097 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5098 if(weapons[player[0].weaponids[0]].getType()==knife){
5099 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5100 if(abs(Random()%2==0))
5101 player[i].setAnimation(backhandspringanim);
5103 player[i].setAnimation(rollanim);
5104 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5105 player[i].wentforweapon=0;
5107 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5108 player[i].setAnimation(flipanim);
5111 player[i].forwardkeydown=0;
5112 player[i].aiupdatedelay=.02;
5114 //get confused by flips
5115 if(player[0].isFlip()&&
5116 !player[0].skeleton.free&&
5117 player[0].targetanimation!=walljumprightkickanim&&
5118 player[0].targetanimation!=walljumpleftkickanim){
5119 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5120 if((1-player[i].damage/player[i].damagetolerance)>.5)
5121 player[i].stunned=1;
5123 //go for weapon on the ground
5124 if(player[i].wentforweapon<3)
5125 for(int k=0;k<weapons.size();k++)
5126 if(player[i].creature!=wolftype)
5127 if(player[i].num_weapons==0&&
5128 weapons[k].owner==-1&&
5129 weapons[i].velocity.x==0&&
5130 weapons[i].velocity.z==0&&
5131 weapons[i].velocity.y==0){
5132 if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
5133 player[i].wentforweapon++;
5134 player[i].lastchecktime=6;
5135 player[i].aitype=getweapontype;
5139 //dodge/reverse walljump kicks
5140 if(player[i].damage<player[i].damagetolerance/2)
5141 if(animation[player[i].targetanimation].height!=highheight)
5142 if(player[i].damage<player[i].damagetolerance*.5&&
5143 ((player[0].targetanimation==walljumprightkickanim||
5144 player[0].targetanimation==walljumpleftkickanim)&&
5145 ((player[i].aiupdatedelay<.15&&
5147 (player[i].aiupdatedelay<.08&&
5149 player[i].crouchkeydown=1;
5151 //walked off a ledge (?)
5152 if(player[i].isRun()&&!player[i].onground)
5153 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5154 XYZ test2=player[i].coords+player[i].facing;
5156 XYZ test=player[i].coords+player[i].facing;
5158 j=checkcollide(test2,test,player[i].laststanding);
5160 j=checkcollide(test2,test);
5162 player[i].velocity=0;
5163 player[i].setAnimation(player[i].getStop());
5164 player[i].targetrotation+=180;
5165 player[i].stunned=.5;
5166 player[i].aitype=pathfindtype;
5167 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5168 player[i].finalpathfindpoint=-1;
5169 player[i].targetpathfindpoint=-1;
5170 player[i].lastpathfindpoint=-1;
5171 player[i].lastpathfindpoint2=-1;
5172 player[i].lastpathfindpoint3=-1;
5173 player[i].lastpathfindpoint4=-1;
5175 player[i].laststanding=j;
5177 //lose sight of player in the air (?)
5178 if(player[0].coords.y>player[i].coords.y+5&&
5179 animation[player[0].targetanimation].height!=highheight&&
5180 !player[0].onterrain){
5181 player[i].aitype=pathfindtype;
5182 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5183 player[i].finalpathfindpoint=-1;
5184 player[i].targetpathfindpoint=-1;
5185 player[i].lastpathfindpoint=-1;
5186 player[i].lastpathfindpoint2=-1;
5187 player[i].lastpathfindpoint3=-1;
5188 player[i].lastpathfindpoint4=-1;
5190 //it's time to think (?)
5191 if(player[i].aiupdatedelay<0&&
5192 !animation[player[i].targetanimation].attack&&
5193 player[i].targetanimation!=staggerbackhighanim&&
5194 player[i].targetanimation!=staggerbackhardanim&&
5195 player[i].targetanimation!=backhandspringanim&&
5196 player[i].targetanimation!=dodgebackanim){
5198 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5199 player[i].drawkeydown=Random()%2;
5201 player[i].drawkeydown=0;
5202 player[i].rabbitkickenabled=Random()%2;
5204 XYZ rotatetarget=player[0].coords+player[0].velocity;
5205 XYZ targetpoint=player[0].coords;
5206 if(findDistancefast(&player[0].coords,&player[i].coords)<
5207 findDistancefast(&rotatetarget,&player[i].coords))
5208 targetpoint+=player[0].velocity*
5209 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5210 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5211 player[i].lookrotation=player[i].targetrotation;
5212 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5214 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5215 player[i].forwardkeydown=1;
5216 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5217 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5218 player[0].weaponactive!=-1)
5219 player[i].forwardkeydown=1;
5220 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5221 player[i].forwardkeydown=1;
5223 player[i].forwardkeydown=0;
5224 //chill out around the corpse
5226 player[i].forwardkeydown=0;
5228 player[i].forwardkeydown=1;
5229 if(Random()%100==0){
5230 player[i].aitype=pathfindtype;
5231 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5232 player[i].finalpathfindpoint=-1;
5233 player[i].targetpathfindpoint=-1;
5234 player[i].lastpathfindpoint=-1;
5235 player[i].lastpathfindpoint2=-1;
5236 player[i].lastpathfindpoint3=-1;
5237 player[i].lastpathfindpoint4=-1;
5240 player[i].leftkeydown=0;
5241 player[i].backkeydown=0;
5242 player[i].rightkeydown=0;
5243 player[i].crouchkeydown=0;
5244 player[i].throwkeydown=0;
5246 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5247 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5249 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5250 player[i].attackkeydown=1;
5252 player[i].attackkeydown=0;
5253 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5254 player[i].attackkeydown=0;
5257 if(player[i].aitype!=playercontrolled&&
5258 (player[i].isIdle()||
5259 player[i].isCrouch()||
5260 player[i].isRun())){
5262 for(int j=0;j<numplayers;j++)
5263 if(j!=i&&!player[j].skeleton.free&&
5264 player[j].hasvictim&&
5265 (tutoriallevel==1&&reversaltrain||
5266 Random()%2==0&&difficulty==2||
5267 Random()%4==0&&difficulty==1||
5268 Random()%8==0&&difficulty==0||
5269 player[j].lastattack2==player[j].targetanimation&&
5270 player[j].lastattack3==player[j].targetanimation&&
5271 (Random()%2==0||difficulty==2)||
5272 (player[i].isIdle()||player[i].isRun())&&
5273 player[j].weaponactive!=-1||
5274 player[j].targetanimation==swordslashanim&&
5275 player[i].weaponactive!=-1||
5276 player[j].targetanimation==staffhitanim||
5277 player[j].targetanimation==staffspinhitanim))
5278 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5279 player[j].victim==&player[i]&&
5280 (player[j].targetanimation==sweepanim||
5281 player[j].targetanimation==spinkickanim||
5282 player[j].targetanimation==staffhitanim||
5283 player[j].targetanimation==staffspinhitanim||
5284 player[j].targetanimation==winduppunchanim||
5285 player[j].targetanimation==upunchanim||
5286 player[j].targetanimation==wolfslapanim||
5287 player[j].targetanimation==knifeslashstartanim||
5288 player[j].targetanimation==swordslashanim&&
5289 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5290 player[i].weaponactive!=-1))){
5297 player[target].Reverse();
5300 if(player[i].collided<1)
5301 player[i].jumpkeydown=0;
5302 if(player[i].collided>.8&&player[i].jumppower>=5||
5303 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5304 player[i].onterrain&&
5305 player[i].creature==rabbittype)
5306 player[i].jumpkeydown=1;
5307 //TODO: why are we controlling the human?
5308 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5309 player[0].jumpkeydown=0;
5310 if(player[0].targetanimation==jumpdownanim&&
5311 findDistancefast(&player[0].coords,&player[i].coords)<40)
5312 player[i].crouchkeydown=1;
5313 if(player[i].jumpkeydown)
5314 player[i].attackkeydown=0;
5316 if(tutoriallevel==1)
5318 player[i].attackkeydown=0;
5321 XYZ facing=player[i].coords;
5322 XYZ flatfacing=player[0].coords;
5323 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
5324 flatfacing.y+=player[0].getJointFor(head).position.y*player[0].scale;
5325 if(player[i].occluded>=2)
5326 if(-1!=checkcollide(facing,flatfacing)){
5327 if(!player[i].pause)
5328 player[i].lastseentime-=.2;
5329 if(player[i].lastseentime<=0&&
5330 (player[i].creature!=wolftype||
5331 player[i].weaponstuck==-1)){
5332 player[i].aitype=searchtype;
5333 player[i].lastchecktime=12;
5334 player[i].lastseen=player[0].coords;
5335 player[i].lastseentime=12;
5338 player[i].lastseentime=1;
5341 if(animation[player[0].targetanimation].height==highheight&&
5342 (player[i].aitype==attacktypecutoff||
5343 player[i].aitype==searchtype))
5344 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5345 XYZ test=player[0].coords;
5347 if(-1==checkcollide(player[0].coords,test))
5348 player[i].stunned=1;
5351 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5352 player[i].stunned>0||
5353 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5355 player[i].lastseentime=1;
5356 player[i].targetrotation=player[i].rotation;
5357 player[i].forwardkeydown=0;
5358 player[i].leftkeydown=0;
5359 player[i].backkeydown=0;
5360 player[i].rightkeydown=0;
5361 player[i].jumpkeydown=0;
5362 player[i].attackkeydown=0;
5363 player[i].crouchkeydown=0;
5364 player[i].throwkeydown=0;
5372 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5375 if(player[i].aitype==attacktypecutoff){
5376 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5377 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5378 }else if(player[i].howactive>=typesleeping){
5379 player[i].targetheadrotation=player[i].targetrotation;
5380 player[i].targetheadrotation2=0;
5382 if(player[i].interestdelay<=0){
5383 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5384 player[i].headtarget=player[i].coords;
5385 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5386 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5387 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5388 player[i].headtarget+=player[i].facing*1.5;
5390 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5391 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5397 Values of mainmenu :
5399 2 Menu pause (resume/end game)
5401 4 Controls configuration menu
5402 5 Main game menu (choose level or challenge)
5403 6 Deleting user menu
5404 7 User managment menu (select/add)
5405 8 Choose difficulty menu
5406 9 Challenge level selection menu
5407 10 End of the campaign congratulation (is that really a menu?)
5408 11 Same that 9 ??? => unused
5409 18 stereo configuration
5412 void Game::MenuTick(){
5415 // some specific case where we do something even if the left mouse button is not pressed.
5416 if((mainmenu==5) && (endgame==2)) {
5417 accountactive->endGame();
5422 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
5423 stereoseparation-=0.001;
5425 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5431 if(gameon) { //resume
5433 pause_sound(stream_menutheme);
5434 resume_stream(leveltheme);
5436 fireSound(firestartsound);
5438 mainmenu=(accountactive?5:7);
5446 if(newdetail>2) newdetail=detail;
5447 if(newdetail<0) newdetail=detail;
5448 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5449 if(newscreenwidth<0) newscreenwidth=screenwidth;
5450 if(newscreenheight>3000) newscreenheight=screenheight;
5451 if(newscreenheight<0) newscreenheight=screenheight;
5456 if(gameon){ //end game
5461 pause_sound(stream_menutheme);
5468 bool isCustomResolution,found;
5471 extern SDL_Rect **resolutions;
5472 isCustomResolution = true;
5474 for(int i = 0; (!found) && (resolutions[i]); i++) {
5475 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5476 isCustomResolution = false;
5478 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5480 if(resolutions[i] != NULL) {
5481 newscreenwidth = (int) resolutions[i]->w;
5482 newscreenheight = (int) resolutions[i]->h;
5483 } else if(isCustomResolution){
5484 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5485 newscreenwidth = (int) resolutions[0]->w;
5486 newscreenheight = (int) resolutions[0]->h;
5488 newscreenwidth = screenwidth;
5489 newscreenheight = screenheight;
5492 newscreenwidth = (int) resolutions[0]->w;
5493 newscreenheight = (int) resolutions[0]->h;
5500 newscreenwidth = (int) resolutions[0]->w;
5501 newscreenheight = (int) resolutions[0]->h;
5506 if(newdetail>2) newdetail=0;
5510 if(bloodtoggle>2) bloodtoggle=0;
5514 if(difficulty>2) difficulty=0;
5517 ismotionblur = !ismotionblur;
5523 musictoggle = !musictoggle;
5526 emit_stream_np(stream_menutheme);
5528 pause_sound(leveltheme);
5529 pause_sound(stream_fighttheme);
5530 pause_sound(stream_menutheme);
5532 for(int i=0;i<4;i++){
5533 oldmusicvolume[i]=0;
5549 mainmenu=gameon?2:1;
5552 invertmouse = !invertmouse;
5555 usermousesensitivity+=.2;
5556 if(usermousesensitivity>2) usermousesensitivity=.2;
5560 if(volume>1.0001f) volume=0;
5561 OPENAL_SetSFXMasterVolume((int)(volume*255));
5566 newstereomode = stereomode;
5571 showdamagebar = !showdamagebar;
5578 if(selected<(debugmode?10:9) && keyselect==-1)
5582 if(selected==(debugmode?10:9)){
5591 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5601 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5602 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5605 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5609 pause_sound(stream_menutheme);
5626 pause_sound(stream_menutheme);
5635 mainmenu=(gameon?2:1);
5641 vector<string> campaigns = ListCampaigns();
5642 vector<string>::iterator c;
5643 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5644 if(!campaigns.empty())
5645 accountactive->setCurrentCampaign(campaigns.front());
5648 if(c==campaigns.end())
5649 c=campaigns.begin();
5650 accountactive->setCurrentCampaign(*c);
5660 accountactive = Account::destroy(accountactive);
5662 } else if(selected==2) {
5669 if(selected==0 && Account::getNbAccounts()<8){
5671 } else if (selected < Account::getNbAccounts()+1) {
5674 accountactive=Account::get(selected-1);
5675 } else if (selected == Account::getNbAccounts()+1) {
5678 for(int j=0;j<255;j++){
5679 displaytext[0][j]=0;
5690 accountactive->setDifficulty(selected);
5694 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5702 targetlevel=selected;
5707 Loadlevel(selected);
5712 pause_sound(stream_menutheme);
5714 if(selected==numchallengelevels){
5729 stereoseparation+=0.001;
5733 newstereomode = (StereoMode)(newstereomode + 1);
5734 while(!CanInitStereo(newstereomode)){
5735 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5736 newstereomode = (StereoMode)(newstereomode + 1);
5737 if(newstereomode >= stereoCount)
5738 newstereomode = stereoNone;
5740 } else if(selected==2) {
5741 stereoreverse = !stereoreverse;
5742 } else if(selected==3) {
5746 stereomode = newstereomode;
5747 InitStereo(stereomode);
5754 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5761 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5764 inputText(displaytext[0],&displayselected,&displaychars[0]);
5765 if(!waiting) { // the input as finished
5766 if(displaychars[0]){ // with enter
5767 accountactive = Account::add(string(displaytext[0]));
5773 fireSound(firestartsound);
5775 for(int i=0;i<255;i++){
5776 displaytext[0][i]=0;
5785 displayblinkdelay-=multiplier;
5786 if(displayblinkdelay<=0){
5787 displayblinkdelay=.3;
5788 displayblink=1-displayblink;
5794 static XYZ facing,flatfacing;
5797 for(int i=0;i<15;i++){
5798 displaytime[i]+=multiplier;
5801 keyboardfrozen=false;
5804 if(Input::isKeyPressed(SDLK_F6)){
5805 if(Input::isKeyDown(SDLK_LSHIFT))
5808 stereoreverse=false;
5811 printf("Stereo reversed\n");
5813 printf("Stereo unreversed\n");
5816 if(Input::isKeyDown(SDLK_F7)){
5817 if(Input::isKeyDown(SDLK_LSHIFT))
5818 stereoseparation -= 0.001;
5820 stereoseparation -= 0.010;
5821 printf("Stereo decreased increased to %f\n", stereoseparation);
5824 if(Input::isKeyDown(SDLK_F8)){
5825 if(Input::isKeyDown(SDLK_LSHIFT))
5826 stereoseparation += 0.001;
5828 stereoseparation += 0.010;
5829 printf("Stereo separation increased to %f\n", stereoseparation);
5833 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5834 if(tutorialstage!=51)
5835 tutorialstagetime=tutorialmaxtime;
5836 emit_sound_np(consolefailsound, 128.);
5840 Values of mainmenu :
5842 2 Menu pause (resume/end game)
5844 4 Controls configuration menu
5845 5 Main game menu (choose level or challenge)
5846 6 Deleting user menu
5847 7 User managment menu (select/add)
5848 8 Choose difficulty menu
5849 9 Challenge level selection menu
5850 10 End of the campaign congratulation (is that really a menu?)
5851 11 Same that 9 ??? => unused
5852 18 stereo configuration
5857 if(mainmenu&&endgame==1)
5859 //go to level select after completing a campaign level
5860 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
5867 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5868 emit_stream_np(stream_menutheme);
5869 pause_sound(leveltheme);
5873 //escape key pressed
5874 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5875 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5876 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
5878 if(mainmenu==0&&!winfreeze)
5880 else if(mainmenu==1||mainmenu==2){
5881 mainmenu=0; //unpause
5884 if(musictoggle&&(mainmenu==1||mainmenu==2)){
5885 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5886 emit_stream_np(stream_menutheme);
5887 pause_sound(leveltheme);
5889 //on resume, play level music
5891 pause_sound(stream_menutheme);
5892 resume_stream(leveltheme);
5894 //finished with settings menu
5899 if(mainmenu>=3&&mainmenu!=8){
5906 mainmenu=gameon?2:1; break;
5909 case 6: case 7: case 9: case 10:
5920 if(hostile==1)hostiletime+=multiplier;
5922 if(!winfreeze)leveltime+=multiplier;
5925 if(Input::isKeyPressed(SDLK_v)&&debugmode){
5928 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5932 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
5936 inputText(displaytext[0],&displayselected,&displaychars[0]);
5938 if(displaychars[0]){
5939 for(int j=0;j<255;j++)
5940 displaytext[0][j]=0;
5947 displayblinkdelay-=multiplier;
5948 if(displayblinkdelay<=0){
5949 displayblinkdelay=.3;
5950 displayblink=1-displayblink;
5954 keyboardfrozen=true;
5956 if(Input::isKeyPressed(consolekey)&&debugmode) {
5959 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5968 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
5969 inputText(consoletext[0],&consoleselected,&consolechars[0]);
5972 if(consolechars[0]>0) {
5973 consoletext[0][consolechars[0]]='\0';
5974 cmd_dispatch(consoletext[0]);
5975 for(int k=14;k>=1;k--) {
5976 for(int j=0;j<255;j++)
5977 consoletext[k][j]=consoletext[k-1][j];
5978 consolechars[k]=consolechars[k-1];
5980 for(int j=0;j<255;j++)
5981 consoletext[0][j]=0;
5987 consoleblinkdelay-=multiplier;
5988 if(consoleblinkdelay<=0) {
5989 consoleblinkdelay=.3;
5990 consoleblink=1-consoleblink;
5996 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6003 static int oldwinfreeze;
6004 if(winfreeze&&!oldwinfreeze){
6005 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6006 emit_sound_np(consolesuccesssound);
6009 oldwinfreeze=winfreeze;
6013 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6016 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6020 } else if(winfreeze) {
6028 //TODO: what is this test?
6029 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6034 talkdelay-=multiplier;
6036 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6037 for(int i=0;i<numdialogues;i++){
6038 int realdialoguetype;
6040 if(dialoguetype[i]>49){
6041 realdialoguetype=dialoguetype[i]-50;
6044 else if(dialoguetype[i]>39){
6045 realdialoguetype=dialoguetype[i]-40;
6048 else if(dialoguetype[i]>29){
6049 realdialoguetype=dialoguetype[i]-30;
6052 else if(dialoguetype[i]>19){
6053 realdialoguetype=dialoguetype[i]-20;
6056 else if(dialoguetype[i]>9){
6057 realdialoguetype=dialoguetype[i]-10;
6061 realdialoguetype=dialoguetype[i];
6064 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6065 realdialoguetype<numplayers&&
6066 realdialoguetype>0&&
6067 (dialoguegonethrough[i]==0||!special)&&
6068 (special||Input::isKeyPressed(attackkey))){
6069 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6070 player[realdialoguetype].howactive>=typedead1||
6071 dialoguetype[i]>40&&dialoguetype[i]<50){
6073 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6074 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6075 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6076 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6077 player[participantfocus[whichdialogue][j]].velocity=0;
6078 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6079 player[participantfocus[whichdialogue][j]].targetframe=0;
6084 dialoguegonethrough[i]++;
6085 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6086 playdialogueboxsound();
6092 windvar+=multiplier;
6093 smoketex+=multiplier;
6094 tutorialstagetime+=multiplier;
6097 static float hotspotvisual[40];
6101 for(int i=0;i<numhotspots;i++)
6102 hotspotvisual[i]-=multiplier/320;
6104 for(int i=0;i<numhotspots;i++){
6105 //if(hotspottype[i]<=10)
6106 while(hotspotvisual[i]<0){
6108 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6109 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6110 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6111 hotspotsprite+=hotspot[i];
6112 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6113 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6117 for(int i=0;i<numhotspots;i++){
6118 if(hotspottype[i]<=10&&hotspottype[i]>0){
6119 hotspot[i]=player[hotspottype[i]].coords;
6130 if(tutoriallevel!=1){
6133 bonus!=spinecrusher&&
6134 bonus!=tracheotomy&&
6137 emit_sound_np(consolesuccesssound);
6139 } else if(bonustime==0){
6140 emit_sound_np(fireendsound);
6143 if(bonus!=solidhit&&
6145 bonus!=threexcombo&&
6150 bonusnum[bonus]+=0.15;
6153 bonusvalue/=bonusnum[bonus];
6154 bonustotal+=bonusvalue;
6156 bonustime+=multiplier;
6159 if(environment==snowyenvironment){
6160 precipdelay-=multiplier;
6161 while(precipdelay<0){
6165 XYZ footvel,footpoint;
6168 footpoint=viewer+viewerfacing*6;
6169 footpoint.y+=((float)abs(Random()%1200))/100-6;
6170 footpoint.x+=((float)abs(Random()%1200))/100-6;
6171 footpoint.z+=((float)abs(Random()%1200))/100-6;
6172 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6177 doAerialAcrobatics();
6180 static XYZ oldviewer;
6184 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6185 player[0].leftkeydown=Input::isKeyDown(leftkey);
6186 player[0].backkeydown=Input::isKeyDown(backkey);
6187 player[0].rightkeydown=Input::isKeyDown(rightkey);
6188 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6189 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6190 player[0].drawkeydown=Input::isKeyDown(drawkey);
6191 player[0].throwkeydown=Input::isKeyDown(throwkey);
6195 player[0].forwardkeydown=0;
6196 player[0].leftkeydown=0;
6197 player[0].backkeydown=0;
6198 player[0].rightkeydown=0;
6199 player[0].jumpkeydown=0;
6200 player[0].crouchkeydown=0;
6201 player[0].drawkeydown=0;
6202 player[0].throwkeydown=0;
6205 if(!player[0].jumpkeydown)
6206 player[0].jumpclimb=0;
6215 facing=DoRotation(facing,-rotation2,0,0);
6216 facing=DoRotation(facing,0,0-rotation,0);
6221 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6223 if(Input::isKeyDown(forwardkey))
6224 viewer+=facing*multiplier*4;
6225 if(Input::isKeyDown(backkey))
6226 viewer-=facing*multiplier*4;
6227 if(Input::isKeyDown(leftkey))
6228 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6229 if(Input::isKeyDown(rightkey))
6230 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6231 if(Input::isKeyDown(jumpkey))
6232 viewer.y+=multiplier*4;
6233 if(Input::isKeyDown(crouchkey))
6234 viewer.y-=multiplier*4;
6235 if( Input::isKeyPressed(SDLK_1)||
6236 Input::isKeyPressed(SDLK_2)||
6237 Input::isKeyPressed(SDLK_3)||
6238 Input::isKeyPressed(SDLK_4)||
6239 Input::isKeyPressed(SDLK_5)||
6240 Input::isKeyPressed(SDLK_6)||
6241 Input::isKeyPressed(SDLK_7)||
6242 Input::isKeyPressed(SDLK_8)||
6243 Input::isKeyPressed(SDLK_9)||
6244 Input::isKeyPressed(SDLK_0)||
6245 Input::isKeyPressed(SDLK_MINUS)){
6247 if(Input::isKeyPressed(SDLK_1))whichend=1;
6248 if(Input::isKeyPressed(SDLK_2))whichend=2;
6249 if(Input::isKeyPressed(SDLK_3))whichend=3;
6250 if(Input::isKeyPressed(SDLK_4))whichend=4;
6251 if(Input::isKeyPressed(SDLK_5))whichend=5;
6252 if(Input::isKeyPressed(SDLK_6))whichend=6;
6253 if(Input::isKeyPressed(SDLK_7))whichend=7;
6254 if(Input::isKeyPressed(SDLK_8))whichend=8;
6255 if(Input::isKeyPressed(SDLK_9))whichend=9;
6256 if(Input::isKeyPressed(SDLK_0))whichend=0;
6257 if(Input::isKeyPressed(SDLK_MINUS))
6260 participantfocus[whichdialogue][indialogue]=whichend;
6261 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6262 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6265 participantfocus[whichdialogue][indialogue]=-1;
6267 if(player[participantfocus[whichdialogue][indialogue]].dead){
6272 dialoguecamera[whichdialogue][indialogue]=viewer;
6273 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6274 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6276 if(indialogue<numdialogueboxes[whichdialogue]){
6277 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6278 playdialogueboxsound();
6282 for(int j=0;j<numplayers;j++){
6283 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6286 //TODO: should these be KeyDown or KeyPressed?
6287 if( Input::isKeyDown(SDLK_KP1)||
6288 Input::isKeyDown(SDLK_KP2)||
6289 Input::isKeyDown(SDLK_KP3)||
6290 Input::isKeyDown(SDLK_KP4)||
6291 Input::isKeyDown(SDLK_KP5)||
6292 Input::isKeyDown(SDLK_KP6)||
6293 Input::isKeyDown(SDLK_KP7)||
6294 Input::isKeyDown(SDLK_KP8)||
6295 Input::isKeyDown(SDLK_KP9)||
6296 Input::isKeyDown(SDLK_KP0)){
6298 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6299 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6300 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6301 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6302 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6303 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6304 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6305 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6306 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6307 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6308 participantfacing[whichdialogue][indialogue][whichend]=facing;
6310 if(indialogue>=numdialogueboxes[whichdialogue]){
6317 pause_sound(whooshsound);
6318 viewer=dialoguecamera[whichdialogue][indialogue];
6319 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6320 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6321 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6322 if(dialoguetime>0.5)
6323 if( Input::isKeyPressed(SDLK_1)||
6324 Input::isKeyPressed(SDLK_2)||
6325 Input::isKeyPressed(SDLK_3)||
6326 Input::isKeyPressed(SDLK_4)||
6327 Input::isKeyPressed(SDLK_5)||
6328 Input::isKeyPressed(SDLK_6)||
6329 Input::isKeyPressed(SDLK_7)||
6330 Input::isKeyPressed(SDLK_8)||
6331 Input::isKeyPressed(SDLK_9)||
6332 Input::isKeyPressed(SDLK_0)||
6333 Input::isKeyPressed(SDLK_MINUS)||
6334 Input::isKeyPressed(attackkey)){
6336 if(indialogue<numdialogueboxes[whichdialogue]){
6337 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6338 playdialogueboxsound();
6339 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6340 hotspot[numhotspots]=player[0].coords;
6341 hotspotsize[numhotspots]=10;
6342 hotspottype[numhotspots]=-1;
6346 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6350 if(player[participantfocus[whichdialogue][indialogue]].dead){
6358 if(indialogue>=numdialogueboxes[whichdialogue]){
6362 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6365 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6368 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6370 for(int i=1;i<numplayers;i++){
6371 player[i].aitype = attacktypecutoff;
6378 if(!player[0].jumpkeydown){
6379 player[0].jumptogglekeydown=0;
6381 if(player[0].jumpkeydown&&
6382 player[0].targetanimation!=jumpupanim&&
6383 player[0].targetanimation!=jumpdownanim&&
6384 !player[0].isFlip())
6385 player[0].jumptogglekeydown=1;
6388 dialoguetime+=multiplier;
6389 hawkrotation+=multiplier*25;
6391 realhawkcoords.x=25;
6392 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6393 hawkcalldelay-=multiplier/2;
6395 if(hawkcalldelay<=0){
6396 emit_sound_at(hawksound, realhawkcoords);
6398 hawkcalldelay=16+abs(Random()%8);
6405 doPlayerCollisions();
6409 for(int k=0;k<numplayers;k++)
6410 if(k!=0&&player[k].immobile)
6411 player[k].coords=player[k].realoldcoords;
6413 for(int k=0;k<numplayers;k++){
6414 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6415 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6416 player[k].DoDamage(1000);
6422 static bool respawnkeydown;
6425 (Input::isKeyDown(SDLK_z)&&
6426 Input::isKeyDown(SDLK_LMETA)&&
6428 (Input::isKeyDown(jumpkey)&&
6432 targetlevel=whichlevel;
6436 if(!Input::isKeyDown(jumpkey))
6438 if(Input::isKeyDown(jumpkey))
6444 static bool movekey;
6447 for(int i=0;i<numplayers;i++){
6448 static float oldtargetrotation;
6449 if(!player[i].skeleton.free){
6450 oldtargetrotation=player[i].targetrotation;
6451 if(i==0&&indialogue==-1){
6452 //TODO: refactor repetitive code
6453 if(!animation[player[0].targetanimation].attack&&
6454 player[0].targetanimation!=staggerbackhighanim&&
6455 player[0].targetanimation!=staggerbackhardanim&&
6456 player[0].targetanimation!=crouchremoveknifeanim&&
6457 player[0].targetanimation!=removeknifeanim&&
6458 player[0].targetanimation!=backhandspringanim&&
6459 player[0].targetanimation!=dodgebackanim&&
6460 player[0].targetanimation!=walljumprightkickanim&&
6461 player[0].targetanimation!=walljumpleftkickanim){
6463 player[0].targetrotation=0;
6465 player[0].targetrotation=-rotation+180;
6471 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6475 facing=DoRotation(facing,-rotation2,0,0);
6476 facing=DoRotation(facing,0,0-rotation,0);
6479 player[0].lookrotation=-rotation;
6481 player[i].targetheadrotation=rotation;
6482 player[i].targetheadrotation2=rotation2;
6484 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6485 if(!animation[player[i].targetanimation].attack&&
6486 player[i].targetanimation!=staggerbackhighanim&&
6487 player[i].targetanimation!=staggerbackhardanim&&
6488 player[i].targetanimation!=crouchremoveknifeanim&&
6489 player[i].targetanimation!=removeknifeanim&&
6490 player[i].targetanimation!=backhandspringanim&&
6491 player[i].targetanimation!=dodgebackanim&&
6492 player[i].targetanimation!=walljumprightkickanim&&
6493 player[i].targetanimation!=walljumpleftkickanim){
6494 player[i].targetrotation=-player[i].lookrotation+180;
6500 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6502 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6503 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6505 player[i].targetheadrotation=player[i].lookrotation;
6506 player[i].targetheadrotation2=player[i].lookrotation2;
6509 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6510 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6516 player[i].avoidsomething=0;
6518 //avoid flaming things
6519 for(int j=0;j<objects.numobjects;j++)
6520 if(objects.onfire[j])
6521 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6522 if( findDistancefast(&player[i].coords,&objects.position[j])<
6523 findDistancefast(&player[i].coords,&player[0].coords)){
6524 player[i].collided=0;
6525 player[i].avoidcollided=1;
6526 if(player[i].avoidsomething==0||
6527 findDistancefast(&player[i].coords,&objects.position[j])<
6528 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6529 player[i].avoidwhere=objects.position[j];
6530 player[i].avoidsomething=1;
6534 //avoid flaming players
6535 for(int j=0;j<numplayers;j++)
6536 if(player[j].onfire)
6537 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6538 if( findDistancefast(&player[i].coords,&player[j].coords)<
6539 findDistancefast(&player[i].coords,&player[0].coords)){
6540 player[i].collided=0;
6541 player[i].avoidcollided=1;
6542 if(player[i].avoidsomething==0||
6543 findDistancefast(&player[i].coords,&player[j].coords)<
6544 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6545 player[i].avoidwhere=player[j].coords;
6546 player[i].avoidsomething=1;
6550 if(player[i].collided>.8)
6551 player[i].avoidcollided=0;
6555 if(animation[player[i].targetanimation].attack==reversed){
6556 //player[i].targetrotation=player[i].rotation;
6557 player[i].forwardkeydown=0;
6558 player[i].leftkeydown=0;
6559 player[i].backkeydown=0;
6560 player[i].rightkeydown=0;
6561 player[i].jumpkeydown=0;
6562 player[i].attackkeydown=0;
6563 //player[i].crouchkeydown=0;
6564 player[i].throwkeydown=0;
6568 player[i].forwardkeydown=0;
6569 player[i].leftkeydown=0;
6570 player[i].backkeydown=0;
6571 player[i].rightkeydown=0;
6572 player[i].jumpkeydown=0;
6573 player[i].crouchkeydown=0;
6574 player[i].drawkeydown=0;
6575 player[i].throwkeydown=0;
6578 if(player[i].collided<-.3)
6579 player[i].collided=-.3;
6580 if(player[i].collided>1)
6581 player[i].collided=1;
6582 player[i].collided-=multiplier*4;
6583 player[i].whichdirectiondelay-=multiplier;
6584 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6585 player[i].avoidcollided=-.3;
6586 player[i].whichdirection=abs(Random()%2);
6587 player[i].whichdirectiondelay=.4;
6589 if(player[i].avoidcollided>1)
6590 player[i].avoidcollided=1;
6591 player[i].avoidcollided-=multiplier/4;
6592 if(!player[i].skeleton.free){
6593 player[i].stunned-=multiplier;
6594 player[i].surprised-=multiplier;
6596 if(i!=0&&player[i].surprised<=0&&
6597 player[i].aitype==attacktypecutoff&&
6599 !player[i].skeleton.free&&
6600 animation[player[i].targetanimation].attack==neutral)
6603 if(!player[i].throwkeydown)
6604 player[i].throwtogglekeydown=0;
6607 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6608 if(player[i].weaponactive==-1&&
6609 player[i].num_weapons<2&&
6610 (player[i].isIdle()||
6611 player[i].isCrouch()||
6612 player[i].targetanimation==sneakanim||
6613 player[i].targetanimation==rollanim||
6614 player[i].targetanimation==backhandspringanim||
6615 player[i].isFlip()||
6616 player[i].isFlip()||
6617 player[i].aitype!=playercontrolled)){
6618 for(int j=0;j<weapons.size();j++){
6619 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6620 player[i].aitype==playercontrolled)&&
6621 weapons[j].owner==-1&&
6622 player[i].weaponactive==-1)
6623 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
6624 if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
6625 if(player[i].isCrouch()||
6626 player[i].targetanimation==sneakanim||
6628 player[i].isIdle()||
6629 player[i].aitype!=playercontrolled){
6630 player[i].throwtogglekeydown=1;
6631 player[i].setAnimation(crouchremoveknifeanim);
6632 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6633 player[i].hasvictim=0;
6635 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6636 player[i].throwtogglekeydown=1;
6637 player[i].hasvictim=0;
6639 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6640 player[i].aitype==playercontrolled)&&
6641 weapons[j].owner==-1||
6643 weapons[j].owner==player[i].victim->id)
6644 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
6645 if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
6646 if(weapons[j].getType()!=staff)
6647 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6649 player[i].weaponactive=0;
6650 weapons[j].owner=player[i].id;
6651 if(player[i].num_weapons>0)
6652 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6653 player[i].num_weapons++;
6654 player[i].weaponids[0]=j;
6657 }else if((player[i].isIdle()||
6658 player[i].isFlip()||
6659 player[i].aitype!=playercontrolled)&&
6660 findDistancefast(&player[i].coords,&weapons[j].position)<5&&
6661 player[i].coords.y<weapons[j].position.y){
6662 if(!player[i].isFlip()){
6663 player[i].throwtogglekeydown=1;
6664 player[i].setAnimation(removeknifeanim);
6665 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6667 if(player[i].isFlip()){
6668 player[i].throwtogglekeydown=1;
6669 player[i].hasvictim=0;
6671 for(int k=0;k<weapons.size();k++){
6672 if(player[i].weaponactive==-1)
6673 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
6674 player[i].aitype==playercontrolled)&&
6675 weapons[k].owner==-1||
6677 weapons[k].owner==player[i].victim->id)
6678 if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
6679 player[i].weaponactive==-1){
6680 if(weapons[k].getType()!=staff)
6681 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6683 player[i].weaponactive=0;
6684 weapons[k].owner=player[i].id;
6685 if(player[i].num_weapons>0)
6686 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6687 player[i].num_weapons++;
6688 player[i].weaponids[0]=k;
6695 if(player[i].isCrouch()||
6696 player[i].targetanimation==sneakanim||
6698 player[i].isIdle()||player[i].targetanimation==rollanim||
6699 player[i].targetanimation==backhandspringanim){
6701 for(int j=0;j<numplayers;j++){
6702 if(player[i].weaponactive==-1)
6704 if(player[j].num_weapons&&
6705 player[j].skeleton.free&&
6706 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6707 (((player[j].skeleton.forward.y<0&&
6708 player[j].weaponstuckwhere==0)||
6709 (player[j].skeleton.forward.y>0&&
6710 player[j].weaponstuckwhere==1))||
6711 player[j].weaponstuck==-1||
6712 player[j].num_weapons>1)){
6713 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6714 player[i].throwtogglekeydown=1;
6715 player[i].victim=&player[j];
6716 player[i].hasvictim=1;
6717 player[i].setAnimation(crouchremoveknifeanim);
6718 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6720 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6721 player[i].throwtogglekeydown=1;
6722 player[i].victim=&player[j];
6723 player[i].hasvictim=1;
6724 int k = player[j].weaponids[0];
6725 if(player[i].hasvictim){
6728 if(player[i].victim->weaponstuck!=-1){
6729 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6734 if(weapons[k].getType()!=staff)
6735 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6738 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6740 player[i].weaponactive=0;
6741 if(weapons[k].owner!=-1){
6742 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6743 else player[i].victim->num_weapons=1;
6745 player[i].victim->skeleton.longdead=0;
6746 player[i].victim->skeleton.free=1;
6747 player[i].victim->skeleton.broken=0;
6749 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6750 player[i].victim->skeleton.joints[l].velchange=0;
6751 player[i].victim->skeleton.joints[l].locked=0;
6757 Normalise(&relative);
6758 XYZ footvel,footpoint;
6760 footpoint=weapons[k].position;
6761 if(player[i].victim->weaponstuck!=-1){
6762 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6763 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6764 weapons[k].bloody=2;
6765 weapons[k].blooddrip=5;
6766 player[i].victim->weaponstuck=-1;
6767 player[i].victim->bloodloss+=2000;
6768 player[i].victim->DoDamage(2000);
6771 if(player[i].victim->num_weapons>0){
6772 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6773 if(player[i].victim->weaponids[0]==k)
6774 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6777 player[i].victim->weaponactive=-1;
6779 player[i].victim->getJointFor(abdomen).velocity+=relative*6;
6780 player[i].victim->getJointFor(neck).velocity+=relative*6;
6781 player[i].victim->getJointFor(rightshoulder).velocity+=relative*6;
6782 player[i].victim->getJointFor(leftshoulder).velocity+=relative*6;
6785 if(player[i].num_weapons>0){
6786 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6788 player[i].num_weapons++;
6789 player[i].weaponids[0]=k;
6796 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6797 if(weapons[player[i].weaponids[0]].getType()==knife){
6798 if(player[i].isIdle()||
6800 player[i].isCrouch()||
6801 player[i].targetanimation==sneakanim||
6804 for(int j=0;j<numplayers;j++){
6806 if(tutoriallevel!=1||tutorialstage==49)
6808 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6809 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6810 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6811 !player[j].skeleton.free&&
6812 -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
6813 if(!player[i].isFlip()){
6814 player[i].throwtogglekeydown=1;
6815 player[i].victim=&player[j];
6816 player[i].setAnimation(knifethrowanim);
6817 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6818 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6820 if(player[i].isFlip()){
6821 if(player[i].weaponactive!=-1){
6822 player[i].throwtogglekeydown=1;
6823 player[i].victim=&player[j];
6825 weapons[player[i].weaponids[0]].owner=-1;
6826 aim=player[i].victim->coords+DoRotation(player[i].victim->getJointFor(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].getJointFor(righthand).position,0,player[i].rotation,0)*player[i].scale);
6829 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6831 weapons[player[i].weaponids[0]].velocity=aim*50;
6832 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
6833 weapons[player[i].weaponids[0]].missed=0;
6834 weapons[player[i].weaponids[0]].freetime=0;
6835 weapons[player[i].weaponids[0]].firstfree=1;
6836 weapons[player[i].weaponids[0]].physics=0;
6837 player[i].num_weapons--;
6838 if(player[i].num_weapons){
6839 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6841 player[i].weaponactive=-1;
6848 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6849 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6850 player[i].throwtogglekeydown=1;
6851 weapons[player[i].weaponids[0]].owner=-1;
6852 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
6853 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
6854 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
6855 weapons[player[i].weaponids[0]].missed=1;
6856 weapons[player[i].weaponids[0]].freetime=0;
6857 weapons[player[i].weaponids[0]].firstfree=1;
6858 weapons[player[i].weaponids[0]].physics=1;
6859 player[i].num_weapons--;
6860 if(player[i].num_weapons){
6861 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6862 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6865 player[i].weaponactive=-1;
6866 for(int j=0;j<numplayers;j++){
6867 player[j].wentforweapon=0;
6875 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
6876 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6877 player[i].num_weapons==2&&
6878 player[i].weaponactive==-1&&
6879 player[i].isIdle()||
6881 player[i].weaponactive!=-1&&
6884 if(player[i].weaponactive!=-1)
6885 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
6887 if(isgood&&player[i].creature!=wolftype){
6888 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6889 player[i].setAnimation(drawrightanim);
6890 player[i].drawtogglekeydown=1;
6892 if((player[i].isIdle()||
6893 (player[i].aitype!=playercontrolled&&
6894 player[0].weaponactive!=-1&&
6895 player[i].isRun()))&&
6896 player[i].num_weapons&&
6897 weapons[player[i].weaponids[0]].getType()==sword){
6898 player[i].setAnimation(drawleftanim);
6899 player[i].drawtogglekeydown=1;
6901 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6902 player[i].setAnimation(crouchdrawrightanim);
6903 player[i].drawtogglekeydown=1;
6910 if(player[i].weaponactive!=-1) {
6911 if (player[i].isCrouch()&&
6912 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
6914 player[i].onterrain&&
6915 player[i].num_weapons&&
6916 player[i].attackkeydown&&
6917 musictype!=stream_fighttheme) {
6918 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
6919 player[i].setAnimation(crouchstabanim);
6920 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
6921 player[i].setAnimation(swordgroundstabanim);
6922 player[i].hasvictim=0;
6926 if(!player[i].drawkeydown)
6927 player[i].drawtogglekeydown=0;
6934 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
6936 absflatfacing=flatfacing;
6939 player[i].forwardkeydown=0;
6940 player[i].leftkeydown=0;
6941 player[i].backkeydown=0;
6942 player[i].rightkeydown=0;
6943 player[i].jumpkeydown=0;
6944 player[i].crouchkeydown=0;
6945 player[i].drawkeydown=0;
6946 player[i].throwkeydown=0;
6950 if(!animation[player[i].targetanimation].attack&&
6951 player[i].targetanimation!=staggerbackhighanim&&
6952 player[i].targetanimation!=staggerbackhardanim&&
6953 player[i].targetanimation!=backhandspringanim&&
6954 player[i].targetanimation!=dodgebackanim){
6955 if(!player[i].forwardkeydown)
6956 player[i].forwardstogglekeydown=0;
6957 if(player[i].crouchkeydown){
6961 player[i].superruntoggle=1;
6963 for(int j=0;j<numplayers;j++)
6964 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
6965 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
6966 player[i].superruntoggle=0;
6970 for(int j=0;j<numplayers;j++){
6971 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
6972 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
6973 player[j].victim==&player[i]&&
6974 (player[j].targetanimation==sweepanim||
6975 player[j].targetanimation==upunchanim||
6976 player[j].targetanimation==wolfslapanim||
6977 ((player[j].targetanimation==swordslashanim||
6978 player[j].targetanimation==knifeslashstartanim||
6979 player[j].targetanimation==staffhitanim||
6980 player[j].targetanimation==staffspinhitanim)&&
6981 findDistancefast(&player[j].coords,&player[i].coords)<2))){
6990 player[target].Reverse();
6991 player[i].lowreversaldelay=.5;
6993 if(player[i].isIdle()){
6994 player[i].setAnimation(player[i].getCrouch());
6995 player[i].transspeed=10;
6997 if(player[i].isRun()||
6998 (player[i].isStop()&&
6999 (player[i].leftkeydown||
7000 player[i].rightkeydown||
7001 player[i].forwardkeydown||
7002 player[i].backkeydown))){
7003 player[i].setAnimation(rollanim);
7004 player[i].transspeed=20;
7007 if(!player[i].crouchkeydown){
7009 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7011 if(player[i].isCrouch()){
7013 for(int j=0;j<numplayers;j++){
7015 !player[j].skeleton.free&&
7017 player[i].highreversaldelay<=0){
7018 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7019 player[j].victim==&player[i]&&
7020 (player[j].targetanimation==spinkickanim)&&
7021 player[i].isCrouch()){
7030 player[target].Reverse();
7031 player[i].highreversaldelay=.5;
7033 if(player[i].isCrouch()){
7034 if(!player[i].wasCrouch()){
7035 player[i].currentanimation=player[i].getCrouch();
7036 player[i].currentframe=0;
7038 player[i].setAnimation(player[i].getIdle());
7039 player[i].transspeed=10;
7042 if(player[i].targetanimation==sneakanim){
7043 player[i].setAnimation(player[i].getIdle());
7044 player[i].transspeed=10;
7047 if(player[i].forwardkeydown){
7048 if(player[i].isIdle()||
7049 (player[i].isStop()&&
7050 player[i].targetrotation==player[i].rotation)||
7051 (player[i].isLanding()&&
7052 player[i].targetframe>0&&
7053 !player[i].jumpkeydown)||
7054 (player[i].isLandhard()&&
7055 player[i].targetframe>0&&
7056 !player[i].jumpkeydown&&
7057 player[i].crouchkeydown)){
7058 if(player[i].aitype==passivetype)
7059 player[i].setAnimation(walkanim);
7061 player[i].setAnimation(player[i].getRun());
7063 if(player[i].isCrouch()){
7064 player[i].targetanimation=sneakanim;
7065 if(player[i].wasCrouch())
7067 player[i].targetframe=0;
7069 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7070 player[i].setAnimation(climbanim);
7071 player[i].targetframe=1;
7072 player[i].jumpclimb=1;
7074 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7075 player[i].velocity+=absflatfacing*5*multiplier;
7077 player[i].forwardstogglekeydown=1;
7080 if (player[i].rightkeydown){
7081 if(player[i].isIdle()||
7082 (player[i].isStop()&&
7083 player[i].targetrotation==player[i].rotation)||
7084 (player[i].isLanding()&&
7085 player[i].targetframe>0&&
7086 !player[i].jumpkeydown)||
7087 (player[i].isLandhard()&&
7088 player[i].targetframe>0&&
7089 !player[i].jumpkeydown&&
7090 player[i].crouchkeydown)){
7091 player[i].setAnimation(player[i].getRun());
7093 if(player[i].isCrouch()){
7094 player[i].targetanimation=sneakanim;
7095 if(player[i].wasCrouch())
7097 player[i].targetframe=0;
7099 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7100 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7102 player[i].targetrotation-=90;
7103 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7104 if(player[i].backkeydown)player[i].targetrotation-=45;
7107 if ( player[i].leftkeydown){
7108 if(player[i].isIdle()||
7109 (player[i].isStop()&&
7110 player[i].targetrotation==player[i].rotation)||
7111 (player[i].isLanding()&&
7112 player[i].targetframe>0&&
7113 !player[i].jumpkeydown)||
7114 (player[i].isLandhard()&&
7115 player[i].targetframe>0&&
7116 !player[i].jumpkeydown&&
7117 player[i].crouchkeydown)){
7118 player[i].setAnimation(player[i].getRun());
7120 if(player[i].isCrouch()){
7121 player[i].targetanimation=sneakanim;
7122 if(player[i].wasCrouch())
7124 player[i].targetframe=0;
7126 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7127 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7129 player[i].targetrotation+=90;
7130 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7131 if(player[i].backkeydown)player[i].targetrotation+=45;
7134 if(player[i].backkeydown){
7135 if(player[i].isIdle()||
7136 (player[i].isStop()&&
7137 player[i].targetrotation==player[i].rotation)||
7138 (player[i].isLanding()&&
7139 player[i].targetframe>0&&
7140 !player[i].jumpkeydown)||
7141 (player[i].isLandhard()&&
7142 player[i].targetframe>0&&
7143 !player[i].jumpkeydown&&
7144 player[i].crouchkeydown)){
7145 player[i].setAnimation(player[i].getRun());
7147 if(player[i].isCrouch()){
7148 player[i].targetanimation=sneakanim;
7149 if(player[i].wasCrouch())
7151 player[i].targetframe=0;
7153 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7154 player[i].velocity-=absflatfacing*5*multiplier;
7156 if(player[i].targetanimation==hanganim){
7157 player[i].currentanimation=jumpdownanim;
7158 player[i].targetanimation=jumpdownanim;
7160 player[i].currentframe=0;
7161 player[i].targetframe=1;
7162 player[i].velocity=0;
7163 player[i].velocity.y+=gravity;
7164 player[i].coords.y-=1.4;
7165 player[i].grabdelay=1;
7167 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7168 player[i].targetrotation+=180;
7171 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7172 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7174 player[i].targetanimation==walkanim||
7175 player[i].isCrouch()||
7176 player[i].targetanimation==sneakanim)&&
7177 player[i].jumppower>1)&&
7178 ((player[i].targetanimation!=rabbitrunninganim&&
7179 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7180 player[i].jumpstart=0;
7181 player[i].setAnimation(jumpupanim);
7182 player[i].rotation=player[i].targetrotation;
7183 player[i].transspeed=20;
7184 player[i].FootLand(0,1);
7185 player[i].FootLand(1,1);
7189 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7191 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7192 if(!movekey)player[i].velocity=0;
7197 for(int j=0;j<numplayers;j++){
7198 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7199 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7200 player[j].victim==&player[i]&&
7201 (player[j].targetanimation==sweepanim)){
7202 if(target>=0)target=-1;
7207 if(target>=0)player[i].velocity.y=1;
7208 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7209 player[i].velocity.y=7;
7210 player[i].crouchtogglekeydown=1;
7212 else player[i].velocity.y=5;
7214 if(mousejump&&i==0&&debugmode){
7215 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7216 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7219 player[i].coords.y+=.2;
7220 player[i].jumppower-=1;
7223 emit_sound_at(whooshsound, player[i].coords, 128.);
7225 emit_sound_at(jumpsound, player[i].coords, 128.);
7227 if((player[i].isIdle())&&player[i].jumppower>1){
7228 player[i].setAnimation(player[i].getLanding());
7229 player[i].targetframe=2;
7230 player[i].landhard=0;
7231 player[i].jumpstart=1;
7232 player[i].tempdeltav=deltav;
7234 if(player[i].targetanimation==jumpupanim&&
7238 player[i].aitype!=playercontrolled)){
7239 if(player[i].jumppower>multiplier*6){
7240 player[i].velocity.y+=multiplier*6;
7241 player[i].jumppower-=multiplier*6;
7243 if(player[i].jumppower<=multiplier*6){
7244 player[i].velocity.y+=player[i].jumppower;
7245 player[i].jumppower=0;
7248 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7252 if(player[i].isRun()||player[i].targetanimation==walkanim)
7253 player[i].setAnimation(player[i].getStop());
7254 if(player[i].targetanimation==sneakanim){
7255 player[i].targetanimation=player[i].getCrouch();
7256 if(player[i].currentanimation==sneakanim)
7258 player[i].targetframe=0;
7261 if(player[i].targetanimation==walkanim&&
7262 (player[i].aitype==attacktypecutoff||
7263 player[i].aitype==searchtype||
7264 (player[i].aitype==passivetype&&
7265 player[i].numwaypoints<=1)))
7266 player[i].setAnimation(player[i].getStop());
7267 if(player[i].isRun()&&(player[i].aitype==passivetype))
7268 player[i].setAnimation(player[i].getStop());
7271 if(player[i].targetanimation==rollanim)
7272 player[i].targetrotation=oldtargetrotation;
7276 for(int k=0;k<numplayers;k++){
7277 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7278 if(player[k].rotation>player[k].targetrotation)
7279 player[k].rotation-=360;
7281 player[k].rotation+=360;
7284 //stop to turn in right direction
7285 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7286 player[k].setAnimation(player[k].getStop());
7288 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7289 player[k].targettilt=0;
7291 if(player[k].targetanimation!=jumpupanim&&
7292 player[k].targetanimation!=backhandspringanim&&
7293 player[k].targetanimation!=jumpdownanim&&
7294 !player[k].isFlip()){
7295 player[k].targettilt=0;
7296 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7297 player[k].jumppower=0;
7298 player[k].jumppower+=multiplier*7;
7299 if(player[k].isCrouch())
7300 player[k].jumppower+=multiplier*7;
7301 if(player[k].jumppower>5)
7302 player[k].jumppower=5;
7305 if(player[k].isRun())
7306 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7308 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7309 player[k].grabdelay-=multiplier;
7313 for(int k=0;k<numplayers;k++){
7314 player[k].DoAnimations();
7315 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7316 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7322 for(int j=numenvsounds-1;j>=0;j--){
7323 envsoundlife[j]-=multiplier;
7324 if(envsoundlife[j]<0){
7326 envsoundlife[j]=envsoundlife[numenvsounds];
7327 envsound[j]=envsound[numenvsounds];
7331 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7333 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7335 if(tutoriallevel==1){
7352 if(tutorialstage>=51)
7353 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7354 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7355 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7357 emit_stream_np(stream_menutheme);
7366 if(tutorialstage<51)
7367 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7368 emit_sound_at(fireendsound, player[0].coords);
7370 player[0].coords=(oldtemp+oldtemp2)/2;
7374 if(tutorialstage>=14&&tutorialstage<50)
7375 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7376 emit_sound_at(fireendsound, player[1].coords);
7378 for(int i=0;i<player[1].skeleton.num_joints;i++){
7380 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7381 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7382 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;
7383 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7384 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7388 player[1].coords=(oldtemp+oldtemp2)/2;
7389 for(int i=0;i<player[1].skeleton.num_joints;i++){
7390 player[1].skeleton.joints[i].velocity=0;
7392 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7393 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7394 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;
7395 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7396 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7404 static float gLoc[3];
7408 static float vel[3];
7409 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7410 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7411 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7413 //Set orientation with forward and up vectors
7414 static XYZ upvector;
7418 upvector=DoRotation(upvector,-rotation2+90,0,0);
7419 upvector=DoRotation(upvector,0,0-rotation,0);
7424 facing=DoRotation(facing,-rotation2,0,0);
7425 facing=DoRotation(facing,0,0-rotation,0);
7428 static float ori[6];
7432 ori[3] = -upvector.x;
7433 ori[4] = upvector.y;
7434 ori[5] = -upvector.z;
7436 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7443 if(Input::isKeyPressed(SDLK_F1))
7447 void Game::TickOnce(){
7449 rotation+=multiplier*5;
7451 if(directing||indialogue==-1) {
7452 rotation+=deltah*.7;
7454 rotation2+=deltav*.7;
7456 rotation2-=deltav*.7;
7464 void Game::TickOnceAfter(){
7465 static XYZ colviewer;
7466 static XYZ coltarget;
7470 static float changedelay;
7471 static bool alldead;
7472 static float unseendelay;
7473 static float cameraspeed;
7477 if(environment==snowyenvironment)
7478 leveltheme=stream_snowtheme;
7479 if(environment==grassyenvironment)
7480 leveltheme=stream_grasstheme;
7481 if(environment==desertenvironment)
7482 leveltheme=stream_deserttheme;
7486 musictype=leveltheme;
7487 for(int i=0;i<numplayers;i++){
7488 if((player[i].aitype==attacktypecutoff||
7489 player[i].aitype==getweapontype||
7490 player[i].aitype==gethelptype||
7491 player[i].aitype==searchtype)&&
7492 !player[i].dead/*&&player[i].surprised<=0*/&&
7493 (player[i].targetanimation!=sneakattackedanim&&
7494 player[i].targetanimation!=knifesneakattackedanim&&
7495 player[i].targetanimation!=swordsneakattackedanim)){
7496 musictype=stream_fighttheme;
7501 musictype=stream_menutheme;
7504 if(musictype==stream_fighttheme)
7507 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7508 unseendelay-=multiplier;
7510 musictype=stream_fighttheme;
7515 musictype=stream_menutheme;
7523 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7524 emit_sound_np(alarmsound);
7525 musicselected=musictype;
7527 if(musicselected==leveltheme)
7528 musicvolume[0]+=multiplier*450;
7530 musicvolume[0]-=multiplier*450;
7531 if(musicselected==stream_fighttheme)
7532 musicvolume[1]+=multiplier*450;
7534 musicvolume[1]-=multiplier*450;
7535 if(musicselected==stream_menutheme)
7536 musicvolume[2]+=multiplier*450;
7538 musicvolume[2]-=multiplier*450;
7540 for(int i=0;i<3;i++){
7541 if(musicvolume[i]<0)
7543 if(musicvolume[i]>512)
7547 if(musicvolume[2]>128&&!loading&&!mainmenu)
7551 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7552 emit_stream_np(leveltheme, musicvolume[0]);
7553 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7554 emit_stream_np(stream_fighttheme, musicvolume[1]);
7555 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7556 emit_stream_np(stream_menutheme, musicvolume[2]);
7557 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7558 pause_sound(leveltheme);
7559 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7560 pause_sound(stream_fighttheme);
7561 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7562 pause_sound(stream_menutheme);
7564 if(musicvolume[0]!=oldmusicvolume[0])
7565 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7566 if(musicvolume[1]!=oldmusicvolume[1])
7567 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7568 if(musicvolume[2]!=oldmusicvolume[2])
7569 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7571 for(int i=0;i<3;i++)
7572 oldmusicvolume[i]=musicvolume[i];
7574 pause_sound(leveltheme);
7575 pause_sound(stream_fighttheme);
7576 pause_sound(stream_menutheme);
7578 for(int i=0;i<4;i++){
7579 oldmusicvolume[i]=0;
7585 for(int i=0;i<numhotspots;i++){
7586 if(hotspottype[i]>10&&hotspottype[i]<20){
7587 if(player[hotspottype[i]-10].dead==0)
7589 else if(killhotspot==2)
7598 for(int i=0;i<numhotspots;i++)
7599 if(hotspottype[i]==-1)
7600 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7604 for(int i=1;i<numplayers;i++)
7605 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7607 if(numalarmed>maxalarmed)
7608 maxalarmed=numalarmed;
7610 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7611 if(player[0].dead&&changedelay<=0){
7613 targetlevel=whichlevel;
7616 for(int i=1;i<numplayers;i++) {
7617 if(!player[i].dead&&player[i].howactive<typedead1) {
7624 if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
7626 targetlevel=whichlevel+1;
7627 if(targetlevel>numchallengelevels-1)targetlevel=0;
7629 if(winhotspot||windialogue) {
7631 targetlevel=whichlevel+1;
7632 if(targetlevel>numchallengelevels-1)targetlevel=0;
7638 targetlevel=whichlevel+1;
7639 if(targetlevel>numchallengelevels-1)targetlevel=0;
7642 if(changedelay>0&&!player[0].dead&&!won) {
7643 //high scores, awards, win
7645 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7648 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7664 if(!editorenabled&&gameon&&!mainmenu) {
7665 if(changedelay!=-999)
7666 changedelay-=multiplier/7;
7668 targetlevel=whichlevel;
7669 if(loading==2&&!campaign){
7672 fireSound(firestartsound);
7674 if(!player[0].dead&&targetlevel!=whichlevel)
7675 startbonustotal=bonustotal;
7677 Loadlevel(whichlevel);
7679 Loadlevel(targetlevel);
7685 if(loading==2&&targetlevel==whichlevel){
7689 fireSound(firestartsound);
7691 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
7697 if(changedelay<=-999&&
7701 (alldead&&maptype==mapkilleveryone)||
7705 if((player[0].dead||
7706 (alldead&&maptype==mapkilleveryone)||
7711 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7721 // campaignchoosenext determines what to do when the level is complete:
7722 // 0 = load next level
7723 // 1 = go back to level select screen
7724 // 2 = stealthload next level
7725 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
7726 if(campaignlevels[actuallevel].nextlevel.empty())
7728 } else if(mainmenu==0&&winfreeze) {
7729 stealthloading = (campaignlevels[actuallevel].choosenext==2);
7731 if(!stealthloading){
7732 fireSound(firestartsound);
7747 actuallevel=campaignlevels[actuallevel].nextlevel.front();
7750 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
7754 pause_sound(stream_menutheme);
7765 oldmusictype=musictype;
7771 facing=DoRotation(facing,-rotation2,0,0);
7772 facing=DoRotation(facing,0,0-rotation,0);
7773 viewerfacing=facing;
7776 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;
7777 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;
7779 if(player[0].skeleton.free){
7780 for(int i=0;i<player[0].skeleton.num_joints;i++){
7781 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7782 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7786 if(player[0].skeleton.free!=2&&!autocam){
7788 if(findLengthfast(&player[0].velocity)>400){
7789 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7791 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7792 coltarget=target-cameraloc;
7793 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7795 Normalise(&coltarget);
7796 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7797 else cameraloc=cameraloc+coltarget*multiplier*8;
7799 if(editorenabled)cameraloc=target;
7800 cameradist+=multiplier*5;
7801 if(cameradist>2.3)cameradist=2.3;
7802 viewer=cameraloc-facing*cameradist;
7804 coltarget=cameraloc;
7805 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7806 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7807 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7808 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7810 coltarget=cameraloc;
7811 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7813 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7814 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7815 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7817 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7821 cameradist=findDistance(&viewer,&target);
7822 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7823 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7824 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7827 if(player[0].skeleton.free!=2&&autocam){
7829 if(findLengthfast(&player[0].velocity)>400){
7830 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7832 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7833 cameradist+=multiplier*5;
7834 if(cameradist>3.3)cameradist=3.3;
7835 coltarget=target-cameraloc;
7836 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7837 else if(findLengthfast(&coltarget)>1)
7839 Normalise(&coltarget);
7840 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7841 else cameraloc=cameraloc+coltarget*multiplier*8;
7843 if(editorenabled)cameraloc=target;
7846 coltarget=cameraloc;
7847 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7848 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7849 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7850 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7852 coltarget=cameraloc;
7853 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7855 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7856 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7857 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7859 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7863 cameradist=findDistance(&viewer,&target);
7864 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7865 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7866 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7869 if(camerashake>.8)camerashake=.8;
7870 //if(woozy>10)woozy=10;
7871 //woozy+=multiplier;
7873 if(player[0].dead)camerashake=0;
7874 if(player[0].dead)woozy=0;
7875 camerashake-=multiplier*2;
7876 blackout-=multiplier*2;
7877 //if(player[0].isCrouch())woozy-=multiplier*8;
7878 if(camerashake<0)camerashake=0;
7879 if(blackout<0)blackout=0;
7880 //if(woozy<0)woozy=0;
7882 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7883 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7884 viewer.z+=(float)(Random()%100)*.0005*camerashake;