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"
45 // Added more evilness needed for MSVC
47 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
48 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
52 extern float multiplier;
54 extern int environment;
55 extern Terrain terrain;
56 extern float screenwidth,screenheight;
59 extern float texdetail;
60 extern Objects objects;
62 extern float slomodelay;
63 extern bool floatjump;
66 extern float camerashake;
68 extern float blackout;
69 extern bool cellophane;
70 extern bool musictoggle;
71 extern int difficulty;
72 extern int bloodtoggle;
73 extern bool invertmouse;
75 extern float precipdelay;
76 extern XYZ viewerfacing;
77 extern bool ambientsound;
78 extern bool mousejump;
79 extern float viewdistance;
81 extern bool keyboardfrozen;
82 extern bool loadingstuff;
83 extern XYZ windvector;
84 extern bool debugmode;
85 static int leveltheme;
87 extern int oldmainmenu;
88 extern bool visibleloading;
89 extern XYZ envsound[30];
90 extern float envsoundvol[30];
91 extern int numenvsounds;
92 extern float envsoundlife[30];
93 extern float usermousesensitivity;
94 extern bool ismotionblur;
95 extern bool showdamagebar; // (des)activate the damage bar
97 extern float tintr,tintg,tintb;
98 extern bool skyboxtexture;
100 extern float skyboxg;
101 extern float skyboxb;
102 extern float skyboxlightr;
103 extern float skyboxlightg;
104 extern float skyboxlightb;
105 extern float fadestart;
106 extern float slomospeed;
107 extern float slomofreq;
108 extern int tutoriallevel;
109 extern float smoketex;
110 extern float tutorialstagetime;
111 extern int tutorialstage;
112 extern float tutorialmaxtime;
113 extern float tutorialsuccess;
114 extern bool againbonus;
115 extern bool reversaltrain;
116 extern bool canattack;
117 extern bool cananger;
118 extern float damagedealt;
120 extern int editoractive;
121 extern int editorpathtype;
123 extern float hostiletime;
125 extern bool gamestarted;
127 extern int numhotspots;
128 extern int killhotspot;
129 extern XYZ hotspot[40];
130 extern int hotspottype[40];
131 extern float hotspotsize[40];
132 extern char hotspottext[40][256];
133 extern int currenthotspot;
137 extern bool stillloading;
138 extern bool winfreeze;
140 extern bool campaign;
142 static const char *rabbitskin[] = {
143 ":Data:Textures:Fur3.jpg",
144 ":Data:Textures:Fur.jpg",
145 ":Data:Textures:Fur2.jpg",
146 ":Data:Textures:Lynx.jpg",
147 ":Data:Textures:Otter.jpg",
148 ":Data:Textures:Opal.jpg",
149 ":Data:Textures:Sable.jpg",
150 ":Data:Textures:Chocolate.jpg",
151 ":Data:Textures:BW2.jpg",
152 ":Data:Textures:WB2.jpg"
155 static const char *wolfskin[] = {
156 ":Data:Textures:Wolf.jpg",
157 ":Data:Textures:Darkwolf.jpg",
158 ":Data:Textures:Snowwolf.jpg"
161 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
162 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
164 static const char **creatureskin[] = {rabbitskin, wolfskin};
166 /* Return true if PFX is a prefix of STR (case-insensitive). */
167 static bool stripfx(const char *str, const char *pfx)
169 return !strncasecmp(str, pfx, strlen(pfx));
172 static const char *cmd_names[] = {
173 #define DECLARE_COMMAND(cmd) #cmd,
174 #include "ConsoleCmds.h"
175 #undef DECLARE_COMMAND
178 typedef void (*console_handler)(const char *args);
180 #define DECLARE_COMMAND(cmd) static void ch_##cmd(const char *args);
181 #include "ConsoleCmds.h"
182 #undef DECLARE_COMMAND
184 static console_handler cmd_handlers[] = {
185 #define DECLARE_COMMAND(cmd) ch_##cmd,
186 #include "ConsoleCmds.h"
187 #undef DECLARE_COMMAND
192 // added utility functions -sf17k =============================================================
194 //TODO: this is incorrect but I'm afraid to change it and break something,
195 //probably causes quirky behavior that I might want to preserve
196 inline float roughDirection(XYZ vec){
198 float angle=-asin(-vec.x)*180/M_PI;
203 inline float roughDirectionTo(XYZ start, XYZ end){
204 return roughDirection(end-start);
207 //TODO: gotta be a better way
208 inline float pitch(XYZ vec){
210 return -asin(vec.y)*180/M_PI;
212 inline float pitchTo(XYZ start, XYZ end){
213 return pitch(end-start);
216 inline float sq(float n) { return n*n; }
218 inline float stepTowardf(float from, float to, float by){
219 if(fabs(from-to)<by) return to;
220 else if(from>to) return from-by;
224 void playdialogueboxsound(){
226 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
227 temppos=temppos-viewer;
232 switch(dialogueboxsound[whichdialogue][indialogue]){
233 case -6: sound=alarmsound; break;
234 case -4: sound=consolefailsound; break;
235 case -3: sound=consolesuccesssound; break;
236 case -2: sound=firestartsound; break;
237 case -1: sound=fireendsound; break;
238 case 1: sound=rabbitchitter; break;
239 case 2: sound=rabbitchitter2; break;
240 case 3: sound=rabbitpainsound; break;
241 case 4: sound=rabbitpain1sound; break;
242 case 5: sound=rabbitattacksound; break;
243 case 6: sound=rabbitattack2sound; break;
244 case 7: sound=rabbitattack3sound; break;
245 case 8: sound=rabbitattack4sound; break;
246 case 9: sound=growlsound; break;
247 case 10: sound=growl2sound; break;
248 case 11: sound=snarlsound; break;
249 case 12: sound=snarl2sound; break;
250 case 13: sound=barksound; break;
251 case 14: sound=bark2sound; break;
252 case 15: sound=bark3sound; break;
253 case 16: sound=barkgrowlsound; break;
257 emit_sound_at(sound, temppos);
260 // end added utility functions ================================================================
264 static void ch_quit(const char *args)
269 static void ch_map(const char *args)
276 static void ch_save(const char *args){
278 snprintf(buf, 63, ":Data:Maps:%s", args);
283 tfile=fopen( ConvertFileName(buf), "wb" );
284 fpackf(tfile, "Bi", mapvers);
285 fpackf(tfile, "Bi", maptype);
286 fpackf(tfile, "Bi", hostile);
287 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
288 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
289 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
290 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
291 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
292 if(player[0].num_weapons>0&&player[0].num_weapons<5)
293 for(int j=0;j<player[0].num_weapons;j++)
294 fpackf(tfile, "Bi", weapons[player[0].weaponids[j]].getType());
296 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
297 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
298 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
299 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
301 fpackf(tfile, "Bi", player[0].numclothes);
303 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
305 fpackf(tfile, "Bi", numdialogues);
307 for(int k=0;k<numdialogues;k++){
308 fpackf(tfile, "Bi", numdialogueboxes[k]);
309 fpackf(tfile, "Bi", dialoguetype[k]);
310 for(int l=0;l<10;l++){
311 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
312 fpackf(tfile, "Bf", participantrotation[k][l]);
314 for(int l=0;l<numdialogueboxes[k];l++){
315 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
316 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
317 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
318 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
319 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
321 int templength=strlen(dialoguetext[k][l]);
322 fpackf(tfile, "Bi",(templength));
323 for(int m=0;m<templength;m++){
324 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
325 if(dialoguetext[k][l][m]=='\0')
329 templength=strlen(dialoguename[k][l]);
330 fpackf(tfile, "Bi",templength);
331 for(int m=0;m<templength;m++){
332 fpackf(tfile, "Bb", dialoguename[k][l][m]);
333 if(dialoguename[k][l][m]=='\0')
337 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
338 fpackf(tfile, "Bi", participantfocus[k][l]);
339 fpackf(tfile, "Bi", participantaction[k][l]);
341 for(int m=0;m<10;m++)
342 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
344 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
348 for(int k=0;k<player[0].numclothes;k++){
349 int templength=strlen(player[0].clothes[k]);
350 fpackf(tfile, "Bi", templength);
351 for(int l=0;l<templength;l++)
352 fpackf(tfile, "Bb", player[0].clothes[k][l]);
353 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
356 fpackf(tfile, "Bi", environment);
358 fpackf(tfile, "Bi", objects.numobjects);
360 for(int k=0;k<objects.numobjects;k++)
361 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
362 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
364 fpackf(tfile, "Bi", numhotspots);
365 for(int i=0;i<numhotspots;i++){
366 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
367 int templength=strlen(hotspottext[i]);
368 fpackf(tfile, "Bi",templength);
369 for(int l=0;l<templength;l++)
370 fpackf(tfile, "Bb", hotspottext[i][l]);
373 fpackf(tfile, "Bi", numplayers);
374 if(numplayers<maxplayers)
375 for(int j=1;j<numplayers;j++){
376 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
377 player[j].coords.x, player[j].coords.y, player[j].coords.z,
378 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
379 if(player[j].num_weapons<5)
380 for(int k=0;k<player[j].num_weapons;k++)
381 fpackf(tfile, "Bi", weapons[player[j].weaponids[k]].getType());
382 if(player[j].numwaypoints<30){
383 fpackf(tfile, "Bi", player[j].numwaypoints);
384 for(int k=0;k<player[j].numwaypoints;k++){
385 fpackf(tfile, "Bf", player[j].waypoints[k].x);
386 fpackf(tfile, "Bf", player[j].waypoints[k].y);
387 fpackf(tfile, "Bf", player[j].waypoints[k].z);
388 fpackf(tfile, "Bi", player[j].waypointtype[k]);
390 fpackf(tfile, "Bi", player[j].waypoint);
392 player[j].numwaypoints=0;
393 player[j].waypoint=0;
394 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
397 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
398 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
399 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
400 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
402 float headprop, bodyprop, armprop, legprop;
403 if(player[j].creature==wolftype){
404 headprop=player[j].proportionhead.x/1.1;
405 bodyprop=player[j].proportionbody.x/1.1;
406 armprop=player[j].proportionarms.x/1.1;
407 legprop=player[j].proportionlegs.x/1.1;
408 }else if(player[j].creature==rabbittype){
409 headprop=player[j].proportionhead.x/1.2;
410 bodyprop=player[j].proportionbody.x/1.05;
411 armprop=player[j].proportionarms.x/1.00;
412 legprop=player[j].proportionlegs.x/1.1;
415 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
417 fpackf(tfile, "Bi", player[j].numclothes);
418 if(player[j].numclothes)
419 for(int k=0;k<player[j].numclothes;k++){
421 templength=strlen(player[j].clothes[k]);
422 fpackf(tfile, "Bi", templength);
423 for(int l=0;l<templength;l++)
424 fpackf(tfile, "Bb", player[j].clothes[k][l]);
425 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
429 fpackf(tfile, "Bi", numpathpoints);
430 for(int j=0;j<numpathpoints;j++){
431 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
432 for(int k=0;k<numpathpointconnect[j];k++)
433 fpackf(tfile, "Bi", pathpointconnect[j][k]);
436 fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
441 static void ch_cellar(const char *args)
443 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
446 static void ch_tint(const char *args)
448 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
451 static void ch_tintr(const char *args)
456 static void ch_tintg(const char *args)
461 static void ch_tintb(const char *args)
466 static void ch_speed(const char *args)
468 player[0].speedmult = atof(args);
471 static void ch_strength(const char *args)
473 player[0].power = atof(args);
476 static void ch_power(const char *args)
478 player[0].power = atof(args);
481 static void ch_size(const char *args)
483 player[0].scale = atof(args) * .2;
486 static int find_closest()
489 float closestdist = std::numeric_limits<float>::max();
491 for (int i = 1; i < numplayers; i++) {
493 distance = findDistancefast(&player[i].coords,&player[0].coords);
494 if (distance < closestdist) {
495 closestdist = distance;
502 static void ch_sizenear(const char *args)
504 int closest = find_closest();
507 player[closest].scale = atof(args) * .2;
510 static void set_proportion(int pnum, const char *args)
512 float headprop,bodyprop,armprop,legprop;
514 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
516 if(player[pnum].creature==wolftype){
517 player[pnum].proportionhead=1.1*headprop;
518 player[pnum].proportionbody=1.1*bodyprop;
519 player[pnum].proportionarms=1.1*armprop;
520 player[pnum].proportionlegs=1.1*legprop;
521 } else if(player[pnum].creature==rabbittype){
522 player[pnum].proportionhead=1.2*headprop;
523 player[pnum].proportionbody=1.05*bodyprop;
524 player[pnum].proportionarms=1.00*armprop;
525 player[pnum].proportionlegs=1.1*legprop;
526 player[pnum].proportionlegs.y=1.05*legprop;
530 static void ch_proportion(const char *args)
532 set_proportion(0, args);
535 static void ch_proportionnear(const char *args)
537 int closest = find_closest();
539 set_proportion(closest, args);
542 static void set_protection(int pnum, const char *args)
544 float head, high, low;
545 sscanf(args, "%f%f%f", &head, &high, &low);
547 player[pnum].protectionhead = head;
548 player[pnum].protectionhigh = high;
549 player[pnum].protectionlow = low;
552 static void ch_protection(const char *args)
554 set_protection(0, args);
557 static void ch_protectionnear(const char *args)
559 int closest = find_closest();
561 set_protection(closest, args);
564 static void set_armor(int pnum, const char *args)
566 float head, high, low;
567 sscanf(args, "%f%f%f", &head, &high, &low);
569 player[pnum].armorhead = head;
570 player[pnum].armorhigh = high;
571 player[pnum].armorlow = low;
574 static void ch_armor(const char *args)
579 static void ch_armornear(const char *args)
581 int closest = find_closest();
583 set_armor(closest, args);
586 static void ch_protectionreset(const char *args)
588 set_protection(0, "1 1 1");
589 set_armor(0, "1 1 1");
592 static void set_metal(int pnum, const char *args)
594 float head, high, low;
595 sscanf(args, "%f%f%f", &head, &high, &low);
597 player[pnum].metalhead = head;
598 player[pnum].metalhigh = high;
599 player[pnum].metallow = low;
602 static void ch_metal(const char *args)
607 static void set_noclothes(int pnum, const char *args)
609 player[pnum].numclothes = 0;
610 LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
611 &player[pnum].skeleton.drawmodel.textureptr,1,
612 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
615 static void ch_noclothes(const char *args)
617 set_noclothes(0, args);
620 static void ch_noclothesnear(const char *args)
622 int closest = find_closest();
624 set_noclothes(closest, args);
628 static void set_clothes(int pnum, const char *args)
631 snprintf(buf, 63, ":Data:Textures:%s.png", args);
633 if (!AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
636 player[pnum].DoMipmaps();
637 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
638 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
639 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
640 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
641 player[pnum].numclothes++;
644 static void ch_clothes(const char *args)
646 set_clothes(0, args);
649 static void ch_clothesnear(const char *args)
651 int closest = find_closest();
653 set_clothes(closest, args);
656 static void ch_belt(const char *args)
658 player[0].skeleton.clothes = !player[0].skeleton.clothes;
662 static void ch_cellophane(const char *args)
664 cellophane = !cellophane;
665 float mul = cellophane ? 0 : 1;
667 for (int i = 0; i < numplayers; i++) {
668 player[i].proportionhead.z = player[i].proportionhead.x * mul;
669 player[i].proportionbody.z = player[i].proportionbody.x * mul;
670 player[i].proportionarms.z = player[i].proportionarms.x * mul;
671 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
675 static void ch_funnybunny(const char *args)
677 player[0].skeleton.id=0;
678 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
679 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
680 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
681 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
682 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
683 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
684 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
685 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
686 player[0].creature=rabbittype;
688 player[0].headless=0;
689 player[0].damagetolerance=200;
690 set_proportion(0, "1 1 1 1");
693 static void ch_wolfie(const char *args)
695 player[0].skeleton.id=0;
696 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
697 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
698 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
699 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
700 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
701 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
702 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
703 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
704 player[0].creature=wolftype;
705 player[0].damagetolerance=300;
706 set_proportion(0, "1 1 1 1");
709 static void ch_wolfieisgod(const char *args)
714 static void ch_wolf(const char *args)
716 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
717 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
720 static void ch_snowwolf(const char *args)
722 LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
723 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
726 static void ch_darkwolf(const char *args)
728 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
729 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
732 static void ch_lizardwolf(const char *args)
734 LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
735 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
738 static void ch_white(const char *args)
740 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
741 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
744 static void ch_brown(const char *args)
746 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
747 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
750 static void ch_black(const char *args)
752 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
753 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
756 static void ch_sizemin(const char *args)
758 for (int i = 1; i < numplayers; i++)
759 if (player[i].scale < 0.8 * 0.2)
760 player[i].scale = 0.8 * 0.2;
763 static void ch_tutorial(const char *args)
765 tutoriallevel = atoi(args);
768 static void ch_hostile(const char *args)
770 hostile = atoi(args);
773 static void ch_indemo(const char *args)
776 hotspot[numhotspots]=player[0].coords;
777 hotspotsize[numhotspots]=0;
778 hotspottype[numhotspots]=-111;
779 strcpy(hotspottext[numhotspots],"mapname");
783 static void ch_notindemo(const char *args)
789 static void ch_type(const char *args)
791 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
792 for (int i = 0; i < n; i++)
793 if (stripfx(args, editortypenames[i])) {
799 static void ch_path(const char *args)
801 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
802 for (int i = 0; i < n; i++)
803 if (stripfx(args, pathtypenames[i])) {
809 static void ch_hs(const char *args)
811 hotspot[numhotspots]=player[0].coords;
815 sscanf(args, "%f%d %n", &size, &type, &shift);
817 hotspotsize[numhotspots] = size;
818 hotspottype[numhotspots] = type;
820 strcpy(hotspottext[numhotspots], args + shift);
821 strcat(hotspottext[numhotspots], "\n");
826 static void ch_dialogue(const char *args)
829 char buf1[32], buf2[64];
831 sscanf(args, "%d %31s", &dlg, buf1);
832 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
834 dialoguetype[numdialogues] = dlg;
836 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
837 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
839 ifstream ipstream(ConvertFileName(buf2));
840 ipstream.ignore(256,':');
841 ipstream >> numdialogueboxes[numdialogues];
842 for(int i=0;i<numdialogueboxes[numdialogues];i++){
843 ipstream.ignore(256,':');
844 ipstream.ignore(256,':');
845 ipstream.ignore(256,' ');
846 ipstream >> dialogueboxlocation[numdialogues][i];
847 ipstream.ignore(256,':');
848 ipstream >> dialogueboxcolor[numdialogues][i][0];
849 ipstream >> dialogueboxcolor[numdialogues][i][1];
850 ipstream >> dialogueboxcolor[numdialogues][i][2];
851 ipstream.ignore(256,':');
852 ipstream.getline(dialoguename[numdialogues][i],64);
853 ipstream.ignore(256,':');
854 ipstream.ignore(256,' ');
855 ipstream.getline(dialoguetext[numdialogues][i],128);
856 for(int j=0;j<128;j++){
857 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
859 ipstream.ignore(256,':');
860 ipstream >> dialogueboxsound[numdialogues][i];
863 for(int i=0;i<numdialogueboxes[numdialogues];i++){
864 for(int j=0;j<numplayers;j++){
865 participantfacing[numdialogues][i][j]=player[j].facing;
872 whichdialogue=numdialogues;
877 static void ch_fixdialogue(const char *args)
879 char buf1[32], buf2[64];
882 sscanf(args, "%d %31s", &whichdi, buf1);
883 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
885 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
886 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
888 ifstream ipstream(ConvertFileName(buf2));
889 ipstream.ignore(256,':');
890 ipstream >> numdialogueboxes[whichdi];
891 for(int i=0;i<numdialogueboxes[whichdi];i++){
892 ipstream.ignore(256,':');
893 ipstream.ignore(256,':');
894 ipstream.ignore(256,' ');
895 ipstream >> dialogueboxlocation[whichdi][i];
896 ipstream.ignore(256,':');
897 ipstream >> dialogueboxcolor[whichdi][i][0];
898 ipstream >> dialogueboxcolor[whichdi][i][1];
899 ipstream >> dialogueboxcolor[whichdi][i][2];
900 ipstream.ignore(256,':');
901 ipstream.getline(dialoguename[whichdi][i],64);
902 ipstream.ignore(256,':');
903 ipstream.ignore(256,' ');
904 ipstream.getline(dialoguetext[whichdi][i],128);
905 for(int j=0;j<128;j++){
906 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
908 ipstream.ignore(256,':');
909 ipstream >> dialogueboxsound[whichdi][i];
915 static void ch_fixtype(const char *args)
918 sscanf(args, "%d", &dlg);
919 dialoguetype[0] = dlg;
922 static void ch_fixrotation(const char *args)
924 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
927 static void ch_ddialogue(const char *args)
933 static void ch_dhs(const char *args)
939 static void ch_immobile(const char *args)
941 player[0].immobile = 1;
944 static void ch_allimmobile(const char *args)
946 for (int i = 1; i < numplayers; i++)
947 player[i].immobile = 1;
950 static void ch_mobile(const char *args)
952 player[0].immobile = 0;
955 static void ch_default(const char *args)
957 player[0].armorhead=1;
958 player[0].armorhigh=1;
959 player[0].armorlow=1;
960 player[0].protectionhead=1;
961 player[0].protectionhigh=1;
962 player[0].protectionlow=1;
963 player[0].metalhead=1;
964 player[0].metalhigh=1;
965 player[0].metallow=1;
967 player[0].speedmult=1;
970 if(player[0].creature==wolftype){
971 player[0].proportionhead=1.1;
972 player[0].proportionbody=1.1;
973 player[0].proportionarms=1.1;
974 player[0].proportionlegs=1.1;
975 } else if(player[0].creature==rabbittype){
976 player[0].proportionhead=1.2;
977 player[0].proportionbody=1.05;
978 player[0].proportionarms=1.00;
979 player[0].proportionlegs=1.1;
980 player[0].proportionlegs.y=1.05;
983 player[0].numclothes=0;
984 LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
985 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
986 &player[0].skeleton.skinsize);
988 editoractive=typeactive;
989 player[0].immobile=0;
992 static void ch_play(const char *args)
995 sscanf(args, "%d", &dlg);
998 if (whichdialogue >= numdialogues)
1001 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1002 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1003 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1004 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1005 player[participantfocus[whichdialogue][i]].velocity=0;
1006 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1007 player[participantfocus[whichdialogue][i]].targetframe=0;
1013 playdialogueboxsound();
1016 static void ch_mapkilleveryone(const char *args)
1018 maptype = mapkilleveryone;
1021 static void ch_mapkillmost(const char *args)
1023 maptype = mapkillmost;
1026 static void ch_mapkillsomeone(const char *args)
1028 maptype = mapkillsomeone;
1031 static void ch_mapgosomewhere(const char *args)
1033 maptype = mapgosomewhere;
1036 static void ch_viewdistance(const char *args)
1038 viewdistance = atof(args)*100;
1041 static void ch_fadestart(const char *args)
1043 fadestart = atof(args);
1046 static void ch_slomo(const char *args)
1048 slomospeed = atof(args);
1053 static void ch_slofreq(const char *args)
1055 slomofreq = atof(args);
1058 static void ch_skytint(const char *args)
1060 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1062 skyboxlightr=skyboxr;
1063 skyboxlightg=skyboxg;
1064 skyboxlightb=skyboxb;
1068 terrain.DoShadows();
1069 objects.DoShadows();
1072 static void ch_skylight(const char *args)
1074 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1078 terrain.DoShadows();
1079 objects.DoShadows();
1082 static void ch_skybox(const char *args)
1084 skyboxtexture = !skyboxtexture;
1088 terrain.DoShadows();
1089 objects.DoShadows();
1092 static void cmd_dispatch(const string cmd)
1094 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1096 for (i = 0; i < n_cmds; i++)
1097 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1099 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1100 cmd_handlers[i](cmd.substr(cmd.find(' ')+1).c_str());
1103 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1106 /********************> Tick() <*****/
1107 extern bool save_image(const char * fname);
1108 void Screenshot (void)
1111 time_t t = time(NULL);
1112 struct tm *tme = localtime(&t);
1113 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);
1116 mkdir("Screenshots");
1118 mkdir("Screenshots", S_IRWXU);
1124 void Game::SetUpLighting(){
1125 if(environment==snowyenvironment)
1126 light.setColors(.65,.65,.7,.4,.4,.44);
1127 if(environment==desertenvironment)
1128 light.setColors(.95,.95,.95,.4,.35,.3);
1129 if(environment==grassyenvironment)
1130 light.setColors(.95,.95,1,.4,.4,.44);
1132 light.setColors(1,1,1,.4,.4,.4);
1134 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1135 light.color[0]*=(skyboxlightr+average)/2;
1136 light.color[1]*=(skyboxlightg+average)/2;
1137 light.color[2]*=(skyboxlightb+average)/2;
1138 light.ambient[0]*=(skyboxlightr+average)/2;
1139 light.ambient[1]*=(skyboxlightg+average)/2;
1140 light.ambient[2]*=(skyboxlightb+average)/2;
1143 int Game::findPathDist(int start,int end){
1144 int smallestcount,count,connected;
1145 int last,last2,last3,last4;
1149 for(int i=0;i<50;i++){
1155 while(last!=end&&count<30){
1157 for(int j=0;j<numpathpoints;j++){
1158 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1161 if(numpathpointconnect[j])
1162 for(int k=0;k<numpathpointconnect[j];k++){
1163 if(pathpointconnect[j][k]==last)connected=1;
1166 if(numpathpointconnect[last])
1167 for(int k=0;k<numpathpointconnect[last];k++){
1168 if(pathpointconnect[last][k]==j)connected=1;
1171 if(closest==-1||Random()%2==0){
1182 if(count<smallestcount)smallestcount=count;
1184 return smallestcount;
1187 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1188 static XYZ colpoint,colviewer,coltarget;
1189 static float minx,minz,maxx,maxz,miny,maxy;
1191 minx=min(startpoint.x,endpoint.x)-1;
1192 miny=min(startpoint.y,endpoint.y)-1;
1193 minz=min(startpoint.z,endpoint.z)-1;
1194 maxx=max(startpoint.x,endpoint.x)+1;
1195 maxy=max(startpoint.y,endpoint.y)+1;
1196 maxz=max(startpoint.z,endpoint.z)+1;
1198 for(int i=0;i<objects.numobjects;i++){
1199 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1200 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1201 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1202 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1203 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1204 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1205 if( objects.type[i]!=treeleavestype&&
1206 objects.type[i]!=bushtype&&
1207 objects.type[i]!=firetype){
1208 colviewer=startpoint;
1210 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1215 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1220 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1221 static XYZ colpoint,colviewer,coltarget;
1222 static float minx,minz,maxx,maxz,miny,maxy;
1223 static int i; //FIXME: see below
1225 minx=min(startpoint.x,endpoint.x)-1;
1226 miny=min(startpoint.y,endpoint.y)-1;
1227 minz=min(startpoint.z,endpoint.z)-1;
1228 maxx=max(startpoint.x,endpoint.x)+1;
1229 maxy=max(startpoint.y,endpoint.y)+1;
1230 maxz=max(startpoint.z,endpoint.z)+1;
1233 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1234 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1235 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1236 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1237 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1238 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1239 if( objects.type[what]!=treeleavestype&&
1240 objects.type[what]!=bushtype&&
1241 objects.type[what]!=firetype){
1242 colviewer=startpoint;
1245 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1250 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1255 void Game::Setenvironment(int which)
1259 LOG(" Setting environment...");
1261 float temptexdetail;
1264 pause_sound(stream_snowtheme);
1265 pause_sound(stream_grasstheme);
1266 pause_sound(stream_deserttheme);
1267 pause_sound(stream_wind);
1268 pause_sound(stream_desertambient);
1271 if(environment==snowyenvironment){
1275 emit_stream_np(stream_wind);
1277 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1278 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1279 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1280 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1282 footstepsound = footstepsn1;
1283 footstepsound2 = footstepsn2;
1284 footstepsound3 = footstepst1;
1285 footstepsound4 = footstepst2;
1287 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1289 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1291 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1296 temptexdetail=texdetail;
1297 if(texdetail>1)texdetail=4;
1298 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1299 ":Data:Textures:Skybox(snow):Left.jpg",
1300 ":Data:Textures:Skybox(snow):Back.jpg",
1301 ":Data:Textures:Skybox(snow):Right.jpg",
1302 ":Data:Textures:Skybox(snow):Up.jpg",
1303 ":Data:Textures:Skybox(snow):Down.jpg");
1308 texdetail=temptexdetail;
1309 } else if(environment==desertenvironment){
1312 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1313 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1314 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1315 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1319 emit_stream_np(stream_desertambient);
1321 footstepsound = footstepsn1;
1322 footstepsound2 = footstepsn2;
1323 footstepsound3 = footstepsn1;
1324 footstepsound4 = footstepsn2;
1326 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1328 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1330 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1334 temptexdetail=texdetail;
1335 if(texdetail>1)texdetail=4;
1336 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1337 ":Data:Textures:Skybox(sand):Left.jpg",
1338 ":Data:Textures:Skybox(sand):Back.jpg",
1339 ":Data:Textures:Skybox(sand):Right.jpg",
1340 ":Data:Textures:Skybox(sand):Up.jpg",
1341 ":Data:Textures:Skybox(sand):Down.jpg");
1346 texdetail=temptexdetail;
1347 } else if(environment==grassyenvironment){
1350 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1351 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1352 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1353 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1356 emit_stream_np(stream_wind, 100.);
1358 footstepsound = footstepgr1;
1359 footstepsound2 = footstepgr2;
1360 footstepsound3 = footstepst1;
1361 footstepsound4 = footstepst2;
1363 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1365 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1367 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1371 temptexdetail=texdetail;
1372 if(texdetail>1)texdetail=4;
1373 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1374 ":Data:Textures:Skybox(grass):Left.jpg",
1375 ":Data:Textures:Skybox(grass):Back.jpg",
1376 ":Data:Textures:Skybox(grass):Right.jpg",
1377 ":Data:Textures:Skybox(grass):Up.jpg",
1378 ":Data:Textures:Skybox(grass):Down.jpg");
1382 texdetail=temptexdetail;
1384 temptexdetail=texdetail;
1386 terrain.load(":Data:Textures:heightmap.png");
1388 texdetail=temptexdetail;
1391 void Game::Loadlevel(int which) {
1397 Loadlevel("tutorial");
1398 } else if(which >= 0 && which <= 15) {
1400 snprintf(buf, 32, "map%d", which + 1); // challenges
1403 Loadlevel("mapsave");
1406 void Game::Loadlevel(const char *name) {
1409 static const char *pfx = ":Data:Maps:";
1412 float headprop,legprop,armprop,bodyprop;
1416 LOG(std::string("Loading level...") + name);
1428 if(tutoriallevel!=-1)
1433 if(tutoriallevel==1)
1435 if(tutorialstage==0) {
1436 tutorialstagetime=0;
1440 pause_sound(whooshsound);
1441 pause_sound(stream_firesound);
1443 // Change the map filename into something that is os specific
1444 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1445 sprintf(buf, "%s%s", pfx, name);
1446 const char *FixedFN = ConvertFileName(buf);
1450 //~ char* buff=getcwd(NULL,0);
1451 //~ cout << buff << " " << FixedFN << endl;
1453 tfile=fopen( FixedFN, "rb" );
1455 pause_sound(stream_firesound);
1461 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1465 for(int i=0;i<20;i++)
1466 dialoguegonethrough[i]=0;
1475 difficulty=accountactive->getDifficulty();
1494 for(int i=0;i<100;i++)
1514 bonustotal=startbonustotal;
1519 emit_sound_np(consolesuccesssound);
1524 if(!stealthloading){
1525 terrain.numdecals=0;
1526 Sprite::deleteSprites();
1527 for(int i=0;i<objects.numobjects;i++)
1528 objects.model[i].numdecals=0;
1530 int j=objects.numobjects;
1531 for(int i=0;i<j;i++){
1532 objects.DeleteObject(0);
1537 for(int i=0;i<subdivision;i++)
1538 for(int j=0;j<subdivision;j++)
1539 terrain.patchobjectnum[i][j]=0;
1546 funpackf(tfile, "Bi", &mapvers);
1548 funpackf(tfile, "Bi", &indemo);
1552 funpackf(tfile, "Bi", &maptype);
1554 maptype=mapkilleveryone;
1556 funpackf(tfile, "Bi", &hostile);
1560 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1566 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1574 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1576 skyboxlightr=skyboxr;
1577 skyboxlightg=skyboxg;
1578 skyboxlightb=skyboxb;
1581 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);
1583 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1584 player[0].originalcoords=player[0].coords;
1585 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1586 for(int j=0;j<player[0].num_weapons;j++){
1587 player[0].weaponids[j]=weapons.size();
1589 funpackf(tfile, "Bi", &type);
1590 weapons.push_back(Weapon(type,0));
1596 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1597 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1598 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1599 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1601 funpackf(tfile, "Bi", &player[0].numclothes);
1604 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1606 player[0].whichskin=0;
1607 player[0].creature=rabbittype;
1610 player[0].lastattack=-1;
1611 player[0].lastattack2=-1;
1612 player[0].lastattack3=-1;
1616 funpackf(tfile, "Bi", &numdialogues);
1617 for(int k=0;k<numdialogues;k++){
1618 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1619 funpackf(tfile, "Bi", &dialoguetype[k]);
1620 for(int l=0;l<10;l++){
1621 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1622 funpackf(tfile, "Bf", &participantrotation[k][l]);
1624 for(int l=0;l<numdialogueboxes[k];l++){
1625 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1626 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1627 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1628 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1629 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1631 funpackf(tfile, "Bi",&templength);
1632 if(templength>128||templength<=0)
1635 for(m=0;m<templength;m++){
1636 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1637 if(dialoguetext[k][l][m]=='\0')
1640 dialoguetext[k][l][m] = 0;
1642 funpackf(tfile, "Bi",&templength);
1643 if(templength>64||templength<=0)templength=64;
1644 for(m=0;m<templength;m++){
1645 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1646 if(dialoguename[k][l][m]=='\0')
1649 dialoguename[k][l][m] = 0;
1650 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1651 funpackf(tfile, "Bi", &participantfocus[k][l]);
1652 funpackf(tfile, "Bi", &participantaction[k][l]);
1655 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1657 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1663 for(int k=0;k<player[0].numclothes;k++){
1664 funpackf(tfile, "Bi", &templength);
1665 for(int l=0;l<templength;l++)
1666 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1667 player[0].clothes[k][templength]='\0';
1668 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1671 funpackf(tfile, "Bi", &environment);
1673 funpackf(tfile, "Bi", &objects.numobjects);
1674 for(int i=0;i<objects.numobjects;i++){
1675 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]);
1676 if(objects.type[i]==treeleavestype)
1677 objects.scale[i]=objects.scale[i-1];
1681 funpackf(tfile, "Bi", &numhotspots);
1682 for(int i=0;i<numhotspots;i++){
1683 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1684 funpackf(tfile, "Bi", &templength);
1686 for(int l=0;l<templength;l++)
1687 funpackf(tfile, "Bb", &hotspottext[i][l]);
1688 hotspottext[i][templength]='\0';
1689 if(hotspottype[i]==-111)
1698 if(!stealthloading){
1700 for(int i=0;i<objects.numobjects;i++)
1701 objects.center+=objects.position[i];
1702 objects.center/=objects.numobjects;
1708 float maxdistance=0;
1710 //~ int whichclosest;
1711 for(int i=0;i<objects.numobjects;i++){
1712 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1713 if(tempdist>maxdistance){
1715 maxdistance=tempdist;
1718 objects.radius=fast_sqrt(maxdistance);
1723 //mapcenter=objects.center;
1724 //mapradius=objects.radius;
1726 funpackf(tfile, "Bi", &numplayers);
1727 int howmanyremoved=0;
1728 bool removeanother=0;
1729 if(numplayers>1&&numplayers<maxplayers){
1730 for(int i=1;i<numplayers;i++){
1735 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);
1737 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1739 player[i-howmanyremoved].howactive=typeactive;
1741 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1743 player[i-howmanyremoved].scale=-1;
1745 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1747 player[i-howmanyremoved].immobile=0;
1749 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1751 player[i-howmanyremoved].rotation=0;
1752 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1753 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1758 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1759 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1760 player[i-howmanyremoved].weaponids[j]=weapons.size();
1762 funpackf(tfile, "Bi", &type);
1763 weapons.push_back(Weapon(type,i));
1766 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1767 //player[i-howmanyremoved].numwaypoints=10;
1768 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1769 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1770 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1771 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1773 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1775 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1778 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1779 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1780 player[i-howmanyremoved].waypoint=0;
1782 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1783 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1784 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1785 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1788 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1795 if(player[i-howmanyremoved].creature==wolftype){
1796 player[i-howmanyremoved].proportionhead=1.1*headprop;
1797 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1798 player[i-howmanyremoved].proportionarms=1.1*armprop;
1799 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1802 if(player[i-howmanyremoved].creature==rabbittype){
1803 player[i-howmanyremoved].proportionhead=1.2*headprop;
1804 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1805 player[i-howmanyremoved].proportionarms=1.00*armprop;
1806 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1807 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1810 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1811 if(player[i-howmanyremoved].numclothes){
1812 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1814 funpackf(tfile, "Bi", &templength);
1815 for(int l=0;l<templength;l++)
1816 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1817 player[i-howmanyremoved].clothes[k][templength]='\0';
1818 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1827 numplayers-=howmanyremoved;
1828 funpackf(tfile, "Bi", &numpathpoints);
1829 if(numpathpoints>30||numpathpoints<0)
1831 for(int j=0;j<numpathpoints;j++){
1832 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1833 for(int k=0;k<numpathpointconnect[j];k++){
1834 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1840 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1843 if(environment!=oldenvironment)
1844 Setenvironment(environment);
1845 oldenvironment=environment;
1847 if(!stealthloading){
1848 int j=objects.numobjects;
1849 objects.numobjects=0;
1850 for(int i=0;i<j;i++){
1851 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1856 terrain.DoShadows();
1859 objects.DoShadows();
1866 if(numplayers>maxplayers-1)
1867 numplayers=maxplayers-1;
1868 for(int i=0;i<numplayers;i++){
1874 if(i==0||player[i].scale<0)
1876 player[i].skeleton.free=0;
1877 player[i].skeleton.id=i;
1879 player[i].creature=rabbittype;
1880 if(player[i].creature!=wolftype){
1881 player[i].skeleton.Load(
1882 (char *)":Data:Skeleton:Basic Figure",
1883 (char *)":Data:Skeleton:Basic Figurelow",
1884 (char *)":Data:Skeleton:Rabbitbelt",
1885 (char *)":Data:Models:Body.solid",
1886 (char *)":Data:Models:Body2.solid",
1887 (char *)":Data:Models:Body3.solid",
1888 (char *)":Data:Models:Body4.solid",
1889 (char *)":Data:Models:Body5.solid",
1890 (char *)":Data:Models:Body6.solid",
1891 (char *)":Data:Models:Body7.solid",
1892 (char *)":Data:Models:Bodylow.solid",
1893 (char *)":Data:Models:Belt.solid",0);
1895 if(player[i].creature!=wolftype){
1896 player[i].skeleton.Load(
1897 (char *)":Data:Skeleton:Basic Figure",
1898 (char *)":Data:Skeleton:Basic Figurelow",
1899 (char *)":Data:Skeleton:Rabbitbelt",
1900 (char *)":Data:Models:Body.solid",
1901 (char *)":Data:Models:Body2.solid",
1902 (char *)":Data:Models:Body3.solid",
1903 (char *)":Data:Models:Body4.solid",
1904 (char *)":Data:Models:Body5.solid",
1905 (char *)":Data:Models:Body6.solid",
1906 (char *)":Data:Models:Body7.solid",
1907 (char *)":Data:Models:Bodylow.solid",
1908 (char *)":Data:Models:Belt.solid",1);
1909 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1911 if(player[i].creature==wolftype){
1912 player[i].skeleton.Load(
1913 (char *)":Data:Skeleton:Basic Figure Wolf",
1914 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1915 (char *)":Data:Skeleton:Rabbitbelt",
1916 (char *)":Data:Models:Wolf.solid",
1917 (char *)":Data:Models:Wolf2.solid",
1918 (char *)":Data:Models:Wolf3.solid",
1919 (char *)":Data:Models:Wolf4.solid",
1920 (char *)":Data:Models:Wolf5.solid",
1921 (char *)":Data:Models:Wolf6.solid",
1922 (char *)":Data:Models:Wolf7.solid",
1923 (char *)":Data:Models:Wolflow.solid",
1924 (char *)":Data:Models:Belt.solid",0);
1930 //~ texsize=512*512*3/texdetail/texdetail;
1932 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1934 if(player[i].numclothes){
1935 for(int j=0;j<player[i].numclothes;j++){
1936 tintr=player[i].clothestintr[j];
1937 tintg=player[i].clothestintg[j];
1938 tintb=player[i].clothestintb[j];
1939 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1941 player[i].DoMipmaps();
1944 player[i].currentanimation=bounceidleanim;
1945 player[i].targetanimation=bounceidleanim;
1946 player[i].currentframe=0;
1947 player[i].targetframe=1;
1949 player[i].speed=1+(float)(Random()%100)/1000;
1951 player[i].speed-=.2;
1953 player[i].speed-=.1;
1955 player[i].velocity=0;
1956 player[i].oldcoords=player[i].coords;
1957 player[i].realoldcoords=player[i].coords;
1960 player[i].skeleton.id=i;
1961 player[i].updatedelay=0;
1962 player[i].normalsupdatedelay=0;
1964 player[i].aitype=passivetype;
1965 player[i].madskills=0;
1968 player[i].proportionhead=1.2;
1969 player[i].proportionbody=1.05;
1970 player[i].proportionarms=1.00;
1971 player[i].proportionlegs=1.1;
1972 player[i].proportionlegs.y=1.05;
1974 player[i].headless=0;
1975 player[i].currentoffset=0;
1976 player[i].targetoffset=0;
1978 player[i].damagetolerance=200;
1980 if(player[i].creature==wolftype){
1981 if(i==0||player[i].scale<0)
1982 player[i].scale=.23;
1983 player[i].damagetolerance=300;
1989 player[i].proportionhead.z=0;
1990 player[i].proportionbody.z=0;
1991 player[i].proportionarms.z=0;
1992 player[i].proportionlegs.z=0;
1995 player[i].tempanimation.Load((char *)"Tempanim",0,0);
1997 player[i].headmorphness=0;
1998 player[i].targetheadmorphness=1;
1999 player[i].headmorphstart=0;
2000 player[i].headmorphend=0;
2002 player[i].pausetime=0;
2005 player[i].jumppower=5;
2007 player[i].permanentdamage=0;
2008 player[i].superpermanentdamage=0;
2010 player[i].forwardkeydown=0;
2011 player[i].leftkeydown=0;
2012 player[i].backkeydown=0;
2013 player[i].rightkeydown=0;
2014 player[i].jumpkeydown=0;
2015 player[i].crouchkeydown=0;
2016 player[i].throwkeydown=0;
2018 player[i].collided=-10;
2020 player[i].bloodloss=0;
2021 player[i].weaponactive=-1;
2022 player[i].weaponstuck=-1;
2023 player[i].bleeding=0;
2024 player[i].deathbleeding=0;
2025 player[i].stunned=0;
2026 player[i].hasvictim=0;
2027 player[i].wentforweapon=0;
2030 player[0].aitype=playercontrolled;
2031 player[0].weaponactive=-1;
2034 player[0].power=1/.9;
2037 player[0].power=1/.8;
2040 player[0].damagetolerance=250;
2042 player[0].damagetolerance=300;
2044 player[0].armorhead*=1.5;
2046 player[0].armorhigh*=1.5;
2048 player[0].armorlow*=1.5;
2049 cameraloc=player[0].coords;
2051 rotation=player[0].rotation;
2053 hawkcoords=player[0].coords;
2058 //~ for(int i=0;i<weapons.size();i++){
2061 LOG("Starting background music...");
2063 OPENAL_StopSound(OPENAL_ALL);
2064 if(environment==snowyenvironment){
2066 emit_stream_np(stream_wind);
2067 }else if(environment==desertenvironment){
2069 emit_stream_np(stream_desertambient);
2070 }else if(environment==grassyenvironment){
2072 emit_stream_np(stream_wind, 100.);
2074 oldmusicvolume[0]=0;
2075 oldmusicvolume[1]=0;
2076 oldmusicvolume[2]=0;
2077 oldmusicvolume[3]=0;
2089 void Game::doTutorial(){
2090 if(tutorialstagetime>tutorialmaxtime){
2093 if(tutorialstage<=1){
2098 switch(tutorialstage){
2104 tutorialmaxtime=600;
2106 tutorialmaxtime=1000;
2108 tutorialmaxtime=600;
2110 tutorialmaxtime=600;
2112 tutorialmaxtime=600;
2114 tutorialmaxtime=600;
2116 tutorialmaxtime=600;
2120 tutorialmaxtime=1000;
2122 tutorialmaxtime=1000;
2137 player[1].coords=(temp+temp2)/2;
2139 emit_sound_at(fireendsound, player[1].coords);
2141 for(int i=0;i<player[1].skeleton.num_joints;i++){
2143 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2144 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2145 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;
2146 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2147 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2152 tutorialmaxtime=500;
2154 tutorialmaxtime=500;
2156 tutorialmaxtime=500;
2158 tutorialmaxtime=500;
2161 //tutorialmaxtime=500;
2163 tutorialmaxtime=500;
2165 tutorialmaxtime=500;
2172 tutorialmaxtime=500;
2174 tutorialmaxtime=500;
2176 tutorialmaxtime=500;
2178 tutorialmaxtime=500;
2185 player[1].aitype=attacktypecutoff;
2187 tutorialmaxtime=400;
2189 tutorialmaxtime=400;
2190 player[0].escapednum=0;
2195 player[1].aitype=passivetype;
2201 tutorialmaxtime=400;
2204 player[1].aitype=attacktypecutoff;
2206 tutorialmaxtime=400;
2208 tutorialmaxtime=400;
2213 player[1].aitype=passivetype;
2220 player[1].aitype=attacktypecutoff;
2225 player[1].aitype=passivetype;
2237 w.position=(temp+temp2)/2;
2238 w.tippoint=(temp+temp2)/2;
2248 weapons.push_back(w);
2251 tutorialmaxtime=300;
2253 tutorialmaxtime=300;
2257 tutorialmaxtime=300;
2260 player[0].weaponactive=-1;
2261 player[0].num_weapons=0;
2262 player[1].weaponactive=0;
2263 player[1].num_weapons=1;
2264 player[1].weaponids[0]=0;
2268 player[1].aitype=attacktypecutoff;
2270 tutorialmaxtime=300;
2273 player[0].weaponactive=-1;
2274 player[0].num_weapons=0;
2275 player[1].weaponactive=0;
2276 player[1].num_weapons=1;
2277 player[1].weaponids[0]=0;
2279 tutorialmaxtime=300;
2282 player[0].weaponactive=-1;
2283 player[0].num_weapons=0;
2284 player[1].weaponactive=0;
2285 player[1].num_weapons=1;
2286 player[1].weaponids[0]=0;
2288 weapons[0].setType(sword);
2290 tutorialmaxtime=300;
2304 w.position=(temp+temp2)/2;
2305 w.tippoint=(temp+temp2)/2;
2315 weapons.push_back(w);
2319 player[0].weaponactive=0;
2320 player[0].num_weapons=1;
2321 player[0].weaponids[0]=1;
2322 player[1].weaponactive=0;
2323 player[1].num_weapons=1;
2324 player[1].weaponids[0]=0;
2330 player[1].aitype=passivetype;
2336 player[0].weaponactive=0;
2337 player[0].num_weapons=1;
2338 player[0].weaponids[0]=1;
2339 player[1].weaponactive=0;
2340 player[1].num_weapons=1;
2341 player[1].weaponids[0]=0;
2343 if(player[0].weaponactive!=-1)
2344 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2346 weapons[0].setType(staff);
2350 player[1].aitype=passivetype;
2352 tutorialmaxtime=200;
2354 weapons[1].position=1000;
2355 weapons[1].tippoint=1000;
2357 weapons[0].setType(knife);
2360 player[1].weaponactive=-1;
2361 player[1].num_weapons=0;
2362 player[0].weaponactive=0;
2363 player[0].num_weapons=1;
2364 player[0].weaponids[0]=0;
2370 emit_sound_at(fireendsound, player[1].coords);
2372 for(int i=0;i<player[1].skeleton.num_joints;i++){
2374 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2375 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2376 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;
2377 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2378 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2382 player[1].num_weapons=0;
2383 player[1].weaponstuck=-1;
2384 player[1].weaponactive=-1;
2389 tutorialmaxtime=80000;
2390 break; default: break;
2392 if(tutorialstage<=51)tutorialstagetime=0;
2396 if(tutorialstagetime<tutorialmaxtime-3){
2397 switch(tutorialstage){
2398 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2399 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2400 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2401 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2402 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2403 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2404 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2405 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2406 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2407 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2408 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2409 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2410 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2411 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2412 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2413 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2414 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2415 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2416 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2417 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2418 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2420 if(player[0].escapednum==2) {
2424 player[1].aitype=passivetype;
2426 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2427 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2429 if(animation[player[0].targetanimation].attack==reversal){
2433 player[1].aitype=passivetype;
2435 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2436 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2437 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2438 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2439 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2440 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2441 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2442 break; default: break;
2444 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2447 if(tutorialstagetime==tutorialmaxtime-3){
2448 emit_sound_np(consolesuccesssound);
2451 if(tutorialsuccess>=1){
2452 if(tutorialstage==34||tutorialstage==35)
2453 tutorialstagetime=tutorialmaxtime-1;
2457 if(tutorialstage<14||tutorialstage>=50){
2458 player[1].coords.y=300;
2459 player[1].velocity=0;
2463 void Game::doDebugKeys(){
2464 float headprop,bodyprop,armprop,legprop;
2466 if(Input::isKeyPressed(SDLK_h)){
2467 player[0].damagetolerance=200000;
2470 player[0].permanentdamage=0;
2471 player[0].superpermanentdamage=0;
2474 if(Input::isKeyPressed(SDLK_j)){
2478 Setenvironment(environment);
2481 if(Input::isKeyPressed(SDLK_c)){
2482 cameramode=1-cameramode;
2485 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2486 if(player[0].num_weapons>0){
2487 if(weapons[player[0].weaponids[0]].getType()==sword)
2488 weapons[player[0].weaponids[0]].setType(staff);
2489 else if(weapons[player[0].weaponids[0]].getType()==staff)
2490 weapons[player[0].weaponids[0]].setType(knife);
2492 weapons[player[0].weaponids[0]].setType(sword);
2496 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2498 float closestdist=-1;
2501 for(int i=1;i<numplayers;i++){
2502 distance=findDistancefast(&player[i].coords,&player[0].coords);
2503 if(closestdist==-1||distance<closestdist){
2504 closestdist=distance;
2509 if(player[closest].num_weapons){
2510 if(weapons[player[closest].weaponids[0]].getType()==sword)
2511 weapons[player[closest].weaponids[0]].setType(staff);
2512 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2513 weapons[player[closest].weaponids[0]].setType(knife);
2515 weapons[player[closest].weaponids[0]].setType(sword);
2517 if(!player[closest].num_weapons){
2518 player[closest].weaponids[0]=weapons.size();
2520 weapons.push_back(Weapon(knife,closest));
2522 player[closest].num_weapons=1;
2527 if(Input::isKeyDown(SDLK_u)){
2529 float closestdist=-1;
2532 for(int i=1;i<numplayers;i++){
2533 distance=findDistancefast(&player[i].coords,&player[0].coords);
2534 if(closestdist==-1||distance<closestdist){
2535 closestdist=distance;
2539 player[closest].rotation+=multiplier*50;
2540 player[closest].targetrotation=player[closest].rotation;
2544 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2546 float closestdist=-1;
2549 for(int i=1;i<numplayers;i++){
2550 distance=findDistancefast(&player[i].coords,&player[0].coords);
2551 if(closestdist==-1||distance<closestdist){
2552 closestdist=distance;
2556 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2559 player[closest].whichskin++;
2560 if(player[closest].whichskin>9)
2561 player[closest].whichskin=0;
2562 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2563 player[closest].whichskin=0;
2565 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2566 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2569 if(player[closest].numclothes){
2570 for(int i=0;i<player[closest].numclothes;i++){
2571 tintr=player[closest].clothestintr[i];
2572 tintg=player[closest].clothestintg[i];
2573 tintb=player[closest].clothestintb[i];
2574 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2576 player[closest].DoMipmaps();
2580 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2582 float closestdist=-1;
2585 for(int i=1;i<numplayers;i++){
2586 distance=findDistancefast(&player[i].coords,&player[0].coords);
2587 if(closestdist==-1||distance<closestdist){
2588 closestdist=distance;
2593 if(player[closest].creature==wolftype){
2594 headprop=player[closest].proportionhead.x/1.1;
2595 bodyprop=player[closest].proportionbody.x/1.1;
2596 armprop=player[closest].proportionarms.x/1.1;
2597 legprop=player[closest].proportionlegs.x/1.1;
2600 if(player[closest].creature==rabbittype){
2601 headprop=player[closest].proportionhead.x/1.2;
2602 bodyprop=player[closest].proportionbody.x/1.05;
2603 armprop=player[closest].proportionarms.x/1.00;
2604 legprop=player[closest].proportionlegs.x/1.1;
2608 if(player[closest].creature==rabbittype){
2609 player[closest].skeleton.id=closest;
2610 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);
2611 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2612 player[closest].whichskin=0;
2613 player[closest].creature=wolftype;
2615 player[closest].proportionhead=1.1;
2616 player[closest].proportionbody=1.1;
2617 player[closest].proportionarms=1.1;
2618 player[closest].proportionlegs=1.1;
2619 player[closest].proportionlegs.y=1.1;
2620 player[closest].scale=.23*5*player[0].scale;
2622 player[closest].damagetolerance=300;
2626 player[closest].skeleton.id=closest;
2627 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);
2628 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2629 player[closest].whichskin=0;
2630 player[closest].creature=rabbittype;
2632 player[closest].proportionhead=1.2;
2633 player[closest].proportionbody=1.05;
2634 player[closest].proportionarms=1.00;
2635 player[closest].proportionlegs=1.1;
2636 player[closest].proportionlegs.y=1.05;
2637 player[closest].scale=.2*5*player[0].scale;
2639 player[closest].damagetolerance=200;
2642 if(player[closest].creature==wolftype){
2643 player[closest].proportionhead=1.1*headprop;
2644 player[closest].proportionbody=1.1*bodyprop;
2645 player[closest].proportionarms=1.1*armprop;
2646 player[closest].proportionlegs=1.1*legprop;
2649 if(player[closest].creature==rabbittype){
2650 player[closest].proportionhead=1.2*headprop;
2651 player[closest].proportionbody=1.05*bodyprop;
2652 player[closest].proportionarms=1.00*armprop;
2653 player[closest].proportionlegs=1.1*legprop;
2654 player[closest].proportionlegs.y=1.05*legprop;
2660 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2666 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2668 float closestdist=-1;
2670 XYZ flatfacing2,flatvelocity2;
2673 for(int i=1;i<numplayers;i++){
2674 distance=findDistancefast(&player[i].coords,&player[0].coords);
2675 if(distance<144&&!player[i].headless)
2676 if(closestdist==-1||distance<closestdist){
2677 closestdist=distance;
2679 blah = player[i].coords;
2684 XYZ headspurtdirection;
2685 //int i = player[closest].skeleton.jointlabels[head];
2686 Joint& headjoint= player[closest].getJointFor(head);
2687 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2688 if(!player[closest].skeleton.free)
2689 flatvelocity2=player[closest].velocity;
2690 if(player[closest].skeleton.free)
2691 flatvelocity2=headjoint.velocity;
2692 if(!player[closest].skeleton.free)
2693 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;
2694 if(player[closest].skeleton.free)
2695 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2696 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2697 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2698 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2699 headspurtdirection=headjoint.position-player[closest].getJointFor(neck).position;
2700 Normalise(&headspurtdirection);
2701 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2702 flatvelocity2+=headspurtdirection*8;
2703 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2705 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2707 emit_sound_at(splattersound, blah);
2708 emit_sound_at(breaksound2, blah, 100.);
2710 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2711 player[closest].RagDoll(0);
2712 player[closest].dead=2;
2713 player[closest].headless=1;
2714 player[closest].DoBloodBig(3,165);
2720 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2722 float closestdist=-1;
2724 XYZ flatfacing2,flatvelocity2;
2727 for(int i=1;i<numplayers;i++){
2728 distance=findDistancefast(&player[i].coords,&player[0].coords);
2730 if(closestdist==-1||distance<closestdist){
2731 closestdist=distance;
2733 blah=player[i].coords;
2738 emit_sound_at(splattersound, blah);
2740 emit_sound_at(breaksound2, blah);
2742 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2743 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2744 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2745 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;
2746 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2747 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2748 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2749 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2750 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2751 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2752 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2755 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2756 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2757 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2758 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;
2759 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2760 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2761 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2762 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2763 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2764 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2767 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2768 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2769 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2770 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;
2771 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2772 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2773 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2774 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2775 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2776 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2779 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2780 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2781 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2782 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;
2783 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2784 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2785 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2786 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2787 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2788 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2792 for(int j=0;j<numplayers; j++){
2794 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2795 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2796 if(player[j].skeleton.free==2)
2797 player[j].skeleton.free=1;
2798 player[j].skeleton.longdead=0;
2799 player[j].RagDoll(0);
2800 for(int i=0;i<player[j].skeleton.num_joints; i++){
2801 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2802 if(findDistancefast(&temppos,&player[closest].coords)<25){
2803 flatvelocity2=temppos-player[closest].coords;
2804 Normalise(&flatvelocity2);
2805 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2812 player[closest].DoDamage(10000);
2813 player[closest].RagDoll(0);
2814 player[closest].dead=2;
2815 player[closest].coords=20;
2816 player[closest].skeleton.free=2;
2823 if(Input::isKeyPressed(SDLK_f)){
2824 player[0].onfire=1-player[0].onfire;
2825 if(player[0].onfire){
2826 player[0].CatchFire();
2828 if(!player[0].onfire){
2829 emit_sound_at(fireendsound, player[0].coords);
2830 pause_sound(stream_firesound);
2834 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2835 //if(!player[0].skeleton.free)player[0].damage+=500;
2836 player[0].RagDoll(0);
2837 //player[0].spurt=1;
2838 //player[0].DoDamage(1000);
2840 emit_sound_at(whooshsound, player[0].coords, 128.);
2843 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2844 for(int i=0;i<objects.numobjects;i++){
2845 if(objects.type[i]==treeleavestype){
2846 objects.scale[i]*=.9;
2851 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2852 editorenabled=1-editorenabled;
2854 player[0].damagetolerance=100000;
2856 player[0].damagetolerance=200;
2858 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2859 player[0].permanentdamage=0;
2860 player[0].superpermanentdamage=0;
2861 player[0].bloodloss=0;
2862 player[0].deathbleeding=0;
2866 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2868 if(targetlevel>numchallengelevels-1)
2875 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2877 float closestdist=-1;
2880 for(int i=1;i<numplayers;i++){
2881 distance=findDistancefast(&player[i].coords,&player[0].coords);
2882 if(closestdist==-1||distance<closestdist){
2883 closestdist=distance;
2887 if(closestdist>0&&closest>=0){
2888 //player[closest]=player[numplayers-1];
2889 //player[closest].skeleton=player[numplayers-1].skeleton;
2894 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2896 float closestdist=-1;
2899 for(int i=1;i<max_objects;i++){
2900 distance=findDistancefast(&objects.position[i],&player[0].coords);
2901 if(closestdist==-1||distance<closestdist){
2902 closestdist=distance;
2906 if(closestdist>0&&closest>=0){
2907 objects.position[closest].y-=500;
2911 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2913 //if(drawmode>2)drawmode=0;
2914 if(objects.numobjects<max_objects-1){
2916 boxcoords.x=player[0].coords.x;
2917 boxcoords.z=player[0].coords.z;
2918 boxcoords.y=player[0].coords.y-3;
2919 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
2920 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
2921 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
2922 float temprotat,temprotat2;
2923 temprotat=editorrotation;
2924 temprotat2=editorrotation2;
2925 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
2926 if(temprotat2<0)temprotat2=Random()%360;
2928 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
2929 if(editortype==treetrunktype)
2930 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
2934 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
2935 if(numplayers<maxplayers-1){
2936 player[numplayers].scale=.2*5*player[0].scale;
2937 player[numplayers].creature=rabbittype;
2938 player[numplayers].howactive=editoractive;
2939 player[numplayers].skeleton.id=numplayers;
2940 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);
2942 //texsize=512*512*3/texdetail/texdetail;
2943 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
2944 //player[numplayers].skeleton.skinText.resize(texsize);
2946 int k=abs(Random()%2)+1;
2948 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2949 player[numplayers].whichskin=0;
2952 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2953 player[numplayers].whichskin=1;
2956 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2957 player[numplayers].whichskin=2;
2960 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
2961 player[numplayers].power=1;
2962 player[numplayers].speedmult=1;
2963 player[numplayers].currentanimation=bounceidleanim;
2964 player[numplayers].targetanimation=bounceidleanim;
2965 player[numplayers].currentframe=0;
2966 player[numplayers].targetframe=1;
2967 player[numplayers].target=0;
2968 player[numplayers].bled=0;
2969 player[numplayers].speed=1+(float)(Random()%100)/1000;
2971 player[numplayers].targetrotation=player[0].targetrotation;
2972 player[numplayers].rotation=player[0].rotation;
2974 player[numplayers].velocity=0;
2975 player[numplayers].coords=player[0].coords;
2976 player[numplayers].oldcoords=player[numplayers].coords;
2977 player[numplayers].realoldcoords=player[numplayers].coords;
2979 player[numplayers].id=numplayers;
2980 player[numplayers].skeleton.id=numplayers;
2981 player[numplayers].updatedelay=0;
2982 player[numplayers].normalsupdatedelay=0;
2984 player[numplayers].aitype=passivetype;
2986 if(player[0].creature==wolftype){
2987 headprop=player[0].proportionhead.x/1.1;
2988 bodyprop=player[0].proportionbody.x/1.1;
2989 armprop=player[0].proportionarms.x/1.1;
2990 legprop=player[0].proportionlegs.x/1.1;
2993 if(player[0].creature==rabbittype){
2994 headprop=player[0].proportionhead.x/1.2;
2995 bodyprop=player[0].proportionbody.x/1.05;
2996 armprop=player[0].proportionarms.x/1.00;
2997 legprop=player[0].proportionlegs.x/1.1;
3000 if(player[numplayers].creature==wolftype){
3001 player[numplayers].proportionhead=1.1*headprop;
3002 player[numplayers].proportionbody=1.1*bodyprop;
3003 player[numplayers].proportionarms=1.1*armprop;
3004 player[numplayers].proportionlegs=1.1*legprop;
3007 if(player[numplayers].creature==rabbittype){
3008 player[numplayers].proportionhead=1.2*headprop;
3009 player[numplayers].proportionbody=1.05*bodyprop;
3010 player[numplayers].proportionarms=1.00*armprop;
3011 player[numplayers].proportionlegs=1.1*legprop;
3012 player[numplayers].proportionlegs.y=1.05*legprop;
3015 player[numplayers].headless=0;
3016 player[numplayers].onfire=0;
3019 player[numplayers].proportionhead.z=0;
3020 player[numplayers].proportionbody.z=0;
3021 player[numplayers].proportionarms.z=0;
3022 player[numplayers].proportionlegs.z=0;
3025 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3027 player[numplayers].damagetolerance=200;
3029 player[numplayers].protectionhead=player[0].protectionhead;
3030 player[numplayers].protectionhigh=player[0].protectionhigh;
3031 player[numplayers].protectionlow=player[0].protectionlow;
3032 player[numplayers].armorhead=player[0].armorhead;
3033 player[numplayers].armorhigh=player[0].armorhigh;
3034 player[numplayers].armorlow=player[0].armorlow;
3035 player[numplayers].metalhead=player[0].metalhead;
3036 player[numplayers].metalhigh=player[0].metalhigh;
3037 player[numplayers].metallow=player[0].metallow;
3039 player[numplayers].immobile=player[0].immobile;
3041 player[numplayers].numclothes=player[0].numclothes;
3042 if(player[numplayers].numclothes)
3043 for(int i=0;i<player[numplayers].numclothes;i++){
3044 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3045 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3046 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3047 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3048 tintr=player[numplayers].clothestintr[i];
3049 tintg=player[numplayers].clothestintg[i];
3050 tintb=player[numplayers].clothestintb[i];
3051 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3053 if(player[numplayers].numclothes){
3054 player[numplayers].DoMipmaps();
3057 player[numplayers].power=player[0].power;
3058 player[numplayers].speedmult=player[0].speedmult;
3060 player[numplayers].damage=0;
3061 player[numplayers].permanentdamage=0;
3062 player[numplayers].superpermanentdamage=0;
3063 player[numplayers].deathbleeding=0;
3064 player[numplayers].bleeding=0;
3065 player[numplayers].numwaypoints=0;
3066 player[numplayers].waypoint=0;
3067 player[numplayers].jumppath=0;
3068 player[numplayers].weaponstuck=-1;
3069 player[numplayers].weaponactive=-1;
3070 player[numplayers].num_weapons=0;
3071 player[numplayers].bloodloss=0;
3072 player[numplayers].dead=0;
3074 player[numplayers].loaded=1;
3080 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3081 if(player[numplayers-1].numwaypoints<90){
3082 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3083 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3084 player[numplayers-1].numwaypoints++;
3088 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3089 if(numpathpoints<30){
3090 bool connected,alreadyconnected;
3093 for(int i=0;i<numpathpoints;i++){
3094 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3096 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3097 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3099 if(!alreadyconnected){
3100 numpathpointconnect[pathpointselected]++;
3102 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3108 pathpoint[numpathpoints-1]=player[0].coords;
3109 numpathpointconnect[numpathpoints-1]=0;
3110 if(numpathpoints>1&&pathpointselected!=-1){
3111 numpathpointconnect[pathpointselected]++;
3112 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3114 pathpointselected=numpathpoints-1;
3119 if(Input::isKeyPressed(SDLK_PERIOD)){
3120 pathpointselected++;
3121 if(pathpointselected>=numpathpoints)
3122 pathpointselected=-1;
3124 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3125 pathpointselected--;
3126 if(pathpointselected<=-2)
3127 pathpointselected=numpathpoints-1;
3129 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3130 if(pathpointselected!=-1){
3132 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3133 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3134 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3135 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3137 for(int i=0;i<numpathpoints;i++){
3138 for(int j=0;j<numpathpointconnect[i];j++){
3139 if(pathpointconnect[i][j]==pathpointselected){
3140 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3141 numpathpointconnect[i]--;
3143 if(pathpointconnect[i][j]==numpathpoints){
3144 pathpointconnect[i][j]=pathpointselected;
3148 pathpointselected=numpathpoints-1;
3152 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3154 if(editortype==treeleavestype||editortype==10)editortype--;
3155 if(editortype<0)editortype=firetype;
3158 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3160 if(editortype==treeleavestype||editortype==10)editortype++;
3161 if(editortype>firetype)editortype=0;
3164 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3165 editorrotation-=multiplier*100;
3166 if(editorrotation<-.01)editorrotation=-.01;
3169 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3170 editorrotation+=multiplier*100;
3173 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3174 editorsize+=multiplier;
3177 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3178 editorsize-=multiplier;
3179 if(editorsize<.1)editorsize=.1;
3183 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3184 mapradius-=multiplier*10;
3187 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3188 mapradius+=multiplier*10;
3190 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3191 editorrotation2+=multiplier*100;
3194 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3195 editorrotation2-=multiplier*100;
3196 if(editorrotation2<-.01)editorrotation2=-.01;
3198 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3200 float closestdist=-1;
3202 for(int i=0;i<objects.numobjects;i++){
3203 distance=findDistancefast(&objects.position[i],&player[0].coords);
3204 if(closestdist==-1||distance<closestdist){
3205 closestdist=distance;
3209 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3215 void Game::doJumpReversals(){
3216 for(int k=0;k<numplayers;k++)
3217 for(int i=k;i<numplayers;i++){
3219 if( player[k].skeleton.free==0&&
3220 player[i].skeleton.oldfree==0&&
3221 (player[i].targetanimation==jumpupanim||
3222 player[k].targetanimation==jumpupanim)&&
3223 (player[i].aitype==playercontrolled||
3224 player[k].aitype==playercontrolled)&&
3225 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3226 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3227 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3228 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3229 //TODO: refactor two huge similar ifs
3230 if(player[i].targetanimation==jumpupanim&&
3231 player[k].targetanimation!=getupfrombackanim&&
3232 player[k].targetanimation!=getupfromfrontanim&&
3233 animation[player[k].targetanimation].height==middleheight&&
3234 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3235 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3236 player[k].aitype!=playercontrolled)){
3237 player[i].victim=&player[k];
3238 player[i].velocity=0;
3239 player[i].currentanimation=jumpreversedanim;
3240 player[i].targetanimation=jumpreversedanim;
3241 player[i].currentframe=0;
3242 player[i].targetframe=1;
3243 player[i].targettilt2=0;
3244 player[k].victim=&player[i];
3245 player[k].velocity=0;
3246 player[k].currentanimation=jumpreversalanim;
3247 player[k].targetanimation=jumpreversalanim;
3248 player[k].currentframe=0;
3249 player[k].targetframe=1;
3250 player[k].targettilt2=0;
3251 if(player[i].coords.y<player[k].coords.y+1){
3252 player[i].currentanimation=rabbitkickreversedanim;
3253 player[i].targetanimation=rabbitkickreversedanim;
3254 player[i].currentframe=1;
3255 player[i].targetframe=2;
3256 player[k].currentanimation=rabbitkickreversalanim;
3257 player[k].targetanimation=rabbitkickreversalanim;
3258 player[k].currentframe=1;
3259 player[k].targetframe=2;
3262 player[k].oldcoords=player[k].coords;
3263 player[i].coords=player[k].coords;
3264 player[k].targetrotation=player[i].targetrotation;
3265 player[k].rotation=player[i].targetrotation;
3266 if(player[k].aitype==attacktypecutoff)
3267 player[k].stunned=.5;
3269 if(player[k].targetanimation==jumpupanim&&
3270 player[i].targetanimation!=getupfrombackanim&&
3271 player[i].targetanimation!=getupfromfrontanim&&
3272 animation[player[i].targetanimation].height==middleheight&&
3273 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3274 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3275 player[i].aitype!=playercontrolled)){
3276 player[k].victim=&player[i];
3277 player[k].velocity=0;
3278 player[k].currentanimation=jumpreversedanim;
3279 player[k].targetanimation=jumpreversedanim;
3280 player[k].currentframe=0;
3281 player[k].targetframe=1;
3282 player[k].targettilt2=0;
3283 player[i].victim=&player[k];
3284 player[i].velocity=0;
3285 player[i].currentanimation=jumpreversalanim;
3286 player[i].targetanimation=jumpreversalanim;
3287 player[i].currentframe=0;
3288 player[i].targetframe=1;
3289 player[i].targettilt2=0;
3290 if(player[k].coords.y<player[i].coords.y+1){
3291 player[k].targetanimation=rabbitkickreversedanim;
3292 player[k].currentanimation=rabbitkickreversedanim;
3293 player[i].currentanimation=rabbitkickreversalanim;
3294 player[i].targetanimation=rabbitkickreversalanim;
3295 player[k].currentframe=1;
3296 player[k].targetframe=2;
3297 player[i].currentframe=1;
3298 player[i].targetframe=2;
3301 player[i].oldcoords=player[i].coords;
3302 player[k].coords=player[i].coords;
3303 player[i].targetrotation=player[k].targetrotation;
3304 player[i].rotation=player[k].targetrotation;
3305 if(player[i].aitype==attacktypecutoff)
3306 player[i].stunned=.5;
3313 void Game::doAerialAcrobatics(){
3314 static XYZ facing,flatfacing;
3315 for(int k=0;k<numplayers;k++){
3316 player[k].turnspeed=500;
3318 if((player[k].isRun()&&
3319 ((player[k].targetrotation!=rabbitrunninganim&&
3320 player[k].targetrotation!=wolfrunninganim)||
3321 player[k].targetframe==4))||
3322 player[k].targetanimation==removeknifeanim||
3323 player[k].targetanimation==crouchremoveknifeanim||
3324 player[k].targetanimation==flipanim||
3325 player[k].targetanimation==fightsidestep||
3326 player[k].targetanimation==walkanim){
3327 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3331 if(player[k].isStop()||
3332 player[k].isLanding()||
3333 player[k].targetanimation==staggerbackhighanim||
3334 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3335 player[k].targetanimation==staggerbackhardanim||
3336 player[k].targetanimation==backhandspringanim||
3337 player[k].targetanimation==dodgebackanim||
3338 player[k].targetanimation==rollanim||
3339 (animation[player[k].targetanimation].attack&&
3340 player[k].targetanimation!=rabbitkickanim&&
3341 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3342 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3343 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3346 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3347 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3350 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3351 player[k].DoStuff();
3352 if(player[k].immobile&&k!=0)
3353 player[k].coords=player[k].realoldcoords;
3355 //if player's position has changed (?)
3356 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3357 !player[k].skeleton.free&&
3358 player[k].targetanimation!=climbanim&&
3359 player[k].targetanimation!=hanganim){
3360 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3364 if(player[k].collide<-.3)
3365 player[k].collide=-.3;
3366 if(player[k].collide>1)
3367 player[k].collide=1;
3368 player[k].collide-=multiplier*30;
3371 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3373 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3374 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3375 if(objects.type[i]!=rocktype||
3376 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3377 objects.position[i].y>player[k].coords.y){
3378 lowpoint=player[k].coords;
3379 if(player[k].targetanimation!=jumpupanim&&
3380 player[k].targetanimation!=jumpdownanim&&
3381 !player[k].isFlip())
3385 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3386 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3387 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3388 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3389 flatfacing=lowpoint-player[k].coords;
3390 player[k].coords=lowpoint;
3391 player[k].coords.y-=1.3;
3392 player[k].collide=1;
3395 //TODO: refactor four similar blocks
3396 if(player[k].aitype==playercontrolled&&
3397 (player[k].targetanimation==jumpupanim||
3398 player[k].targetanimation==jumpdownanim||
3399 player[k].isFlip())&&
3400 !player[k].jumptogglekeydown&&
3401 player[k].jumpkeydown){
3402 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3403 XYZ tempcoords1=lowpoint;
3404 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3405 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3406 player[k].setAnimation(walljumpleftanim);
3407 emit_sound_at(movewhooshsound, player[k].coords);
3409 pause_sound(whooshsound);
3411 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3412 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3413 if(lowpointtarget.z<0)
3414 player[k].rotation=180-player[k].rotation;
3415 player[k].targetrotation=player[k].rotation;
3416 player[k].lowrotation=player[k].rotation;
3422 lowpoint=tempcoords1;
3423 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3424 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3425 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3426 player[k].setAnimation(walljumprightanim);
3427 emit_sound_at(movewhooshsound, player[k].coords);
3428 if(k==0)pause_sound(whooshsound);
3430 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3431 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3432 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3433 player[k].targetrotation=player[k].rotation;
3434 player[k].lowrotation=player[k].rotation;
3435 if(k==0)numwallflipped++;
3439 lowpoint=tempcoords1;
3440 lowpointtarget=lowpoint+player[k].facing*2;
3441 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3442 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3443 player[k].setAnimation(walljumpbackanim);
3444 emit_sound_at(movewhooshsound, player[k].coords);
3445 if(k==0)pause_sound(whooshsound);
3447 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3448 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3449 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3450 player[k].targetrotation=player[k].rotation;
3451 player[k].lowrotation=player[k].rotation;
3452 if(k==0)numwallflipped++;
3456 lowpoint=tempcoords1;
3457 lowpointtarget=lowpoint-player[k].facing*2;
3458 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3459 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3460 player[k].setAnimation(walljumpfrontanim);
3461 emit_sound_at(movewhooshsound, player[k].coords);
3462 if(k==0)pause_sound(whooshsound);
3464 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3465 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3466 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3467 player[k].rotation+=180;
3468 player[k].targetrotation=player[k].rotation;
3469 player[k].lowrotation=player[k].rotation;
3470 if(k==0)numwallflipped++;
3478 else if(objects.type[i]==rocktype){
3479 lowpoint2=player[k].coords;
3480 lowpoint=player[k].coords;
3482 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3483 player[k].coords=colpoint;
3484 player[k].collide=1;
3487 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3488 //flipped into a rock
3489 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3490 player[k].RagDoll(0);
3492 if(player[k].targetanimation==jumpupanim){
3493 player[k].jumppower=-4;
3494 player[k].targetanimation=player[k].getIdle();
3497 player[k].targetframe=0;
3498 player[k].onterrain=1;
3500 if(player[k].id==0){
3501 pause_sound(whooshsound);
3502 OPENAL_SetVolume(channels[whooshsound], 0);
3506 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3507 if(player[k].isFlip())
3508 player[k].jumppower=-4;
3509 player[k].targetanimation=player[k].getLanding();
3510 emit_sound_at(landsound, player[k].coords, 128.);
3512 envsound[numenvsounds]=player[k].coords;
3513 envsoundvol[numenvsounds]=16;
3514 envsoundlife[numenvsounds]=.4;
3524 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3525 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3526 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3527 lowpoint=player[k].coords;
3529 if(objects.type[i]!=rocktype)
3530 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3531 if(player[k].targetanimation!=jumpupanim&&
3532 player[k].targetanimation!=jumpdownanim&&
3533 player[k].onterrain)
3534 player[k].avoidcollided=1;
3535 player[k].coords=lowpoint;
3536 player[k].coords.y-=1.35;
3537 player[k].collide=1;
3539 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3540 (player[k].currentanimation!=climbanim&&
3541 player[k].currentanimation!=hanganim&&
3542 !player[k].isWallJump()||
3543 player[k].targetanimation==jumpupanim||
3544 player[k].targetanimation==jumpdownanim)){
3545 lowpoint=player[k].coords;
3546 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3547 lowpoint=player[k].coords;
3551 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3552 lowpointtarget=lowpoint+facing*1.4;
3553 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3555 lowpoint=player[k].coords;
3557 lowpointtarget=lowpoint+facing*1.4;
3559 lowpointtarget2=lowpointtarget;
3561 lowpointtarget3=lowpointtarget;
3563 lowpointtarget4=lowpointtarget;
3565 lowpointtarget5=lowpointtarget;
3567 lowpointtarget6=lowpointtarget;
3569 lowpointtarget7=lowpoint;
3571 lowpointtarget2.x+=.1;
3573 lowpointtarget3.z+=.1;
3575 lowpointtarget4.x-=.1;
3577 lowpointtarget5.z-=.1;
3579 lowpointtarget6.y+=45/13;
3580 lowpointtarget6+=facing*.6;
3581 lowpointtarget7.y+=90/13;
3582 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3583 if(objects.friction[i]>.5)
3585 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3586 player[k].collided=1;
3587 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3588 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3589 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3590 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3591 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3592 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3593 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3594 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3595 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3596 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3597 for(int j=0;j<45;j++){
3598 lowpoint=player[k].coords;
3599 lowpoint.y+=(float)j/13;
3600 lowpointtarget=lowpoint+facing*1.4;
3601 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3602 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3603 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3605 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3606 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3607 lowpoint=player[k].coords;
3608 lowpoint.y+=(float)j/13;
3609 lowpointtarget=lowpoint+facing*1.3;
3610 flatfacing=player[k].coords;
3611 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3612 player[k].coords.y=lowpointtarget.y-.07;
3613 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3615 if(j>10||!player[k].isRun()){
3616 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3618 pause_sound(whooshsound);
3620 emit_sound_at(jumpsound, player[k].coords, 128.);
3622 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3623 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3624 if(lowpointtarget.z<0)
3625 player[k].rotation=180-player[k].rotation;
3626 player[k].targetrotation=player[k].rotation;
3627 player[k].lowrotation=player[k].rotation;
3629 //player[k].velocity=lowpointtarget*.03;
3630 player[k].velocity=0;
3633 if(player[k].targetanimation==jumpupanim){
3634 player[k].targetanimation=climbanim;
3635 player[k].jumppower=0;
3636 player[k].jumpclimb=1;
3638 player[k].transspeed=6;
3640 player[k].targetframe=1;
3643 player[k].setAnimation(hanganim);
3644 player[k].jumppower=0;
3656 if(player[k].collide<=0){
3658 if(!player[k].onterrain&&
3659 player[k].targetanimation!=jumpupanim&&
3660 player[k].targetanimation!=jumpdownanim&&
3661 player[k].targetanimation!=climbanim&&
3662 player[k].targetanimation!=hanganim&&
3663 !player[k].isWallJump()&&
3664 !player[k].isFlip()){
3665 if(player[k].currentanimation!=climbanim&&
3666 player[k].currentanimation!=tempanim&&
3667 player[k].targetanimation!=backhandspringanim&&
3668 (player[k].targetanimation!=rollanim||
3669 player[k].targetframe<2||
3670 player[k].targetframe>6)){
3671 //stagger off ledge (?)
3672 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3673 player[k].RagDoll(0);
3674 player[k].setAnimation(jumpdownanim);
3677 emit_sound_at(whooshsound, player[k].coords, 128.);
3680 player[k].velocity.y+=gravity;
3684 player[k].realoldcoords=player[k].coords;
3688 void Game::doAttacks(){
3689 static XYZ relative;
3690 static int randattack;
3691 static bool playerrealattackkeydown=0;
3693 if(!Input::isKeyDown(attackkey))
3696 player[0].attackkeydown=0;
3698 playerrealattackkeydown=0;
3700 playerrealattackkeydown=Input::isKeyDown(attackkey);
3701 if((player[0].parriedrecently<=0||
3702 player[0].weaponactive==-1)&&
3705 player[0].lastattack!=swordslashanim&&
3706 player[0].lastattack!=knifeslashstartanim&&
3707 player[0].lastattack!=staffhitanim&&
3708 player[0].lastattack!=staffspinhitanim)))
3709 player[0].attackkeydown=Input::isKeyDown(attackkey);
3710 if(Input::isKeyDown(attackkey)&&
3712 !player[0].backkeydown){
3713 for(int k=0;k<numplayers;k++){
3714 if((player[k].targetanimation==swordslashanim||
3715 player[k].targetanimation==staffhitanim||
3716 player[k].targetanimation==staffspinhitanim)&&
3717 player[0].currentanimation!=dodgebackanim&&
3718 !player[k].skeleton.free)
3719 player[k].Reverse();
3723 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3725 for(int k=0;k<numplayers;k++){
3726 if(indialogue!=-1)player[k].attackkeydown=0;
3727 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3728 if(player[k].aitype!=playercontrolled)
3729 player[k].victim=&player[0];
3730 //attack key pressed
3731 if(player[k].attackkeydown){
3733 if(player[k].backkeydown&&
3734 player[k].targetanimation!=backhandspringanim&&
3735 (player[k].isIdle()||
3736 player[k].isStop()||
3738 player[k].targetanimation==walkanim)){
3739 if(player[k].jumppower<=1){
3740 player[k].jumppower-=2;
3742 for(int i=0;i<numplayers;i++){
3744 if(player[i].targetanimation==swordslashanim||
3745 player[i].targetanimation==knifeslashstartanim||
3746 player[i].targetanimation==staffhitanim||
3747 player[i].targetanimation==staffspinhitanim)
3748 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3749 player[k].setAnimation(dodgebackanim);
3750 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3751 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3754 if(player[k].targetanimation!=dodgebackanim){
3755 if(k==0)numflipped++;
3756 player[k].setAnimation(backhandspringanim);
3757 player[k].targetrotation=-rotation+180;
3758 if(player[k].leftkeydown)
3759 player[k].targetrotation-=45;
3760 if(player[k].rightkeydown)
3761 player[k].targetrotation+=45;
3762 player[k].rotation=player[k].targetrotation;
3763 player[k].jumppower-=2;
3768 if(!animation[player[k].targetanimation].attack&&
3769 !player[k].backkeydown&&
3770 (player[k].isIdle()||
3772 player[k].targetanimation==walkanim||
3773 player[k].targetanimation==sneakanim||
3774 player[k].isCrouch())){
3775 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3776 //normal attacks (?)
3777 player[k].hasvictim=0;
3779 for(int i=0;i<numplayers;i++){
3780 if(i==k||!(k==0||i==0))continue;
3781 if(!player[k].hasvictim)
3782 if(animation[player[k].targetanimation].attack!=reversal){
3784 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3786 !player[i].skeleton.free&&
3787 player[i].howactive<typedead1&&
3788 player[i].targetanimation!=jumpreversedanim&&
3789 player[i].targetanimation!=rabbitkickreversedanim&&
3790 player[i].targetanimation!=rabbitkickanim&&
3791 player[k].targetanimation!=rabbitkickanim&&
3792 player[i].targetanimation!=getupfrombackanim&&
3793 (player[i].targetanimation!=staggerbackhighanim&&
3794 (player[i].targetanimation!=staggerbackhardanim||
3795 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3796 player[i].targetanimation!=jumpdownanim&&
3797 player[i].targetanimation!=jumpupanim&&
3798 player[i].targetanimation!=getupfromfrontanim){
3799 player[k].victim=&player[i];
3800 player[k].hasvictim=1;
3801 if(player[k].aitype==playercontrolled){ //human player
3803 if(distance<2.5*sq(player[k].scale*5)&&
3804 player[k].crouchkeydown&&
3805 animation[player[i].targetanimation].height!=lowheight)
3806 player[k].targetanimation=sweepanim;
3808 else if(distance<1.5*sq(player[k].scale*5)&&
3809 animation[player[i].targetanimation].height!=lowheight&&
3810 !player[k].forwardkeydown&&
3811 !player[k].leftkeydown&&
3812 !player[k].rightkeydown&&
3813 !player[k].crouchkeydown&&
3816 player[k].targetanimation=winduppunchanim;
3818 else if(distance<2.5*sq(player[k].scale*5)&&
3819 animation[player[i].targetanimation].height!=lowheight&&
3820 !player[k].forwardkeydown&&
3821 !player[k].leftkeydown&&
3822 !player[k].rightkeydown&&
3823 !player[k].crouchkeydown&&
3825 player[k].targetanimation=upunchanim;
3827 else if(distance<2.5*sq(player[k].scale*5)&&
3828 player[i].staggerdelay>0&&
3829 attackweapon==knife&&
3830 player[i].bloodloss>player[i].damagetolerance/2)
3831 player[k].targetanimation=knifefollowanim;
3833 else if(distance<2.5*sq(player[k].scale*5)&&
3834 animation[player[i].targetanimation].height!=lowheight&&
3835 !player[k].forwardkeydown&&
3836 !player[k].leftkeydown&&
3837 !player[k].rightkeydown&&
3838 !player[k].crouchkeydown&&
3839 attackweapon==knife&&
3840 player[k].weaponmissdelay<=0)
3841 player[k].targetanimation=knifeslashstartanim;
3843 else if(distance<4.5*sq(player[k].scale*5)&&
3844 animation[player[i].targetanimation].height!=lowheight&&
3845 !player[k].crouchkeydown&&
3846 attackweapon==sword&&
3847 player[k].weaponmissdelay<=0)
3848 player[k].targetanimation=swordslashanim;
3850 else if(distance<4.5*sq(player[k].scale*5)&&
3851 animation[player[i].targetanimation].height!=lowheight&&
3852 !player[k].crouchkeydown&&
3853 attackweapon==staff&&
3854 player[k].weaponmissdelay<=0&&
3855 !player[k].leftkeydown&&
3856 !player[k].rightkeydown&&
3857 !player[k].forwardkeydown)
3858 player[k].targetanimation=staffhitanim;
3860 else if(distance<4.5*sq(player[k].scale*5)&&
3861 animation[player[i].targetanimation].height!=lowheight&&
3862 !player[k].crouchkeydown&&
3863 attackweapon==staff&&
3864 player[k].weaponmissdelay<=0)
3865 player[k].targetanimation=staffspinhitanim;
3867 else if(distance<2.5*sq(player[k].scale*5)&&
3868 animation[player[i].targetanimation].height!=lowheight)
3869 player[k].targetanimation=spinkickanim;
3871 else if(distance<2.5*sq(player[k].scale*5)&&
3872 animation[player[i].targetanimation].height==lowheight&&
3873 animation[player[k].targetanimation].attack!=normalattack)
3874 player[k].targetanimation=lowkickanim;
3875 } else { //AI player
3876 if(distance<4.5*sq(player[k].scale*5)){
3877 randattack=abs(Random()%5);
3878 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3880 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3881 player[k].targetanimation=sweepanim;
3883 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3885 player[k].targetanimation=upunchanim;
3887 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3888 player[k].targetanimation=spinkickanim;
3890 else if(animation[player[i].targetanimation].height==lowheight)
3891 player[k].targetanimation=lowkickanim;
3895 if((tutoriallevel!=1||!attackweapon)&&
3896 distance<2.5*sq(player[k].scale*5)&&
3898 animation[player[i].targetanimation].height!=lowheight)
3899 player[k].targetanimation=sweepanim;
3901 else if(distance<2.5*sq(player[k].scale*5)&&
3902 attackweapon==knife&&
3903 player[k].weaponmissdelay<=0)
3904 player[k].targetanimation=knifeslashstartanim;
3906 else if(!(player[0].victim==&player[i]&&
3907 player[0].hasvictim&&
3908 player[0].targetanimation==swordslashanim)&&
3909 attackweapon==sword&&
3910 player[k].weaponmissdelay<=0)
3911 player[k].targetanimation=swordslashanim;
3913 else if(!(player[0].victim==&player[i]&&
3914 player[0].hasvictim&&
3915 player[0].targetanimation==swordslashanim)&&
3916 attackweapon==staff&&
3917 player[k].weaponmissdelay<=0&&
3919 player[k].targetanimation=staffhitanim;
3921 else if(!(player[0].victim==&player[i]&&
3922 player[0].hasvictim&&
3923 player[0].targetanimation==swordslashanim)&&
3924 attackweapon==staff&&
3925 player[k].weaponmissdelay<=0&&
3927 player[k].targetanimation=staffspinhitanim;
3929 else if((tutoriallevel!=1||!attackweapon)&&
3930 distance<2.5*sq(player[k].scale*5)&&
3932 animation[player[i].targetanimation].height!=lowheight)
3933 player[k].targetanimation=spinkickanim;
3935 else if(distance<2.5*sq(player[k].scale*5)&&
3936 animation[player[i].targetanimation].height==lowheight&&
3937 animation[player[k].targetanimation].attack!=normalattack)
3938 player[k].targetanimation=lowkickanim;
3942 //upunch becomes wolfslap
3943 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
3944 player[k].targetanimation=wolfslapanim;
3947 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
3948 player[i].howactive<typedead1&&
3949 distance<1.5*sq(player[k].scale*5)&&
3950 !player[i].skeleton.free&&
3951 player[i].targetanimation!=getupfrombackanim&&
3952 player[i].targetanimation!=getupfromfrontanim&&
3953 (player[i].stunned>0&&player[k].madskills||
3954 player[i].surprised>0||
3955 player[i].aitype==passivetype||
3956 attackweapon&&player[i].stunned>0)&&
3957 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
3960 player[k].currentanimation=sneakattackanim;
3961 player[k].targetanimation=sneakattackanim;
3962 player[i].currentanimation=sneakattackedanim;
3963 player[i].targetanimation=sneakattackedanim;
3964 player[k].oldcoords=player[k].coords;
3965 player[k].coords=player[i].coords;
3968 if(attackweapon==knife){
3969 player[k].currentanimation=knifesneakattackanim;
3970 player[k].targetanimation=knifesneakattackanim;
3971 player[i].currentanimation=knifesneakattackedanim;
3972 player[i].targetanimation=knifesneakattackedanim;
3973 player[i].oldcoords=player[i].coords;
3974 player[i].coords=player[k].coords;
3977 if(attackweapon==sword){
3978 player[k].currentanimation=swordsneakattackanim;
3979 player[k].targetanimation=swordsneakattackanim;
3980 player[i].currentanimation=swordsneakattackedanim;
3981 player[i].targetanimation=swordsneakattackedanim;
3982 player[i].oldcoords=player[i].coords;
3983 player[i].coords=player[k].coords;
3985 if(attackweapon!=staff){
3986 player[k].victim=&player[i];
3987 player[k].hasvictim=1;
3988 player[i].targettilt2=0;
3989 player[i].targetframe=1;
3990 player[i].currentframe=0;
3992 player[i].velocity=0;
3993 player[k].targettilt2=player[i].targettilt2;
3994 player[k].currentframe=player[i].currentframe;
3995 player[k].targetframe=player[i].targetframe;
3996 player[k].target=player[i].target;
3997 player[k].velocity=0;
3998 player[k].targetrotation=player[i].rotation;
3999 player[k].rotation=player[i].rotation;
4000 player[i].targetrotation=player[i].rotation;
4003 if(animation[player[k].targetanimation].attack==normalattack&&
4004 player[k].victim==&player[i]&&
4005 (!player[i].skeleton.free)){
4007 player[k].targetframe=0;
4010 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4011 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4012 player[k].lastattack3=player[k].lastattack2;
4013 player[k].lastattack2=player[k].lastattack;
4014 player[k].lastattack=player[k].targetanimation;
4016 if(player[k].targetanimation==knifefollowanim&&
4017 player[k].victim==&player[i]){
4019 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4020 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4021 player[k].victim=&player[i];
4022 player[k].hasvictim=1;
4023 player[i].targetanimation=knifefollowedanim;
4024 player[i].currentanimation=knifefollowedanim;
4025 player[i].targettilt2=0;
4026 player[i].targettilt2=player[k].targettilt2;
4027 player[i].targetframe=1;
4028 player[i].currentframe=0;
4030 player[i].velocity=0;
4031 player[k].currentanimation=knifefollowanim;
4032 player[k].targetanimation=knifefollowanim;
4033 player[k].targettilt2=player[i].targettilt2;
4034 player[k].currentframe=player[i].currentframe;
4035 player[k].targetframe=player[i].targetframe;
4036 player[k].target=player[i].target;
4037 player[k].velocity=0;
4038 player[k].oldcoords=player[k].coords;
4039 player[i].coords=player[k].coords;
4040 player[i].targetrotation=player[k].targetrotation;
4041 player[i].rotation=player[k].targetrotation;
4042 player[k].rotation=player[k].targetrotation;
4043 player[i].rotation=player[k].targetrotation;
4047 const bool hasstaff=attackweapon==staff;
4048 if(k==0&&numplayers>1)
4049 for(int i=0;i<numplayers;i++){
4051 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4052 animation[player[k].targetanimation].attack==neutral){
4053 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4054 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4055 if(player[i].skeleton.free)
4056 if(distance<3.5*sq(player[k].scale*5)&&
4058 player[i].skeleton.longdead>1000||
4062 (player[i].skeleton.longdead>2000||
4063 player[i].damage>player[i].damagetolerance/8||
4064 player[i].bloodloss>player[i].damagetolerance/2)&&
4065 distance<1.5*sq(player[k].scale*5)))){
4066 player[k].victim=&player[i];
4067 player[k].hasvictim=1;
4068 if(attackweapon&&tutoriallevel!=1){
4070 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4071 player[k].targetanimation=crouchstabanim;
4073 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4074 player[k].targetanimation=swordgroundstabanim;
4076 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4077 player[k].targetanimation=staffgroundsmashanim;
4080 player[k].crouchkeydown&&
4081 player[k].targetanimation!=crouchstabanim&&
4084 player[i].skeleton.free&&
4085 player[i].skeleton.longdead>1000){
4086 player[k].targetanimation=killanim;
4087 //TODO: refactor this out, what does it do?
4088 for(int j=0;j<terrain.numdecals;j++){
4089 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4090 terrain.decalalivetime[j]<2)
4091 terrain.DeleteDecal(j);
4093 for(int l=0;l<objects.numobjects;l++){
4094 if(objects.model[l].type==decalstype)
4095 for(int j=0;j<objects.model[l].numdecals;j++){
4096 if((objects.model[l].decaltype[j]==blooddecal||
4097 objects.model[l].decaltype[j]==blooddecalslow)&&
4098 objects.model[l].decalalivetime[j]<2)
4099 objects.model[l].DeleteDecal(j);
4103 if(!player[i].dead||musictype!=2)
4105 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4106 player[k].staggerdelay<=0&&
4108 player[i].skeleton.longdead<300&&
4109 player[k].lastattack!=spinkickanim&&
4110 player[i].skeleton.free)&&
4111 (!player[i].dead||musictype!=stream_fighttheme)){
4112 player[k].targetanimation=dropkickanim;
4113 for(int j=0;j<terrain.numdecals;j++){
4114 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4115 terrain.decalalivetime[j]<2){
4116 terrain.DeleteDecal(j);
4119 for(int l=0;l<objects.numobjects;l++){
4120 if(objects.model[l].type==decalstype)
4121 for(int j=0;j<objects.model[l].numdecals;j++){
4122 if((objects.model[l].decaltype[j]==blooddecal||
4123 objects.model[l].decaltype[j]==blooddecalslow)&&
4124 objects.model[l].decalalivetime[j]<2){
4125 objects.model[l].DeleteDecal(j);
4131 if(animation[player[k].targetanimation].attack==normalattack&&
4132 player[k].victim==&player[i]&&
4133 (!player[i].skeleton.free||
4134 player[k].targetanimation==killanim||
4135 player[k].targetanimation==crouchstabanim||
4136 player[k].targetanimation==swordgroundstabanim||
4137 player[k].targetanimation==staffgroundsmashanim||
4138 player[k].targetanimation==dropkickanim)){
4140 player[k].targetframe=0;
4143 XYZ targetpoint=player[i].coords;
4144 if(player[k].targetanimation==crouchstabanim||
4145 player[k].targetanimation==swordgroundstabanim||
4146 player[k].targetanimation==staffgroundsmashanim){
4147 targetpoint+=(player[i].getJointFor(abdomen).position+
4148 player[i].getJointFor(neck).position)/2*
4151 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4152 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4154 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4155 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4158 if(player[k].targetanimation==staffgroundsmashanim)
4159 player[k].targettilt2+=10;
4161 player[k].lastattack3=player[k].lastattack2;
4162 player[k].lastattack2=player[k].lastattack;
4163 player[k].lastattack=player[k].targetanimation;
4165 if(player[k].targetanimation==swordgroundstabanim){
4166 player[k].targetrotation+=30;
4171 if(!player[k].hasvictim){
4173 for(int i=0;i<numplayers;i++){
4174 if(i==k||!(i==0||k==0))continue;
4175 if(!player[i].skeleton.free){
4176 if(player[k].hasvictim){
4177 if(findDistancefast(&player[k].coords,&player[i].coords)<
4178 findDistancefast(&player[k].coords,&player[k].victim->coords))
4179 player[k].victim=&player[i];
4181 player[k].victim=&player[i];
4182 player[k].hasvictim=1;
4187 if(player[k].aitype==playercontrolled)
4189 if(player[k].attackkeydown&&
4191 player[k].wasRun()&&
4192 ((player[k].hasvictim&&
4193 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4194 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4195 !player[k].victim->skeleton.free&&
4196 player[k].victim->targetanimation!=getupfrombackanim&&
4197 player[k].victim->targetanimation!=getupfromfrontanim&&
4198 animation[player[k].victim->targetanimation].height!=lowheight&&
4199 player[k].aitype!=playercontrolled&& //wat???
4200 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4201 player[k].rabbitkickenabled)||
4202 player[k].jumpkeydown)){
4204 player[k].setAnimation(rabbitkickanim);
4207 if(animation[player[k].targetanimation].attack&&k==0){
4209 switch(attackweapon){
4210 case 0: numunarmedattack++; break;
4211 case knife: numknifeattack++; break;
4212 case sword: numswordattack++; break;
4213 case staff: numstaffattack++; break;
4222 void Game::doPlayerCollisions(){
4223 static XYZ rotatetarget;
4224 static float collisionradius;
4226 for(int k=0;k<numplayers;k++)
4227 for(int i=k+1;i<numplayers;i++){
4228 //neither player is part of a reversal
4229 if((animation[player[i].targetanimation].attack!=reversed&&
4230 animation[player[i].targetanimation].attack!=reversal&&
4231 animation[player[k].targetanimation].attack!=reversed&&
4232 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4233 if((animation[player[i].currentanimation].attack!=reversed&&
4234 animation[player[i].currentanimation].attack!=reversal&&
4235 animation[player[k].currentanimation].attack!=reversed&&
4236 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4237 //neither is sleeping
4238 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4239 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4240 //in same patch, neither is climbing
4241 if(player[i].whichpatchx==player[k].whichpatchx&&
4242 player[i].whichpatchz==player[k].whichpatchz&&
4243 player[k].skeleton.oldfree==player[k].skeleton.free&&
4244 player[i].skeleton.oldfree==player[i].skeleton.free&&
4245 player[i].targetanimation!=climbanim&&
4246 player[i].targetanimation!=hanganim&&
4247 player[k].targetanimation!=climbanim&&
4248 player[k].targetanimation!=hanganim)
4249 //players are close (bounding box test)
4250 if(player[i].coords.y>player[k].coords.y-3)
4251 if(player[i].coords.y<player[k].coords.y+3)
4252 if(player[i].coords.x>player[k].coords.x-3)
4253 if(player[i].coords.x<player[k].coords.x+3)
4254 if(player[i].coords.z>player[k].coords.z-3)
4255 if(player[i].coords.z<player[k].coords.z+3){
4256 //spread fire from player to player
4257 if(findDistancefast(&player[i].coords,&player[k].coords)
4258 <3*sq((player[i].scale+player[k].scale)*2.5)){
4259 if(player[i].onfire||player[k].onfire){
4260 if(!player[i].onfire)player[i].CatchFire();
4261 if(!player[k].onfire)player[k].CatchFire();
4265 XYZ tempcoords1=player[i].coords;
4266 XYZ tempcoords2=player[k].coords;
4267 if(!player[i].skeleton.oldfree)
4268 tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale;
4269 if(!player[k].skeleton.oldfree)
4270 tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale;
4271 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4272 if(player[0].hasvictim)
4273 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4275 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4276 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4277 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4278 //jump down on a dead body
4281 if(player[0].targetanimation==jumpdownanim&&
4282 !player[0].skeleton.oldfree&&
4283 !player[0].skeleton.free&&
4284 player[l].skeleton.oldfree&&
4285 player[l].skeleton.free&&
4287 player[0].lastcollide<=0&&
4288 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4289 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4290 player[0].coords.y=player[l].coords.y;
4291 player[l].velocity=player[0].velocity;
4292 player[l].skeleton.free=0;
4293 player[l].rotation=0;
4294 player[l].RagDoll(0);
4295 player[l].DoDamage(20);
4297 player[l].skeleton.longdead=0;
4298 player[0].lastcollide=1;
4302 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4303 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4304 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4305 rotatetarget=player[k].velocity-player[i].velocity;
4306 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4307 player[i].skeleton.free)&&
4308 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4309 player[k].skeleton.free))
4310 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4311 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4312 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4314 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4315 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4316 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4317 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4318 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4320 if( (i!=0||player[i].skeleton.free)&&
4321 (k!=0||player[k].skeleton.free)||
4322 (animation[player[i].targetanimation].height==highheight&&
4323 animation[player[k].targetanimation].height==highheight)){
4324 if(tutoriallevel!=1){
4325 emit_sound_at(heavyimpactsound, player[i].coords);
4328 player[i].RagDoll(0);
4329 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4330 award_bonus(0, aimbonus);
4332 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4333 player[k].RagDoll(0);
4334 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4335 award_bonus(0, aimbonus); // Huh, again?
4337 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4339 for(int j=0;j<player[i].skeleton.num_joints;j++){
4340 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4342 for(int j=0;j<player[k].skeleton.num_joints;j++){
4343 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4348 if( (animation[player[i].targetanimation].attack==neutral||
4349 animation[player[i].targetanimation].attack==normalattack)&&
4350 (animation[player[k].targetanimation].attack==neutral||
4351 animation[player[k].targetanimation].attack==normalattack)){
4353 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4354 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4355 rotatetarget=player[k].coords-player[i].coords;
4356 Normalise(&rotatetarget);
4357 player[k].coords=(player[k].coords+player[i].coords)/2;
4358 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4359 *sq((player[i].scale+player[k].scale)*2.5);
4360 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4361 if(player[k].howactive==typeactive||hostile)
4362 if(player[k].isIdle()){
4363 if(player[k].howactive<typesleeping)
4364 player[k].setAnimation(player[k].getStop());
4365 else if(player[k].howactive==typesleeping)
4366 player[k].setAnimation(getupfromfrontanim);
4368 player[k].howactive=typeactive;
4370 if(player[i].howactive==typeactive||hostile)
4371 if(player[i].isIdle()){
4372 if(player[i].howactive<typesleeping)
4373 player[i].setAnimation(player[k].getStop());
4375 player[i].setAnimation(getupfromfrontanim);
4377 player[i].howactive=typeactive;
4380 //jump down on player
4382 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4383 !player[i].isCrouch()&&
4384 player[i].targetanimation!=rollanim&&
4385 !player[k].skeleton.oldfree&&!
4386 player[k].skeleton.free&&
4387 player[k].lastcollide<=0&&
4388 player[k].velocity.y<-10){
4389 player[i].velocity=player[k].velocity;
4390 player[k].velocity=player[k].velocity*-.5;
4391 player[k].velocity.y=player[i].velocity.y;
4392 player[i].DoDamage(20);
4393 player[i].RagDoll(0);
4394 player[k].lastcollide=1;
4395 award_bonus(k, AboveBonus);
4397 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4398 !player[k].isCrouch()&&
4399 player[k].targetanimation!=rollanim&&
4400 !player[i].skeleton.oldfree&&
4401 !player[i].skeleton.free&&
4402 player[i].lastcollide<=0&&
4403 player[i].velocity.y<-10){
4404 player[k].velocity=player[i].velocity;
4405 player[i].velocity=player[i].velocity*-.3;
4406 player[i].velocity.y=player[k].velocity.y;
4407 player[k].DoDamage(20);
4408 player[k].RagDoll(0);
4409 player[i].lastcollide=1;
4410 award_bonus(i, AboveBonus);
4416 player[i].CheckKick();
4417 player[k].CheckKick();
4423 void Game::doAI(int i){
4424 static bool connected;
4425 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4426 player[i].jumpclimb=0;
4427 //disable movement in editor
4429 player[i].stunned=1;
4432 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4433 player[0].coords.y>player[i].coords.y+2&&
4434 !player[0].onterrain)
4438 if(player[i].aitype==pathfindtype){
4439 if(player[i].finalpathfindpoint==-1){
4440 float closestdistance;
4446 for(int j=0;j<numpathpoints;j++)
4447 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4448 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4450 player[i].finaltarget=pathpoint[j];
4452 player[i].finalpathfindpoint=closest;
4453 for(int j=0;j<numpathpoints;j++)
4454 for(int k=0;k<numpathpointconnect[j];k++){
4455 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4456 if(sq(tempdist)<closestdistance)
4457 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4458 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4459 closestdistance=sq(tempdist);
4461 player[i].finaltarget=colpoint;
4464 player[i].finalpathfindpoint=closest;
4467 if(player[i].targetpathfindpoint==-1){
4468 float closestdistance;
4474 if(player[i].lastpathfindpoint==-1){
4475 for(int j=0;j<numpathpoints;j++){
4476 if(j!=player[i].lastpathfindpoint)
4477 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4478 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4482 player[i].targetpathfindpoint=closest;
4483 for(int j=0;j<numpathpoints;j++)
4484 if(j!=player[i].lastpathfindpoint)
4485 for(int k=0;k<numpathpointconnect[j];k++){
4486 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4487 if(sq(tempdist)<closestdistance){
4488 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4489 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4490 closestdistance=sq(tempdist);
4495 player[i].targetpathfindpoint=closest;
4499 for(int j=0;j<numpathpoints;j++)
4500 if(j!=player[i].lastpathfindpoint&&
4501 j!=player[i].lastpathfindpoint2&&
4502 j!=player[i].lastpathfindpoint3&&
4503 j!=player[i].lastpathfindpoint4){
4505 if(numpathpointconnect[j])
4506 for(int k=0;k<numpathpointconnect[j];k++)
4507 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4510 if(numpathpointconnect[player[i].lastpathfindpoint])
4511 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4512 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4515 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4516 if(closest==-1||tempdist<closestdistance){
4517 closestdistance=tempdist;
4522 player[i].targetpathfindpoint=closest;
4525 player[i].losupdatedelay-=multiplier;
4527 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4528 player[i].lookrotation=player[i].targetrotation;
4530 //reached target point
4531 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4532 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4533 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4534 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4535 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4536 if(player[i].lastpathfindpoint2==-1)
4537 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4538 if(player[i].lastpathfindpoint3==-1)
4539 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4540 if(player[i].lastpathfindpoint4==-1)
4541 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4542 player[i].targetpathfindpoint=-1;
4544 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4545 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4546 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4547 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4548 player[i].aitype=passivetype;
4551 player[i].forwardkeydown=1;
4552 player[i].leftkeydown=0;
4553 player[i].backkeydown=0;
4554 player[i].rightkeydown=0;
4555 player[i].crouchkeydown=0;
4556 player[i].attackkeydown=0;
4557 player[i].throwkeydown=0;
4559 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4560 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4562 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4563 player[i].jumpkeydown=0;
4564 if((player[i].collided>.8&&player[i].jumppower>=5))
4565 player[i].jumpkeydown=1;
4567 if((tutoriallevel!=1||cananger)&&
4570 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4571 player[i].occluded<25){
4572 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4573 animation[player[0].targetanimation].height!=lowheight&&
4575 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4576 player[i].aitype=attacktypecutoff;
4577 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4578 animation[player[0].targetanimation].height==highheight&&
4580 player[i].aitype=attacktypecutoff;
4582 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4583 player[i].losupdatedelay=.2;
4584 for(int j=0;j<numplayers;j++)
4585 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4586 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4587 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4588 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4589 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4590 if(!player[j].isWallJump()&&-1==checkcollide(
4591 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)
4592 *player[i].scale+player[i].coords,
4593 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)
4594 *player[j].scale+player[j].coords)||
4595 (player[j].targetanimation==hanganim&&
4596 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4597 player[i].aitype=searchtype;
4598 player[i].lastchecktime=12;
4599 player[i].lastseen=player[j].coords;
4600 player[i].lastseentime=12;
4604 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4605 if(player[i].creature!=wolftype){
4606 player[i].stunned=.6;
4607 player[i].surprised=.6;
4611 if(player[i].aitype!=passivetype&&leveltime>.5)
4612 player[i].howactive=typeactive;
4614 if(player[i].aitype==passivetype){
4615 player[i].aiupdatedelay-=multiplier;
4616 player[i].losupdatedelay-=multiplier;
4617 player[i].lastseentime+=multiplier;
4618 player[i].pausetime-=multiplier;
4619 if(player[i].lastseentime>1)
4620 player[i].lastseentime=1;
4622 if(player[i].aiupdatedelay<0){
4623 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4624 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4625 player[i].lookrotation=player[i].targetrotation;
4626 player[i].aiupdatedelay=.05;
4628 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4629 if(player[i].waypointtype[player[i].waypoint]==wppause)
4630 player[i].pausetime=4;
4631 player[i].waypoint++;
4632 if(player[i].waypoint>player[i].numwaypoints-1)
4633 player[i].waypoint=0;
4638 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4639 player[i].forwardkeydown=1;
4641 player[i].forwardkeydown=0;
4642 player[i].leftkeydown=0;
4643 player[i].backkeydown=0;
4644 player[i].rightkeydown=0;
4645 player[i].crouchkeydown=0;
4646 player[i].attackkeydown=0;
4647 player[i].throwkeydown=0;
4649 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4650 if(!player[i].avoidsomething)
4651 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4653 XYZ leftpos,rightpos;
4654 float leftdist,rightdist;
4655 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4656 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4657 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4658 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4659 if(leftdist<rightdist)
4660 player[i].targetrotation+=90;
4662 player[i].targetrotation-=90;
4666 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4667 player[i].jumpkeydown=0;
4668 if((player[i].collided>.8&&player[i].jumppower>=5))
4669 player[i].jumpkeydown=1;
4674 if(player[i].howactive<=typesleeping)
4675 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4676 for(int j=0;j<numenvsounds;j++){
4677 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4678 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4679 2*(vol+vol*(player[i].creature==rabbittype)*3))
4680 player[i].aitype=attacktypecutoff;
4683 if(player[i].aitype!=passivetype){
4684 if(player[i].howactive==typesleeping)
4685 player[i].setAnimation(getupfromfrontanim);
4686 player[i].howactive=typeactive;
4690 if(player[i].howactive<typesleeping&&
4691 ((tutoriallevel!=1||cananger)&&hostile)&&
4693 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4694 player[i].occluded<25){
4695 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4696 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4697 player[i].aitype=attacktypecutoff;
4698 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4699 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4700 player[i].aitype=attacktypecutoff;
4703 if(player[i].creature==wolftype){
4705 for(int j=0;j<numplayers;j++){
4706 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4707 float smelldistance=50;
4708 if(j==0&&player[j].num_weapons>0){
4709 if(weapons[player[j].weaponids[0]].bloody)
4711 if(player[j].num_weapons==2)
4712 if(weapons[player[j].weaponids[1]].bloody)
4717 windsmell=windvector;
4718 Normalise(&windsmell);
4719 windsmell=windsmell*2+player[j].coords;
4720 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4721 player[i].aitype=attacktypecutoff;
4726 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4727 player[i].losupdatedelay=.2;
4728 for(int j=0;j<numplayers;j++){
4729 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4730 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4731 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4732 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4733 if((-1==checkcollide(
4734 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4735 player[i].scale+player[i].coords,
4736 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*
4737 player[j].scale+player[j].coords)&&
4738 !player[j].isWallJump())||
4739 (player[j].targetanimation==hanganim&&
4740 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4741 player[i].lastseentime-=.2;
4742 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4743 player[i].lastseentime-=.4;
4745 player[i].lastseentime-=.6;
4747 if(player[i].lastseentime<=0){
4748 player[i].aitype=searchtype;
4749 player[i].lastchecktime=12;
4750 player[i].lastseen=player[j].coords;
4751 player[i].lastseentime=12;
4758 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4759 if(player[i].creature!=wolftype){
4760 player[i].stunned=.6;
4761 player[i].surprised=.6;
4763 if(player[i].creature==wolftype){
4764 player[i].stunned=.47;
4765 player[i].surprised=.47;
4773 if(player[i].aitype==searchtype){
4774 player[i].aiupdatedelay-=multiplier;
4775 player[i].losupdatedelay-=multiplier;
4776 if(!player[i].pause)
4777 player[i].lastseentime-=multiplier;
4778 player[i].lastchecktime-=multiplier;
4780 if(player[i].isRun()&&!player[i].onground){
4781 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4782 XYZ test2=player[i].coords+player[i].facing;
4784 XYZ test=player[i].coords+player[i].facing;
4786 j=checkcollide(test2,test,player[i].laststanding);
4788 j=checkcollide(test2,test);
4790 player[i].velocity=0;
4791 player[i].setAnimation(player[i].getStop());
4792 player[i].targetrotation+=180;
4793 player[i].stunned=.5;
4794 //player[i].aitype=passivetype;
4795 player[i].aitype=pathfindtype;
4796 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4797 player[i].finalpathfindpoint=-1;
4798 player[i].targetpathfindpoint=-1;
4799 player[i].lastpathfindpoint=-1;
4800 player[i].lastpathfindpoint2=-1;
4801 player[i].lastpathfindpoint3=-1;
4802 player[i].lastpathfindpoint4=-1;
4804 else player[i].laststanding=j;
4807 //check out last seen location
4808 if(player[i].aiupdatedelay<0){
4809 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4810 player[i].lookrotation=player[i].targetrotation;
4811 player[i].aiupdatedelay=.05;
4812 player[i].forwardkeydown=1;
4814 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4815 player[i].forwardkeydown=0;
4816 player[i].aiupdatedelay=1;
4817 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4818 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4819 player[i].lastchecktime=3;
4822 player[i].leftkeydown=0;
4823 player[i].backkeydown=0;
4824 player[i].rightkeydown=0;
4825 player[i].crouchkeydown=0;
4826 player[i].attackkeydown=0;
4827 player[i].throwkeydown=0;
4829 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4830 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4832 XYZ leftpos,rightpos;
4833 float leftdist,rightdist;
4834 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4835 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4836 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4837 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4838 if(leftdist<rightdist)player[i].targetrotation+=90;
4839 else player[i].targetrotation-=90;
4843 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4844 player[i].jumpkeydown=0;
4845 if((player[i].collided>.8&&player[i].jumppower>=5))
4846 player[i].jumpkeydown=1;
4848 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4849 for(int k=0;k<numenvsounds;k++){
4850 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4851 player[i].aitype=attacktypecutoff;
4855 if(!player[0].dead&&
4856 player[i].losupdatedelay<0&&
4858 player[i].occluded<2&&
4859 ((tutoriallevel!=1||cananger)&&hostile)){
4860 player[i].losupdatedelay=.2;
4861 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4862 player[i].aitype=attacktypecutoff;
4863 player[i].lastseentime=1;
4865 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4866 //TODO: factor out canSeePlayer()
4867 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4868 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4870 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4871 player[i].scale+player[i].coords,
4872 DoRotation(player[0].getJointFor(head).position,0,player[0].rotation,0)*
4873 player[0].scale+player[0].coords)==-1)||
4874 (player[0].targetanimation==hanganim&&normaldotproduct(
4875 player[0].facing,player[i].coords-player[0].coords)<0)){
4876 /* //TODO: changed j to 0 on a whim, make sure this is correct
4877 (player[j].targetanimation==hanganim&&normaldotproduct(
4878 player[j].facing,player[i].coords-player[j].coords)<0)
4880 player[i].aitype=attacktypecutoff;
4881 player[i].lastseentime=1;
4885 if(player[i].lastseentime<0){
4886 //player[i].aitype=passivetype;
4888 player[i].aitype=pathfindtype;
4889 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4890 player[i].finalpathfindpoint=-1;
4891 player[i].targetpathfindpoint=-1;
4892 player[i].lastpathfindpoint=-1;
4893 player[i].lastpathfindpoint2=-1;
4894 player[i].lastpathfindpoint3=-1;
4895 player[i].lastpathfindpoint4=-1;
4899 if(player[i].aitype!=gethelptype)
4900 player[i].runninghowlong=0;
4902 //get help from buddies
4903 if(player[i].aitype==gethelptype) {
4904 player[i].runninghowlong+=multiplier;
4905 player[i].aiupdatedelay-=multiplier;
4907 if(player[i].aiupdatedelay<0||player[i].ally==0) {
4908 player[i].aiupdatedelay=.2;
4911 //TODO: factor out closest search somehow
4912 if(!player[i].ally) {
4914 float closestdist=-1;
4915 for(int k=0;k<numplayers;k++) {
4916 if(k!=i&&k!=0&&!player[k].dead&&
4917 player[k].howactive<typedead1&&
4918 !player[k].skeleton.free&&
4919 player[k].aitype==passivetype) {
4920 float distance=findDistancefast(&player[i].coords,&player[k].coords);
4921 if(closestdist==-1||distance<closestdist) {
4922 closestdist=distance;
4929 player[i].ally=closest;
4932 player[i].lastseen=player[0].coords;
4933 player[i].lastseentime=12;
4937 player[i].lastchecktime=12;
4939 XYZ facing=player[i].coords;
4940 XYZ flatfacing=player[player[i].ally].coords;
4941 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
4942 flatfacing.y+=player[player[i].ally].getJointFor(head).position.y*player[player[i].ally].scale;
4943 if(-1!=checkcollide(facing,flatfacing))
4944 player[i].lastseentime-=.1;
4946 //no available ally, run back to player
4947 if(player[i].ally<=0||
4948 player[player[i].ally].skeleton.free||
4949 player[player[i].ally].aitype!=passivetype||
4950 player[i].lastseentime<=0){
4951 player[i].aitype=searchtype;
4952 player[i].lastseentime=12;
4956 if(player[i].ally>0){
4957 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
4958 player[i].lookrotation=player[i].targetrotation;
4959 player[i].aiupdatedelay=.05;
4960 player[i].forwardkeydown=1;
4962 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
4963 player[i].aitype=searchtype;
4964 player[i].lastseentime=12;
4965 player[player[i].ally].aitype=searchtype;
4966 if(player[player[i].ally].lastseentime<player[i].lastseentime){
4967 player[player[i].ally].lastseen=player[i].lastseen;
4968 player[player[i].ally].lastseentime=player[i].lastseentime;
4969 player[player[i].ally].lastchecktime=player[i].lastchecktime;
4973 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4974 if(!player[i].avoidsomething)
4975 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4977 XYZ leftpos,rightpos;
4978 float leftdist,rightdist;
4979 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4980 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4981 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4982 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4983 if(leftdist<rightdist)
4984 player[i].targetrotation+=90;
4986 player[i].targetrotation-=90;
4991 player[i].leftkeydown=0;
4992 player[i].backkeydown=0;
4993 player[i].rightkeydown=0;
4994 player[i].crouchkeydown=0;
4995 player[i].attackkeydown=0;
4997 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4998 player[i].jumpkeydown=0;
4999 if(player[i].collided>.8&&player[i].jumppower>=5)
5000 player[i].jumpkeydown=1;
5003 //retreiving a weapon on the ground
5004 if(player[i].aitype==getweapontype){
5005 player[i].aiupdatedelay-=multiplier;
5006 player[i].lastchecktime-=multiplier;
5008 if(player[i].aiupdatedelay<0){
5009 player[i].aiupdatedelay=.2;
5012 if(player[i].ally<0){
5014 float closestdist=-1;
5015 for(int k=0;k<weapons.size();k++)
5016 if(weapons[k].owner==-1){
5017 float distance=findDistancefast(&player[i].coords,&weapons[k].position);
5018 if(closestdist==-1||distance<closestdist){
5019 closestdist=distance;
5025 player[i].ally=closest;
5030 player[i].lastseentime=12;
5032 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5033 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5034 player[i].aitype=attacktypecutoff;
5035 player[i].lastseentime=1;
5038 if(player[i].ally>=0){
5039 if(weapons[player[i].ally].owner!=-1||
5040 findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
5041 player[i].aitype=attacktypecutoff;
5042 player[i].lastseentime=1;
5044 //TODO: factor these out as moveToward()
5045 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5046 player[i].lookrotation=player[i].targetrotation;
5047 player[i].aiupdatedelay=.05;
5048 player[i].forwardkeydown=1;
5051 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5052 if(!player[i].avoidsomething)
5053 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5055 XYZ leftpos,rightpos;
5056 float leftdist,rightdist;
5057 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5058 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5059 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5060 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5061 if(leftdist<rightdist)
5062 player[i].targetrotation+=90;
5064 player[i].targetrotation-=90;
5069 player[i].leftkeydown=0;
5070 player[i].backkeydown=0;
5071 player[i].rightkeydown=0;
5072 player[i].attackkeydown=0;
5073 player[i].throwkeydown=1;
5074 player[i].crouchkeydown=0;
5075 if(player[i].targetanimation!=crouchremoveknifeanim&&
5076 player[i].targetanimation!=removeknifeanim)
5077 player[i].throwtogglekeydown=0;
5078 player[i].drawkeydown=0;
5080 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5081 player[i].jumpkeydown=0;
5082 if((player[i].collided>.8&&player[i].jumppower>=5))
5083 player[i].jumpkeydown=1;
5086 if(player[i].aitype==attacktypecutoff){
5087 player[i].aiupdatedelay-=multiplier;
5088 //dodge or reverse rabbit kicks, knife throws, flips
5089 if(player[i].damage<player[i].damagetolerance*2/3)
5090 if((player[0].targetanimation==rabbitkickanim||
5091 player[0].targetanimation==knifethrowanim||
5092 (player[0].isFlip()&&
5093 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5094 !player[0].skeleton.free&&
5095 (player[i].aiupdatedelay<.1)){
5096 player[i].attackkeydown=0;
5097 if(player[i].isIdle())
5098 player[i].crouchkeydown=1;
5099 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5100 if(weapons[player[0].weaponids[0]].getType()==knife){
5101 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5102 if(abs(Random()%2==0))
5103 player[i].setAnimation(backhandspringanim);
5105 player[i].setAnimation(rollanim);
5106 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5107 player[i].wentforweapon=0;
5109 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5110 player[i].setAnimation(flipanim);
5113 player[i].forwardkeydown=0;
5114 player[i].aiupdatedelay=.02;
5116 //get confused by flips
5117 if(player[0].isFlip()&&
5118 !player[0].skeleton.free&&
5119 player[0].targetanimation!=walljumprightkickanim&&
5120 player[0].targetanimation!=walljumpleftkickanim){
5121 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5122 if((1-player[i].damage/player[i].damagetolerance)>.5)
5123 player[i].stunned=1;
5125 //go for weapon on the ground
5126 if(player[i].wentforweapon<3)
5127 for(int k=0;k<weapons.size();k++)
5128 if(player[i].creature!=wolftype)
5129 if(player[i].num_weapons==0&&
5130 weapons[k].owner==-1&&
5131 weapons[i].velocity.x==0&&
5132 weapons[i].velocity.z==0&&
5133 weapons[i].velocity.y==0){
5134 if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
5135 player[i].wentforweapon++;
5136 player[i].lastchecktime=6;
5137 player[i].aitype=getweapontype;
5141 //dodge/reverse walljump kicks
5142 if(player[i].damage<player[i].damagetolerance/2)
5143 if(animation[player[i].targetanimation].height!=highheight)
5144 if(player[i].damage<player[i].damagetolerance*.5&&
5145 ((player[0].targetanimation==walljumprightkickanim||
5146 player[0].targetanimation==walljumpleftkickanim)&&
5147 ((player[i].aiupdatedelay<.15&&
5149 (player[i].aiupdatedelay<.08&&
5151 player[i].crouchkeydown=1;
5153 //walked off a ledge (?)
5154 if(player[i].isRun()&&!player[i].onground)
5155 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5156 XYZ test2=player[i].coords+player[i].facing;
5158 XYZ test=player[i].coords+player[i].facing;
5160 j=checkcollide(test2,test,player[i].laststanding);
5162 j=checkcollide(test2,test);
5164 player[i].velocity=0;
5165 player[i].setAnimation(player[i].getStop());
5166 player[i].targetrotation+=180;
5167 player[i].stunned=.5;
5168 player[i].aitype=pathfindtype;
5169 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5170 player[i].finalpathfindpoint=-1;
5171 player[i].targetpathfindpoint=-1;
5172 player[i].lastpathfindpoint=-1;
5173 player[i].lastpathfindpoint2=-1;
5174 player[i].lastpathfindpoint3=-1;
5175 player[i].lastpathfindpoint4=-1;
5177 player[i].laststanding=j;
5179 //lose sight of player in the air (?)
5180 if(player[0].coords.y>player[i].coords.y+5&&
5181 animation[player[0].targetanimation].height!=highheight&&
5182 !player[0].onterrain){
5183 player[i].aitype=pathfindtype;
5184 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5185 player[i].finalpathfindpoint=-1;
5186 player[i].targetpathfindpoint=-1;
5187 player[i].lastpathfindpoint=-1;
5188 player[i].lastpathfindpoint2=-1;
5189 player[i].lastpathfindpoint3=-1;
5190 player[i].lastpathfindpoint4=-1;
5192 //it's time to think (?)
5193 if(player[i].aiupdatedelay<0&&
5194 !animation[player[i].targetanimation].attack&&
5195 player[i].targetanimation!=staggerbackhighanim&&
5196 player[i].targetanimation!=staggerbackhardanim&&
5197 player[i].targetanimation!=backhandspringanim&&
5198 player[i].targetanimation!=dodgebackanim){
5200 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5201 player[i].drawkeydown=Random()%2;
5203 player[i].drawkeydown=0;
5204 player[i].rabbitkickenabled=Random()%2;
5206 XYZ rotatetarget=player[0].coords+player[0].velocity;
5207 XYZ targetpoint=player[0].coords;
5208 if(findDistancefast(&player[0].coords,&player[i].coords)<
5209 findDistancefast(&rotatetarget,&player[i].coords))
5210 targetpoint+=player[0].velocity*
5211 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5212 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5213 player[i].lookrotation=player[i].targetrotation;
5214 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5216 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5217 player[i].forwardkeydown=1;
5218 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5219 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5220 player[0].weaponactive!=-1)
5221 player[i].forwardkeydown=1;
5222 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5223 player[i].forwardkeydown=1;
5225 player[i].forwardkeydown=0;
5226 //chill out around the corpse
5228 player[i].forwardkeydown=0;
5230 player[i].forwardkeydown=1;
5231 if(Random()%100==0){
5232 player[i].aitype=pathfindtype;
5233 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5234 player[i].finalpathfindpoint=-1;
5235 player[i].targetpathfindpoint=-1;
5236 player[i].lastpathfindpoint=-1;
5237 player[i].lastpathfindpoint2=-1;
5238 player[i].lastpathfindpoint3=-1;
5239 player[i].lastpathfindpoint4=-1;
5242 player[i].leftkeydown=0;
5243 player[i].backkeydown=0;
5244 player[i].rightkeydown=0;
5245 player[i].crouchkeydown=0;
5246 player[i].throwkeydown=0;
5248 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5249 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5251 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5252 player[i].attackkeydown=1;
5254 player[i].attackkeydown=0;
5255 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5256 player[i].attackkeydown=0;
5259 if(player[i].aitype!=playercontrolled&&
5260 (player[i].isIdle()||
5261 player[i].isCrouch()||
5262 player[i].isRun())){
5264 for(int j=0;j<numplayers;j++)
5265 if(j!=i&&!player[j].skeleton.free&&
5266 player[j].hasvictim&&
5267 (tutoriallevel==1&&reversaltrain||
5268 Random()%2==0&&difficulty==2||
5269 Random()%4==0&&difficulty==1||
5270 Random()%8==0&&difficulty==0||
5271 player[j].lastattack2==player[j].targetanimation&&
5272 player[j].lastattack3==player[j].targetanimation&&
5273 (Random()%2==0||difficulty==2)||
5274 (player[i].isIdle()||player[i].isRun())&&
5275 player[j].weaponactive!=-1||
5276 player[j].targetanimation==swordslashanim&&
5277 player[i].weaponactive!=-1||
5278 player[j].targetanimation==staffhitanim||
5279 player[j].targetanimation==staffspinhitanim))
5280 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5281 player[j].victim==&player[i]&&
5282 (player[j].targetanimation==sweepanim||
5283 player[j].targetanimation==spinkickanim||
5284 player[j].targetanimation==staffhitanim||
5285 player[j].targetanimation==staffspinhitanim||
5286 player[j].targetanimation==winduppunchanim||
5287 player[j].targetanimation==upunchanim||
5288 player[j].targetanimation==wolfslapanim||
5289 player[j].targetanimation==knifeslashstartanim||
5290 player[j].targetanimation==swordslashanim&&
5291 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5292 player[i].weaponactive!=-1))){
5299 player[target].Reverse();
5302 if(player[i].collided<1)
5303 player[i].jumpkeydown=0;
5304 if(player[i].collided>.8&&player[i].jumppower>=5||
5305 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5306 player[i].onterrain&&
5307 player[i].creature==rabbittype)
5308 player[i].jumpkeydown=1;
5309 //TODO: why are we controlling the human?
5310 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5311 player[0].jumpkeydown=0;
5312 if(player[0].targetanimation==jumpdownanim&&
5313 findDistancefast(&player[0].coords,&player[i].coords)<40)
5314 player[i].crouchkeydown=1;
5315 if(player[i].jumpkeydown)
5316 player[i].attackkeydown=0;
5318 if(tutoriallevel==1)
5320 player[i].attackkeydown=0;
5323 XYZ facing=player[i].coords;
5324 XYZ flatfacing=player[0].coords;
5325 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
5326 flatfacing.y+=player[0].getJointFor(head).position.y*player[0].scale;
5327 if(player[i].occluded>=2)
5328 if(-1!=checkcollide(facing,flatfacing)){
5329 if(!player[i].pause)
5330 player[i].lastseentime-=.2;
5331 if(player[i].lastseentime<=0&&
5332 (player[i].creature!=wolftype||
5333 player[i].weaponstuck==-1)){
5334 player[i].aitype=searchtype;
5335 player[i].lastchecktime=12;
5336 player[i].lastseen=player[0].coords;
5337 player[i].lastseentime=12;
5340 player[i].lastseentime=1;
5343 if(animation[player[0].targetanimation].height==highheight&&
5344 (player[i].aitype==attacktypecutoff||
5345 player[i].aitype==searchtype))
5346 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5347 XYZ test=player[0].coords;
5349 if(-1==checkcollide(player[0].coords,test))
5350 player[i].stunned=1;
5353 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5354 player[i].stunned>0||
5355 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5357 player[i].lastseentime=1;
5358 player[i].targetrotation=player[i].rotation;
5359 player[i].forwardkeydown=0;
5360 player[i].leftkeydown=0;
5361 player[i].backkeydown=0;
5362 player[i].rightkeydown=0;
5363 player[i].jumpkeydown=0;
5364 player[i].attackkeydown=0;
5365 player[i].crouchkeydown=0;
5366 player[i].throwkeydown=0;
5374 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5377 if(player[i].aitype==attacktypecutoff){
5378 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5379 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5380 }else if(player[i].howactive>=typesleeping){
5381 player[i].targetheadrotation=player[i].targetrotation;
5382 player[i].targetheadrotation2=0;
5384 if(player[i].interestdelay<=0){
5385 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5386 player[i].headtarget=player[i].coords;
5387 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5388 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5389 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5390 player[i].headtarget+=player[i].facing*1.5;
5392 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5393 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5400 void updateSettingsMenu(){
5402 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)
5403 sprintf (sbuf, "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
5405 sprintf (sbuf, "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
5406 Menu::setText(0,sbuf);
5407 if(newdetail==0) Menu::setText(1,"Detail: Low");
5408 if(newdetail==1) Menu::setText(1,"Detail: Medium");
5409 if(newdetail==2) Menu::setText(1,"Detail: High");
5410 if(bloodtoggle==0) Menu::setText(2,"Blood: Off");
5411 if(bloodtoggle==1) Menu::setText(2,"Blood: On, low detail");
5412 if(bloodtoggle==2) Menu::setText(2,"Blood: On, high detail (slower)");
5413 if(difficulty==0) Menu::setText(3,"Difficulty: Easier");
5414 if(difficulty==1) Menu::setText(3,"Difficulty: Difficult");
5415 if(difficulty==2) Menu::setText(3,"Difficulty: Insane");
5416 Menu::setText(4,ismotionblur?"Blur Effects: Enabled (less compatible)":"Blur Effects: Disabled (more compatible)");
5417 Menu::setText(5,decals?"Decals: Enabled (slower)":"Decals: Disabled");
5418 Menu::setText(6,musictoggle?"Music: Enabled":"Music: Disabled");
5419 Menu::setText(9,invertmouse?"Invert mouse: Yes":"Invert mouse: No");
5420 sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity*5));
5421 Menu::setText(10,sbuf);
5422 sprintf (sbuf, "Volume: %d%%", (int)(volume*100));
5423 Menu::setText(11,sbuf);
5424 Menu::setText(13,showdamagebar?"Damage Bar: On":"Damage Bar: Off");
5425 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)
5426 sprintf (sbuf, "Back");
5428 sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)");
5429 Menu::setText(8,sbuf);
5432 void updateStereoConfigMenu(){
5434 sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode));
5435 Menu::setText(0,sbuf);
5436 sprintf(sbuf, "Stereo separation: %.3f", stereoseparation);
5437 Menu::setText(1,sbuf);
5438 sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
5439 Menu::setText(2,sbuf);
5442 void updateControlsMenu(){
5443 Menu::setText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey)));
5444 Menu::setText(1,(string)"Back: " +(keyselect==1?"_":Input::keyToChar(backkey)));
5445 Menu::setText(2,(string)"Left: " +(keyselect==2?"_":Input::keyToChar(leftkey)));
5446 Menu::setText(3,(string)"Right: " +(keyselect==3?"_":Input::keyToChar(rightkey)));
5447 Menu::setText(4,(string)"Crouch: " +(keyselect==4?"_":Input::keyToChar(crouchkey)));
5448 Menu::setText(5,(string)"Jump: " +(keyselect==5?"_":Input::keyToChar(jumpkey)));
5449 Menu::setText(6,(string)"Draw: " +(keyselect==6?"_":Input::keyToChar(drawkey)));
5450 Menu::setText(7,(string)"Throw: " +(keyselect==7?"_":Input::keyToChar(throwkey)));
5451 Menu::setText(8,(string)"Attack: " +(keyselect==8?"_":Input::keyToChar(attackkey)));
5453 Menu::setText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey)));
5457 Values of mainmenu :
5459 2 Menu pause (resume/end game)
5461 4 Controls configuration menu
5462 5 Main game menu (choose level or challenge)
5463 6 Deleting user menu
5464 7 User managment menu (select/add)
5465 8 Choose difficulty menu
5466 9 Challenge level selection menu
5467 10 End of the campaign congratulation (is that really a menu?)
5468 11 Same that 9 ??? => unused
5469 18 stereo configuration
5472 void Game::LoadMenu(){
5477 Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128);
5478 Menu::addButtonImage(1,Mainmenuitems[mainmenu==1?1:5],18,480-152-32,128,32);
5479 Menu::addButtonImage(2,Mainmenuitems[2],18,480-228-32,112,32);
5480 Menu::addButtonImage(3,Mainmenuitems[mainmenu==1?3:6],18,480-306-32,mainmenu==1?68:132,32);
5483 Menu::addButton( 0,"",10+20,440);
5484 Menu::addButton( 1,"",10+60,405);
5485 Menu::addButton( 2,"",10+70,370);
5486 Menu::addButton( 3,"",10+20-1000,335-1000);
5487 Menu::addButton( 4,"",10 ,335);
5488 Menu::addButton( 5,"",10+60,300);
5489 Menu::addButton( 6,"",10+70,265);
5490 Menu::addButton( 9,"",10 ,230);
5491 Menu::addButton(10,"",20 ,195);
5492 Menu::addButton(11,"",10+60,160);
5493 Menu::addButton(13,"",30 ,125);
5494 Menu::addButton( 7,"-Configure Controls-",10+15, 90);
5495 Menu::addButton(12,"-Configure Stereo -",10+15, 55);
5496 Menu::addButton(8,"Back",10,10);
5497 updateSettingsMenu();
5500 Menu::addButton(0,"",10 ,400);
5501 Menu::addButton(1,"",10+40,360);
5502 Menu::addButton(2,"",10+40,320);
5503 Menu::addButton(3,"",10+30,280);
5504 Menu::addButton(4,"",10+20,240);
5505 Menu::addButton(5,"",10+40,200);
5506 Menu::addButton(6,"",10+40,160);
5507 Menu::addButton(7,"",10+30,120);
5508 Menu::addButton(8,"",10+20,80);
5510 Menu::addButton(9,"",10+10,40);
5511 Menu::addButton(debugmode?10:9,"Back",10,10);
5512 updateControlsMenu();
5516 Menu::addLabel(-1,accountactive->getName(),5,400);
5517 Menu::addButton(1,"Tutorial",5,300);
5518 Menu::addButton(2,"Challenge",5,240);
5519 Menu::addButton(3,"Delete User",400,10);
5520 Menu::addButton(4,"Main Menu",5,10);
5521 Menu::addButton(5,"Change User",5,180);
5522 Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),200,420);
5525 //with (2,-5) offset from old code
5526 Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400);
5528 int numlevels = accountactive->getCampaignChoicesMade();
5529 numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1;
5530 for(int i=0;i<numlevels;i++){
5531 XYZ midpoint=campaignlevels[i].getCenter();
5532 float itemsize=campaignlevels[i].getWidth();
5533 const bool active=i>=accountactive->getCampaignChoicesMade();
5538 XYZ start=campaignlevels[i-1].getCenter();
5539 Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0);
5541 Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture,
5542 midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0);
5545 Menu::addMapLabel(-2,campaignlevels[i].description,
5546 campaignlevels[i].getStartX()+10,
5547 campaignlevels[i].getStartY()-4);
5552 Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400);
5553 Menu::addButton(1,"Yes",10,360);
5554 Menu::addButton(2,"No",10,320);
5557 if(Account::getNbAccounts()<8)
5558 Menu::addButton(0,"New User",10,400);
5560 Menu::addLabel(0,"No More Users",10,400);
5561 Menu::addLabel(-2,"",20,400);
5562 Menu::addButton(Account::getNbAccounts()+1,"Back",10,10);
5563 for(int i=0;i<Account::getNbAccounts();i++)
5564 Menu::addButton(i+1,Account::get(i)->getName(),10,340-20*(i+1));
5567 Menu::addButton(0,"Easier",10,400);
5568 Menu::addButton(1,"Difficult",10,360);
5569 Menu::addButton(2,"Insane",10,320);
5572 for(int i=0;i<numchallengelevels;i++){
5575 sprintf (temp, "Level %d",i+1);
5576 for(int j=strlen(temp);j<17;j++)
5579 sprintf (temp, "%d",(int)accountactive->getHighScore(i));
5580 for(int j=strlen(temp);j<(32-17);j++)
5583 sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60));
5584 if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0");
5586 sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60);
5589 Menu::addButton(i,name,10,400-i*25,i>accountactive->getProgress()?0.5:1,0,0);
5592 Menu::addButton(-1," High Score Best Time",10,440);
5593 Menu::addButton(numchallengelevels,"Back",10,10);
5596 Menu::addLabel(0,"Congratulations!",220,330);
5597 Menu::addLabel(1,"You have avenged your family and",140,300);
5598 Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270);
5599 Menu::addButton(3,"Back",10,10);
5601 sprintf(sbuf,"Your score: %d",(int)accountactive->getCampaignScore());
5602 Menu::addLabel(4,sbuf,190,200);
5603 sprintf(sbuf,"Highest score: %d",(int)accountactive->getCampaignHighScore());
5604 Menu::addLabel(5,sbuf,190,180);
5607 Menu::addButton(0,"",70,400);
5608 Menu::addButton(1,"",10,360);
5609 Menu::addButton(2,"",40,320);
5610 Menu::addButton(3,"Back",10,10);
5611 updateStereoConfigMenu();
5616 void Game::MenuTick(){
5618 selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight);
5620 // some specific case where we do something even if the left mouse button is not pressed.
5621 if((mainmenu==5) && (endgame==2)) {
5622 accountactive->endGame();
5627 if(mainmenu==18 && Input::isKeyPressed(MOUSEBUTTON2) && selected==1){
5628 stereoseparation-=0.001;
5629 updateStereoConfigMenu();
5632 static int oldmainmenu=mainmenu;
5636 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5642 if(gameon) { //resume
5644 pause_sound(stream_menutheme);
5645 resume_stream(leveltheme);
5647 fireSound(firestartsound);
5649 mainmenu=(accountactive?5:7);
5657 if(newdetail>2) newdetail=detail;
5658 if(newdetail<0) newdetail=detail;
5659 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5660 if(newscreenwidth<0) newscreenwidth=screenwidth;
5661 if(newscreenheight>3000) newscreenheight=screenheight;
5662 if(newscreenheight<0) newscreenheight=screenheight;
5667 if(gameon){ //end game
5672 pause_sound(stream_menutheme);
5679 bool isCustomResolution,found;
5682 extern SDL_Rect **resolutions;
5683 isCustomResolution = true;
5685 for(int i = 0; (!found) && (resolutions[i]); i++) {
5686 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5687 isCustomResolution = false;
5689 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5691 if(resolutions[i] != NULL) {
5692 newscreenwidth = (int) resolutions[i]->w;
5693 newscreenheight = (int) resolutions[i]->h;
5694 } else if(isCustomResolution){
5695 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5696 newscreenwidth = (int) resolutions[0]->w;
5697 newscreenheight = (int) resolutions[0]->h;
5699 newscreenwidth = screenwidth;
5700 newscreenheight = screenheight;
5703 newscreenwidth = (int) resolutions[0]->w;
5704 newscreenheight = (int) resolutions[0]->h;
5711 newscreenwidth = (int) resolutions[0]->w;
5712 newscreenheight = (int) resolutions[0]->h;
5717 if(newdetail>2) newdetail=0;
5721 if(bloodtoggle>2) bloodtoggle=0;
5725 if(difficulty>2) difficulty=0;
5728 ismotionblur = !ismotionblur;
5734 musictoggle = !musictoggle;
5736 emit_stream_np(stream_menutheme);
5738 pause_sound(leveltheme);
5739 pause_sound(stream_fighttheme);
5740 pause_sound(stream_menutheme);
5742 for(int i=0;i<4;i++){
5743 oldmusicvolume[i]=0;
5757 mainmenu=gameon?2:1;
5760 invertmouse = !invertmouse;
5763 usermousesensitivity+=.2;
5764 if(usermousesensitivity>2)
5765 usermousesensitivity=.2;
5771 OPENAL_SetSFXMasterVolume((int)(volume*255));
5775 newstereomode = stereomode;
5780 showdamagebar = !showdamagebar;
5783 updateSettingsMenu();
5788 if(selected<(debugmode?10:9) && keyselect==-1)
5792 if(selected==(debugmode?10:9)){
5797 updateControlsMenu();
5802 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5812 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5813 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5816 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5820 pause_sound(stream_menutheme);
5837 pause_sound(stream_menutheme);
5846 mainmenu=(gameon?2:1);
5852 vector<string> campaigns = ListCampaigns();
5853 vector<string>::iterator c;
5854 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5855 if(!campaigns.empty())
5856 accountactive->setCurrentCampaign(campaigns.front());
5859 if(c==campaigns.end())
5860 c=campaigns.begin();
5861 accountactive->setCurrentCampaign(*c);
5871 accountactive = Account::destroy(accountactive);
5873 } else if(selected==2) {
5880 if(selected==0 && Account::getNbAccounts()<8){
5882 } else if (selected < Account::getNbAccounts()+1) {
5885 accountactive=Account::get(selected-1);
5886 } else if (selected == Account::getNbAccounts()+1) {
5892 for(int j=0;j<255;j++){
5893 displaytext[0][j]=0;
5904 accountactive->setDifficulty(selected);
5908 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5916 targetlevel=selected;
5921 Loadlevel(selected);
5926 pause_sound(stream_menutheme);
5928 if(selected==numchallengelevels){
5943 stereoseparation+=0.001;
5947 newstereomode = (StereoMode)(newstereomode + 1);
5948 while(!CanInitStereo(newstereomode)){
5949 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5950 newstereomode = (StereoMode)(newstereomode + 1);
5951 if(newstereomode >= stereoCount)
5952 newstereomode = stereoNone;
5954 } else if(selected==2) {
5955 stereoreverse = !stereoreverse;
5956 } else if(selected==3) {
5960 stereomode = newstereomode;
5961 InitStereo(stereomode);
5964 updateStereoConfigMenu();
5969 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5976 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5979 inputText(displaytext[0],&displayselected,&displaychars[0]);
5980 if(!waiting) { // the input as finished
5981 if(displaychars[0]){ // with enter
5982 accountactive = Account::add(string(displaytext[0]));
5988 fireSound(firestartsound);
5990 for(int i=0;i<255;i++){
5991 displaytext[0][i]=0;
6000 displayblinkdelay-=multiplier;
6001 if(displayblinkdelay<=0){
6002 displayblinkdelay=.3;
6003 displayblink=1-displayblink;
6008 Menu::setText(0,displaytext[0],20,400,-1,-1);
6009 Menu::setText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1);
6012 if(oldmainmenu!=mainmenu)
6014 oldmainmenu=mainmenu;
6019 static XYZ facing,flatfacing;
6022 for(int i=0;i<15;i++){
6023 displaytime[i]+=multiplier;
6026 keyboardfrozen=false;
6029 if(Input::isKeyPressed(SDLK_F6)){
6030 if(Input::isKeyDown(SDLK_LSHIFT))
6033 stereoreverse=false;
6036 printf("Stereo reversed\n");
6038 printf("Stereo unreversed\n");
6041 if(Input::isKeyDown(SDLK_F7)){
6042 if(Input::isKeyDown(SDLK_LSHIFT))
6043 stereoseparation -= 0.001;
6045 stereoseparation -= 0.010;
6046 printf("Stereo decreased increased to %f\n", stereoseparation);
6049 if(Input::isKeyDown(SDLK_F8)){
6050 if(Input::isKeyDown(SDLK_LSHIFT))
6051 stereoseparation += 0.001;
6053 stereoseparation += 0.010;
6054 printf("Stereo separation increased to %f\n", stereoseparation);
6058 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
6059 if(tutorialstage!=51)
6060 tutorialstagetime=tutorialmaxtime;
6061 emit_sound_np(consolefailsound, 128.);
6065 Values of mainmenu :
6067 2 Menu pause (resume/end game)
6069 4 Controls configuration menu
6070 5 Main game menu (choose level or challenge)
6071 6 Deleting user menu
6072 7 User managment menu (select/add)
6073 8 Choose difficulty menu
6074 9 Challenge level selection menu
6075 10 End of the campaign congratulation (is that really a menu?)
6076 11 Same that 9 ??? => unused
6077 18 stereo configuration
6082 if(mainmenu&&endgame==1)
6084 //go to level select after completing a campaign level
6085 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
6092 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6093 emit_stream_np(stream_menutheme);
6094 pause_sound(leveltheme);
6098 //escape key pressed
6099 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
6100 if(Input::isKeyPressed(SDLK_ESCAPE)&&
6101 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
6103 if(mainmenu==0&&!winfreeze)
6105 else if(mainmenu==1||mainmenu==2){
6106 mainmenu=0; //unpause
6109 if(musictoggle&&(mainmenu==1||mainmenu==2)){
6110 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6111 emit_stream_np(stream_menutheme);
6112 pause_sound(leveltheme);
6114 //on resume, play level music
6116 pause_sound(stream_menutheme);
6117 resume_stream(leveltheme);
6119 //finished with settings menu
6124 if(mainmenu>=3&&mainmenu!=8){
6131 mainmenu=gameon?2:1; break;
6134 case 6: case 7: case 9: case 10:
6145 if(hostile==1)hostiletime+=multiplier;
6147 if(!winfreeze)leveltime+=multiplier;
6150 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6153 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6157 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6161 inputText(displaytext[0],&displayselected,&displaychars[0]);
6163 if(displaychars[0]){
6164 for(int j=0;j<255;j++)
6165 displaytext[0][j]=0;
6172 displayblinkdelay-=multiplier;
6173 if(displayblinkdelay<=0){
6174 displayblinkdelay=.3;
6175 displayblink=1-displayblink;
6179 keyboardfrozen=true;
6181 if(Input::isKeyPressed(consolekey)&&debugmode) {
6184 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6193 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
6194 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6197 if(consolechars[0]>0) {
6198 consoletext[0][consolechars[0]]='\0';
6199 cmd_dispatch(consoletext[0]);
6200 for(int k=14;k>=1;k--) {
6201 for(int j=0;j<255;j++)
6202 consoletext[k][j]=consoletext[k-1][j];
6203 consolechars[k]=consolechars[k-1];
6205 for(int j=0;j<255;j++)
6206 consoletext[0][j]=0;
6212 consoleblinkdelay-=multiplier;
6213 if(consoleblinkdelay<=0) {
6214 consoleblinkdelay=.3;
6215 consoleblink=1-consoleblink;
6221 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6228 static int oldwinfreeze;
6229 if(winfreeze&&!oldwinfreeze){
6230 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6231 emit_sound_np(consolesuccesssound);
6234 oldwinfreeze=winfreeze;
6238 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6241 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6245 } else if(winfreeze) {
6253 //TODO: what is this test?
6254 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6259 talkdelay-=multiplier;
6261 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6262 for(int i=0;i<numdialogues;i++){
6263 int realdialoguetype;
6265 if(dialoguetype[i]>49){
6266 realdialoguetype=dialoguetype[i]-50;
6269 else if(dialoguetype[i]>39){
6270 realdialoguetype=dialoguetype[i]-40;
6273 else if(dialoguetype[i]>29){
6274 realdialoguetype=dialoguetype[i]-30;
6277 else if(dialoguetype[i]>19){
6278 realdialoguetype=dialoguetype[i]-20;
6281 else if(dialoguetype[i]>9){
6282 realdialoguetype=dialoguetype[i]-10;
6286 realdialoguetype=dialoguetype[i];
6289 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6290 realdialoguetype<numplayers&&
6291 realdialoguetype>0&&
6292 (dialoguegonethrough[i]==0||!special)&&
6293 (special||Input::isKeyPressed(attackkey))){
6294 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6295 player[realdialoguetype].howactive>=typedead1||
6296 dialoguetype[i]>40&&dialoguetype[i]<50){
6298 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6299 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6300 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6301 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6302 player[participantfocus[whichdialogue][j]].velocity=0;
6303 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6304 player[participantfocus[whichdialogue][j]].targetframe=0;
6309 dialoguegonethrough[i]++;
6310 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6311 playdialogueboxsound();
6317 windvar+=multiplier;
6318 smoketex+=multiplier;
6319 tutorialstagetime+=multiplier;
6322 static float hotspotvisual[40];
6326 for(int i=0;i<numhotspots;i++)
6327 hotspotvisual[i]-=multiplier/320;
6329 for(int i=0;i<numhotspots;i++){
6330 //if(hotspottype[i]<=10)
6331 while(hotspotvisual[i]<0){
6333 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6334 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6335 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6336 hotspotsprite+=hotspot[i];
6337 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6338 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6342 for(int i=0;i<numhotspots;i++){
6343 if(hotspottype[i]<=10&&hotspottype[i]>0){
6344 hotspot[i]=player[hotspottype[i]].coords;
6355 if(tutoriallevel!=1){
6358 bonus!=spinecrusher&&
6359 bonus!=tracheotomy&&
6362 emit_sound_np(consolesuccesssound);
6364 } else if(bonustime==0){
6365 emit_sound_np(fireendsound);
6368 if(bonus!=solidhit&&
6370 bonus!=threexcombo&&
6375 bonusnum[bonus]+=0.15;
6378 bonusvalue/=bonusnum[bonus];
6379 bonustotal+=bonusvalue;
6381 bonustime+=multiplier;
6384 if(environment==snowyenvironment){
6385 precipdelay-=multiplier;
6386 while(precipdelay<0){
6390 XYZ footvel,footpoint;
6393 footpoint=viewer+viewerfacing*6;
6394 footpoint.y+=((float)abs(Random()%1200))/100-6;
6395 footpoint.x+=((float)abs(Random()%1200))/100-6;
6396 footpoint.z+=((float)abs(Random()%1200))/100-6;
6397 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6402 doAerialAcrobatics();
6405 static XYZ oldviewer;
6409 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6410 player[0].leftkeydown=Input::isKeyDown(leftkey);
6411 player[0].backkeydown=Input::isKeyDown(backkey);
6412 player[0].rightkeydown=Input::isKeyDown(rightkey);
6413 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6414 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6415 player[0].drawkeydown=Input::isKeyDown(drawkey);
6416 player[0].throwkeydown=Input::isKeyDown(throwkey);
6420 player[0].forwardkeydown=0;
6421 player[0].leftkeydown=0;
6422 player[0].backkeydown=0;
6423 player[0].rightkeydown=0;
6424 player[0].jumpkeydown=0;
6425 player[0].crouchkeydown=0;
6426 player[0].drawkeydown=0;
6427 player[0].throwkeydown=0;
6430 if(!player[0].jumpkeydown)
6431 player[0].jumpclimb=0;
6440 facing=DoRotation(facing,-rotation2,0,0);
6441 facing=DoRotation(facing,0,0-rotation,0);
6446 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6448 if(Input::isKeyDown(forwardkey))
6449 viewer+=facing*multiplier*4;
6450 if(Input::isKeyDown(backkey))
6451 viewer-=facing*multiplier*4;
6452 if(Input::isKeyDown(leftkey))
6453 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6454 if(Input::isKeyDown(rightkey))
6455 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6456 if(Input::isKeyDown(jumpkey))
6457 viewer.y+=multiplier*4;
6458 if(Input::isKeyDown(crouchkey))
6459 viewer.y-=multiplier*4;
6460 if( Input::isKeyPressed(SDLK_1)||
6461 Input::isKeyPressed(SDLK_2)||
6462 Input::isKeyPressed(SDLK_3)||
6463 Input::isKeyPressed(SDLK_4)||
6464 Input::isKeyPressed(SDLK_5)||
6465 Input::isKeyPressed(SDLK_6)||
6466 Input::isKeyPressed(SDLK_7)||
6467 Input::isKeyPressed(SDLK_8)||
6468 Input::isKeyPressed(SDLK_9)||
6469 Input::isKeyPressed(SDLK_0)||
6470 Input::isKeyPressed(SDLK_MINUS)){
6472 if(Input::isKeyPressed(SDLK_1))whichend=1;
6473 if(Input::isKeyPressed(SDLK_2))whichend=2;
6474 if(Input::isKeyPressed(SDLK_3))whichend=3;
6475 if(Input::isKeyPressed(SDLK_4))whichend=4;
6476 if(Input::isKeyPressed(SDLK_5))whichend=5;
6477 if(Input::isKeyPressed(SDLK_6))whichend=6;
6478 if(Input::isKeyPressed(SDLK_7))whichend=7;
6479 if(Input::isKeyPressed(SDLK_8))whichend=8;
6480 if(Input::isKeyPressed(SDLK_9))whichend=9;
6481 if(Input::isKeyPressed(SDLK_0))whichend=0;
6482 if(Input::isKeyPressed(SDLK_MINUS))
6485 participantfocus[whichdialogue][indialogue]=whichend;
6486 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6487 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6490 participantfocus[whichdialogue][indialogue]=-1;
6492 if(player[participantfocus[whichdialogue][indialogue]].dead){
6497 dialoguecamera[whichdialogue][indialogue]=viewer;
6498 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6499 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6501 if(indialogue<numdialogueboxes[whichdialogue]){
6502 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6503 playdialogueboxsound();
6507 for(int j=0;j<numplayers;j++){
6508 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6511 //TODO: should these be KeyDown or KeyPressed?
6512 if( Input::isKeyDown(SDLK_KP1)||
6513 Input::isKeyDown(SDLK_KP2)||
6514 Input::isKeyDown(SDLK_KP3)||
6515 Input::isKeyDown(SDLK_KP4)||
6516 Input::isKeyDown(SDLK_KP5)||
6517 Input::isKeyDown(SDLK_KP6)||
6518 Input::isKeyDown(SDLK_KP7)||
6519 Input::isKeyDown(SDLK_KP8)||
6520 Input::isKeyDown(SDLK_KP9)||
6521 Input::isKeyDown(SDLK_KP0)){
6523 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6524 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6525 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6526 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6527 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6528 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6529 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6530 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6531 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6532 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6533 participantfacing[whichdialogue][indialogue][whichend]=facing;
6535 if(indialogue>=numdialogueboxes[whichdialogue]){
6542 pause_sound(whooshsound);
6543 viewer=dialoguecamera[whichdialogue][indialogue];
6544 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6545 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6546 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6547 if(dialoguetime>0.5)
6548 if( Input::isKeyPressed(SDLK_1)||
6549 Input::isKeyPressed(SDLK_2)||
6550 Input::isKeyPressed(SDLK_3)||
6551 Input::isKeyPressed(SDLK_4)||
6552 Input::isKeyPressed(SDLK_5)||
6553 Input::isKeyPressed(SDLK_6)||
6554 Input::isKeyPressed(SDLK_7)||
6555 Input::isKeyPressed(SDLK_8)||
6556 Input::isKeyPressed(SDLK_9)||
6557 Input::isKeyPressed(SDLK_0)||
6558 Input::isKeyPressed(SDLK_MINUS)||
6559 Input::isKeyPressed(attackkey)){
6561 if(indialogue<numdialogueboxes[whichdialogue]){
6562 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6563 playdialogueboxsound();
6564 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6565 hotspot[numhotspots]=player[0].coords;
6566 hotspotsize[numhotspots]=10;
6567 hotspottype[numhotspots]=-1;
6571 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6575 if(player[participantfocus[whichdialogue][indialogue]].dead){
6583 if(indialogue>=numdialogueboxes[whichdialogue]){
6587 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6590 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6593 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6595 for(int i=1;i<numplayers;i++){
6596 player[i].aitype = attacktypecutoff;
6603 if(!player[0].jumpkeydown){
6604 player[0].jumptogglekeydown=0;
6606 if(player[0].jumpkeydown&&
6607 player[0].targetanimation!=jumpupanim&&
6608 player[0].targetanimation!=jumpdownanim&&
6609 !player[0].isFlip())
6610 player[0].jumptogglekeydown=1;
6613 dialoguetime+=multiplier;
6614 hawkrotation+=multiplier*25;
6616 realhawkcoords.x=25;
6617 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6618 hawkcalldelay-=multiplier/2;
6620 if(hawkcalldelay<=0){
6621 emit_sound_at(hawksound, realhawkcoords);
6623 hawkcalldelay=16+abs(Random()%8);
6630 doPlayerCollisions();
6634 for(int k=0;k<numplayers;k++)
6635 if(k!=0&&player[k].immobile)
6636 player[k].coords=player[k].realoldcoords;
6638 for(int k=0;k<numplayers;k++){
6639 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6640 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6641 player[k].DoDamage(1000);
6647 static bool respawnkeydown;
6650 (Input::isKeyDown(SDLK_z)&&
6651 Input::isKeyDown(SDLK_LMETA)&&
6653 (Input::isKeyDown(jumpkey)&&
6657 targetlevel=whichlevel;
6661 if(!Input::isKeyDown(jumpkey))
6663 if(Input::isKeyDown(jumpkey))
6669 static bool movekey;
6672 for(int i=0;i<numplayers;i++){
6673 static float oldtargetrotation;
6674 if(!player[i].skeleton.free){
6675 oldtargetrotation=player[i].targetrotation;
6676 if(i==0&&indialogue==-1){
6677 //TODO: refactor repetitive code
6678 if(!animation[player[0].targetanimation].attack&&
6679 player[0].targetanimation!=staggerbackhighanim&&
6680 player[0].targetanimation!=staggerbackhardanim&&
6681 player[0].targetanimation!=crouchremoveknifeanim&&
6682 player[0].targetanimation!=removeknifeanim&&
6683 player[0].targetanimation!=backhandspringanim&&
6684 player[0].targetanimation!=dodgebackanim&&
6685 player[0].targetanimation!=walljumprightkickanim&&
6686 player[0].targetanimation!=walljumpleftkickanim){
6688 player[0].targetrotation=0;
6690 player[0].targetrotation=-rotation+180;
6696 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6700 facing=DoRotation(facing,-rotation2,0,0);
6701 facing=DoRotation(facing,0,0-rotation,0);
6704 player[0].lookrotation=-rotation;
6706 player[i].targetheadrotation=rotation;
6707 player[i].targetheadrotation2=rotation2;
6709 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6710 if(!animation[player[i].targetanimation].attack&&
6711 player[i].targetanimation!=staggerbackhighanim&&
6712 player[i].targetanimation!=staggerbackhardanim&&
6713 player[i].targetanimation!=crouchremoveknifeanim&&
6714 player[i].targetanimation!=removeknifeanim&&
6715 player[i].targetanimation!=backhandspringanim&&
6716 player[i].targetanimation!=dodgebackanim&&
6717 player[i].targetanimation!=walljumprightkickanim&&
6718 player[i].targetanimation!=walljumpleftkickanim){
6719 player[i].targetrotation=-player[i].lookrotation+180;
6725 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6727 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6728 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6730 player[i].targetheadrotation=player[i].lookrotation;
6731 player[i].targetheadrotation2=player[i].lookrotation2;
6734 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6735 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6741 player[i].avoidsomething=0;
6743 //avoid flaming things
6744 for(int j=0;j<objects.numobjects;j++)
6745 if(objects.onfire[j])
6746 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6747 if( findDistancefast(&player[i].coords,&objects.position[j])<
6748 findDistancefast(&player[i].coords,&player[0].coords)){
6749 player[i].collided=0;
6750 player[i].avoidcollided=1;
6751 if(player[i].avoidsomething==0||
6752 findDistancefast(&player[i].coords,&objects.position[j])<
6753 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6754 player[i].avoidwhere=objects.position[j];
6755 player[i].avoidsomething=1;
6759 //avoid flaming players
6760 for(int j=0;j<numplayers;j++)
6761 if(player[j].onfire)
6762 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6763 if( findDistancefast(&player[i].coords,&player[j].coords)<
6764 findDistancefast(&player[i].coords,&player[0].coords)){
6765 player[i].collided=0;
6766 player[i].avoidcollided=1;
6767 if(player[i].avoidsomething==0||
6768 findDistancefast(&player[i].coords,&player[j].coords)<
6769 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6770 player[i].avoidwhere=player[j].coords;
6771 player[i].avoidsomething=1;
6775 if(player[i].collided>.8)
6776 player[i].avoidcollided=0;
6780 if(animation[player[i].targetanimation].attack==reversed){
6781 //player[i].targetrotation=player[i].rotation;
6782 player[i].forwardkeydown=0;
6783 player[i].leftkeydown=0;
6784 player[i].backkeydown=0;
6785 player[i].rightkeydown=0;
6786 player[i].jumpkeydown=0;
6787 player[i].attackkeydown=0;
6788 //player[i].crouchkeydown=0;
6789 player[i].throwkeydown=0;
6793 player[i].forwardkeydown=0;
6794 player[i].leftkeydown=0;
6795 player[i].backkeydown=0;
6796 player[i].rightkeydown=0;
6797 player[i].jumpkeydown=0;
6798 player[i].crouchkeydown=0;
6799 player[i].drawkeydown=0;
6800 player[i].throwkeydown=0;
6803 if(player[i].collided<-.3)
6804 player[i].collided=-.3;
6805 if(player[i].collided>1)
6806 player[i].collided=1;
6807 player[i].collided-=multiplier*4;
6808 player[i].whichdirectiondelay-=multiplier;
6809 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6810 player[i].avoidcollided=-.3;
6811 player[i].whichdirection=abs(Random()%2);
6812 player[i].whichdirectiondelay=.4;
6814 if(player[i].avoidcollided>1)
6815 player[i].avoidcollided=1;
6816 player[i].avoidcollided-=multiplier/4;
6817 if(!player[i].skeleton.free){
6818 player[i].stunned-=multiplier;
6819 player[i].surprised-=multiplier;
6821 if(i!=0&&player[i].surprised<=0&&
6822 player[i].aitype==attacktypecutoff&&
6824 !player[i].skeleton.free&&
6825 animation[player[i].targetanimation].attack==neutral)
6828 if(!player[i].throwkeydown)
6829 player[i].throwtogglekeydown=0;
6832 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6833 if(player[i].weaponactive==-1&&
6834 player[i].num_weapons<2&&
6835 (player[i].isIdle()||
6836 player[i].isCrouch()||
6837 player[i].targetanimation==sneakanim||
6838 player[i].targetanimation==rollanim||
6839 player[i].targetanimation==backhandspringanim||
6840 player[i].isFlip()||
6841 player[i].isFlip()||
6842 player[i].aitype!=playercontrolled)){
6843 for(int j=0;j<weapons.size();j++){
6844 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6845 player[i].aitype==playercontrolled)&&
6846 weapons[j].owner==-1&&
6847 player[i].weaponactive==-1)
6848 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
6849 if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
6850 if(player[i].isCrouch()||
6851 player[i].targetanimation==sneakanim||
6853 player[i].isIdle()||
6854 player[i].aitype!=playercontrolled){
6855 player[i].throwtogglekeydown=1;
6856 player[i].setAnimation(crouchremoveknifeanim);
6857 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6858 player[i].hasvictim=0;
6860 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6861 player[i].throwtogglekeydown=1;
6862 player[i].hasvictim=0;
6864 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6865 player[i].aitype==playercontrolled)&&
6866 weapons[j].owner==-1||
6868 weapons[j].owner==player[i].victim->id)
6869 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
6870 if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
6871 if(weapons[j].getType()!=staff)
6872 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6874 player[i].weaponactive=0;
6875 weapons[j].owner=player[i].id;
6876 if(player[i].num_weapons>0)
6877 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6878 player[i].num_weapons++;
6879 player[i].weaponids[0]=j;
6882 }else if((player[i].isIdle()||
6883 player[i].isFlip()||
6884 player[i].aitype!=playercontrolled)&&
6885 findDistancefast(&player[i].coords,&weapons[j].position)<5&&
6886 player[i].coords.y<weapons[j].position.y){
6887 if(!player[i].isFlip()){
6888 player[i].throwtogglekeydown=1;
6889 player[i].setAnimation(removeknifeanim);
6890 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6892 if(player[i].isFlip()){
6893 player[i].throwtogglekeydown=1;
6894 player[i].hasvictim=0;
6896 for(int k=0;k<weapons.size();k++){
6897 if(player[i].weaponactive==-1)
6898 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
6899 player[i].aitype==playercontrolled)&&
6900 weapons[k].owner==-1||
6902 weapons[k].owner==player[i].victim->id)
6903 if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
6904 player[i].weaponactive==-1){
6905 if(weapons[k].getType()!=staff)
6906 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6908 player[i].weaponactive=0;
6909 weapons[k].owner=player[i].id;
6910 if(player[i].num_weapons>0)
6911 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6912 player[i].num_weapons++;
6913 player[i].weaponids[0]=k;
6920 if(player[i].isCrouch()||
6921 player[i].targetanimation==sneakanim||
6923 player[i].isIdle()||player[i].targetanimation==rollanim||
6924 player[i].targetanimation==backhandspringanim){
6926 for(int j=0;j<numplayers;j++){
6927 if(player[i].weaponactive==-1)
6929 if(player[j].num_weapons&&
6930 player[j].skeleton.free&&
6931 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6932 (((player[j].skeleton.forward.y<0&&
6933 player[j].weaponstuckwhere==0)||
6934 (player[j].skeleton.forward.y>0&&
6935 player[j].weaponstuckwhere==1))||
6936 player[j].weaponstuck==-1||
6937 player[j].num_weapons>1)){
6938 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6939 player[i].throwtogglekeydown=1;
6940 player[i].victim=&player[j];
6941 player[i].hasvictim=1;
6942 player[i].setAnimation(crouchremoveknifeanim);
6943 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6945 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6946 player[i].throwtogglekeydown=1;
6947 player[i].victim=&player[j];
6948 player[i].hasvictim=1;
6949 int k = player[j].weaponids[0];
6950 if(player[i].hasvictim){
6953 if(player[i].victim->weaponstuck!=-1){
6954 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6959 if(weapons[k].getType()!=staff)
6960 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6963 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6965 player[i].weaponactive=0;
6966 if(weapons[k].owner!=-1){
6967 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6968 else player[i].victim->num_weapons=1;
6970 player[i].victim->skeleton.longdead=0;
6971 player[i].victim->skeleton.free=1;
6972 player[i].victim->skeleton.broken=0;
6974 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6975 player[i].victim->skeleton.joints[l].velchange=0;
6976 player[i].victim->skeleton.joints[l].locked=0;
6982 Normalise(&relative);
6983 XYZ footvel,footpoint;
6985 footpoint=weapons[k].position;
6986 if(player[i].victim->weaponstuck!=-1){
6987 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6988 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6989 weapons[k].bloody=2;
6990 weapons[k].blooddrip=5;
6991 player[i].victim->weaponstuck=-1;
6992 player[i].victim->bloodloss+=2000;
6993 player[i].victim->DoDamage(2000);
6996 if(player[i].victim->num_weapons>0){
6997 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6998 if(player[i].victim->weaponids[0]==k)
6999 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
7002 player[i].victim->weaponactive=-1;
7004 player[i].victim->getJointFor(abdomen).velocity+=relative*6;
7005 player[i].victim->getJointFor(neck).velocity+=relative*6;
7006 player[i].victim->getJointFor(rightshoulder).velocity+=relative*6;
7007 player[i].victim->getJointFor(leftshoulder).velocity+=relative*6;
7010 if(player[i].num_weapons>0){
7011 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7013 player[i].num_weapons++;
7014 player[i].weaponids[0]=k;
7021 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7022 if(weapons[player[i].weaponids[0]].getType()==knife){
7023 if(player[i].isIdle()||
7025 player[i].isCrouch()||
7026 player[i].targetanimation==sneakanim||
7029 for(int j=0;j<numplayers;j++){
7031 if(tutoriallevel!=1||tutorialstage==49)
7033 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
7034 findDistancefast(&player[i].coords,&player[j].coords)<100&&
7035 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
7036 !player[j].skeleton.free&&
7037 -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)){
7038 if(!player[i].isFlip()){
7039 player[i].throwtogglekeydown=1;
7040 player[i].victim=&player[j];
7041 player[i].setAnimation(knifethrowanim);
7042 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
7043 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
7045 if(player[i].isFlip()){
7046 if(player[i].weaponactive!=-1){
7047 player[i].throwtogglekeydown=1;
7048 player[i].victim=&player[j];
7050 weapons[player[i].weaponids[0]].owner=-1;
7051 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);
7054 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
7056 weapons[player[i].weaponids[0]].velocity=aim*50;
7057 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
7058 weapons[player[i].weaponids[0]].missed=0;
7059 weapons[player[i].weaponids[0]].freetime=0;
7060 weapons[player[i].weaponids[0]].firstfree=1;
7061 weapons[player[i].weaponids[0]].physics=0;
7062 player[i].num_weapons--;
7063 if(player[i].num_weapons){
7064 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7066 player[i].weaponactive=-1;
7073 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7074 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
7075 player[i].throwtogglekeydown=1;
7076 weapons[player[i].weaponids[0]].owner=-1;
7077 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
7078 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
7079 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
7080 weapons[player[i].weaponids[0]].missed=1;
7081 weapons[player[i].weaponids[0]].freetime=0;
7082 weapons[player[i].weaponids[0]].firstfree=1;
7083 weapons[player[i].weaponids[0]].physics=1;
7084 player[i].num_weapons--;
7085 if(player[i].num_weapons){
7086 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7087 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7090 player[i].weaponactive=-1;
7091 for(int j=0;j<numplayers;j++){
7092 player[j].wentforweapon=0;
7100 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
7101 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
7102 player[i].num_weapons==2&&
7103 player[i].weaponactive==-1&&
7104 player[i].isIdle()||
7106 player[i].weaponactive!=-1&&
7109 if(player[i].weaponactive!=-1)
7110 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
7112 if(isgood&&player[i].creature!=wolftype){
7113 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7114 player[i].setAnimation(drawrightanim);
7115 player[i].drawtogglekeydown=1;
7117 if((player[i].isIdle()||
7118 (player[i].aitype!=playercontrolled&&
7119 player[0].weaponactive!=-1&&
7120 player[i].isRun()))&&
7121 player[i].num_weapons&&
7122 weapons[player[i].weaponids[0]].getType()==sword){
7123 player[i].setAnimation(drawleftanim);
7124 player[i].drawtogglekeydown=1;
7126 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7127 player[i].setAnimation(crouchdrawrightanim);
7128 player[i].drawtogglekeydown=1;
7135 if(player[i].weaponactive!=-1) {
7136 if (player[i].isCrouch()&&
7137 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
7139 player[i].onterrain&&
7140 player[i].num_weapons&&
7141 player[i].attackkeydown&&
7142 musictype!=stream_fighttheme) {
7143 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
7144 player[i].setAnimation(crouchstabanim);
7145 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
7146 player[i].setAnimation(swordgroundstabanim);
7147 player[i].hasvictim=0;
7151 if(!player[i].drawkeydown)
7152 player[i].drawtogglekeydown=0;
7159 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7161 absflatfacing=flatfacing;
7164 player[i].forwardkeydown=0;
7165 player[i].leftkeydown=0;
7166 player[i].backkeydown=0;
7167 player[i].rightkeydown=0;
7168 player[i].jumpkeydown=0;
7169 player[i].crouchkeydown=0;
7170 player[i].drawkeydown=0;
7171 player[i].throwkeydown=0;
7175 if(!animation[player[i].targetanimation].attack&&
7176 player[i].targetanimation!=staggerbackhighanim&&
7177 player[i].targetanimation!=staggerbackhardanim&&
7178 player[i].targetanimation!=backhandspringanim&&
7179 player[i].targetanimation!=dodgebackanim){
7180 if(!player[i].forwardkeydown)
7181 player[i].forwardstogglekeydown=0;
7182 if(player[i].crouchkeydown){
7186 player[i].superruntoggle=1;
7188 for(int j=0;j<numplayers;j++)
7189 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7190 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7191 player[i].superruntoggle=0;
7195 for(int j=0;j<numplayers;j++){
7196 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7197 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7198 player[j].victim==&player[i]&&
7199 (player[j].targetanimation==sweepanim||
7200 player[j].targetanimation==upunchanim||
7201 player[j].targetanimation==wolfslapanim||
7202 ((player[j].targetanimation==swordslashanim||
7203 player[j].targetanimation==knifeslashstartanim||
7204 player[j].targetanimation==staffhitanim||
7205 player[j].targetanimation==staffspinhitanim)&&
7206 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7215 player[target].Reverse();
7216 player[i].lowreversaldelay=.5;
7218 if(player[i].isIdle()){
7219 player[i].setAnimation(player[i].getCrouch());
7220 player[i].transspeed=10;
7222 if(player[i].isRun()||
7223 (player[i].isStop()&&
7224 (player[i].leftkeydown||
7225 player[i].rightkeydown||
7226 player[i].forwardkeydown||
7227 player[i].backkeydown))){
7228 player[i].setAnimation(rollanim);
7229 player[i].transspeed=20;
7232 if(!player[i].crouchkeydown){
7234 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7236 if(player[i].isCrouch()){
7238 for(int j=0;j<numplayers;j++){
7240 !player[j].skeleton.free&&
7242 player[i].highreversaldelay<=0){
7243 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7244 player[j].victim==&player[i]&&
7245 (player[j].targetanimation==spinkickanim)&&
7246 player[i].isCrouch()){
7255 player[target].Reverse();
7256 player[i].highreversaldelay=.5;
7258 if(player[i].isCrouch()){
7259 if(!player[i].wasCrouch()){
7260 player[i].currentanimation=player[i].getCrouch();
7261 player[i].currentframe=0;
7263 player[i].setAnimation(player[i].getIdle());
7264 player[i].transspeed=10;
7267 if(player[i].targetanimation==sneakanim){
7268 player[i].setAnimation(player[i].getIdle());
7269 player[i].transspeed=10;
7272 if(player[i].forwardkeydown){
7273 if(player[i].isIdle()||
7274 (player[i].isStop()&&
7275 player[i].targetrotation==player[i].rotation)||
7276 (player[i].isLanding()&&
7277 player[i].targetframe>0&&
7278 !player[i].jumpkeydown)||
7279 (player[i].isLandhard()&&
7280 player[i].targetframe>0&&
7281 !player[i].jumpkeydown&&
7282 player[i].crouchkeydown)){
7283 if(player[i].aitype==passivetype)
7284 player[i].setAnimation(walkanim);
7286 player[i].setAnimation(player[i].getRun());
7288 if(player[i].isCrouch()){
7289 player[i].targetanimation=sneakanim;
7290 if(player[i].wasCrouch())
7292 player[i].targetframe=0;
7294 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7295 player[i].setAnimation(climbanim);
7296 player[i].targetframe=1;
7297 player[i].jumpclimb=1;
7299 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7300 player[i].velocity+=absflatfacing*5*multiplier;
7302 player[i].forwardstogglekeydown=1;
7305 if (player[i].rightkeydown){
7306 if(player[i].isIdle()||
7307 (player[i].isStop()&&
7308 player[i].targetrotation==player[i].rotation)||
7309 (player[i].isLanding()&&
7310 player[i].targetframe>0&&
7311 !player[i].jumpkeydown)||
7312 (player[i].isLandhard()&&
7313 player[i].targetframe>0&&
7314 !player[i].jumpkeydown&&
7315 player[i].crouchkeydown)){
7316 player[i].setAnimation(player[i].getRun());
7318 if(player[i].isCrouch()){
7319 player[i].targetanimation=sneakanim;
7320 if(player[i].wasCrouch())
7322 player[i].targetframe=0;
7324 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7325 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7327 player[i].targetrotation-=90;
7328 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7329 if(player[i].backkeydown)player[i].targetrotation-=45;
7332 if ( player[i].leftkeydown){
7333 if(player[i].isIdle()||
7334 (player[i].isStop()&&
7335 player[i].targetrotation==player[i].rotation)||
7336 (player[i].isLanding()&&
7337 player[i].targetframe>0&&
7338 !player[i].jumpkeydown)||
7339 (player[i].isLandhard()&&
7340 player[i].targetframe>0&&
7341 !player[i].jumpkeydown&&
7342 player[i].crouchkeydown)){
7343 player[i].setAnimation(player[i].getRun());
7345 if(player[i].isCrouch()){
7346 player[i].targetanimation=sneakanim;
7347 if(player[i].wasCrouch())
7349 player[i].targetframe=0;
7351 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7352 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7354 player[i].targetrotation+=90;
7355 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7356 if(player[i].backkeydown)player[i].targetrotation+=45;
7359 if(player[i].backkeydown){
7360 if(player[i].isIdle()||
7361 (player[i].isStop()&&
7362 player[i].targetrotation==player[i].rotation)||
7363 (player[i].isLanding()&&
7364 player[i].targetframe>0&&
7365 !player[i].jumpkeydown)||
7366 (player[i].isLandhard()&&
7367 player[i].targetframe>0&&
7368 !player[i].jumpkeydown&&
7369 player[i].crouchkeydown)){
7370 player[i].setAnimation(player[i].getRun());
7372 if(player[i].isCrouch()){
7373 player[i].targetanimation=sneakanim;
7374 if(player[i].wasCrouch())
7376 player[i].targetframe=0;
7378 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7379 player[i].velocity-=absflatfacing*5*multiplier;
7381 if(player[i].targetanimation==hanganim){
7382 player[i].currentanimation=jumpdownanim;
7383 player[i].targetanimation=jumpdownanim;
7385 player[i].currentframe=0;
7386 player[i].targetframe=1;
7387 player[i].velocity=0;
7388 player[i].velocity.y+=gravity;
7389 player[i].coords.y-=1.4;
7390 player[i].grabdelay=1;
7392 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7393 player[i].targetrotation+=180;
7396 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7397 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7399 player[i].targetanimation==walkanim||
7400 player[i].isCrouch()||
7401 player[i].targetanimation==sneakanim)&&
7402 player[i].jumppower>1)&&
7403 ((player[i].targetanimation!=rabbitrunninganim&&
7404 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7405 player[i].jumpstart=0;
7406 player[i].setAnimation(jumpupanim);
7407 player[i].rotation=player[i].targetrotation;
7408 player[i].transspeed=20;
7409 player[i].FootLand(0,1);
7410 player[i].FootLand(1,1);
7414 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7416 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7417 if(!movekey)player[i].velocity=0;
7422 for(int j=0;j<numplayers;j++){
7423 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7424 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7425 player[j].victim==&player[i]&&
7426 (player[j].targetanimation==sweepanim)){
7427 if(target>=0)target=-1;
7432 if(target>=0)player[i].velocity.y=1;
7433 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7434 player[i].velocity.y=7;
7435 player[i].crouchtogglekeydown=1;
7437 else player[i].velocity.y=5;
7439 if(mousejump&&i==0&&debugmode){
7440 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7441 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7444 player[i].coords.y+=.2;
7445 player[i].jumppower-=1;
7448 emit_sound_at(whooshsound, player[i].coords, 128.);
7450 emit_sound_at(jumpsound, player[i].coords, 128.);
7452 if((player[i].isIdle())&&player[i].jumppower>1){
7453 player[i].setAnimation(player[i].getLanding());
7454 player[i].targetframe=2;
7455 player[i].landhard=0;
7456 player[i].jumpstart=1;
7457 player[i].tempdeltav=deltav;
7459 if(player[i].targetanimation==jumpupanim&&
7463 player[i].aitype!=playercontrolled)){
7464 if(player[i].jumppower>multiplier*6){
7465 player[i].velocity.y+=multiplier*6;
7466 player[i].jumppower-=multiplier*6;
7468 if(player[i].jumppower<=multiplier*6){
7469 player[i].velocity.y+=player[i].jumppower;
7470 player[i].jumppower=0;
7473 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7477 if(player[i].isRun()||player[i].targetanimation==walkanim)
7478 player[i].setAnimation(player[i].getStop());
7479 if(player[i].targetanimation==sneakanim){
7480 player[i].targetanimation=player[i].getCrouch();
7481 if(player[i].currentanimation==sneakanim)
7483 player[i].targetframe=0;
7486 if(player[i].targetanimation==walkanim&&
7487 (player[i].aitype==attacktypecutoff||
7488 player[i].aitype==searchtype||
7489 (player[i].aitype==passivetype&&
7490 player[i].numwaypoints<=1)))
7491 player[i].setAnimation(player[i].getStop());
7492 if(player[i].isRun()&&(player[i].aitype==passivetype))
7493 player[i].setAnimation(player[i].getStop());
7496 if(player[i].targetanimation==rollanim)
7497 player[i].targetrotation=oldtargetrotation;
7501 for(int k=0;k<numplayers;k++){
7502 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7503 if(player[k].rotation>player[k].targetrotation)
7504 player[k].rotation-=360;
7506 player[k].rotation+=360;
7509 //stop to turn in right direction
7510 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7511 player[k].setAnimation(player[k].getStop());
7513 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7514 player[k].targettilt=0;
7516 if(player[k].targetanimation!=jumpupanim&&
7517 player[k].targetanimation!=backhandspringanim&&
7518 player[k].targetanimation!=jumpdownanim&&
7519 !player[k].isFlip()){
7520 player[k].targettilt=0;
7521 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7522 player[k].jumppower=0;
7523 player[k].jumppower+=multiplier*7;
7524 if(player[k].isCrouch())
7525 player[k].jumppower+=multiplier*7;
7526 if(player[k].jumppower>5)
7527 player[k].jumppower=5;
7530 if(player[k].isRun())
7531 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7533 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7534 player[k].grabdelay-=multiplier;
7538 for(int k=0;k<numplayers;k++){
7539 player[k].DoAnimations();
7540 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7541 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7547 for(int j=numenvsounds-1;j>=0;j--){
7548 envsoundlife[j]-=multiplier;
7549 if(envsoundlife[j]<0){
7551 envsoundlife[j]=envsoundlife[numenvsounds];
7552 envsound[j]=envsound[numenvsounds];
7556 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7558 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7560 if(tutoriallevel==1){
7577 if(tutorialstage>=51)
7578 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7579 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7580 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7582 emit_stream_np(stream_menutheme);
7591 if(tutorialstage<51)
7592 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7593 emit_sound_at(fireendsound, player[0].coords);
7595 player[0].coords=(oldtemp+oldtemp2)/2;
7599 if(tutorialstage>=14&&tutorialstage<50)
7600 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7601 emit_sound_at(fireendsound, player[1].coords);
7603 for(int i=0;i<player[1].skeleton.num_joints;i++){
7605 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7606 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7607 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;
7608 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7609 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7613 player[1].coords=(oldtemp+oldtemp2)/2;
7614 for(int i=0;i<player[1].skeleton.num_joints;i++){
7615 player[1].skeleton.joints[i].velocity=0;
7617 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7618 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7619 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;
7620 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7621 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7629 static float gLoc[3];
7633 static float vel[3];
7634 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7635 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7636 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7638 //Set orientation with forward and up vectors
7639 static XYZ upvector;
7643 upvector=DoRotation(upvector,-rotation2+90,0,0);
7644 upvector=DoRotation(upvector,0,0-rotation,0);
7649 facing=DoRotation(facing,-rotation2,0,0);
7650 facing=DoRotation(facing,0,0-rotation,0);
7653 static float ori[6];
7657 ori[3] = -upvector.x;
7658 ori[4] = upvector.y;
7659 ori[5] = -upvector.z;
7661 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7668 if(Input::isKeyPressed(SDLK_F1))
7672 void Game::TickOnce(){
7674 rotation+=multiplier*5;
7676 if(directing||indialogue==-1) {
7677 rotation+=deltah*.7;
7679 rotation2+=deltav*.7;
7681 rotation2-=deltav*.7;
7689 void Game::TickOnceAfter(){
7690 static XYZ colviewer;
7691 static XYZ coltarget;
7695 static float changedelay;
7696 static bool alldead;
7697 static float unseendelay;
7698 static float cameraspeed;
7702 if(environment==snowyenvironment)
7703 leveltheme=stream_snowtheme;
7704 if(environment==grassyenvironment)
7705 leveltheme=stream_grasstheme;
7706 if(environment==desertenvironment)
7707 leveltheme=stream_deserttheme;
7711 musictype=leveltheme;
7712 for(int i=0;i<numplayers;i++){
7713 if((player[i].aitype==attacktypecutoff||
7714 player[i].aitype==getweapontype||
7715 player[i].aitype==gethelptype||
7716 player[i].aitype==searchtype)&&
7717 !player[i].dead/*&&player[i].surprised<=0*/&&
7718 (player[i].targetanimation!=sneakattackedanim&&
7719 player[i].targetanimation!=knifesneakattackedanim&&
7720 player[i].targetanimation!=swordsneakattackedanim)){
7721 musictype=stream_fighttheme;
7726 musictype=stream_menutheme;
7729 if(musictype==stream_fighttheme)
7732 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7733 unseendelay-=multiplier;
7735 musictype=stream_fighttheme;
7740 musictype=stream_menutheme;
7748 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7749 emit_sound_np(alarmsound);
7750 musicselected=musictype;
7752 if(musicselected==leveltheme)
7753 musicvolume[0]+=multiplier*450;
7755 musicvolume[0]-=multiplier*450;
7756 if(musicselected==stream_fighttheme)
7757 musicvolume[1]+=multiplier*450;
7759 musicvolume[1]-=multiplier*450;
7760 if(musicselected==stream_menutheme)
7761 musicvolume[2]+=multiplier*450;
7763 musicvolume[2]-=multiplier*450;
7765 for(int i=0;i<3;i++){
7766 if(musicvolume[i]<0)
7768 if(musicvolume[i]>512)
7772 if(musicvolume[2]>128&&!loading&&!mainmenu)
7776 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7777 emit_stream_np(leveltheme, musicvolume[0]);
7778 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7779 emit_stream_np(stream_fighttheme, musicvolume[1]);
7780 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7781 emit_stream_np(stream_menutheme, musicvolume[2]);
7782 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7783 pause_sound(leveltheme);
7784 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7785 pause_sound(stream_fighttheme);
7786 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7787 pause_sound(stream_menutheme);
7789 if(musicvolume[0]!=oldmusicvolume[0])
7790 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7791 if(musicvolume[1]!=oldmusicvolume[1])
7792 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7793 if(musicvolume[2]!=oldmusicvolume[2])
7794 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7796 for(int i=0;i<3;i++)
7797 oldmusicvolume[i]=musicvolume[i];
7799 pause_sound(leveltheme);
7800 pause_sound(stream_fighttheme);
7801 pause_sound(stream_menutheme);
7803 for(int i=0;i<4;i++){
7804 oldmusicvolume[i]=0;
7810 for(int i=0;i<numhotspots;i++){
7811 if(hotspottype[i]>10&&hotspottype[i]<20){
7812 if(player[hotspottype[i]-10].dead==0)
7814 else if(killhotspot==2)
7823 for(int i=0;i<numhotspots;i++)
7824 if(hotspottype[i]==-1)
7825 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7829 for(int i=1;i<numplayers;i++)
7830 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7832 if(numalarmed>maxalarmed)
7833 maxalarmed=numalarmed;
7835 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7836 if(player[0].dead&&changedelay<=0){
7838 targetlevel=whichlevel;
7841 for(int i=1;i<numplayers;i++) {
7842 if(!player[i].dead&&player[i].howactive<typedead1) {
7849 if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
7851 targetlevel=whichlevel+1;
7852 if(targetlevel>numchallengelevels-1)targetlevel=0;
7854 if(winhotspot||windialogue) {
7856 targetlevel=whichlevel+1;
7857 if(targetlevel>numchallengelevels-1)targetlevel=0;
7863 targetlevel=whichlevel+1;
7864 if(targetlevel>numchallengelevels-1)targetlevel=0;
7867 if(changedelay>0&&!player[0].dead&&!won) {
7868 //high scores, awards, win
7870 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7873 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7889 if(!editorenabled&&gameon&&!mainmenu) {
7890 if(changedelay!=-999)
7891 changedelay-=multiplier/7;
7893 targetlevel=whichlevel;
7894 if(loading==2&&!campaign){
7897 fireSound(firestartsound);
7899 if(!player[0].dead&&targetlevel!=whichlevel)
7900 startbonustotal=bonustotal;
7902 Loadlevel(whichlevel);
7904 Loadlevel(targetlevel);
7910 if(loading==2&&targetlevel==whichlevel){
7914 fireSound(firestartsound);
7916 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
7922 if(changedelay<=-999&&
7926 (alldead&&maptype==mapkilleveryone)||
7930 if((player[0].dead||
7931 (alldead&&maptype==mapkilleveryone)||
7936 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7946 // campaignchoosenext determines what to do when the level is complete:
7947 // 0 = load next level
7948 // 1 = go back to level select screen
7949 // 2 = stealthload next level
7950 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
7951 if(campaignlevels[actuallevel].nextlevel.empty())
7953 } else if(mainmenu==0&&winfreeze) {
7954 stealthloading = (campaignlevels[actuallevel].choosenext==2);
7956 if(!stealthloading){
7957 fireSound(firestartsound);
7972 actuallevel=campaignlevels[actuallevel].nextlevel.front();
7975 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
7979 pause_sound(stream_menutheme);
7990 oldmusictype=musictype;
7996 facing=DoRotation(facing,-rotation2,0,0);
7997 facing=DoRotation(facing,0,0-rotation,0);
7998 viewerfacing=facing;
8001 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;
8002 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;
8004 if(player[0].skeleton.free){
8005 for(int i=0;i<player[0].skeleton.num_joints;i++){
8006 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
8007 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
8011 if(player[0].skeleton.free!=2&&!autocam){
8013 if(findLengthfast(&player[0].velocity)>400){
8014 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8016 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8017 coltarget=target-cameraloc;
8018 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8020 Normalise(&coltarget);
8021 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8022 else cameraloc=cameraloc+coltarget*multiplier*8;
8024 if(editorenabled)cameraloc=target;
8025 cameradist+=multiplier*5;
8026 if(cameradist>2.3)cameradist=2.3;
8027 viewer=cameraloc-facing*cameradist;
8029 coltarget=cameraloc;
8030 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8031 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8032 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8033 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8035 coltarget=cameraloc;
8036 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8038 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8039 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8040 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8042 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8046 cameradist=findDistance(&viewer,&target);
8047 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8048 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8049 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8052 if(player[0].skeleton.free!=2&&autocam){
8054 if(findLengthfast(&player[0].velocity)>400){
8055 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8057 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8058 cameradist+=multiplier*5;
8059 if(cameradist>3.3)cameradist=3.3;
8060 coltarget=target-cameraloc;
8061 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8062 else if(findLengthfast(&coltarget)>1)
8064 Normalise(&coltarget);
8065 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8066 else cameraloc=cameraloc+coltarget*multiplier*8;
8068 if(editorenabled)cameraloc=target;
8071 coltarget=cameraloc;
8072 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8073 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8074 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8075 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8077 coltarget=cameraloc;
8078 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8080 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8081 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8082 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8084 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8088 cameradist=findDistance(&viewer,&target);
8089 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8090 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8091 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8094 if(camerashake>.8)camerashake=.8;
8095 //if(woozy>10)woozy=10;
8096 //woozy+=multiplier;
8098 if(player[0].dead)camerashake=0;
8099 if(player[0].dead)woozy=0;
8100 camerashake-=multiplier*2;
8101 blackout-=multiplier*2;
8102 //if(player[0].isCrouch())woozy-=multiplier*8;
8103 if(camerashake<0)camerashake=0;
8104 if(blackout<0)blackout=0;
8105 //if(woozy<0)woozy=0;
8107 viewer.x+=(float)(Random()%100)*.0005*camerashake;
8108 viewer.y+=(float)(Random()%100)*.0005*camerashake;
8109 viewer.z+=(float)(Random()%100)*.0005*camerashake;