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"
43 // Added more evilness needed for MSVC
45 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
46 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
50 extern float multiplier;
52 extern int environment;
53 extern Terrain terrain;
54 extern float screenwidth,screenheight;
57 extern float texdetail;
58 extern Objects objects;
60 extern float slomodelay;
61 extern bool floatjump;
64 extern float camerashake;
66 extern float blackout;
67 extern bool cellophane;
68 extern bool musictoggle;
69 extern int difficulty;
70 extern int bloodtoggle;
71 extern bool invertmouse;
73 extern float precipdelay;
74 extern XYZ viewerfacing;
75 extern bool ambientsound;
76 extern bool mousejump;
77 extern float viewdistance;
79 extern bool keyboardfrozen;
80 extern bool loadingstuff;
81 extern XYZ windvector;
82 extern bool debugmode;
83 static int leveltheme;
85 extern bool visibleloading;
86 extern XYZ envsound[30];
87 extern float envsoundvol[30];
88 extern int numenvsounds;
89 extern float envsoundlife[30];
90 extern float usermousesensitivity;
91 extern bool ismotionblur;
92 extern bool showdamagebar; // (des)activate the damage bar
94 extern float tintr,tintg,tintb;
95 extern bool skyboxtexture;
99 extern float skyboxlightr;
100 extern float skyboxlightg;
101 extern float skyboxlightb;
102 extern float fadestart;
103 extern float slomospeed;
104 extern float slomofreq;
105 extern int tutoriallevel;
106 extern float smoketex;
107 extern float tutorialstagetime;
108 extern int tutorialstage;
109 extern float tutorialmaxtime;
110 extern float tutorialsuccess;
111 extern bool againbonus;
112 extern bool reversaltrain;
113 extern bool canattack;
114 extern bool cananger;
115 extern float damagedealt;
117 extern int editoractive;
118 extern int editorpathtype;
120 extern float hostiletime;
122 extern bool gamestarted;
124 extern int numhotspots;
125 extern int winhotspot;
126 extern int windialogue;
127 extern int killhotspot;
128 extern XYZ hotspot[40];
129 extern int hotspottype[40];
130 extern float hotspotsize[40];
131 extern char hotspottext[40][256];
132 extern int currenthotspot;
136 extern bool stillloading;
137 extern bool winfreeze;
139 extern bool campaign;
141 static const char *rabbitskin[] = {
142 ":Data:Textures:Fur3.jpg",
143 ":Data:Textures:Fur.jpg",
144 ":Data:Textures:Fur2.jpg",
145 ":Data:Textures:Lynx.jpg",
146 ":Data:Textures:Otter.jpg",
147 ":Data:Textures:Opal.jpg",
148 ":Data:Textures:Sable.jpg",
149 ":Data:Textures:Chocolate.jpg",
150 ":Data:Textures:BW2.jpg",
151 ":Data:Textures:WB2.jpg"
154 static const char *wolfskin[] = {
155 ":Data:Textures:Wolf.jpg",
156 ":Data:Textures:Darkwolf.jpg",
157 ":Data:Textures:Snowwolf.jpg"
160 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
161 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
163 static const char **creatureskin[] = {rabbitskin, wolfskin};
165 /* Return true if PFX is a prefix of STR (case-insensitive). */
166 static bool stripfx(const char *str, const char *pfx)
168 return !strncasecmp(str, pfx, strlen(pfx));
171 static const char *cmd_names[] = {
172 #define DECLARE_COMMAND(cmd) #cmd,
173 #include "ConsoleCmds.h"
174 #undef DECLARE_COMMAND
177 typedef void (*console_handler)(Game *game, const char *args);
179 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
180 #include "ConsoleCmds.h"
181 #undef DECLARE_COMMAND
183 static console_handler cmd_handlers[] = {
184 #define DECLARE_COMMAND(cmd) ch_##cmd,
185 #include "ConsoleCmds.h"
186 #undef DECLARE_COMMAND
191 // added utility functions -sf17k =============================================================
193 //TODO: try to hide these variables completely with a better interface
194 inline void setAnimation(int playerid,int animation){
195 player[playerid].targetanimation=animation;
196 player[playerid].targetframe=0;
197 player[playerid].target=0;
200 //TODO: this is incorrect but I'm afraid to change it and break something,
201 //probably causes quirky behavior that I might want to preserve
202 inline float roughDirection(XYZ vec){
204 float angle=-asin(-vec.x)*180/M_PI;
209 inline float roughDirectionTo(XYZ start, XYZ end){
210 return roughDirection(end-start);
213 //TODO: gotta be a better way
214 inline float pitch(XYZ vec){
216 return -asin(vec.y)*180/M_PI;
218 inline float pitchTo(XYZ start, XYZ end){
219 return pitch(end-start);
222 //change these to a Person method
223 inline Joint& playerJoint(int playerid, int bodypart){
224 return player[playerid].skeleton.joints[player[playerid].skeleton.jointlabels[bodypart]]; }
225 inline Joint& playerJoint(Person* pplayer, int bodypart){
226 return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; }
228 inline float sq(float n) { return n*n; }
230 inline float stepTowardf(float from, float to, float by){
231 if(fabs(from-to)<by) return to;
232 else if(from>to) return from-by;
236 void playdialogueboxsound(){
238 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
239 temppos=temppos-viewer;
244 switch(dialogueboxsound[whichdialogue][indialogue]){
245 case -6: sound=alarmsound; break;
246 case -4: sound=consolefailsound; break;
247 case -3: sound=consolesuccesssound; break;
248 case -2: sound=firestartsound; break;
249 case -1: sound=fireendsound; break;
250 case 1: sound=rabbitchitter; break;
251 case 2: sound=rabbitchitter2; break;
252 case 3: sound=rabbitpainsound; break;
253 case 4: sound=rabbitpain1sound; break;
254 case 5: sound=rabbitattacksound; break;
255 case 6: sound=rabbitattack2sound; break;
256 case 7: sound=rabbitattack3sound; break;
257 case 8: sound=rabbitattack4sound; break;
258 case 9: sound=growlsound; break;
259 case 10: sound=growl2sound; break;
260 case 11: sound=snarlsound; break;
261 case 12: sound=snarl2sound; break;
262 case 13: sound=barksound; break;
263 case 14: sound=bark2sound; break;
264 case 15: sound=bark3sound; break;
265 case 16: sound=barkgrowlsound; break;
269 emit_sound_at(sound, temppos);
272 // end added utility functions ================================================================
276 static void ch_quit(Game *game, const char *args)
281 static void ch_map(Game *game, const char *args)
283 game->Loadlevel(args);
284 game->whichlevel = -2;
288 static void ch_save(Game *game, const char *args){
290 snprintf(buf, 63, ":Data:Maps:%s", args);
295 tfile=fopen( ConvertFileName(buf), "wb" );
296 fpackf(tfile, "Bi", mapvers);
297 fpackf(tfile, "Bi", maptype);
298 fpackf(tfile, "Bi", hostile);
299 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
300 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
301 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
302 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
303 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
304 if(player[0].num_weapons>0&&player[0].num_weapons<5)
305 for(int j=0;j<player[0].num_weapons;j++)
306 fpackf(tfile, "Bi", weapons[player[0].weaponids[j]].getType());
308 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
309 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
310 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
311 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
313 fpackf(tfile, "Bi", player[0].numclothes);
315 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
317 fpackf(tfile, "Bi", numdialogues);
319 for(int k=0;k<numdialogues;k++){
320 fpackf(tfile, "Bi", numdialogueboxes[k]);
321 fpackf(tfile, "Bi", dialoguetype[k]);
322 for(int l=0;l<10;l++){
323 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
324 fpackf(tfile, "Bf", participantrotation[k][l]);
326 for(int l=0;l<numdialogueboxes[k];l++){
327 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
328 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
329 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
330 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
331 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
333 int templength=strlen(dialoguetext[k][l]);
334 fpackf(tfile, "Bi",(templength));
335 for(int m=0;m<templength;m++){
336 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
337 if(dialoguetext[k][l][m]=='\0')
341 templength=strlen(dialoguename[k][l]);
342 fpackf(tfile, "Bi",templength);
343 for(int m=0;m<templength;m++){
344 fpackf(tfile, "Bb", dialoguename[k][l][m]);
345 if(dialoguename[k][l][m]=='\0')
349 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
350 fpackf(tfile, "Bi", participantfocus[k][l]);
351 fpackf(tfile, "Bi", participantaction[k][l]);
353 for(int m=0;m<10;m++)
354 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
356 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
360 for(int k=0;k<player[0].numclothes;k++){
361 int templength=strlen(player[0].clothes[k]);
362 fpackf(tfile, "Bi", templength);
363 for(int l=0;l<templength;l++)
364 fpackf(tfile, "Bb", player[0].clothes[k][l]);
365 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
368 fpackf(tfile, "Bi", environment);
370 fpackf(tfile, "Bi", objects.numobjects);
372 for(int k=0;k<objects.numobjects;k++)
373 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
374 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
376 fpackf(tfile, "Bi", numhotspots);
377 for(int i=0;i<numhotspots;i++){
378 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
379 int templength=strlen(hotspottext[i]);
380 fpackf(tfile, "Bi",templength);
381 for(int l=0;l<templength;l++)
382 fpackf(tfile, "Bb", hotspottext[i][l]);
385 fpackf(tfile, "Bi", numplayers);
386 if(numplayers<maxplayers)
387 for(int j=1;j<numplayers;j++){
388 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
389 player[j].coords.x, player[j].coords.y, player[j].coords.z,
390 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
391 if(player[j].num_weapons<5)
392 for(int k=0;k<player[j].num_weapons;k++)
393 fpackf(tfile, "Bi", weapons[player[j].weaponids[k]].getType());
394 if(player[j].numwaypoints<30){
395 fpackf(tfile, "Bi", player[j].numwaypoints);
396 for(int k=0;k<player[j].numwaypoints;k++){
397 fpackf(tfile, "Bf", player[j].waypoints[k].x);
398 fpackf(tfile, "Bf", player[j].waypoints[k].y);
399 fpackf(tfile, "Bf", player[j].waypoints[k].z);
400 fpackf(tfile, "Bi", player[j].waypointtype[k]);
402 fpackf(tfile, "Bi", player[j].waypoint);
404 player[j].numwaypoints=0;
405 player[j].waypoint=0;
406 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
409 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
410 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
411 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
412 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
414 float headprop, bodyprop, armprop, legprop;
415 if(player[j].creature==wolftype){
416 headprop=player[j].proportionhead.x/1.1;
417 bodyprop=player[j].proportionbody.x/1.1;
418 armprop=player[j].proportionarms.x/1.1;
419 legprop=player[j].proportionlegs.x/1.1;
420 }else if(player[j].creature==rabbittype){
421 headprop=player[j].proportionhead.x/1.2;
422 bodyprop=player[j].proportionbody.x/1.05;
423 armprop=player[j].proportionarms.x/1.00;
424 legprop=player[j].proportionlegs.x/1.1;
427 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
429 fpackf(tfile, "Bi", player[j].numclothes);
430 if(player[j].numclothes)
431 for(int k=0;k<player[j].numclothes;k++){
433 templength=strlen(player[j].clothes[k]);
434 fpackf(tfile, "Bi", templength);
435 for(int l=0;l<templength;l++)
436 fpackf(tfile, "Bb", player[j].clothes[k][l]);
437 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
441 fpackf(tfile, "Bi", game->numpathpoints);
442 for(int j=0;j<game->numpathpoints;j++){
443 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
444 for(int k=0;k<game->numpathpointconnect[j];k++)
445 fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
448 fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
453 static void ch_cellar(Game *game, const char *args)
455 game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
458 static void ch_tint(Game *game, const char *args)
460 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
463 static void ch_tintr(Game *game, const char *args)
468 static void ch_tintg(Game *game, const char *args)
473 static void ch_tintb(Game *game, const char *args)
478 static void ch_speed(Game *game, const char *args)
480 player[0].speedmult = atof(args);
483 static void ch_strength(Game *game, const char *args)
485 player[0].power = atof(args);
488 static void ch_power(Game *game, const char *args)
490 player[0].power = atof(args);
493 static void ch_size(Game *game, const char *args)
495 player[0].scale = atof(args) * .2;
498 static int find_closest()
501 float closestdist = std::numeric_limits<float>::max();
503 for (int i = 1; i < numplayers; i++) {
505 distance = findDistancefast(&player[i].coords,&player[0].coords);
506 if (distance < closestdist) {
507 closestdist = distance;
514 static void ch_sizenear(Game *game, const char *args)
516 int closest = find_closest();
519 player[closest].scale = atof(args) * .2;
522 static void set_proportion(int pnum, const char *args)
524 float headprop,bodyprop,armprop,legprop;
526 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
528 if(player[pnum].creature==wolftype){
529 player[pnum].proportionhead=1.1*headprop;
530 player[pnum].proportionbody=1.1*bodyprop;
531 player[pnum].proportionarms=1.1*armprop;
532 player[pnum].proportionlegs=1.1*legprop;
533 } else if(player[pnum].creature==rabbittype){
534 player[pnum].proportionhead=1.2*headprop;
535 player[pnum].proportionbody=1.05*bodyprop;
536 player[pnum].proportionarms=1.00*armprop;
537 player[pnum].proportionlegs=1.1*legprop;
538 player[pnum].proportionlegs.y=1.05*legprop;
542 static void ch_proportion(Game *game, const char *args)
544 set_proportion(0, args);
547 static void ch_proportionnear(Game *game, const char *args)
549 int closest = find_closest();
551 set_proportion(closest, args);
554 static void set_protection(int pnum, const char *args)
556 float head, high, low;
557 sscanf(args, "%f%f%f", &head, &high, &low);
559 player[pnum].protectionhead = head;
560 player[pnum].protectionhigh = high;
561 player[pnum].protectionlow = low;
564 static void ch_protection(Game *game, const char *args)
566 set_protection(0, args);
569 static void ch_protectionnear(Game *game, const char *args)
571 int closest = find_closest();
573 set_protection(closest, args);
576 static void set_armor(int pnum, const char *args)
578 float head, high, low;
579 sscanf(args, "%f%f%f", &head, &high, &low);
581 player[pnum].armorhead = head;
582 player[pnum].armorhigh = high;
583 player[pnum].armorlow = low;
586 static void ch_armor(Game *game, const char *args)
591 static void ch_armornear(Game *game, const char *args)
593 int closest = find_closest();
595 set_armor(closest, args);
598 static void ch_protectionreset(Game *game, const char *args)
600 set_protection(0, "1 1 1");
601 set_armor(0, "1 1 1");
604 static void set_metal(int pnum, const char *args)
606 float head, high, low;
607 sscanf(args, "%f%f%f", &head, &high, &low);
609 player[pnum].metalhead = head;
610 player[pnum].metalhigh = high;
611 player[pnum].metallow = low;
614 static void ch_metal(Game *game, const char *args)
619 static void set_noclothes(int pnum, Game *game, const char *args)
621 player[pnum].numclothes = 0;
622 game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
623 &player[pnum].skeleton.drawmodel.textureptr,1,
624 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
627 static void ch_noclothes(Game *game, const char *args)
629 set_noclothes(0, game, args);
632 static void ch_noclothesnear(Game *game, const char *args)
634 int closest = find_closest();
636 set_noclothes(closest, game, args);
640 static void set_clothes(int pnum, Game *game, const char *args)
643 snprintf(buf, 63, ":Data:Textures:%s.png", args);
645 if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
648 player[pnum].DoMipmaps();
649 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
650 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
651 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
652 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
653 player[pnum].numclothes++;
656 static void ch_clothes(Game *game, const char *args)
658 set_clothes(0, game, args);
661 static void ch_clothesnear(Game *game, const char *args)
663 int closest = find_closest();
665 set_clothes(closest, game, args);
668 static void ch_belt(Game *game, const char *args)
670 player[0].skeleton.clothes = !player[0].skeleton.clothes;
674 static void ch_cellophane(Game *game, const char *args)
676 cellophane = !cellophane;
677 float mul = cellophane ? 0 : 1;
679 for (int i = 0; i < numplayers; i++) {
680 player[i].proportionhead.z = player[i].proportionhead.x * mul;
681 player[i].proportionbody.z = player[i].proportionbody.x * mul;
682 player[i].proportionarms.z = player[i].proportionarms.x * mul;
683 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
687 static void ch_funnybunny(Game *game, const char *args)
689 player[0].skeleton.id=0;
690 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
691 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
692 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
693 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
694 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
695 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
696 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
697 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
698 player[0].creature=rabbittype;
700 player[0].headless=0;
701 player[0].damagetolerance=200;
702 set_proportion(0, "1 1 1 1");
705 static void ch_wolfie(Game *game, const char *args)
707 player[0].skeleton.id=0;
708 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
709 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
710 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
711 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
712 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
713 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
714 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
715 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
716 player[0].creature=wolftype;
717 player[0].damagetolerance=300;
718 set_proportion(0, "1 1 1 1");
721 static void ch_wolfieisgod(Game *game, const char *args)
723 ch_wolfie(game, args);
726 static void ch_wolf(Game *game, const char *args)
728 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
729 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
732 static void ch_snowwolf(Game *game, const char *args)
734 game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
735 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
738 static void ch_darkwolf(Game *game, const char *args)
740 game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
741 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
744 static void ch_lizardwolf(Game *game, const char *args)
746 game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
747 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
750 static void ch_white(Game *game, const char *args)
752 game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
753 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
756 static void ch_brown(Game *game, const char *args)
758 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
759 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
762 static void ch_black(Game *game, const char *args)
764 game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
765 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
768 static void ch_sizemin(Game *game, const char *args)
770 for (int i = 1; i < numplayers; i++)
771 if (player[i].scale < 0.8 * 0.2)
772 player[i].scale = 0.8 * 0.2;
775 static void ch_tutorial(Game *game, const char *args)
777 tutoriallevel = atoi(args);
780 static void ch_hostile(Game *game, const char *args)
782 hostile = atoi(args);
785 static void ch_indemo(Game *game, const char *args)
788 hotspot[numhotspots]=player[0].coords;
789 hotspotsize[numhotspots]=0;
790 hotspottype[numhotspots]=-111;
791 strcpy(hotspottext[numhotspots],"mapname");
795 static void ch_notindemo(Game *game, const char *args)
801 static void ch_type(Game *game, const char *args)
803 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
804 for (int i = 0; i < n; i++)
805 if (stripfx(args, editortypenames[i])) {
811 static void ch_path(Game *game, const char *args)
813 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
814 for (int i = 0; i < n; i++)
815 if (stripfx(args, pathtypenames[i])) {
821 static void ch_hs(Game *game, const char *args)
823 hotspot[numhotspots]=player[0].coords;
827 sscanf(args, "%f%d %n", &size, &type, &shift);
829 hotspotsize[numhotspots] = size;
830 hotspottype[numhotspots] = type;
832 strcpy(hotspottext[numhotspots], args + shift);
833 strcat(hotspottext[numhotspots], "\n");
838 static void ch_dialogue(Game *game, const char *args)
841 char buf1[32], buf2[64];
843 sscanf(args, "%d %31s", &dlg, buf1);
844 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
846 dialoguetype[numdialogues] = dlg;
848 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
849 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
851 ifstream ipstream(ConvertFileName(buf2));
852 ipstream.ignore(256,':');
853 ipstream >> numdialogueboxes[numdialogues];
854 for(int i=0;i<numdialogueboxes[numdialogues];i++){
855 ipstream.ignore(256,':');
856 ipstream.ignore(256,':');
857 ipstream.ignore(256,' ');
858 ipstream >> dialogueboxlocation[numdialogues][i];
859 ipstream.ignore(256,':');
860 ipstream >> dialogueboxcolor[numdialogues][i][0];
861 ipstream >> dialogueboxcolor[numdialogues][i][1];
862 ipstream >> dialogueboxcolor[numdialogues][i][2];
863 ipstream.ignore(256,':');
864 ipstream.getline(dialoguename[numdialogues][i],64);
865 ipstream.ignore(256,':');
866 ipstream.ignore(256,' ');
867 ipstream.getline(dialoguetext[numdialogues][i],128);
868 for(int j=0;j<128;j++){
869 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
871 ipstream.ignore(256,':');
872 ipstream >> dialogueboxsound[numdialogues][i];
875 for(int i=0;i<numdialogueboxes[numdialogues];i++){
876 for(int j=0;j<numplayers;j++){
877 participantfacing[numdialogues][i][j]=player[j].facing;
884 whichdialogue=numdialogues;
889 static void ch_fixdialogue(Game *game, const char *args)
891 char buf1[32], buf2[64];
894 sscanf(args, "%d %31s", &whichdi, buf1);
895 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
897 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
898 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
900 ifstream ipstream(ConvertFileName(buf2));
901 ipstream.ignore(256,':');
902 ipstream >> numdialogueboxes[whichdi];
903 for(int i=0;i<numdialogueboxes[whichdi];i++){
904 ipstream.ignore(256,':');
905 ipstream.ignore(256,':');
906 ipstream.ignore(256,' ');
907 ipstream >> dialogueboxlocation[whichdi][i];
908 ipstream.ignore(256,':');
909 ipstream >> dialogueboxcolor[whichdi][i][0];
910 ipstream >> dialogueboxcolor[whichdi][i][1];
911 ipstream >> dialogueboxcolor[whichdi][i][2];
912 ipstream.ignore(256,':');
913 ipstream.getline(dialoguename[whichdi][i],64);
914 ipstream.ignore(256,':');
915 ipstream.ignore(256,' ');
916 ipstream.getline(dialoguetext[whichdi][i],128);
917 for(int j=0;j<128;j++){
918 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
920 ipstream.ignore(256,':');
921 ipstream >> dialogueboxsound[whichdi][i];
927 static void ch_fixtype(Game *game, const char *args)
930 sscanf(args, "%d", &dlg);
931 dialoguetype[0] = dlg;
934 static void ch_fixrotation(Game *game, const char *args)
936 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
939 static void ch_ddialogue(Game *game, const char *args)
945 static void ch_dhs(Game *game, const char *args)
951 static void ch_immobile(Game *game, const char *args)
953 player[0].immobile = 1;
956 static void ch_allimmobile(Game *game, const char *args)
958 for (int i = 1; i < numplayers; i++)
959 player[i].immobile = 1;
962 static void ch_mobile(Game *game, const char *args)
964 player[0].immobile = 0;
967 static void ch_default(Game *game, const char *args)
969 player[0].armorhead=1;
970 player[0].armorhigh=1;
971 player[0].armorlow=1;
972 player[0].protectionhead=1;
973 player[0].protectionhigh=1;
974 player[0].protectionlow=1;
975 player[0].metalhead=1;
976 player[0].metalhigh=1;
977 player[0].metallow=1;
979 player[0].speedmult=1;
982 if(player[0].creature==wolftype){
983 player[0].proportionhead=1.1;
984 player[0].proportionbody=1.1;
985 player[0].proportionarms=1.1;
986 player[0].proportionlegs=1.1;
987 } else if(player[0].creature==rabbittype){
988 player[0].proportionhead=1.2;
989 player[0].proportionbody=1.05;
990 player[0].proportionarms=1.00;
991 player[0].proportionlegs=1.1;
992 player[0].proportionlegs.y=1.05;
995 player[0].numclothes=0;
996 game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
997 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
998 &player[0].skeleton.skinsize);
1000 editoractive=typeactive;
1001 player[0].immobile=0;
1004 static void ch_play(Game *game, const char *args)
1007 sscanf(args, "%d", &dlg);
1008 whichdialogue = dlg;
1010 if (whichdialogue >= numdialogues)
1013 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1014 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1015 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1016 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1017 player[participantfocus[whichdialogue][i]].velocity=0;
1018 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1019 player[participantfocus[whichdialogue][i]].targetframe=0;
1025 playdialogueboxsound();
1028 static void ch_mapkilleveryone(Game *game, const char *args)
1030 maptype = mapkilleveryone;
1033 static void ch_mapkillmost(Game *game, const char *args)
1035 maptype = mapkillmost;
1038 static void ch_mapkillsomeone(Game *game, const char *args)
1040 maptype = mapkillsomeone;
1043 static void ch_mapgosomewhere(Game *game, const char *args)
1045 maptype = mapgosomewhere;
1048 static void ch_viewdistance(Game *game, const char *args)
1050 viewdistance = atof(args)*100;
1053 static void ch_fadestart(Game *game, const char *args)
1055 fadestart = atof(args);
1058 static void ch_slomo(Game *game, const char *args)
1060 slomospeed = atof(args);
1065 static void ch_slofreq(Game *game, const char *args)
1067 slomofreq = atof(args);
1070 static void ch_skytint(Game *game, const char *args)
1072 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1074 skyboxlightr=skyboxr;
1075 skyboxlightg=skyboxg;
1076 skyboxlightb=skyboxb;
1078 game->SetUpLighting();
1080 terrain.DoShadows();
1081 objects.DoShadows();
1084 static void ch_skylight(Game *game, const char *args)
1086 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1088 game->SetUpLighting();
1090 terrain.DoShadows();
1091 objects.DoShadows();
1094 static void ch_skybox(Game *game, const char *args)
1096 skyboxtexture = !skyboxtexture;
1098 game->SetUpLighting();
1100 terrain.DoShadows();
1101 objects.DoShadows();
1104 static void cmd_dispatch(Game *game, const string cmd)
1106 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1108 for (i = 0; i < n_cmds; i++)
1109 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1111 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1112 cmd_handlers[i](game, cmd.substr(cmd.find(' ')+1).c_str());
1115 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1118 /********************> Tick() <*****/
1119 extern bool save_image(const char * fname);
1120 void Screenshot (void)
1123 time_t t = time(NULL);
1124 struct tm *tme = localtime(&t);
1125 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);
1128 mkdir("Screenshots");
1130 mkdir("Screenshots", S_IRWXU);
1136 void Game::SetUpLighting(){
1137 if(environment==snowyenvironment)
1138 light.setColors(.65,.65,.7,.4,.4,.44);
1139 if(environment==desertenvironment)
1140 light.setColors(.95,.95,.95,.4,.35,.3);
1141 if(environment==grassyenvironment)
1142 light.setColors(.95,.95,1,.4,.4,.44);
1144 light.setColors(1,1,1,.4,.4,.4);
1146 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1147 light.color[0]*=(skyboxlightr+average)/2;
1148 light.color[1]*=(skyboxlightg+average)/2;
1149 light.color[2]*=(skyboxlightb+average)/2;
1150 light.ambient[0]*=(skyboxlightr+average)/2;
1151 light.ambient[1]*=(skyboxlightg+average)/2;
1152 light.ambient[2]*=(skyboxlightb+average)/2;
1155 int Game::findPathDist(int start,int end){
1156 int smallestcount,count,connected;
1157 int last,last2,last3,last4;
1161 for(int i=0;i<50;i++){
1167 while(last!=end&&count<30){
1169 for(int j=0;j<numpathpoints;j++){
1170 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1173 if(numpathpointconnect[j])
1174 for(int k=0;k<numpathpointconnect[j];k++){
1175 if(pathpointconnect[j][k]==last)connected=1;
1178 if(numpathpointconnect[last])
1179 for(int k=0;k<numpathpointconnect[last];k++){
1180 if(pathpointconnect[last][k]==j)connected=1;
1183 if(closest==-1||Random()%2==0){
1194 if(count<smallestcount)smallestcount=count;
1196 return smallestcount;
1199 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1200 static XYZ colpoint,colviewer,coltarget;
1201 static float minx,minz,maxx,maxz,miny,maxy;
1203 minx=min(startpoint.x,endpoint.x)-1;
1204 miny=min(startpoint.y,endpoint.y)-1;
1205 minz=min(startpoint.z,endpoint.z)-1;
1206 maxx=max(startpoint.x,endpoint.x)+1;
1207 maxy=max(startpoint.y,endpoint.y)+1;
1208 maxz=max(startpoint.z,endpoint.z)+1;
1210 for(int i=0;i<objects.numobjects;i++){
1211 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1212 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1213 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1214 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1215 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1216 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1217 if( objects.type[i]!=treeleavestype&&
1218 objects.type[i]!=bushtype&&
1219 objects.type[i]!=firetype){
1220 colviewer=startpoint;
1222 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1227 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1232 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1233 static XYZ colpoint,colviewer,coltarget;
1234 static float minx,minz,maxx,maxz,miny,maxy;
1235 static int i; //FIXME: see below
1237 minx=min(startpoint.x,endpoint.x)-1;
1238 miny=min(startpoint.y,endpoint.y)-1;
1239 minz=min(startpoint.z,endpoint.z)-1;
1240 maxx=max(startpoint.x,endpoint.x)+1;
1241 maxy=max(startpoint.y,endpoint.y)+1;
1242 maxz=max(startpoint.z,endpoint.z)+1;
1245 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1246 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1247 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1248 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1249 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1250 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1251 if( objects.type[what]!=treeleavestype&&
1252 objects.type[what]!=bushtype&&
1253 objects.type[what]!=firetype){
1254 colviewer=startpoint;
1257 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1262 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1267 void Game::Setenvironment(int which)
1271 LOG(" Setting environment...");
1273 float temptexdetail;
1276 pause_sound(stream_snowtheme);
1277 pause_sound(stream_grasstheme);
1278 pause_sound(stream_deserttheme);
1279 pause_sound(stream_wind);
1280 pause_sound(stream_desertambient);
1283 if(environment==snowyenvironment){
1287 emit_stream_np(stream_wind);
1289 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1290 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1291 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1292 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1294 footstepsound = footstepsn1;
1295 footstepsound2 = footstepsn2;
1296 footstepsound3 = footstepst1;
1297 footstepsound4 = footstepst2;
1299 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1301 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1303 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1308 temptexdetail=texdetail;
1309 if(texdetail>1)texdetail=4;
1310 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1311 ":Data:Textures:Skybox(snow):Left.jpg",
1312 ":Data:Textures:Skybox(snow):Back.jpg",
1313 ":Data:Textures:Skybox(snow):Right.jpg",
1314 ":Data:Textures:Skybox(snow):Up.jpg",
1315 ":Data:Textures:Skybox(snow):Down.jpg");
1320 texdetail=temptexdetail;
1321 } else if(environment==desertenvironment){
1324 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1325 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1326 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1327 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1331 emit_stream_np(stream_desertambient);
1333 footstepsound = footstepsn1;
1334 footstepsound2 = footstepsn2;
1335 footstepsound3 = footstepsn1;
1336 footstepsound4 = footstepsn2;
1338 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1340 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1342 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1346 temptexdetail=texdetail;
1347 if(texdetail>1)texdetail=4;
1348 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1349 ":Data:Textures:Skybox(sand):Left.jpg",
1350 ":Data:Textures:Skybox(sand):Back.jpg",
1351 ":Data:Textures:Skybox(sand):Right.jpg",
1352 ":Data:Textures:Skybox(sand):Up.jpg",
1353 ":Data:Textures:Skybox(sand):Down.jpg");
1358 texdetail=temptexdetail;
1359 } else if(environment==grassyenvironment){
1362 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1363 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1364 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1365 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1368 emit_stream_np(stream_wind, 100.);
1370 footstepsound = footstepgr1;
1371 footstepsound2 = footstepgr2;
1372 footstepsound3 = footstepst1;
1373 footstepsound4 = footstepst2;
1375 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1377 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1379 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1383 temptexdetail=texdetail;
1384 if(texdetail>1)texdetail=4;
1385 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1386 ":Data:Textures:Skybox(grass):Left.jpg",
1387 ":Data:Textures:Skybox(grass):Back.jpg",
1388 ":Data:Textures:Skybox(grass):Right.jpg",
1389 ":Data:Textures:Skybox(grass):Up.jpg",
1390 ":Data:Textures:Skybox(grass):Down.jpg");
1394 texdetail=temptexdetail;
1396 temptexdetail=texdetail;
1398 terrain.load(":Data:Textures:heightmap.png");
1400 texdetail=temptexdetail;
1403 void Game::Loadlevel(int which) {
1409 Loadlevel("tutorial");
1410 } else if(which >= 0 && which <= 15) {
1412 snprintf(buf, 32, "map%d", which + 1); // challenges
1415 Loadlevel("mapsave");
1418 void Game::Loadlevel(const char *name) {
1421 static const char *pfx = ":Data:Maps:";
1424 float headprop,legprop,armprop,bodyprop;
1428 LOG(std::string("Loading level...") + name);
1440 if(tutoriallevel!=-1)
1445 if(tutoriallevel==1)
1447 if(tutorialstage==0) {
1448 tutorialstagetime=0;
1452 pause_sound(whooshsound);
1453 pause_sound(stream_firesound);
1455 // Change the map filename into something that is os specific
1456 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1457 sprintf(buf, "%s%s", pfx, name);
1458 const char *FixedFN = ConvertFileName(buf);
1462 //~ char* buff=getcwd(NULL,0);
1463 //~ cout << buff << " " << FixedFN << endl;
1465 tfile=fopen( FixedFN, "rb" );
1467 pause_sound(stream_firesound);
1473 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1477 for(int i=0;i<20;i++)
1478 dialoguegonethrough[i]=0;
1487 difficulty=accountactive->getDifficulty();
1506 for(int i=0;i<100;i++)
1526 bonustotal=startbonustotal;
1531 emit_sound_np(consolesuccesssound);
1536 if(!stealthloading){
1537 terrain.numdecals=0;
1538 Sprite::deleteSprites();
1539 for(int i=0;i<objects.numobjects;i++)
1540 objects.model[i].numdecals=0;
1542 int j=objects.numobjects;
1543 for(int i=0;i<j;i++){
1544 objects.DeleteObject(0);
1549 for(int i=0;i<subdivision;i++)
1550 for(int j=0;j<subdivision;j++)
1551 terrain.patchobjectnum[i][j]=0;
1558 funpackf(tfile, "Bi", &mapvers);
1560 funpackf(tfile, "Bi", &indemo);
1564 funpackf(tfile, "Bi", &maptype);
1566 maptype=mapkilleveryone;
1568 funpackf(tfile, "Bi", &hostile);
1572 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1578 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1586 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1588 skyboxlightr=skyboxr;
1589 skyboxlightg=skyboxg;
1590 skyboxlightb=skyboxb;
1593 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);
1595 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1596 player[0].originalcoords=player[0].coords;
1597 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1598 for(int j=0;j<player[0].num_weapons;j++){
1599 player[0].weaponids[j]=weapons.size();
1601 funpackf(tfile, "Bi", &type);
1602 weapons.push_back(Weapon(type,0));
1608 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1609 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1610 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1611 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1613 funpackf(tfile, "Bi", &player[0].numclothes);
1616 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1618 player[0].whichskin=0;
1619 player[0].creature=rabbittype;
1622 player[0].lastattack=-1;
1623 player[0].lastattack2=-1;
1624 player[0].lastattack3=-1;
1628 funpackf(tfile, "Bi", &numdialogues);
1629 for(int k=0;k<numdialogues;k++){
1630 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1631 funpackf(tfile, "Bi", &dialoguetype[k]);
1632 for(int l=0;l<10;l++){
1633 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1634 funpackf(tfile, "Bf", &participantrotation[k][l]);
1636 for(int l=0;l<numdialogueboxes[k];l++){
1637 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1638 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1639 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1640 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1641 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1643 funpackf(tfile, "Bi",&templength);
1644 if(templength>128||templength<=0)
1647 for(m=0;m<templength;m++){
1648 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1649 if(dialoguetext[k][l][m]=='\0')
1652 dialoguetext[k][l][m] = 0;
1654 funpackf(tfile, "Bi",&templength);
1655 if(templength>64||templength<=0)templength=64;
1656 for(m=0;m<templength;m++){
1657 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1658 if(dialoguename[k][l][m]=='\0')
1661 dialoguename[k][l][m] = 0;
1662 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1663 funpackf(tfile, "Bi", &participantfocus[k][l]);
1664 funpackf(tfile, "Bi", &participantaction[k][l]);
1667 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1669 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1675 for(int k=0;k<player[0].numclothes;k++){
1676 funpackf(tfile, "Bi", &templength);
1677 for(int l=0;l<templength;l++)
1678 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1679 player[0].clothes[k][templength]='\0';
1680 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1683 funpackf(tfile, "Bi", &environment);
1685 funpackf(tfile, "Bi", &objects.numobjects);
1686 for(int i=0;i<objects.numobjects;i++){
1687 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]);
1688 if(objects.type[i]==treeleavestype)
1689 objects.scale[i]=objects.scale[i-1];
1693 funpackf(tfile, "Bi", &numhotspots);
1694 for(int i=0;i<numhotspots;i++){
1695 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1696 funpackf(tfile, "Bi", &templength);
1698 for(int l=0;l<templength;l++)
1699 funpackf(tfile, "Bb", &hotspottext[i][l]);
1700 hotspottext[i][templength]='\0';
1701 if(hotspottype[i]==-111)
1710 if(!stealthloading){
1712 for(int i=0;i<objects.numobjects;i++)
1713 objects.center+=objects.position[i];
1714 objects.center/=objects.numobjects;
1720 float maxdistance=0;
1722 //~ int whichclosest;
1723 for(int i=0;i<objects.numobjects;i++){
1724 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1725 if(tempdist>maxdistance){
1727 maxdistance=tempdist;
1730 objects.radius=fast_sqrt(maxdistance);
1735 //mapcenter=objects.center;
1736 //mapradius=objects.radius;
1738 funpackf(tfile, "Bi", &numplayers);
1739 int howmanyremoved=0;
1740 bool removeanother=0;
1741 if(numplayers>1&&numplayers<maxplayers){
1742 for(int i=1;i<numplayers;i++){
1747 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);
1749 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1751 player[i-howmanyremoved].howactive=typeactive;
1753 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1755 player[i-howmanyremoved].scale=-1;
1757 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1759 player[i-howmanyremoved].immobile=0;
1761 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1763 player[i-howmanyremoved].rotation=0;
1764 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1765 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1770 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1771 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1772 player[i-howmanyremoved].weaponids[j]=weapons.size();
1774 funpackf(tfile, "Bi", &type);
1775 weapons.push_back(Weapon(type,i));
1778 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1779 //player[i-howmanyremoved].numwaypoints=10;
1780 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1781 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1782 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1783 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1785 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1787 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1790 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1791 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1792 player[i-howmanyremoved].waypoint=0;
1794 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1795 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1796 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1797 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1800 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1807 if(player[i-howmanyremoved].creature==wolftype){
1808 player[i-howmanyremoved].proportionhead=1.1*headprop;
1809 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1810 player[i-howmanyremoved].proportionarms=1.1*armprop;
1811 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1814 if(player[i-howmanyremoved].creature==rabbittype){
1815 player[i-howmanyremoved].proportionhead=1.2*headprop;
1816 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1817 player[i-howmanyremoved].proportionarms=1.00*armprop;
1818 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1819 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1822 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1823 if(player[i-howmanyremoved].numclothes){
1824 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1826 funpackf(tfile, "Bi", &templength);
1827 for(int l=0;l<templength;l++)
1828 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1829 player[i-howmanyremoved].clothes[k][templength]='\0';
1830 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1839 numplayers-=howmanyremoved;
1840 funpackf(tfile, "Bi", &numpathpoints);
1841 if(numpathpoints>30||numpathpoints<0)
1843 for(int j=0;j<numpathpoints;j++){
1844 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1845 for(int k=0;k<numpathpointconnect[j];k++){
1846 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1852 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1855 if(environment!=oldenvironment)
1856 Setenvironment(environment);
1857 oldenvironment=environment;
1859 if(!stealthloading){
1860 int j=objects.numobjects;
1861 objects.numobjects=0;
1862 for(int i=0;i<j;i++){
1863 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1868 terrain.DoShadows();
1871 objects.DoShadows();
1878 if(numplayers>maxplayers-1)
1879 numplayers=maxplayers-1;
1880 for(int i=0;i<numplayers;i++){
1886 if(i==0||player[i].scale<0)
1888 player[i].skeleton.free=0;
1889 player[i].skeleton.id=i;
1891 player[i].creature=rabbittype;
1892 if(player[i].creature!=wolftype){
1893 player[i].skeleton.Load(
1894 (char *)":Data:Skeleton:Basic Figure",
1895 (char *)":Data:Skeleton:Basic Figurelow",
1896 (char *)":Data:Skeleton:Rabbitbelt",
1897 (char *)":Data:Models:Body.solid",
1898 (char *)":Data:Models:Body2.solid",
1899 (char *)":Data:Models:Body3.solid",
1900 (char *)":Data:Models:Body4.solid",
1901 (char *)":Data:Models:Body5.solid",
1902 (char *)":Data:Models:Body6.solid",
1903 (char *)":Data:Models:Body7.solid",
1904 (char *)":Data:Models:Bodylow.solid",
1905 (char *)":Data:Models:Belt.solid",0);
1907 if(player[i].creature!=wolftype){
1908 player[i].skeleton.Load(
1909 (char *)":Data:Skeleton:Basic Figure",
1910 (char *)":Data:Skeleton:Basic Figurelow",
1911 (char *)":Data:Skeleton:Rabbitbelt",
1912 (char *)":Data:Models:Body.solid",
1913 (char *)":Data:Models:Body2.solid",
1914 (char *)":Data:Models:Body3.solid",
1915 (char *)":Data:Models:Body4.solid",
1916 (char *)":Data:Models:Body5.solid",
1917 (char *)":Data:Models:Body6.solid",
1918 (char *)":Data:Models:Body7.solid",
1919 (char *)":Data:Models:Bodylow.solid",
1920 (char *)":Data:Models:Belt.solid",1);
1921 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1923 if(player[i].creature==wolftype){
1924 player[i].skeleton.Load(
1925 (char *)":Data:Skeleton:Basic Figure Wolf",
1926 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1927 (char *)":Data:Skeleton:Rabbitbelt",
1928 (char *)":Data:Models:Wolf.solid",
1929 (char *)":Data:Models:Wolf2.solid",
1930 (char *)":Data:Models:Wolf3.solid",
1931 (char *)":Data:Models:Wolf4.solid",
1932 (char *)":Data:Models:Wolf5.solid",
1933 (char *)":Data:Models:Wolf6.solid",
1934 (char *)":Data:Models:Wolf7.solid",
1935 (char *)":Data:Models:Wolflow.solid",
1936 (char *)":Data:Models:Belt.solid",0);
1942 //~ texsize=512*512*3/texdetail/texdetail;
1944 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1946 if(player[i].numclothes){
1947 for(int j=0;j<player[i].numclothes;j++){
1948 tintr=player[i].clothestintr[j];
1949 tintg=player[i].clothestintg[j];
1950 tintb=player[i].clothestintb[j];
1951 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1953 player[i].DoMipmaps();
1956 player[i].currentanimation=bounceidleanim;
1957 player[i].targetanimation=bounceidleanim;
1958 player[i].currentframe=0;
1959 player[i].targetframe=1;
1961 player[i].speed=1+(float)(Random()%100)/1000;
1963 player[i].speed-=.2;
1965 player[i].speed-=.1;
1967 player[i].velocity=0;
1968 player[i].oldcoords=player[i].coords;
1969 player[i].realoldcoords=player[i].coords;
1972 player[i].skeleton.id=i;
1973 player[i].updatedelay=0;
1974 player[i].normalsupdatedelay=0;
1976 player[i].aitype=passivetype;
1977 player[i].madskills=0;
1980 player[i].proportionhead=1.2;
1981 player[i].proportionbody=1.05;
1982 player[i].proportionarms=1.00;
1983 player[i].proportionlegs=1.1;
1984 player[i].proportionlegs.y=1.05;
1986 player[i].headless=0;
1987 player[i].currentoffset=0;
1988 player[i].targetoffset=0;
1990 player[i].damagetolerance=200;
1992 if(player[i].creature==wolftype){
1993 if(i==0||player[i].scale<0)
1994 player[i].scale=.23;
1995 player[i].damagetolerance=300;
2001 player[i].proportionhead.z=0;
2002 player[i].proportionbody.z=0;
2003 player[i].proportionarms.z=0;
2004 player[i].proportionlegs.z=0;
2007 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2009 player[i].headmorphness=0;
2010 player[i].targetheadmorphness=1;
2011 player[i].headmorphstart=0;
2012 player[i].headmorphend=0;
2014 player[i].pausetime=0;
2017 player[i].jumppower=5;
2019 player[i].permanentdamage=0;
2020 player[i].superpermanentdamage=0;
2022 player[i].forwardkeydown=0;
2023 player[i].leftkeydown=0;
2024 player[i].backkeydown=0;
2025 player[i].rightkeydown=0;
2026 player[i].jumpkeydown=0;
2027 player[i].crouchkeydown=0;
2028 player[i].throwkeydown=0;
2030 player[i].collided=-10;
2032 player[i].bloodloss=0;
2033 player[i].weaponactive=-1;
2034 player[i].weaponstuck=-1;
2035 player[i].bleeding=0;
2036 player[i].deathbleeding=0;
2037 player[i].stunned=0;
2038 player[i].hasvictim=0;
2039 player[i].wentforweapon=0;
2042 player[0].aitype=playercontrolled;
2043 player[0].weaponactive=-1;
2046 player[0].power=1/.9;
2049 player[0].power=1/.8;
2052 player[0].damagetolerance=250;
2054 player[0].damagetolerance=300;
2056 player[0].armorhead*=1.5;
2058 player[0].armorhigh*=1.5;
2060 player[0].armorlow*=1.5;
2061 cameraloc=player[0].coords;
2063 rotation=player[0].rotation;
2065 hawkcoords=player[0].coords;
2070 //~ for(int i=0;i<weapons.size();i++){
2073 LOG("Starting background music...");
2075 OPENAL_StopSound(OPENAL_ALL);
2076 if(environment==snowyenvironment){
2078 emit_stream_np(stream_wind);
2079 }else if(environment==desertenvironment){
2081 emit_stream_np(stream_desertambient);
2082 }else if(environment==grassyenvironment){
2084 emit_stream_np(stream_wind, 100.);
2086 oldmusicvolume[0]=0;
2087 oldmusicvolume[1]=0;
2088 oldmusicvolume[2]=0;
2089 oldmusicvolume[3]=0;
2101 void Game::doTutorial(){
2102 if(tutorialstagetime>tutorialmaxtime){
2105 if(tutorialstage<=1){
2110 switch(tutorialstage){
2116 tutorialmaxtime=600;
2118 tutorialmaxtime=1000;
2120 tutorialmaxtime=600;
2122 tutorialmaxtime=600;
2124 tutorialmaxtime=600;
2126 tutorialmaxtime=600;
2128 tutorialmaxtime=600;
2132 tutorialmaxtime=1000;
2134 tutorialmaxtime=1000;
2149 player[1].coords=(temp+temp2)/2;
2151 emit_sound_at(fireendsound, player[1].coords);
2153 for(int i=0;i<player[1].skeleton.num_joints;i++){
2155 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2156 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2157 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;
2158 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2159 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2164 tutorialmaxtime=500;
2166 tutorialmaxtime=500;
2168 tutorialmaxtime=500;
2170 tutorialmaxtime=500;
2173 //tutorialmaxtime=500;
2175 tutorialmaxtime=500;
2177 tutorialmaxtime=500;
2184 tutorialmaxtime=500;
2186 tutorialmaxtime=500;
2188 tutorialmaxtime=500;
2190 tutorialmaxtime=500;
2197 player[1].aitype=attacktypecutoff;
2199 tutorialmaxtime=400;
2201 tutorialmaxtime=400;
2202 player[0].escapednum=0;
2207 player[1].aitype=passivetype;
2213 tutorialmaxtime=400;
2216 player[1].aitype=attacktypecutoff;
2218 tutorialmaxtime=400;
2220 tutorialmaxtime=400;
2225 player[1].aitype=passivetype;
2232 player[1].aitype=attacktypecutoff;
2237 player[1].aitype=passivetype;
2249 w.position=(temp+temp2)/2;
2250 w.tippoint=(temp+temp2)/2;
2260 weapons.push_back(w);
2263 tutorialmaxtime=300;
2265 tutorialmaxtime=300;
2269 tutorialmaxtime=300;
2272 player[0].weaponactive=-1;
2273 player[0].num_weapons=0;
2274 player[1].weaponactive=0;
2275 player[1].num_weapons=1;
2276 player[1].weaponids[0]=0;
2280 player[1].aitype=attacktypecutoff;
2282 tutorialmaxtime=300;
2285 player[0].weaponactive=-1;
2286 player[0].num_weapons=0;
2287 player[1].weaponactive=0;
2288 player[1].num_weapons=1;
2289 player[1].weaponids[0]=0;
2291 tutorialmaxtime=300;
2294 player[0].weaponactive=-1;
2295 player[0].num_weapons=0;
2296 player[1].weaponactive=0;
2297 player[1].num_weapons=1;
2298 player[1].weaponids[0]=0;
2300 weapons[0].setType(sword);
2302 tutorialmaxtime=300;
2316 w.position=(temp+temp2)/2;
2317 w.tippoint=(temp+temp2)/2;
2327 weapons.push_back(w);
2331 player[0].weaponactive=0;
2332 player[0].num_weapons=1;
2333 player[0].weaponids[0]=1;
2334 player[1].weaponactive=0;
2335 player[1].num_weapons=1;
2336 player[1].weaponids[0]=0;
2342 player[1].aitype=passivetype;
2348 player[0].weaponactive=0;
2349 player[0].num_weapons=1;
2350 player[0].weaponids[0]=1;
2351 player[1].weaponactive=0;
2352 player[1].num_weapons=1;
2353 player[1].weaponids[0]=0;
2355 if(player[0].weaponactive!=-1)
2356 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2358 weapons[0].setType(staff);
2362 player[1].aitype=passivetype;
2364 tutorialmaxtime=200;
2366 weapons[1].position=1000;
2367 weapons[1].tippoint=1000;
2369 weapons[0].setType(knife);
2372 player[1].weaponactive=-1;
2373 player[1].num_weapons=0;
2374 player[0].weaponactive=0;
2375 player[0].num_weapons=1;
2376 player[0].weaponids[0]=0;
2382 emit_sound_at(fireendsound, player[1].coords);
2384 for(int i=0;i<player[1].skeleton.num_joints;i++){
2386 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2387 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2388 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;
2389 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2390 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2394 player[1].num_weapons=0;
2395 player[1].weaponstuck=-1;
2396 player[1].weaponactive=-1;
2401 tutorialmaxtime=80000;
2402 break; default: break;
2404 if(tutorialstage<=51)tutorialstagetime=0;
2408 if(tutorialstagetime<tutorialmaxtime-3){
2409 switch(tutorialstage){
2410 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2411 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2412 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2413 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2414 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2415 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2416 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2417 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2418 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2419 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2420 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2421 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2422 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2423 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2424 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2425 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2426 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2427 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2428 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2429 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2430 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2432 if(player[0].escapednum==2) {
2436 player[1].aitype=passivetype;
2438 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2439 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2441 if(animation[player[0].targetanimation].attack==reversal){
2445 player[1].aitype=passivetype;
2447 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2448 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2449 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2450 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2451 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2452 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2453 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2454 break; default: break;
2456 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2459 if(tutorialstagetime==tutorialmaxtime-3){
2460 emit_sound_np(consolesuccesssound);
2463 if(tutorialsuccess>=1){
2464 if(tutorialstage==34||tutorialstage==35)
2465 tutorialstagetime=tutorialmaxtime-1;
2469 if(tutorialstage<14||tutorialstage>=50){
2470 player[1].coords.y=300;
2471 player[1].velocity=0;
2475 void Game::doDebugKeys(){
2476 float headprop,bodyprop,armprop,legprop;
2478 if(Input::isKeyPressed(SDLK_h)){
2479 player[0].damagetolerance=200000;
2482 player[0].permanentdamage=0;
2483 player[0].superpermanentdamage=0;
2486 if(Input::isKeyPressed(SDLK_j)){
2490 Setenvironment(environment);
2493 if(Input::isKeyPressed(SDLK_c)){
2494 cameramode=1-cameramode;
2497 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2498 if(player[0].num_weapons>0){
2499 if(weapons[player[0].weaponids[0]].getType()==sword)
2500 weapons[player[0].weaponids[0]].setType(staff);
2501 else if(weapons[player[0].weaponids[0]].getType()==staff)
2502 weapons[player[0].weaponids[0]].setType(knife);
2504 weapons[player[0].weaponids[0]].setType(sword);
2508 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2510 float closestdist=-1;
2513 for(int i=1;i<numplayers;i++){
2514 distance=findDistancefast(&player[i].coords,&player[0].coords);
2515 if(closestdist==-1||distance<closestdist){
2516 closestdist=distance;
2521 if(player[closest].num_weapons){
2522 if(weapons[player[closest].weaponids[0]].getType()==sword)
2523 weapons[player[closest].weaponids[0]].setType(staff);
2524 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2525 weapons[player[closest].weaponids[0]].setType(knife);
2527 weapons[player[closest].weaponids[0]].setType(sword);
2529 if(!player[closest].num_weapons){
2530 player[closest].weaponids[0]=weapons.size();
2532 weapons.push_back(Weapon(knife,closest));
2534 player[closest].num_weapons=1;
2539 if(Input::isKeyDown(SDLK_u)){
2541 float closestdist=-1;
2544 for(int i=1;i<numplayers;i++){
2545 distance=findDistancefast(&player[i].coords,&player[0].coords);
2546 if(closestdist==-1||distance<closestdist){
2547 closestdist=distance;
2551 player[closest].rotation+=multiplier*50;
2552 player[closest].targetrotation=player[closest].rotation;
2556 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2558 float closestdist=-1;
2561 for(int i=1;i<numplayers;i++){
2562 distance=findDistancefast(&player[i].coords,&player[0].coords);
2563 if(closestdist==-1||distance<closestdist){
2564 closestdist=distance;
2568 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2571 player[closest].whichskin++;
2572 if(player[closest].whichskin>9)
2573 player[closest].whichskin=0;
2574 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2575 player[closest].whichskin=0;
2577 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2578 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2581 if(player[closest].numclothes){
2582 for(int i=0;i<player[closest].numclothes;i++){
2583 tintr=player[closest].clothestintr[i];
2584 tintg=player[closest].clothestintg[i];
2585 tintb=player[closest].clothestintb[i];
2586 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2588 player[closest].DoMipmaps();
2592 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2594 float closestdist=-1;
2597 for(int i=1;i<numplayers;i++){
2598 distance=findDistancefast(&player[i].coords,&player[0].coords);
2599 if(closestdist==-1||distance<closestdist){
2600 closestdist=distance;
2605 if(player[closest].creature==wolftype){
2606 headprop=player[closest].proportionhead.x/1.1;
2607 bodyprop=player[closest].proportionbody.x/1.1;
2608 armprop=player[closest].proportionarms.x/1.1;
2609 legprop=player[closest].proportionlegs.x/1.1;
2612 if(player[closest].creature==rabbittype){
2613 headprop=player[closest].proportionhead.x/1.2;
2614 bodyprop=player[closest].proportionbody.x/1.05;
2615 armprop=player[closest].proportionarms.x/1.00;
2616 legprop=player[closest].proportionlegs.x/1.1;
2620 if(player[closest].creature==rabbittype){
2621 player[closest].skeleton.id=closest;
2622 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);
2623 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2624 player[closest].whichskin=0;
2625 player[closest].creature=wolftype;
2627 player[closest].proportionhead=1.1;
2628 player[closest].proportionbody=1.1;
2629 player[closest].proportionarms=1.1;
2630 player[closest].proportionlegs=1.1;
2631 player[closest].proportionlegs.y=1.1;
2632 player[closest].scale=.23*5*player[0].scale;
2634 player[closest].damagetolerance=300;
2638 player[closest].skeleton.id=closest;
2639 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);
2640 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2641 player[closest].whichskin=0;
2642 player[closest].creature=rabbittype;
2644 player[closest].proportionhead=1.2;
2645 player[closest].proportionbody=1.05;
2646 player[closest].proportionarms=1.00;
2647 player[closest].proportionlegs=1.1;
2648 player[closest].proportionlegs.y=1.05;
2649 player[closest].scale=.2*5*player[0].scale;
2651 player[closest].damagetolerance=200;
2654 if(player[closest].creature==wolftype){
2655 player[closest].proportionhead=1.1*headprop;
2656 player[closest].proportionbody=1.1*bodyprop;
2657 player[closest].proportionarms=1.1*armprop;
2658 player[closest].proportionlegs=1.1*legprop;
2661 if(player[closest].creature==rabbittype){
2662 player[closest].proportionhead=1.2*headprop;
2663 player[closest].proportionbody=1.05*bodyprop;
2664 player[closest].proportionarms=1.00*armprop;
2665 player[closest].proportionlegs=1.1*legprop;
2666 player[closest].proportionlegs.y=1.05*legprop;
2672 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2678 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2680 float closestdist=-1;
2682 XYZ flatfacing2,flatvelocity2;
2685 for(int i=1;i<numplayers;i++){
2686 distance=findDistancefast(&player[i].coords,&player[0].coords);
2687 if(distance<144&&!player[i].headless)
2688 if(closestdist==-1||distance<closestdist){
2689 closestdist=distance;
2691 blah = player[i].coords;
2696 XYZ headspurtdirection;
2697 //int i = player[closest].skeleton.jointlabels[head];
2698 Joint& headjoint=playerJoint(closest,head);
2699 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2700 if(!player[closest].skeleton.free)
2701 flatvelocity2=player[closest].velocity;
2702 if(player[closest].skeleton.free)
2703 flatvelocity2=headjoint.velocity;
2704 if(!player[closest].skeleton.free)
2705 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;
2706 if(player[closest].skeleton.free)
2707 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2708 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2709 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2710 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2711 headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
2712 Normalise(&headspurtdirection);
2713 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2714 flatvelocity2+=headspurtdirection*8;
2715 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2717 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2719 emit_sound_at(splattersound, blah);
2720 emit_sound_at(breaksound2, blah, 100.);
2722 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2723 player[closest].RagDoll(0);
2724 player[closest].dead=2;
2725 player[closest].headless=1;
2726 player[closest].DoBloodBig(3,165);
2732 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2734 float closestdist=-1;
2736 XYZ flatfacing2,flatvelocity2;
2739 for(int i=1;i<numplayers;i++){
2740 distance=findDistancefast(&player[i].coords,&player[0].coords);
2742 if(closestdist==-1||distance<closestdist){
2743 closestdist=distance;
2745 blah=player[i].coords;
2750 emit_sound_at(splattersound, blah);
2752 emit_sound_at(breaksound2, blah);
2754 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2755 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2756 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2757 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;
2758 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2759 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2760 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2761 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2762 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2763 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2764 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
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, 1,1,1, 3, 1);
2776 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 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);
2791 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2792 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2793 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2794 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;
2795 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2796 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2797 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2798 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2799 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2800 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2804 for(int j=0;j<numplayers; j++){
2806 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2807 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2808 if(player[j].skeleton.free==2)
2809 player[j].skeleton.free=1;
2810 player[j].skeleton.longdead=0;
2811 player[j].RagDoll(0);
2812 for(int i=0;i<player[j].skeleton.num_joints; i++){
2813 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2814 if(findDistancefast(&temppos,&player[closest].coords)<25){
2815 flatvelocity2=temppos-player[closest].coords;
2816 Normalise(&flatvelocity2);
2817 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2824 player[closest].DoDamage(10000);
2825 player[closest].RagDoll(0);
2826 player[closest].dead=2;
2827 player[closest].coords=20;
2828 player[closest].skeleton.free=2;
2835 if(Input::isKeyPressed(SDLK_f)){
2836 player[0].onfire=1-player[0].onfire;
2837 if(player[0].onfire){
2838 player[0].CatchFire();
2840 if(!player[0].onfire){
2841 emit_sound_at(fireendsound, player[0].coords);
2842 pause_sound(stream_firesound);
2846 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2847 //if(!player[0].skeleton.free)player[0].damage+=500;
2848 player[0].RagDoll(0);
2849 //player[0].spurt=1;
2850 //player[0].DoDamage(1000);
2852 emit_sound_at(whooshsound, player[0].coords, 128.);
2855 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2856 for(int i=0;i<objects.numobjects;i++){
2857 if(objects.type[i]==treeleavestype){
2858 objects.scale[i]*=.9;
2863 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2864 editorenabled=1-editorenabled;
2866 player[0].damagetolerance=100000;
2868 player[0].damagetolerance=200;
2870 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2871 player[0].permanentdamage=0;
2872 player[0].superpermanentdamage=0;
2873 player[0].bloodloss=0;
2874 player[0].deathbleeding=0;
2878 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2880 if(targetlevel>numchallengelevels-1)
2887 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2889 float closestdist=-1;
2892 for(int i=1;i<numplayers;i++){
2893 distance=findDistancefast(&player[i].coords,&player[0].coords);
2894 if(closestdist==-1||distance<closestdist){
2895 closestdist=distance;
2899 if(closestdist>0&&closest>=0){
2900 //player[closest]=player[numplayers-1];
2901 //player[closest].skeleton=player[numplayers-1].skeleton;
2906 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2908 float closestdist=-1;
2911 for(int i=1;i<max_objects;i++){
2912 distance=findDistancefast(&objects.position[i],&player[0].coords);
2913 if(closestdist==-1||distance<closestdist){
2914 closestdist=distance;
2918 if(closestdist>0&&closest>=0){
2919 objects.position[closest].y-=500;
2923 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2925 //if(drawmode>2)drawmode=0;
2926 if(objects.numobjects<max_objects-1){
2928 boxcoords.x=player[0].coords.x;
2929 boxcoords.z=player[0].coords.z;
2930 boxcoords.y=player[0].coords.y-3;
2931 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
2932 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
2933 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
2934 float temprotat,temprotat2;
2935 temprotat=editorrotation;
2936 temprotat2=editorrotation2;
2937 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
2938 if(temprotat2<0)temprotat2=Random()%360;
2940 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
2941 if(editortype==treetrunktype)
2942 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
2946 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
2947 if(numplayers<maxplayers-1){
2948 player[numplayers].scale=.2*5*player[0].scale;
2949 player[numplayers].creature=rabbittype;
2950 player[numplayers].howactive=editoractive;
2951 player[numplayers].skeleton.id=numplayers;
2952 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);
2954 //texsize=512*512*3/texdetail/texdetail;
2955 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
2956 //player[numplayers].skeleton.skinText.resize(texsize);
2958 int k=abs(Random()%2)+1;
2960 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2961 player[numplayers].whichskin=0;
2964 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2965 player[numplayers].whichskin=1;
2968 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2969 player[numplayers].whichskin=2;
2972 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
2973 player[numplayers].power=1;
2974 player[numplayers].speedmult=1;
2975 player[numplayers].currentanimation=bounceidleanim;
2976 player[numplayers].targetanimation=bounceidleanim;
2977 player[numplayers].currentframe=0;
2978 player[numplayers].targetframe=1;
2979 player[numplayers].target=0;
2980 player[numplayers].bled=0;
2981 player[numplayers].speed=1+(float)(Random()%100)/1000;
2983 player[numplayers].targetrotation=player[0].targetrotation;
2984 player[numplayers].rotation=player[0].rotation;
2986 player[numplayers].velocity=0;
2987 player[numplayers].coords=player[0].coords;
2988 player[numplayers].oldcoords=player[numplayers].coords;
2989 player[numplayers].realoldcoords=player[numplayers].coords;
2991 player[numplayers].id=numplayers;
2992 player[numplayers].skeleton.id=numplayers;
2993 player[numplayers].updatedelay=0;
2994 player[numplayers].normalsupdatedelay=0;
2996 player[numplayers].aitype=passivetype;
2998 if(player[0].creature==wolftype){
2999 headprop=player[0].proportionhead.x/1.1;
3000 bodyprop=player[0].proportionbody.x/1.1;
3001 armprop=player[0].proportionarms.x/1.1;
3002 legprop=player[0].proportionlegs.x/1.1;
3005 if(player[0].creature==rabbittype){
3006 headprop=player[0].proportionhead.x/1.2;
3007 bodyprop=player[0].proportionbody.x/1.05;
3008 armprop=player[0].proportionarms.x/1.00;
3009 legprop=player[0].proportionlegs.x/1.1;
3012 if(player[numplayers].creature==wolftype){
3013 player[numplayers].proportionhead=1.1*headprop;
3014 player[numplayers].proportionbody=1.1*bodyprop;
3015 player[numplayers].proportionarms=1.1*armprop;
3016 player[numplayers].proportionlegs=1.1*legprop;
3019 if(player[numplayers].creature==rabbittype){
3020 player[numplayers].proportionhead=1.2*headprop;
3021 player[numplayers].proportionbody=1.05*bodyprop;
3022 player[numplayers].proportionarms=1.00*armprop;
3023 player[numplayers].proportionlegs=1.1*legprop;
3024 player[numplayers].proportionlegs.y=1.05*legprop;
3027 player[numplayers].headless=0;
3028 player[numplayers].onfire=0;
3031 player[numplayers].proportionhead.z=0;
3032 player[numplayers].proportionbody.z=0;
3033 player[numplayers].proportionarms.z=0;
3034 player[numplayers].proportionlegs.z=0;
3037 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3039 player[numplayers].damagetolerance=200;
3041 player[numplayers].protectionhead=player[0].protectionhead;
3042 player[numplayers].protectionhigh=player[0].protectionhigh;
3043 player[numplayers].protectionlow=player[0].protectionlow;
3044 player[numplayers].armorhead=player[0].armorhead;
3045 player[numplayers].armorhigh=player[0].armorhigh;
3046 player[numplayers].armorlow=player[0].armorlow;
3047 player[numplayers].metalhead=player[0].metalhead;
3048 player[numplayers].metalhigh=player[0].metalhigh;
3049 player[numplayers].metallow=player[0].metallow;
3051 player[numplayers].immobile=player[0].immobile;
3053 player[numplayers].numclothes=player[0].numclothes;
3054 if(player[numplayers].numclothes)
3055 for(int i=0;i<player[numplayers].numclothes;i++){
3056 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3057 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3058 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3059 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3060 tintr=player[numplayers].clothestintr[i];
3061 tintg=player[numplayers].clothestintg[i];
3062 tintb=player[numplayers].clothestintb[i];
3063 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3065 if(player[numplayers].numclothes){
3066 player[numplayers].DoMipmaps();
3069 player[numplayers].power=player[0].power;
3070 player[numplayers].speedmult=player[0].speedmult;
3072 player[numplayers].damage=0;
3073 player[numplayers].permanentdamage=0;
3074 player[numplayers].superpermanentdamage=0;
3075 player[numplayers].deathbleeding=0;
3076 player[numplayers].bleeding=0;
3077 player[numplayers].numwaypoints=0;
3078 player[numplayers].waypoint=0;
3079 player[numplayers].jumppath=0;
3080 player[numplayers].weaponstuck=-1;
3081 player[numplayers].weaponactive=-1;
3082 player[numplayers].num_weapons=0;
3083 player[numplayers].bloodloss=0;
3084 player[numplayers].dead=0;
3086 player[numplayers].loaded=1;
3092 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3093 if(player[numplayers-1].numwaypoints<90){
3094 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3095 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3096 player[numplayers-1].numwaypoints++;
3100 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3101 if(numpathpoints<30){
3102 bool connected,alreadyconnected;
3105 for(int i=0;i<numpathpoints;i++){
3106 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3108 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3109 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3111 if(!alreadyconnected){
3112 numpathpointconnect[pathpointselected]++;
3114 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3120 pathpoint[numpathpoints-1]=player[0].coords;
3121 numpathpointconnect[numpathpoints-1]=0;
3122 if(numpathpoints>1&&pathpointselected!=-1){
3123 numpathpointconnect[pathpointselected]++;
3124 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3126 pathpointselected=numpathpoints-1;
3131 if(Input::isKeyPressed(SDLK_PERIOD)){
3132 pathpointselected++;
3133 if(pathpointselected>=numpathpoints)
3134 pathpointselected=-1;
3136 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3137 pathpointselected--;
3138 if(pathpointselected<=-2)
3139 pathpointselected=numpathpoints-1;
3141 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3142 if(pathpointselected!=-1){
3144 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3145 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3146 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3147 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3149 for(int i=0;i<numpathpoints;i++){
3150 for(int j=0;j<numpathpointconnect[i];j++){
3151 if(pathpointconnect[i][j]==pathpointselected){
3152 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3153 numpathpointconnect[i]--;
3155 if(pathpointconnect[i][j]==numpathpoints){
3156 pathpointconnect[i][j]=pathpointselected;
3160 pathpointselected=numpathpoints-1;
3164 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3166 if(editortype==treeleavestype||editortype==10)editortype--;
3167 if(editortype<0)editortype=firetype;
3170 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3172 if(editortype==treeleavestype||editortype==10)editortype++;
3173 if(editortype>firetype)editortype=0;
3176 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3177 editorrotation-=multiplier*100;
3178 if(editorrotation<-.01)editorrotation=-.01;
3181 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3182 editorrotation+=multiplier*100;
3185 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3186 editorsize+=multiplier;
3189 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3190 editorsize-=multiplier;
3191 if(editorsize<.1)editorsize=.1;
3195 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3196 mapradius-=multiplier*10;
3199 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3200 mapradius+=multiplier*10;
3202 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3203 editorrotation2+=multiplier*100;
3206 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3207 editorrotation2-=multiplier*100;
3208 if(editorrotation2<-.01)editorrotation2=-.01;
3210 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3212 float closestdist=-1;
3214 for(int i=0;i<objects.numobjects;i++){
3215 distance=findDistancefast(&objects.position[i],&player[0].coords);
3216 if(closestdist==-1||distance<closestdist){
3217 closestdist=distance;
3221 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3227 void Game::doJumpReversals(){
3228 for(int k=0;k<numplayers;k++)
3229 for(int i=k;i<numplayers;i++){
3231 if( player[k].skeleton.free==0&&
3232 player[i].skeleton.oldfree==0&&
3233 (player[i].targetanimation==jumpupanim||
3234 player[k].targetanimation==jumpupanim)&&
3235 (player[i].aitype==playercontrolled||
3236 player[k].aitype==playercontrolled)&&
3237 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3238 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3239 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3240 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3241 //TODO: refactor two huge similar ifs
3242 if(player[i].targetanimation==jumpupanim&&
3243 player[k].targetanimation!=getupfrombackanim&&
3244 player[k].targetanimation!=getupfromfrontanim&&
3245 animation[player[k].targetanimation].height==middleheight&&
3246 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3247 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3248 player[k].aitype!=playercontrolled)){
3249 player[i].victim=&player[k];
3250 player[i].velocity=0;
3251 player[i].currentanimation=jumpreversedanim;
3252 player[i].targetanimation=jumpreversedanim;
3253 player[i].currentframe=0;
3254 player[i].targetframe=1;
3255 player[i].targettilt2=0;
3256 player[k].victim=&player[i];
3257 player[k].velocity=0;
3258 player[k].currentanimation=jumpreversalanim;
3259 player[k].targetanimation=jumpreversalanim;
3260 player[k].currentframe=0;
3261 player[k].targetframe=1;
3262 player[k].targettilt2=0;
3263 if(player[i].coords.y<player[k].coords.y+1){
3264 player[i].currentanimation=rabbitkickreversedanim;
3265 player[i].targetanimation=rabbitkickreversedanim;
3266 player[i].currentframe=1;
3267 player[i].targetframe=2;
3268 player[k].currentanimation=rabbitkickreversalanim;
3269 player[k].targetanimation=rabbitkickreversalanim;
3270 player[k].currentframe=1;
3271 player[k].targetframe=2;
3274 player[k].oldcoords=player[k].coords;
3275 player[i].coords=player[k].coords;
3276 player[k].targetrotation=player[i].targetrotation;
3277 player[k].rotation=player[i].targetrotation;
3278 if(player[k].aitype==attacktypecutoff)
3279 player[k].stunned=.5;
3281 if(player[k].targetanimation==jumpupanim&&
3282 player[i].targetanimation!=getupfrombackanim&&
3283 player[i].targetanimation!=getupfromfrontanim&&
3284 animation[player[i].targetanimation].height==middleheight&&
3285 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3286 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3287 player[i].aitype!=playercontrolled)){
3288 player[k].victim=&player[i];
3289 player[k].velocity=0;
3290 player[k].currentanimation=jumpreversedanim;
3291 player[k].targetanimation=jumpreversedanim;
3292 player[k].currentframe=0;
3293 player[k].targetframe=1;
3294 player[k].targettilt2=0;
3295 player[i].victim=&player[k];
3296 player[i].velocity=0;
3297 player[i].currentanimation=jumpreversalanim;
3298 player[i].targetanimation=jumpreversalanim;
3299 player[i].currentframe=0;
3300 player[i].targetframe=1;
3301 player[i].targettilt2=0;
3302 if(player[k].coords.y<player[i].coords.y+1){
3303 player[k].targetanimation=rabbitkickreversedanim;
3304 player[k].currentanimation=rabbitkickreversedanim;
3305 player[i].currentanimation=rabbitkickreversalanim;
3306 player[i].targetanimation=rabbitkickreversalanim;
3307 player[k].currentframe=1;
3308 player[k].targetframe=2;
3309 player[i].currentframe=1;
3310 player[i].targetframe=2;
3313 player[i].oldcoords=player[i].coords;
3314 player[k].coords=player[i].coords;
3315 player[i].targetrotation=player[k].targetrotation;
3316 player[i].rotation=player[k].targetrotation;
3317 if(player[i].aitype==attacktypecutoff)
3318 player[i].stunned=.5;
3325 void Game::doAerialAcrobatics(){
3326 static XYZ facing,flatfacing;
3327 for(int k=0;k<numplayers;k++){
3328 player[k].turnspeed=500;
3330 if((player[k].isRun()&&
3331 ((player[k].targetrotation!=rabbitrunninganim&&
3332 player[k].targetrotation!=wolfrunninganim)||
3333 player[k].targetframe==4))||
3334 player[k].targetanimation==removeknifeanim||
3335 player[k].targetanimation==crouchremoveknifeanim||
3336 player[k].targetanimation==flipanim||
3337 player[k].targetanimation==fightsidestep||
3338 player[k].targetanimation==walkanim){
3339 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3343 if(player[k].isStop()||
3344 player[k].isLanding()||
3345 player[k].targetanimation==staggerbackhighanim||
3346 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3347 player[k].targetanimation==staggerbackhardanim||
3348 player[k].targetanimation==backhandspringanim||
3349 player[k].targetanimation==dodgebackanim||
3350 player[k].targetanimation==rollanim||
3351 (animation[player[k].targetanimation].attack&&
3352 player[k].targetanimation!=rabbitkickanim&&
3353 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3354 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3355 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3358 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3359 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3362 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3363 player[k].DoStuff();
3364 if(player[k].immobile&&k!=0)
3365 player[k].coords=player[k].realoldcoords;
3367 //if player's position has changed (?)
3368 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3369 !player[k].skeleton.free&&
3370 player[k].targetanimation!=climbanim&&
3371 player[k].targetanimation!=hanganim){
3372 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3376 if(player[k].collide<-.3)
3377 player[k].collide=-.3;
3378 if(player[k].collide>1)
3379 player[k].collide=1;
3380 player[k].collide-=multiplier*30;
3383 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3385 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3386 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3387 if(objects.type[i]!=rocktype||
3388 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3389 objects.position[i].y>player[k].coords.y){
3390 lowpoint=player[k].coords;
3391 if(player[k].targetanimation!=jumpupanim&&
3392 player[k].targetanimation!=jumpdownanim&&
3393 !player[k].isFlip())
3397 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3398 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3399 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3400 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3401 flatfacing=lowpoint-player[k].coords;
3402 player[k].coords=lowpoint;
3403 player[k].coords.y-=1.3;
3404 player[k].collide=1;
3407 //TODO: refactor four similar blocks
3408 if(player[k].aitype==playercontrolled&&
3409 (player[k].targetanimation==jumpupanim||
3410 player[k].targetanimation==jumpdownanim||
3411 player[k].isFlip())&&
3412 !player[k].jumptogglekeydown&&
3413 player[k].jumpkeydown){
3414 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3415 XYZ tempcoords1=lowpoint;
3416 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3417 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3418 setAnimation(k,walljumpleftanim);
3419 emit_sound_at(movewhooshsound, player[k].coords);
3421 pause_sound(whooshsound);
3423 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3424 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3425 if(lowpointtarget.z<0)
3426 player[k].rotation=180-player[k].rotation;
3427 player[k].targetrotation=player[k].rotation;
3428 player[k].lowrotation=player[k].rotation;
3434 lowpoint=tempcoords1;
3435 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3436 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3437 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3438 setAnimation(k,walljumprightanim);
3439 emit_sound_at(movewhooshsound, player[k].coords);
3440 if(k==0)pause_sound(whooshsound);
3442 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3443 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3444 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3445 player[k].targetrotation=player[k].rotation;
3446 player[k].lowrotation=player[k].rotation;
3447 if(k==0)numwallflipped++;
3451 lowpoint=tempcoords1;
3452 lowpointtarget=lowpoint+player[k].facing*2;
3453 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3454 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3455 setAnimation(k,walljumpbackanim);
3456 emit_sound_at(movewhooshsound, player[k].coords);
3457 if(k==0)pause_sound(whooshsound);
3459 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3460 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3461 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3462 player[k].targetrotation=player[k].rotation;
3463 player[k].lowrotation=player[k].rotation;
3464 if(k==0)numwallflipped++;
3468 lowpoint=tempcoords1;
3469 lowpointtarget=lowpoint-player[k].facing*2;
3470 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3471 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3472 setAnimation(k,walljumpfrontanim);
3473 emit_sound_at(movewhooshsound, player[k].coords);
3474 if(k==0)pause_sound(whooshsound);
3476 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3477 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3478 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3479 player[k].rotation+=180;
3480 player[k].targetrotation=player[k].rotation;
3481 player[k].lowrotation=player[k].rotation;
3482 if(k==0)numwallflipped++;
3490 else if(objects.type[i]==rocktype){
3491 lowpoint2=player[k].coords;
3492 lowpoint=player[k].coords;
3494 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3495 player[k].coords=colpoint;
3496 player[k].collide=1;
3499 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3500 //flipped into a rock
3501 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3502 player[k].RagDoll(0);
3504 if(player[k].targetanimation==jumpupanim){
3505 player[k].jumppower=-4;
3506 player[k].targetanimation=player[k].getIdle();
3509 player[k].targetframe=0;
3510 player[k].onterrain=1;
3512 if(player[k].id==0){
3513 pause_sound(whooshsound);
3514 OPENAL_SetVolume(channels[whooshsound], 0);
3518 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3519 if(player[k].isFlip())
3520 player[k].jumppower=-4;
3521 player[k].targetanimation=player[k].getLanding();
3522 emit_sound_at(landsound, player[k].coords, 128.);
3524 envsound[numenvsounds]=player[k].coords;
3525 envsoundvol[numenvsounds]=16;
3526 envsoundlife[numenvsounds]=.4;
3536 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3537 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3538 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3539 lowpoint=player[k].coords;
3541 if(objects.type[i]!=rocktype)
3542 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3543 if(player[k].targetanimation!=jumpupanim&&
3544 player[k].targetanimation!=jumpdownanim&&
3545 player[k].onterrain)
3546 player[k].avoidcollided=1;
3547 player[k].coords=lowpoint;
3548 player[k].coords.y-=1.35;
3549 player[k].collide=1;
3551 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3552 (player[k].currentanimation!=climbanim&&
3553 player[k].currentanimation!=hanganim&&
3554 !player[k].isWallJump()||
3555 player[k].targetanimation==jumpupanim||
3556 player[k].targetanimation==jumpdownanim)){
3557 lowpoint=player[k].coords;
3558 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3559 lowpoint=player[k].coords;
3563 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3564 lowpointtarget=lowpoint+facing*1.4;
3565 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3567 lowpoint=player[k].coords;
3569 lowpointtarget=lowpoint+facing*1.4;
3571 lowpointtarget2=lowpointtarget;
3573 lowpointtarget3=lowpointtarget;
3575 lowpointtarget4=lowpointtarget;
3577 lowpointtarget5=lowpointtarget;
3579 lowpointtarget6=lowpointtarget;
3581 lowpointtarget7=lowpoint;
3583 lowpointtarget2.x+=.1;
3585 lowpointtarget3.z+=.1;
3587 lowpointtarget4.x-=.1;
3589 lowpointtarget5.z-=.1;
3591 lowpointtarget6.y+=45/13;
3592 lowpointtarget6+=facing*.6;
3593 lowpointtarget7.y+=90/13;
3594 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3595 if(objects.friction[i]>.5)
3597 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3598 player[k].collided=1;
3599 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3600 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3601 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3602 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3603 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3604 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3605 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3606 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3607 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3608 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3609 for(int j=0;j<45;j++){
3610 lowpoint=player[k].coords;
3611 lowpoint.y+=(float)j/13;
3612 lowpointtarget=lowpoint+facing*1.4;
3613 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3614 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3615 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3617 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3618 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3619 lowpoint=player[k].coords;
3620 lowpoint.y+=(float)j/13;
3621 lowpointtarget=lowpoint+facing*1.3;
3622 flatfacing=player[k].coords;
3623 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3624 player[k].coords.y=lowpointtarget.y-.07;
3625 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3627 if(j>10||!player[k].isRun()){
3628 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3630 pause_sound(whooshsound);
3632 emit_sound_at(jumpsound, player[k].coords, 128.);
3634 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3635 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3636 if(lowpointtarget.z<0)
3637 player[k].rotation=180-player[k].rotation;
3638 player[k].targetrotation=player[k].rotation;
3639 player[k].lowrotation=player[k].rotation;
3641 //player[k].velocity=lowpointtarget*.03;
3642 player[k].velocity=0;
3645 if(player[k].targetanimation==jumpupanim){
3646 player[k].targetanimation=climbanim;
3647 player[k].jumppower=0;
3648 player[k].jumpclimb=1;
3650 player[k].transspeed=6;
3652 player[k].targetframe=1;
3655 setAnimation(k,hanganim);
3656 player[k].jumppower=0;
3668 if(player[k].collide<=0){
3670 if(!player[k].onterrain&&
3671 player[k].targetanimation!=jumpupanim&&
3672 player[k].targetanimation!=jumpdownanim&&
3673 player[k].targetanimation!=climbanim&&
3674 player[k].targetanimation!=hanganim&&
3675 !player[k].isWallJump()&&
3676 !player[k].isFlip()){
3677 if(player[k].currentanimation!=climbanim&&
3678 player[k].currentanimation!=tempanim&&
3679 player[k].targetanimation!=backhandspringanim&&
3680 (player[k].targetanimation!=rollanim||
3681 player[k].targetframe<2||
3682 player[k].targetframe>6)){
3683 //stagger off ledge (?)
3684 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3685 player[k].RagDoll(0);
3686 setAnimation(k,jumpdownanim);
3689 emit_sound_at(whooshsound, player[k].coords, 128.);
3692 player[k].velocity.y+=gravity;
3696 player[k].realoldcoords=player[k].coords;
3700 void Game::doAttacks(){
3701 static XYZ relative;
3702 static int randattack;
3703 static bool playerrealattackkeydown=0;
3705 if(!Input::isKeyDown(attackkey))
3708 player[0].attackkeydown=0;
3710 playerrealattackkeydown=0;
3712 playerrealattackkeydown=Input::isKeyDown(attackkey);
3713 if((player[0].parriedrecently<=0||
3714 player[0].weaponactive==-1)&&
3717 player[0].lastattack!=swordslashanim&&
3718 player[0].lastattack!=knifeslashstartanim&&
3719 player[0].lastattack!=staffhitanim&&
3720 player[0].lastattack!=staffspinhitanim)))
3721 player[0].attackkeydown=Input::isKeyDown(attackkey);
3722 if(Input::isKeyDown(attackkey)&&
3724 !player[0].backkeydown){
3725 for(int k=0;k<numplayers;k++){
3726 if((player[k].targetanimation==swordslashanim||
3727 player[k].targetanimation==staffhitanim||
3728 player[k].targetanimation==staffspinhitanim)&&
3729 player[0].currentanimation!=dodgebackanim&&
3730 !player[k].skeleton.free)
3731 player[k].Reverse();
3735 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3737 for(int k=0;k<numplayers;k++){
3738 if(indialogue!=-1)player[k].attackkeydown=0;
3739 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3740 if(player[k].aitype!=playercontrolled)
3741 player[k].victim=&player[0];
3742 //attack key pressed
3743 if(player[k].attackkeydown){
3745 if(player[k].backkeydown&&
3746 player[k].targetanimation!=backhandspringanim&&
3747 (player[k].isIdle()||
3748 player[k].isStop()||
3750 player[k].targetanimation==walkanim)){
3751 if(player[k].jumppower<=1){
3752 player[k].jumppower-=2;
3754 for(int i=0;i<numplayers;i++){
3756 if(player[i].targetanimation==swordslashanim||
3757 player[i].targetanimation==knifeslashstartanim||
3758 player[i].targetanimation==staffhitanim||
3759 player[i].targetanimation==staffspinhitanim)
3760 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3761 setAnimation(k,dodgebackanim);
3762 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3763 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3766 if(player[k].targetanimation!=dodgebackanim){
3767 if(k==0)numflipped++;
3768 setAnimation(k,backhandspringanim);
3769 player[k].targetrotation=-rotation+180;
3770 if(player[k].leftkeydown)
3771 player[k].targetrotation-=45;
3772 if(player[k].rightkeydown)
3773 player[k].targetrotation+=45;
3774 player[k].rotation=player[k].targetrotation;
3775 player[k].jumppower-=2;
3780 if(!animation[player[k].targetanimation].attack&&
3781 !player[k].backkeydown&&
3782 (player[k].isIdle()||
3784 player[k].targetanimation==walkanim||
3785 player[k].targetanimation==sneakanim||
3786 player[k].isCrouch())){
3787 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3788 //normal attacks (?)
3789 player[k].hasvictim=0;
3791 for(int i=0;i<numplayers;i++){
3792 if(i==k||!(k==0||i==0))continue;
3793 if(!player[k].hasvictim)
3794 if(animation[player[k].targetanimation].attack!=reversal){
3796 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3798 !player[i].skeleton.free&&
3799 player[i].howactive<typedead1&&
3800 player[i].targetanimation!=jumpreversedanim&&
3801 player[i].targetanimation!=rabbitkickreversedanim&&
3802 player[i].targetanimation!=rabbitkickanim&&
3803 player[k].targetanimation!=rabbitkickanim&&
3804 player[i].targetanimation!=getupfrombackanim&&
3805 (player[i].targetanimation!=staggerbackhighanim&&
3806 (player[i].targetanimation!=staggerbackhardanim||
3807 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3808 player[i].targetanimation!=jumpdownanim&&
3809 player[i].targetanimation!=jumpupanim&&
3810 player[i].targetanimation!=getupfromfrontanim){
3811 player[k].victim=&player[i];
3812 player[k].hasvictim=1;
3813 if(player[k].aitype==playercontrolled){ //human player
3815 if(distance<2.5*sq(player[k].scale*5)&&
3816 player[k].crouchkeydown&&
3817 animation[player[i].targetanimation].height!=lowheight)
3818 player[k].targetanimation=sweepanim;
3820 else if(distance<1.5*sq(player[k].scale*5)&&
3821 animation[player[i].targetanimation].height!=lowheight&&
3822 !player[k].forwardkeydown&&
3823 !player[k].leftkeydown&&
3824 !player[k].rightkeydown&&
3825 !player[k].crouchkeydown&&
3828 player[k].targetanimation=winduppunchanim;
3830 else if(distance<2.5*sq(player[k].scale*5)&&
3831 animation[player[i].targetanimation].height!=lowheight&&
3832 !player[k].forwardkeydown&&
3833 !player[k].leftkeydown&&
3834 !player[k].rightkeydown&&
3835 !player[k].crouchkeydown&&
3837 player[k].targetanimation=upunchanim;
3839 else if(distance<2.5*sq(player[k].scale*5)&&
3840 player[i].staggerdelay>0&&
3841 attackweapon==knife&&
3842 player[i].bloodloss>player[i].damagetolerance/2)
3843 player[k].targetanimation=knifefollowanim;
3845 else if(distance<2.5*sq(player[k].scale*5)&&
3846 animation[player[i].targetanimation].height!=lowheight&&
3847 !player[k].forwardkeydown&&
3848 !player[k].leftkeydown&&
3849 !player[k].rightkeydown&&
3850 !player[k].crouchkeydown&&
3851 attackweapon==knife&&
3852 player[k].weaponmissdelay<=0)
3853 player[k].targetanimation=knifeslashstartanim;
3855 else if(distance<4.5*sq(player[k].scale*5)&&
3856 animation[player[i].targetanimation].height!=lowheight&&
3857 !player[k].crouchkeydown&&
3858 attackweapon==sword&&
3859 player[k].weaponmissdelay<=0)
3860 player[k].targetanimation=swordslashanim;
3862 else if(distance<4.5*sq(player[k].scale*5)&&
3863 animation[player[i].targetanimation].height!=lowheight&&
3864 !player[k].crouchkeydown&&
3865 attackweapon==staff&&
3866 player[k].weaponmissdelay<=0&&
3867 !player[k].leftkeydown&&
3868 !player[k].rightkeydown&&
3869 !player[k].forwardkeydown)
3870 player[k].targetanimation=staffhitanim;
3872 else if(distance<4.5*sq(player[k].scale*5)&&
3873 animation[player[i].targetanimation].height!=lowheight&&
3874 !player[k].crouchkeydown&&
3875 attackweapon==staff&&
3876 player[k].weaponmissdelay<=0)
3877 player[k].targetanimation=staffspinhitanim;
3879 else if(distance<2.5*sq(player[k].scale*5)&&
3880 animation[player[i].targetanimation].height!=lowheight)
3881 player[k].targetanimation=spinkickanim;
3883 else if(distance<2.5*sq(player[k].scale*5)&&
3884 animation[player[i].targetanimation].height==lowheight&&
3885 animation[player[k].targetanimation].attack!=normalattack)
3886 player[k].targetanimation=lowkickanim;
3887 } else { //AI player
3888 if(distance<4.5*sq(player[k].scale*5)){
3889 randattack=abs(Random()%5);
3890 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3892 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3893 player[k].targetanimation=sweepanim;
3895 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3897 player[k].targetanimation=upunchanim;
3899 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3900 player[k].targetanimation=spinkickanim;
3902 else if(animation[player[i].targetanimation].height==lowheight)
3903 player[k].targetanimation=lowkickanim;
3907 if((tutoriallevel!=1||!attackweapon)&&
3908 distance<2.5*sq(player[k].scale*5)&&
3910 animation[player[i].targetanimation].height!=lowheight)
3911 player[k].targetanimation=sweepanim;
3913 else if(distance<2.5*sq(player[k].scale*5)&&
3914 attackweapon==knife&&
3915 player[k].weaponmissdelay<=0)
3916 player[k].targetanimation=knifeslashstartanim;
3918 else if(!(player[0].victim==&player[i]&&
3919 player[0].hasvictim&&
3920 player[0].targetanimation==swordslashanim)&&
3921 attackweapon==sword&&
3922 player[k].weaponmissdelay<=0)
3923 player[k].targetanimation=swordslashanim;
3925 else if(!(player[0].victim==&player[i]&&
3926 player[0].hasvictim&&
3927 player[0].targetanimation==swordslashanim)&&
3928 attackweapon==staff&&
3929 player[k].weaponmissdelay<=0&&
3931 player[k].targetanimation=staffhitanim;
3933 else if(!(player[0].victim==&player[i]&&
3934 player[0].hasvictim&&
3935 player[0].targetanimation==swordslashanim)&&
3936 attackweapon==staff&&
3937 player[k].weaponmissdelay<=0&&
3939 player[k].targetanimation=staffspinhitanim;
3941 else if((tutoriallevel!=1||!attackweapon)&&
3942 distance<2.5*sq(player[k].scale*5)&&
3944 animation[player[i].targetanimation].height!=lowheight)
3945 player[k].targetanimation=spinkickanim;
3947 else if(distance<2.5*sq(player[k].scale*5)&&
3948 animation[player[i].targetanimation].height==lowheight&&
3949 animation[player[k].targetanimation].attack!=normalattack)
3950 player[k].targetanimation=lowkickanim;
3954 //upunch becomes wolfslap
3955 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
3956 player[k].targetanimation=wolfslapanim;
3959 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
3960 player[i].howactive<typedead1&&
3961 distance<1.5*sq(player[k].scale*5)&&
3962 !player[i].skeleton.free&&
3963 player[i].targetanimation!=getupfrombackanim&&
3964 player[i].targetanimation!=getupfromfrontanim&&
3965 (player[i].stunned>0&&player[k].madskills||
3966 player[i].surprised>0||
3967 player[i].aitype==passivetype||
3968 attackweapon&&player[i].stunned>0)&&
3969 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
3972 player[k].currentanimation=sneakattackanim;
3973 player[k].targetanimation=sneakattackanim;
3974 player[i].currentanimation=sneakattackedanim;
3975 player[i].targetanimation=sneakattackedanim;
3976 player[k].oldcoords=player[k].coords;
3977 player[k].coords=player[i].coords;
3980 if(attackweapon==knife){
3981 player[k].currentanimation=knifesneakattackanim;
3982 player[k].targetanimation=knifesneakattackanim;
3983 player[i].currentanimation=knifesneakattackedanim;
3984 player[i].targetanimation=knifesneakattackedanim;
3985 player[i].oldcoords=player[i].coords;
3986 player[i].coords=player[k].coords;
3989 if(attackweapon==sword){
3990 player[k].currentanimation=swordsneakattackanim;
3991 player[k].targetanimation=swordsneakattackanim;
3992 player[i].currentanimation=swordsneakattackedanim;
3993 player[i].targetanimation=swordsneakattackedanim;
3994 player[i].oldcoords=player[i].coords;
3995 player[i].coords=player[k].coords;
3997 if(attackweapon!=staff){
3998 player[k].victim=&player[i];
3999 player[k].hasvictim=1;
4000 player[i].targettilt2=0;
4001 player[i].targetframe=1;
4002 player[i].currentframe=0;
4004 player[i].velocity=0;
4005 player[k].targettilt2=player[i].targettilt2;
4006 player[k].currentframe=player[i].currentframe;
4007 player[k].targetframe=player[i].targetframe;
4008 player[k].target=player[i].target;
4009 player[k].velocity=0;
4010 player[k].targetrotation=player[i].rotation;
4011 player[k].rotation=player[i].rotation;
4012 player[i].targetrotation=player[i].rotation;
4015 if(animation[player[k].targetanimation].attack==normalattack&&
4016 player[k].victim==&player[i]&&
4017 (!player[i].skeleton.free)){
4019 player[k].targetframe=0;
4022 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4023 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4024 player[k].lastattack3=player[k].lastattack2;
4025 player[k].lastattack2=player[k].lastattack;
4026 player[k].lastattack=player[k].targetanimation;
4028 if(player[k].targetanimation==knifefollowanim&&
4029 player[k].victim==&player[i]){
4031 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4032 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4033 player[k].victim=&player[i];
4034 player[k].hasvictim=1;
4035 player[i].targetanimation=knifefollowedanim;
4036 player[i].currentanimation=knifefollowedanim;
4037 player[i].targettilt2=0;
4038 player[i].targettilt2=player[k].targettilt2;
4039 player[i].targetframe=1;
4040 player[i].currentframe=0;
4042 player[i].velocity=0;
4043 player[k].currentanimation=knifefollowanim;
4044 player[k].targetanimation=knifefollowanim;
4045 player[k].targettilt2=player[i].targettilt2;
4046 player[k].currentframe=player[i].currentframe;
4047 player[k].targetframe=player[i].targetframe;
4048 player[k].target=player[i].target;
4049 player[k].velocity=0;
4050 player[k].oldcoords=player[k].coords;
4051 player[i].coords=player[k].coords;
4052 player[i].targetrotation=player[k].targetrotation;
4053 player[i].rotation=player[k].targetrotation;
4054 player[k].rotation=player[k].targetrotation;
4055 player[i].rotation=player[k].targetrotation;
4059 const bool hasstaff=attackweapon==staff;
4060 if(k==0&&numplayers>1)
4061 for(int i=0;i<numplayers;i++){
4063 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4064 animation[player[k].targetanimation].attack==neutral){
4065 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4066 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4067 if(player[i].skeleton.free)
4068 if(distance<3.5*sq(player[k].scale*5)&&
4070 player[i].skeleton.longdead>1000||
4074 (player[i].skeleton.longdead>2000||
4075 player[i].damage>player[i].damagetolerance/8||
4076 player[i].bloodloss>player[i].damagetolerance/2)&&
4077 distance<1.5*sq(player[k].scale*5)))){
4078 player[k].victim=&player[i];
4079 player[k].hasvictim=1;
4080 if(attackweapon&&tutoriallevel!=1){
4082 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4083 player[k].targetanimation=crouchstabanim;
4085 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4086 player[k].targetanimation=swordgroundstabanim;
4088 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4089 player[k].targetanimation=staffgroundsmashanim;
4092 player[k].crouchkeydown&&
4093 player[k].targetanimation!=crouchstabanim&&
4096 player[i].skeleton.free&&
4097 player[i].skeleton.longdead>1000){
4098 player[k].targetanimation=killanim;
4099 //TODO: refactor this out, what does it do?
4100 for(int j=0;j<terrain.numdecals;j++){
4101 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4102 terrain.decalalivetime[j]<2)
4103 terrain.DeleteDecal(j);
4105 for(int l=0;l<objects.numobjects;l++){
4106 if(objects.model[l].type==decalstype)
4107 for(int j=0;j<objects.model[l].numdecals;j++){
4108 if((objects.model[l].decaltype[j]==blooddecal||
4109 objects.model[l].decaltype[j]==blooddecalslow)&&
4110 objects.model[l].decalalivetime[j]<2)
4111 objects.model[l].DeleteDecal(j);
4115 if(!player[i].dead||musictype!=2)
4117 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4118 player[k].staggerdelay<=0&&
4120 player[i].skeleton.longdead<300&&
4121 player[k].lastattack!=spinkickanim&&
4122 player[i].skeleton.free)&&
4123 (!player[i].dead||musictype!=stream_fighttheme)){
4124 player[k].targetanimation=dropkickanim;
4125 for(int j=0;j<terrain.numdecals;j++){
4126 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4127 terrain.decalalivetime[j]<2){
4128 terrain.DeleteDecal(j);
4131 for(int l=0;l<objects.numobjects;l++){
4132 if(objects.model[l].type==decalstype)
4133 for(int j=0;j<objects.model[l].numdecals;j++){
4134 if((objects.model[l].decaltype[j]==blooddecal||
4135 objects.model[l].decaltype[j]==blooddecalslow)&&
4136 objects.model[l].decalalivetime[j]<2){
4137 objects.model[l].DeleteDecal(j);
4143 if(animation[player[k].targetanimation].attack==normalattack&&
4144 player[k].victim==&player[i]&&
4145 (!player[i].skeleton.free||
4146 player[k].targetanimation==killanim||
4147 player[k].targetanimation==crouchstabanim||
4148 player[k].targetanimation==swordgroundstabanim||
4149 player[k].targetanimation==staffgroundsmashanim||
4150 player[k].targetanimation==dropkickanim)){
4152 player[k].targetframe=0;
4155 XYZ targetpoint=player[i].coords;
4156 if(player[k].targetanimation==crouchstabanim||
4157 player[k].targetanimation==swordgroundstabanim||
4158 player[k].targetanimation==staffgroundsmashanim){
4159 targetpoint+=(playerJoint(i,abdomen).position+
4160 playerJoint(i,neck).position)/2*
4163 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4164 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4166 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4167 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4170 if(player[k].targetanimation==staffgroundsmashanim)
4171 player[k].targettilt2+=10;
4173 player[k].lastattack3=player[k].lastattack2;
4174 player[k].lastattack2=player[k].lastattack;
4175 player[k].lastattack=player[k].targetanimation;
4177 if(player[k].targetanimation==swordgroundstabanim){
4178 player[k].targetrotation+=30;
4183 if(!player[k].hasvictim){
4185 for(int i=0;i<numplayers;i++){
4186 if(i==k||!(i==0||k==0))continue;
4187 if(!player[i].skeleton.free){
4188 if(player[k].hasvictim){
4189 if(findDistancefast(&player[k].coords,&player[i].coords)<
4190 findDistancefast(&player[k].coords,&player[k].victim->coords))
4191 player[k].victim=&player[i];
4193 player[k].victim=&player[i];
4194 player[k].hasvictim=1;
4199 if(player[k].aitype==playercontrolled)
4201 if(player[k].attackkeydown&&
4203 player[k].wasRun()&&
4204 ((player[k].hasvictim&&
4205 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4206 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4207 !player[k].victim->skeleton.free&&
4208 player[k].victim->targetanimation!=getupfrombackanim&&
4209 player[k].victim->targetanimation!=getupfromfrontanim&&
4210 animation[player[k].victim->targetanimation].height!=lowheight&&
4211 player[k].aitype!=playercontrolled&& //wat???
4212 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4213 player[k].rabbitkickenabled)||
4214 player[k].jumpkeydown)){
4216 setAnimation(k,rabbitkickanim);
4219 if(animation[player[k].targetanimation].attack&&k==0){
4221 switch(attackweapon){
4222 case 0: numunarmedattack++; break;
4223 case knife: numknifeattack++; break;
4224 case sword: numswordattack++; break;
4225 case staff: numstaffattack++; break;
4234 void Game::doPlayerCollisions(){
4235 static XYZ rotatetarget;
4236 static float collisionradius;
4238 for(int k=0;k<numplayers;k++)
4239 for(int i=k+1;i<numplayers;i++){
4240 //neither player is part of a reversal
4241 if((animation[player[i].targetanimation].attack!=reversed&&
4242 animation[player[i].targetanimation].attack!=reversal&&
4243 animation[player[k].targetanimation].attack!=reversed&&
4244 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4245 if((animation[player[i].currentanimation].attack!=reversed&&
4246 animation[player[i].currentanimation].attack!=reversal&&
4247 animation[player[k].currentanimation].attack!=reversed&&
4248 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4249 //neither is sleeping
4250 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4251 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4252 //in same patch, neither is climbing
4253 if(player[i].whichpatchx==player[k].whichpatchx&&
4254 player[i].whichpatchz==player[k].whichpatchz&&
4255 player[k].skeleton.oldfree==player[k].skeleton.free&&
4256 player[i].skeleton.oldfree==player[i].skeleton.free&&
4257 player[i].targetanimation!=climbanim&&
4258 player[i].targetanimation!=hanganim&&
4259 player[k].targetanimation!=climbanim&&
4260 player[k].targetanimation!=hanganim)
4261 //players are close (bounding box test)
4262 if(player[i].coords.y>player[k].coords.y-3)
4263 if(player[i].coords.y<player[k].coords.y+3)
4264 if(player[i].coords.x>player[k].coords.x-3)
4265 if(player[i].coords.x<player[k].coords.x+3)
4266 if(player[i].coords.z>player[k].coords.z-3)
4267 if(player[i].coords.z<player[k].coords.z+3){
4268 //spread fire from player to player
4269 if(findDistancefast(&player[i].coords,&player[k].coords)
4270 <3*sq((player[i].scale+player[k].scale)*2.5)){
4271 if(player[i].onfire||player[k].onfire){
4272 if(!player[i].onfire)player[i].CatchFire();
4273 if(!player[k].onfire)player[k].CatchFire();
4277 XYZ tempcoords1=player[i].coords;
4278 XYZ tempcoords2=player[k].coords;
4279 if(!player[i].skeleton.oldfree)
4280 tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
4281 if(!player[k].skeleton.oldfree)
4282 tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
4283 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4284 if(player[0].hasvictim)
4285 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4287 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4288 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4289 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4290 //jump down on a dead body
4293 if(player[0].targetanimation==jumpdownanim&&
4294 !player[0].skeleton.oldfree&&
4295 !player[0].skeleton.free&&
4296 player[l].skeleton.oldfree&&
4297 player[l].skeleton.free&&
4299 player[0].lastcollide<=0&&
4300 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4301 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4302 player[0].coords.y=player[l].coords.y;
4303 player[l].velocity=player[0].velocity;
4304 player[l].skeleton.free=0;
4305 player[l].rotation=0;
4306 player[l].RagDoll(0);
4307 player[l].DoDamage(20);
4309 player[l].skeleton.longdead=0;
4310 player[0].lastcollide=1;
4314 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4315 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4316 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4317 rotatetarget=player[k].velocity-player[i].velocity;
4318 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4319 player[i].skeleton.free)&&
4320 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4321 player[k].skeleton.free))
4322 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4323 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4324 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4326 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4327 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4328 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4329 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4330 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4332 if( (i!=0||player[i].skeleton.free)&&
4333 (k!=0||player[k].skeleton.free)||
4334 (animation[player[i].targetanimation].height==highheight&&
4335 animation[player[k].targetanimation].height==highheight)){
4336 if(tutoriallevel!=1){
4337 emit_sound_at(heavyimpactsound, player[i].coords);
4340 player[i].RagDoll(0);
4341 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4342 award_bonus(0, aimbonus);
4344 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4345 player[k].RagDoll(0);
4346 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4347 award_bonus(0, aimbonus); // Huh, again?
4349 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4351 for(int j=0;j<player[i].skeleton.num_joints;j++){
4352 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4354 for(int j=0;j<player[k].skeleton.num_joints;j++){
4355 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4360 if( (animation[player[i].targetanimation].attack==neutral||
4361 animation[player[i].targetanimation].attack==normalattack)&&
4362 (animation[player[k].targetanimation].attack==neutral||
4363 animation[player[k].targetanimation].attack==normalattack)){
4365 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4366 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4367 rotatetarget=player[k].coords-player[i].coords;
4368 Normalise(&rotatetarget);
4369 player[k].coords=(player[k].coords+player[i].coords)/2;
4370 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4371 *sq((player[i].scale+player[k].scale)*2.5);
4372 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4373 if(player[k].howactive==typeactive||hostile)
4374 if(player[k].isIdle()){
4375 if(player[k].howactive<typesleeping)
4376 setAnimation(k,player[k].getStop());
4377 else if(player[k].howactive==typesleeping)
4378 setAnimation(k,getupfromfrontanim);
4380 player[k].howactive=typeactive;
4382 if(player[i].howactive==typeactive||hostile)
4383 if(player[i].isIdle()){
4384 if(player[i].howactive<typesleeping)
4385 setAnimation(i,player[k].getStop());
4387 setAnimation(i,getupfromfrontanim);
4389 player[i].howactive=typeactive;
4392 //jump down on player
4394 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4395 !player[i].isCrouch()&&
4396 player[i].targetanimation!=rollanim&&
4397 !player[k].skeleton.oldfree&&!
4398 player[k].skeleton.free&&
4399 player[k].lastcollide<=0&&
4400 player[k].velocity.y<-10){
4401 player[i].velocity=player[k].velocity;
4402 player[k].velocity=player[k].velocity*-.5;
4403 player[k].velocity.y=player[i].velocity.y;
4404 player[i].DoDamage(20);
4405 player[i].RagDoll(0);
4406 player[k].lastcollide=1;
4407 award_bonus(k, AboveBonus);
4409 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4410 !player[k].isCrouch()&&
4411 player[k].targetanimation!=rollanim&&
4412 !player[i].skeleton.oldfree&&
4413 !player[i].skeleton.free&&
4414 player[i].lastcollide<=0&&
4415 player[i].velocity.y<-10){
4416 player[k].velocity=player[i].velocity;
4417 player[i].velocity=player[i].velocity*-.3;
4418 player[i].velocity.y=player[k].velocity.y;
4419 player[k].DoDamage(20);
4420 player[k].RagDoll(0);
4421 player[i].lastcollide=1;
4422 award_bonus(i, AboveBonus);
4428 player[i].CheckKick();
4429 player[k].CheckKick();
4435 void Game::doAI(int i){
4436 static bool connected;
4437 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4438 player[i].jumpclimb=0;
4439 //disable movement in editor
4441 player[i].stunned=1;
4444 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4445 player[0].coords.y>player[i].coords.y+2&&
4446 !player[0].onterrain)
4450 if(player[i].aitype==pathfindtype){
4451 if(player[i].finalpathfindpoint==-1){
4452 float closestdistance;
4458 for(int j=0;j<numpathpoints;j++)
4459 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4460 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4462 player[i].finaltarget=pathpoint[j];
4464 player[i].finalpathfindpoint=closest;
4465 for(int j=0;j<numpathpoints;j++)
4466 for(int k=0;k<numpathpointconnect[j];k++){
4467 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4468 if(sq(tempdist)<closestdistance)
4469 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4470 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4471 closestdistance=sq(tempdist);
4473 player[i].finaltarget=colpoint;
4476 player[i].finalpathfindpoint=closest;
4479 if(player[i].targetpathfindpoint==-1){
4480 float closestdistance;
4486 if(player[i].lastpathfindpoint==-1){
4487 for(int j=0;j<numpathpoints;j++){
4488 if(j!=player[i].lastpathfindpoint)
4489 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4490 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4494 player[i].targetpathfindpoint=closest;
4495 for(int j=0;j<numpathpoints;j++)
4496 if(j!=player[i].lastpathfindpoint)
4497 for(int k=0;k<numpathpointconnect[j];k++){
4498 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4499 if(sq(tempdist)<closestdistance){
4500 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4501 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4502 closestdistance=sq(tempdist);
4507 player[i].targetpathfindpoint=closest;
4511 for(int j=0;j<numpathpoints;j++)
4512 if(j!=player[i].lastpathfindpoint&&
4513 j!=player[i].lastpathfindpoint2&&
4514 j!=player[i].lastpathfindpoint3&&
4515 j!=player[i].lastpathfindpoint4){
4517 if(numpathpointconnect[j])
4518 for(int k=0;k<numpathpointconnect[j];k++)
4519 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4522 if(numpathpointconnect[player[i].lastpathfindpoint])
4523 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4524 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4527 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4528 if(closest==-1||tempdist<closestdistance){
4529 closestdistance=tempdist;
4534 player[i].targetpathfindpoint=closest;
4537 player[i].losupdatedelay-=multiplier;
4539 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4540 player[i].lookrotation=player[i].targetrotation;
4542 //reached target point
4543 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4544 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4545 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4546 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4547 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4548 if(player[i].lastpathfindpoint2==-1)
4549 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4550 if(player[i].lastpathfindpoint3==-1)
4551 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4552 if(player[i].lastpathfindpoint4==-1)
4553 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4554 player[i].targetpathfindpoint=-1;
4556 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4557 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4558 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4559 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4560 player[i].aitype=passivetype;
4563 player[i].forwardkeydown=1;
4564 player[i].leftkeydown=0;
4565 player[i].backkeydown=0;
4566 player[i].rightkeydown=0;
4567 player[i].crouchkeydown=0;
4568 player[i].attackkeydown=0;
4569 player[i].throwkeydown=0;
4571 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4572 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4574 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4575 player[i].jumpkeydown=0;
4576 if((player[i].collided>.8&&player[i].jumppower>=5))
4577 player[i].jumpkeydown=1;
4579 if((tutoriallevel!=1||cananger)&&
4582 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4583 player[i].occluded<25){
4584 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4585 animation[player[0].targetanimation].height!=lowheight&&
4587 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4588 player[i].aitype=attacktypecutoff;
4589 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4590 animation[player[0].targetanimation].height==highheight&&
4592 player[i].aitype=attacktypecutoff;
4594 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4595 player[i].losupdatedelay=.2;
4596 for(int j=0;j<numplayers;j++)
4597 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4598 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4599 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4600 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4601 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4602 if(!player[j].isWallJump()&&-1==checkcollide(
4603 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
4604 *player[i].scale+player[i].coords,
4605 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
4606 *player[j].scale+player[j].coords)||
4607 (player[j].targetanimation==hanganim&&
4608 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4609 player[i].aitype=searchtype;
4610 player[i].lastchecktime=12;
4611 player[i].lastseen=player[j].coords;
4612 player[i].lastseentime=12;
4616 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4617 if(player[i].creature!=wolftype){
4618 player[i].stunned=.6;
4619 player[i].surprised=.6;
4623 if(player[i].aitype!=passivetype&&leveltime>.5)
4624 player[i].howactive=typeactive;
4626 if(player[i].aitype==passivetype){
4627 player[i].aiupdatedelay-=multiplier;
4628 player[i].losupdatedelay-=multiplier;
4629 player[i].lastseentime+=multiplier;
4630 player[i].pausetime-=multiplier;
4631 if(player[i].lastseentime>1)
4632 player[i].lastseentime=1;
4634 if(player[i].aiupdatedelay<0){
4635 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4636 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4637 player[i].lookrotation=player[i].targetrotation;
4638 player[i].aiupdatedelay=.05;
4640 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4641 if(player[i].waypointtype[player[i].waypoint]==wppause)
4642 player[i].pausetime=4;
4643 player[i].waypoint++;
4644 if(player[i].waypoint>player[i].numwaypoints-1)
4645 player[i].waypoint=0;
4650 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4651 player[i].forwardkeydown=1;
4653 player[i].forwardkeydown=0;
4654 player[i].leftkeydown=0;
4655 player[i].backkeydown=0;
4656 player[i].rightkeydown=0;
4657 player[i].crouchkeydown=0;
4658 player[i].attackkeydown=0;
4659 player[i].throwkeydown=0;
4661 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4662 if(!player[i].avoidsomething)
4663 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4665 XYZ leftpos,rightpos;
4666 float leftdist,rightdist;
4667 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4668 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4669 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4670 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4671 if(leftdist<rightdist)
4672 player[i].targetrotation+=90;
4674 player[i].targetrotation-=90;
4678 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4679 player[i].jumpkeydown=0;
4680 if((player[i].collided>.8&&player[i].jumppower>=5))
4681 player[i].jumpkeydown=1;
4686 if(player[i].howactive<=typesleeping)
4687 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4688 for(int j=0;j<numenvsounds;j++){
4689 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4690 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4691 2*(vol+vol*(player[i].creature==rabbittype)*3))
4692 player[i].aitype=attacktypecutoff;
4695 if(player[i].aitype!=passivetype){
4696 if(player[i].howactive==typesleeping)
4697 setAnimation(i,getupfromfrontanim);
4698 player[i].howactive=typeactive;
4702 if(player[i].howactive<typesleeping&&
4703 ((tutoriallevel!=1||cananger)&&hostile)&&
4705 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4706 player[i].occluded<25){
4707 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4708 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4709 player[i].aitype=attacktypecutoff;
4710 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4711 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4712 player[i].aitype=attacktypecutoff;
4715 if(player[i].creature==wolftype){
4717 for(int j=0;j<numplayers;j++){
4718 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4719 float smelldistance=50;
4720 if(j==0&&player[j].num_weapons>0){
4721 if(weapons[player[j].weaponids[0]].bloody)
4723 if(player[j].num_weapons==2)
4724 if(weapons[player[j].weaponids[1]].bloody)
4729 windsmell=windvector;
4730 Normalise(&windsmell);
4731 windsmell=windsmell*2+player[j].coords;
4732 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4733 player[i].aitype=attacktypecutoff;
4738 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4739 player[i].losupdatedelay=.2;
4740 for(int j=0;j<numplayers;j++){
4741 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4742 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4743 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4744 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4745 if((-1==checkcollide(
4746 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4747 player[i].scale+player[i].coords,
4748 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
4749 player[j].scale+player[j].coords)&&
4750 !player[j].isWallJump())||
4751 (player[j].targetanimation==hanganim&&
4752 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4753 player[i].lastseentime-=.2;
4754 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4755 player[i].lastseentime-=.4;
4757 player[i].lastseentime-=.6;
4759 if(player[i].lastseentime<=0){
4760 player[i].aitype=searchtype;
4761 player[i].lastchecktime=12;
4762 player[i].lastseen=player[j].coords;
4763 player[i].lastseentime=12;
4770 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4771 if(player[i].creature!=wolftype){
4772 player[i].stunned=.6;
4773 player[i].surprised=.6;
4775 if(player[i].creature==wolftype){
4776 player[i].stunned=.47;
4777 player[i].surprised=.47;
4785 if(player[i].aitype==searchtype){
4786 player[i].aiupdatedelay-=multiplier;
4787 player[i].losupdatedelay-=multiplier;
4788 if(!player[i].pause)
4789 player[i].lastseentime-=multiplier;
4790 player[i].lastchecktime-=multiplier;
4792 if(player[i].isRun()&&!player[i].onground){
4793 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4794 XYZ test2=player[i].coords+player[i].facing;
4796 XYZ test=player[i].coords+player[i].facing;
4798 j=checkcollide(test2,test,player[i].laststanding);
4800 j=checkcollide(test2,test);
4802 player[i].velocity=0;
4803 setAnimation(i,player[i].getStop());
4804 player[i].targetrotation+=180;
4805 player[i].stunned=.5;
4806 //player[i].aitype=passivetype;
4807 player[i].aitype=pathfindtype;
4808 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4809 player[i].finalpathfindpoint=-1;
4810 player[i].targetpathfindpoint=-1;
4811 player[i].lastpathfindpoint=-1;
4812 player[i].lastpathfindpoint2=-1;
4813 player[i].lastpathfindpoint3=-1;
4814 player[i].lastpathfindpoint4=-1;
4816 else player[i].laststanding=j;
4819 //check out last seen location
4820 if(player[i].aiupdatedelay<0){
4821 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4822 player[i].lookrotation=player[i].targetrotation;
4823 player[i].aiupdatedelay=.05;
4824 player[i].forwardkeydown=1;
4826 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4827 player[i].forwardkeydown=0;
4828 player[i].aiupdatedelay=1;
4829 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4830 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4831 player[i].lastchecktime=3;
4834 player[i].leftkeydown=0;
4835 player[i].backkeydown=0;
4836 player[i].rightkeydown=0;
4837 player[i].crouchkeydown=0;
4838 player[i].attackkeydown=0;
4839 player[i].throwkeydown=0;
4841 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4842 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4844 XYZ leftpos,rightpos;
4845 float leftdist,rightdist;
4846 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4847 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4848 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4849 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4850 if(leftdist<rightdist)player[i].targetrotation+=90;
4851 else player[i].targetrotation-=90;
4855 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4856 player[i].jumpkeydown=0;
4857 if((player[i].collided>.8&&player[i].jumppower>=5))
4858 player[i].jumpkeydown=1;
4860 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4861 for(int k=0;k<numenvsounds;k++){
4862 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4863 player[i].aitype=attacktypecutoff;
4867 if(!player[0].dead&&
4868 player[i].losupdatedelay<0&&
4870 player[i].occluded<2&&
4871 ((tutoriallevel!=1||cananger)&&hostile)){
4872 player[i].losupdatedelay=.2;
4873 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4874 player[i].aitype=attacktypecutoff;
4875 player[i].lastseentime=1;
4877 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4878 //TODO: factor out canSeePlayer()
4879 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4880 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4882 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4883 player[i].scale+player[i].coords,
4884 DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
4885 player[0].scale+player[0].coords)==-1)||
4886 (player[0].targetanimation==hanganim&&normaldotproduct(
4887 player[0].facing,player[i].coords-player[0].coords)<0)){
4888 /* //TODO: changed j to 0 on a whim, make sure this is correct
4889 (player[j].targetanimation==hanganim&&normaldotproduct(
4890 player[j].facing,player[i].coords-player[j].coords)<0)
4892 player[i].aitype=attacktypecutoff;
4893 player[i].lastseentime=1;
4897 if(player[i].lastseentime<0){
4898 //player[i].aitype=passivetype;
4900 player[i].aitype=pathfindtype;
4901 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4902 player[i].finalpathfindpoint=-1;
4903 player[i].targetpathfindpoint=-1;
4904 player[i].lastpathfindpoint=-1;
4905 player[i].lastpathfindpoint2=-1;
4906 player[i].lastpathfindpoint3=-1;
4907 player[i].lastpathfindpoint4=-1;
4911 if(player[i].aitype!=gethelptype)
4912 player[i].runninghowlong=0;
4914 //get help from buddies
4915 if(player[i].aitype==gethelptype){
4916 player[i].runninghowlong+=multiplier;
4917 player[i].aiupdatedelay-=multiplier;
4919 if(player[i].aiupdatedelay<0||player[i].ally==0){
4920 player[i].aiupdatedelay=.2;
4923 //TODO: factor out closest search somehow
4924 if(!player[i].ally){
4926 float closestdist=-1;
4927 for(int k=0;k<numplayers;k++){
4928 if(k!=i&&k!=0&&!player[k].dead&&
4929 player[k].howactive<typedead1&&
4930 !player[k].skeleton.free&&
4931 player[k].aitype==passivetype){
4932 float distance=findDistancefast(&player[i].coords,&player[k].coords);
4933 if(closestdist==-1||distance<closestdist){
4934 closestdist=distance;
4941 player[i].ally=closest;
4944 player[i].lastseen=player[0].coords;
4945 player[i].lastseentime=12;
4949 player[i].lastchecktime=12;
4951 XYZ facing=player[i].coords;
4952 XYZ flatfacing=player[player[i].ally].coords;
4953 facing.y+=playerJoint(i,head).position.y*player[i].scale;
4954 flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
4955 if(-1!=checkcollide(facing,flatfacing))
4956 player[i].lastseentime-=.1;
4958 //no available ally, run back to player
4959 if(player[i].ally<=0||
4960 player[player[i].ally].skeleton.free||
4961 player[player[i].ally].aitype!=passivetype||
4962 player[i].lastseentime<=0){
4963 player[i].aitype=searchtype;
4964 player[i].lastseentime=12;
4968 if(player[i].ally>0){
4969 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
4970 player[i].lookrotation=player[i].targetrotation;
4971 player[i].aiupdatedelay=.05;
4972 player[i].forwardkeydown=1;
4974 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
4975 player[i].aitype=searchtype;
4976 player[i].lastseentime=12;
4977 player[player[i].ally].aitype=searchtype;
4978 if(player[player[i].ally].lastseentime<player[i].lastseentime){
4979 player[player[i].ally].lastseen=player[i].lastseen;
4980 player[player[i].ally].lastseentime=player[i].lastseentime;
4981 player[player[i].ally].lastchecktime=player[i].lastchecktime;
4985 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4986 if(!player[i].avoidsomething)
4987 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4989 XYZ leftpos,rightpos;
4990 float leftdist,rightdist;
4991 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4992 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4993 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4994 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4995 if(leftdist<rightdist)
4996 player[i].targetrotation+=90;
4998 player[i].targetrotation-=90;
5003 player[i].leftkeydown=0;
5004 player[i].backkeydown=0;
5005 player[i].rightkeydown=0;
5006 player[i].crouchkeydown=0;
5007 player[i].attackkeydown=0;
5009 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5010 player[i].jumpkeydown=0;
5011 if(player[i].collided>.8&&player[i].jumppower>=5)
5012 player[i].jumpkeydown=1;
5015 //retreiving a weapon on the ground
5016 if(player[i].aitype==getweapontype){
5017 player[i].aiupdatedelay-=multiplier;
5018 player[i].lastchecktime-=multiplier;
5020 if(player[i].aiupdatedelay<0){
5021 player[i].aiupdatedelay=.2;
5024 if(player[i].ally<0){
5026 float closestdist=-1;
5027 for(int k=0;k<weapons.size();k++)
5028 if(weapons[k].owner==-1){
5029 float distance=findDistancefast(&player[i].coords,&weapons[k].position);
5030 if(closestdist==-1||distance<closestdist){
5031 closestdist=distance;
5037 player[i].ally=closest;
5042 player[i].lastseentime=12;
5044 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5045 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5046 player[i].aitype=attacktypecutoff;
5047 player[i].lastseentime=1;
5050 if(player[i].ally>=0){
5051 if(weapons[player[i].ally].owner!=-1||
5052 findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
5053 player[i].aitype=attacktypecutoff;
5054 player[i].lastseentime=1;
5056 //TODO: factor these out as moveToward()
5057 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5058 player[i].lookrotation=player[i].targetrotation;
5059 player[i].aiupdatedelay=.05;
5060 player[i].forwardkeydown=1;
5063 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5064 if(!player[i].avoidsomething)
5065 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5067 XYZ leftpos,rightpos;
5068 float leftdist,rightdist;
5069 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5070 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5071 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5072 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5073 if(leftdist<rightdist)
5074 player[i].targetrotation+=90;
5076 player[i].targetrotation-=90;
5081 player[i].leftkeydown=0;
5082 player[i].backkeydown=0;
5083 player[i].rightkeydown=0;
5084 player[i].attackkeydown=0;
5085 player[i].throwkeydown=1;
5086 player[i].crouchkeydown=0;
5087 if(player[i].targetanimation!=crouchremoveknifeanim&&
5088 player[i].targetanimation!=removeknifeanim)
5089 player[i].throwtogglekeydown=0;
5090 player[i].drawkeydown=0;
5092 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5093 player[i].jumpkeydown=0;
5094 if((player[i].collided>.8&&player[i].jumppower>=5))
5095 player[i].jumpkeydown=1;
5098 if(player[i].aitype==attacktypecutoff){
5099 player[i].aiupdatedelay-=multiplier;
5100 //dodge or reverse rabbit kicks, knife throws, flips
5101 if(player[i].damage<player[i].damagetolerance*2/3)
5102 if((player[0].targetanimation==rabbitkickanim||
5103 player[0].targetanimation==knifethrowanim||
5104 (player[0].isFlip()&&
5105 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5106 !player[0].skeleton.free&&
5107 (player[i].aiupdatedelay<.1)){
5108 player[i].attackkeydown=0;
5109 if(player[i].isIdle())
5110 player[i].crouchkeydown=1;
5111 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5112 if(weapons[player[0].weaponids[0]].getType()==knife){
5113 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5114 if(abs(Random()%2==0))
5115 setAnimation(i,backhandspringanim);
5117 setAnimation(i,rollanim);
5118 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5119 player[i].wentforweapon=0;
5121 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5122 setAnimation(i,flipanim);
5125 player[i].forwardkeydown=0;
5126 player[i].aiupdatedelay=.02;
5128 //get confused by flips
5129 if(player[0].isFlip()&&
5130 !player[0].skeleton.free&&
5131 player[0].targetanimation!=walljumprightkickanim&&
5132 player[0].targetanimation!=walljumpleftkickanim){
5133 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5134 if((1-player[i].damage/player[i].damagetolerance)>.5)
5135 player[i].stunned=1;
5137 //go for weapon on the ground
5138 if(player[i].wentforweapon<3)
5139 for(int k=0;k<weapons.size();k++)
5140 if(player[i].creature!=wolftype)
5141 if(player[i].num_weapons==0&&
5142 weapons[k].owner==-1&&
5143 weapons[i].velocity.x==0&&
5144 weapons[i].velocity.z==0&&
5145 weapons[i].velocity.y==0){
5146 if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
5147 player[i].wentforweapon++;
5148 player[i].lastchecktime=6;
5149 player[i].aitype=getweapontype;
5153 //dodge/reverse walljump kicks
5154 if(player[i].damage<player[i].damagetolerance/2)
5155 if(animation[player[i].targetanimation].height!=highheight)
5156 if(player[i].damage<player[i].damagetolerance*.5&&
5157 ((player[0].targetanimation==walljumprightkickanim||
5158 player[0].targetanimation==walljumpleftkickanim)&&
5159 ((player[i].aiupdatedelay<.15&&
5161 (player[i].aiupdatedelay<.08&&
5163 player[i].crouchkeydown=1;
5165 //walked off a ledge (?)
5166 if(player[i].isRun()&&!player[i].onground)
5167 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5168 XYZ test2=player[i].coords+player[i].facing;
5170 XYZ test=player[i].coords+player[i].facing;
5172 j=checkcollide(test2,test,player[i].laststanding);
5174 j=checkcollide(test2,test);
5176 player[i].velocity=0;
5177 setAnimation(i,player[i].getStop());
5178 player[i].targetrotation+=180;
5179 player[i].stunned=.5;
5180 player[i].aitype=pathfindtype;
5181 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5182 player[i].finalpathfindpoint=-1;
5183 player[i].targetpathfindpoint=-1;
5184 player[i].lastpathfindpoint=-1;
5185 player[i].lastpathfindpoint2=-1;
5186 player[i].lastpathfindpoint3=-1;
5187 player[i].lastpathfindpoint4=-1;
5189 player[i].laststanding=j;
5191 //lose sight of player in the air (?)
5192 if(player[0].coords.y>player[i].coords.y+5&&
5193 animation[player[0].targetanimation].height!=highheight&&
5194 !player[0].onterrain){
5195 player[i].aitype=pathfindtype;
5196 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5197 player[i].finalpathfindpoint=-1;
5198 player[i].targetpathfindpoint=-1;
5199 player[i].lastpathfindpoint=-1;
5200 player[i].lastpathfindpoint2=-1;
5201 player[i].lastpathfindpoint3=-1;
5202 player[i].lastpathfindpoint4=-1;
5204 //it's time to think (?)
5205 if(player[i].aiupdatedelay<0&&
5206 !animation[player[i].targetanimation].attack&&
5207 player[i].targetanimation!=staggerbackhighanim&&
5208 player[i].targetanimation!=staggerbackhardanim&&
5209 player[i].targetanimation!=backhandspringanim&&
5210 player[i].targetanimation!=dodgebackanim){
5212 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5213 player[i].drawkeydown=Random()%2;
5215 player[i].drawkeydown=0;
5216 player[i].rabbitkickenabled=Random()%2;
5218 XYZ rotatetarget=player[0].coords+player[0].velocity;
5219 XYZ targetpoint=player[0].coords;
5220 if(findDistancefast(&player[0].coords,&player[i].coords)<
5221 findDistancefast(&rotatetarget,&player[i].coords))
5222 targetpoint+=player[0].velocity*
5223 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5224 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5225 player[i].lookrotation=player[i].targetrotation;
5226 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5228 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5229 player[i].forwardkeydown=1;
5230 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5231 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5232 player[0].weaponactive!=-1)
5233 player[i].forwardkeydown=1;
5234 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5235 player[i].forwardkeydown=1;
5237 player[i].forwardkeydown=0;
5238 //chill out around the corpse
5240 player[i].forwardkeydown=0;
5242 player[i].forwardkeydown=1;
5243 if(Random()%100==0){
5244 player[i].aitype=pathfindtype;
5245 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5246 player[i].finalpathfindpoint=-1;
5247 player[i].targetpathfindpoint=-1;
5248 player[i].lastpathfindpoint=-1;
5249 player[i].lastpathfindpoint2=-1;
5250 player[i].lastpathfindpoint3=-1;
5251 player[i].lastpathfindpoint4=-1;
5254 player[i].leftkeydown=0;
5255 player[i].backkeydown=0;
5256 player[i].rightkeydown=0;
5257 player[i].crouchkeydown=0;
5258 player[i].throwkeydown=0;
5260 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5261 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5263 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5264 player[i].attackkeydown=1;
5266 player[i].attackkeydown=0;
5267 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5268 player[i].attackkeydown=0;
5271 if(player[i].aitype!=playercontrolled&&
5272 (player[i].isIdle()||
5273 player[i].isCrouch()||
5274 player[i].isRun())){
5276 for(int j=0;j<numplayers;j++)
5277 if(j!=i&&!player[j].skeleton.free&&
5278 player[j].hasvictim&&
5279 (tutoriallevel==1&&reversaltrain||
5280 Random()%2==0&&difficulty==2||
5281 Random()%4==0&&difficulty==1||
5282 Random()%8==0&&difficulty==0||
5283 player[j].lastattack2==player[j].targetanimation&&
5284 player[j].lastattack3==player[j].targetanimation&&
5285 (Random()%2==0||difficulty==2)||
5286 (player[i].isIdle()||player[i].isRun())&&
5287 player[j].weaponactive!=-1||
5288 player[j].targetanimation==swordslashanim&&
5289 player[i].weaponactive!=-1||
5290 player[j].targetanimation==staffhitanim||
5291 player[j].targetanimation==staffspinhitanim))
5292 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5293 player[j].victim==&player[i]&&
5294 (player[j].targetanimation==sweepanim||
5295 player[j].targetanimation==spinkickanim||
5296 player[j].targetanimation==staffhitanim||
5297 player[j].targetanimation==staffspinhitanim||
5298 player[j].targetanimation==winduppunchanim||
5299 player[j].targetanimation==upunchanim||
5300 player[j].targetanimation==wolfslapanim||
5301 player[j].targetanimation==knifeslashstartanim||
5302 player[j].targetanimation==swordslashanim&&
5303 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5304 player[i].weaponactive!=-1))){
5311 player[target].Reverse();
5314 if(player[i].collided<1)
5315 player[i].jumpkeydown=0;
5316 if(player[i].collided>.8&&player[i].jumppower>=5||
5317 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5318 player[i].onterrain&&
5319 player[i].creature==rabbittype)
5320 player[i].jumpkeydown=1;
5321 //TODO: why are we controlling the human?
5322 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5323 player[0].jumpkeydown=0;
5324 if(player[0].targetanimation==jumpdownanim&&
5325 findDistancefast(&player[0].coords,&player[i].coords)<40)
5326 player[i].crouchkeydown=1;
5327 if(player[i].jumpkeydown)
5328 player[i].attackkeydown=0;
5330 if(tutoriallevel==1)
5332 player[i].attackkeydown=0;
5335 XYZ facing=player[i].coords;
5336 XYZ flatfacing=player[0].coords;
5337 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5338 flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
5339 if(player[i].occluded>=2)
5340 if(-1!=checkcollide(facing,flatfacing)){
5341 if(!player[i].pause)
5342 player[i].lastseentime-=.2;
5343 if(player[i].lastseentime<=0&&
5344 (player[i].creature!=wolftype||
5345 player[i].weaponstuck==-1)){
5346 player[i].aitype=searchtype;
5347 player[i].lastchecktime=12;
5348 player[i].lastseen=player[0].coords;
5349 player[i].lastseentime=12;
5352 player[i].lastseentime=1;
5355 if(animation[player[0].targetanimation].height==highheight&&
5356 (player[i].aitype==attacktypecutoff||
5357 player[i].aitype==searchtype))
5358 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5359 XYZ test=player[0].coords;
5361 if(-1==checkcollide(player[0].coords,test))
5362 player[i].stunned=1;
5365 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5366 player[i].stunned>0||
5367 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5369 player[i].lastseentime=1;
5370 player[i].targetrotation=player[i].rotation;
5371 player[i].forwardkeydown=0;
5372 player[i].leftkeydown=0;
5373 player[i].backkeydown=0;
5374 player[i].rightkeydown=0;
5375 player[i].jumpkeydown=0;
5376 player[i].attackkeydown=0;
5377 player[i].crouchkeydown=0;
5378 player[i].throwkeydown=0;
5386 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5389 if(player[i].aitype==attacktypecutoff){
5390 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5391 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5392 }else if(player[i].howactive>=typesleeping){
5393 player[i].targetheadrotation=player[i].targetrotation;
5394 player[i].targetheadrotation2=0;
5396 if(player[i].interestdelay<=0){
5397 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5398 player[i].headtarget=player[i].coords;
5399 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5400 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5401 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5402 player[i].headtarget+=player[i].facing*1.5;
5404 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5405 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5411 Values of mainmenu :
5413 2 Menu pause (resume/end game)
5415 4 Controls configuration menu
5416 5 Main game menu (choose level or challenge)
5417 6 Deleting user menu
5418 7 User managment menu (select/add)
5419 8 Choose difficulty menu
5420 9 Challenge level selection menu
5421 10 End of the campaign congratulation (is that really a menu?)
5422 11 Same that 9 ??? => unused
5423 18 stereo configuration
5426 void Game::MenuTick(){
5429 // some specific case where we do something even if the left mouse button is not pressed.
5430 if((mainmenu==5) && (endgame==2)) {
5431 accountactive->endGame();
5436 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
5437 stereoseparation-=0.001;
5439 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5445 if(gameon) { //resume
5447 pause_sound(stream_menutheme);
5448 resume_stream(leveltheme);
5450 fireSound(firestartsound);
5452 mainmenu=(accountactive?5:7);
5460 if(newdetail>2) newdetail=detail;
5461 if(newdetail<0) newdetail=detail;
5462 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5463 if(newscreenwidth<0) newscreenwidth=screenwidth;
5464 if(newscreenheight>3000) newscreenheight=screenheight;
5465 if(newscreenheight<0) newscreenheight=screenheight;
5470 if(gameon){ //end game
5475 pause_sound(stream_menutheme);
5482 bool isCustomResolution,found;
5485 extern SDL_Rect **resolutions;
5486 isCustomResolution = true;
5488 for(int i = 0; (!found) && (resolutions[i]); i++) {
5489 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5490 isCustomResolution = false;
5492 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5494 if(resolutions[i] != NULL) {
5495 newscreenwidth = (int) resolutions[i]->w;
5496 newscreenheight = (int) resolutions[i]->h;
5497 } else if(isCustomResolution){
5498 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5499 newscreenwidth = (int) resolutions[0]->w;
5500 newscreenheight = (int) resolutions[0]->h;
5502 newscreenwidth = screenwidth;
5503 newscreenheight = screenheight;
5506 newscreenwidth = (int) resolutions[0]->w;
5507 newscreenheight = (int) resolutions[0]->h;
5514 newscreenwidth = (int) resolutions[0]->w;
5515 newscreenheight = (int) resolutions[0]->h;
5520 if(newdetail>2) newdetail=0;
5524 if(bloodtoggle>2) bloodtoggle=0;
5528 if(difficulty>2) difficulty=0;
5531 ismotionblur = !ismotionblur;
5537 musictoggle = !musictoggle;
5540 emit_stream_np(stream_menutheme);
5542 pause_sound(leveltheme);
5543 pause_sound(stream_fighttheme);
5544 pause_sound(stream_menutheme);
5546 for(int i=0;i<4;i++){
5547 oldmusicvolume[i]=0;
5562 SaveSettings(*this);
5563 mainmenu=gameon?2:1;
5566 invertmouse = !invertmouse;
5569 usermousesensitivity+=.2;
5570 if(usermousesensitivity>2) usermousesensitivity=.2;
5574 if(volume>1.0001f) volume=0;
5575 OPENAL_SetSFXMasterVolume((int)(volume*255));
5580 newstereomode = stereomode;
5585 showdamagebar = !showdamagebar;
5592 if(selected<nummenuitems-1 && keyselect==-1)
5596 if(selected==nummenuitems-1){
5606 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5616 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5617 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5620 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5624 pause_sound(stream_menutheme);
5641 pause_sound(stream_menutheme);
5650 mainmenu=(gameon?2:1);
5656 vector<string> campaigns = ListCampaigns();
5657 vector<string>::iterator c;
5658 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5659 if(!campaigns.empty())
5660 accountactive->setCurrentCampaign(campaigns.front());
5663 if(c==campaigns.end())
5664 c=campaigns.begin();
5665 accountactive->setCurrentCampaign(*c);
5675 accountactive = Account::destroy(accountactive);
5677 } else if(selected==2) {
5684 if(selected==0 && Account::getNbAccounts()<8){
5686 } else if (selected < Account::getNbAccounts()+1) {
5689 accountactive=Account::get(selected-1);
5690 } else if (selected == Account::getNbAccounts()+1) {
5693 for(int j=0;j<255;j++){
5694 displaytext[0][j]=0;
5705 accountactive->setDifficulty(selected);
5709 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5717 targetlevel=selected;
5722 Loadlevel(selected);
5727 pause_sound(stream_menutheme);
5729 if(selected==numchallengelevels){
5744 stereoseparation+=0.001;
5748 newstereomode = (StereoMode)(newstereomode + 1);
5749 while(!CanInitStereo(newstereomode)){
5750 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5751 newstereomode = (StereoMode)(newstereomode + 1);
5752 if(newstereomode >= stereoCount)
5753 newstereomode = stereoNone;
5755 } else if(selected==2) {
5756 stereoreverse = !stereoreverse;
5757 } else if(selected==3) {
5761 stereomode = newstereomode;
5762 InitStereo(stereomode);
5769 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5772 SaveSettings(*this);
5776 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5779 inputText(displaytext[0],&displayselected,&displaychars[0]);
5780 if(!waiting) { // the input as finished
5781 if(displaychars[0]){ // with enter
5782 accountactive = Account::add(string(displaytext[0]));
5788 fireSound(firestartsound);
5790 for(int i=0;i<255;i++){
5791 displaytext[0][i]=0;
5800 displayblinkdelay-=multiplier;
5801 if(displayblinkdelay<=0){
5802 displayblinkdelay=.3;
5803 displayblink=1-displayblink;
5809 static XYZ facing,flatfacing;
5812 for(int i=0;i<15;i++){
5813 displaytime[i]+=multiplier;
5816 keyboardfrozen=false;
5819 if(Input::isKeyPressed(SDLK_F6)){
5820 if(Input::isKeyDown(SDLK_LSHIFT))
5823 stereoreverse=false;
5826 printf("Stereo reversed\n");
5828 printf("Stereo unreversed\n");
5831 if(Input::isKeyDown(SDLK_F7)){
5832 if(Input::isKeyDown(SDLK_LSHIFT))
5833 stereoseparation -= 0.001;
5835 stereoseparation -= 0.010;
5836 printf("Stereo decreased increased to %f\n", stereoseparation);
5839 if(Input::isKeyDown(SDLK_F8)){
5840 if(Input::isKeyDown(SDLK_LSHIFT))
5841 stereoseparation += 0.001;
5843 stereoseparation += 0.010;
5844 printf("Stereo separation increased to %f\n", stereoseparation);
5848 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5849 if(tutorialstage!=51)
5850 tutorialstagetime=tutorialmaxtime;
5851 emit_sound_np(consolefailsound, 128.);
5855 Values of mainmenu :
5857 2 Menu pause (resume/end game)
5859 4 Controls configuration menu
5860 5 Main game menu (choose level or challenge)
5861 6 Deleting user menu
5862 7 User managment menu (select/add)
5863 8 Choose difficulty menu
5864 9 Challenge level selection menu
5865 10 End of the campaign congratulation (is that really a menu?)
5866 11 Same that 9 ??? => unused
5867 18 stereo configuration
5872 if(mainmenu&&endgame==1)
5874 //go to level select after completing a campaign level
5875 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
5882 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5883 emit_stream_np(stream_menutheme);
5884 pause_sound(leveltheme);
5888 //escape key pressed
5889 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5890 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5891 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
5893 if(mainmenu==0&&!winfreeze)
5895 else if(mainmenu==1||mainmenu==2){
5896 mainmenu=0; //unpause
5899 if(musictoggle&&(mainmenu==1||mainmenu==2)){
5900 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5901 emit_stream_np(stream_menutheme);
5902 pause_sound(leveltheme);
5904 //on resume, play level music
5906 pause_sound(stream_menutheme);
5907 resume_stream(leveltheme);
5909 //finished with settings menu
5911 SaveSettings(*this);
5914 if(mainmenu>=3&&mainmenu!=8){
5921 mainmenu=gameon?2:1; break;
5924 case 6: case 7: case 9: case 10:
5935 if(hostile==1)hostiletime+=multiplier;
5937 if(!winfreeze)leveltime+=multiplier;
5940 if(Input::isKeyPressed(SDLK_v)&&debugmode){
5943 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5947 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
5951 inputText(displaytext[0],&displayselected,&displaychars[0]);
5953 if(displaychars[0]){
5954 for(int j=0;j<255;j++)
5955 displaytext[0][j]=0;
5962 displayblinkdelay-=multiplier;
5963 if(displayblinkdelay<=0){
5964 displayblinkdelay=.3;
5965 displayblink=1-displayblink;
5969 keyboardfrozen=true;
5971 if(Input::isKeyPressed(consolekey)&&debugmode) {
5974 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5983 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
5984 inputText(consoletext[0],&consoleselected,&consolechars[0]);
5987 if(consolechars[0]>0) {
5988 consoletext[0][consolechars[0]]='\0';
5989 cmd_dispatch(this, consoletext[0]);
5990 for(int k=14;k>=1;k--) {
5991 for(int j=0;j<255;j++)
5992 consoletext[k][j]=consoletext[k-1][j];
5993 consolechars[k]=consolechars[k-1];
5995 for(int j=0;j<255;j++)
5996 consoletext[0][j]=0;
6002 consoleblinkdelay-=multiplier;
6003 if(consoleblinkdelay<=0) {
6004 consoleblinkdelay=.3;
6005 consoleblink=1-consoleblink;
6011 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6014 SaveSettings(*this);
6018 static int oldwinfreeze;
6019 if(winfreeze&&!oldwinfreeze){
6020 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6021 emit_sound_np(consolesuccesssound);
6024 oldwinfreeze=winfreeze;
6028 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6031 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6035 } else if(winfreeze) {
6043 //TODO: what is this test?
6044 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6049 talkdelay-=multiplier;
6051 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6052 for(int i=0;i<numdialogues;i++){
6053 int realdialoguetype;
6055 if(dialoguetype[i]>49){
6056 realdialoguetype=dialoguetype[i]-50;
6059 else if(dialoguetype[i]>39){
6060 realdialoguetype=dialoguetype[i]-40;
6063 else if(dialoguetype[i]>29){
6064 realdialoguetype=dialoguetype[i]-30;
6067 else if(dialoguetype[i]>19){
6068 realdialoguetype=dialoguetype[i]-20;
6071 else if(dialoguetype[i]>9){
6072 realdialoguetype=dialoguetype[i]-10;
6076 realdialoguetype=dialoguetype[i];
6079 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6080 realdialoguetype<numplayers&&
6081 realdialoguetype>0&&
6082 (dialoguegonethrough[i]==0||!special)&&
6083 (special||Input::isKeyPressed(attackkey))){
6084 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6085 player[realdialoguetype].howactive>=typedead1||
6086 dialoguetype[i]>40&&dialoguetype[i]<50){
6088 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6089 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6090 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6091 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6092 player[participantfocus[whichdialogue][j]].velocity=0;
6093 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6094 player[participantfocus[whichdialogue][j]].targetframe=0;
6099 dialoguegonethrough[i]++;
6100 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6101 playdialogueboxsound();
6107 windvar+=multiplier;
6108 smoketex+=multiplier;
6109 tutorialstagetime+=multiplier;
6112 static float hotspotvisual[40];
6116 for(int i=0;i<numhotspots;i++)
6117 hotspotvisual[i]-=multiplier/320;
6119 for(int i=0;i<numhotspots;i++){
6120 //if(hotspottype[i]<=10)
6121 while(hotspotvisual[i]<0){
6123 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6124 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6125 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6126 hotspotsprite+=hotspot[i];
6127 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6128 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6132 for(int i=0;i<numhotspots;i++){
6133 if(hotspottype[i]<=10&&hotspottype[i]>0){
6134 hotspot[i]=player[hotspottype[i]].coords;
6145 if(tutoriallevel!=1){
6148 bonus!=spinecrusher&&
6149 bonus!=tracheotomy&&
6152 emit_sound_np(consolesuccesssound);
6154 } else if(bonustime==0){
6155 emit_sound_np(fireendsound);
6158 if(bonus!=solidhit&&
6160 bonus!=threexcombo&&
6165 bonusnum[bonus]+=0.15;
6168 bonusvalue/=bonusnum[bonus];
6169 bonustotal+=bonusvalue;
6171 bonustime+=multiplier;
6174 if(environment==snowyenvironment){
6175 precipdelay-=multiplier;
6176 while(precipdelay<0){
6180 XYZ footvel,footpoint;
6183 footpoint=viewer+viewerfacing*6;
6184 footpoint.y+=((float)abs(Random()%1200))/100-6;
6185 footpoint.x+=((float)abs(Random()%1200))/100-6;
6186 footpoint.z+=((float)abs(Random()%1200))/100-6;
6187 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6192 doAerialAcrobatics();
6195 static XYZ oldviewer;
6199 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6200 player[0].leftkeydown=Input::isKeyDown(leftkey);
6201 player[0].backkeydown=Input::isKeyDown(backkey);
6202 player[0].rightkeydown=Input::isKeyDown(rightkey);
6203 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6204 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6205 player[0].drawkeydown=Input::isKeyDown(drawkey);
6206 player[0].throwkeydown=Input::isKeyDown(throwkey);
6210 player[0].forwardkeydown=0;
6211 player[0].leftkeydown=0;
6212 player[0].backkeydown=0;
6213 player[0].rightkeydown=0;
6214 player[0].jumpkeydown=0;
6215 player[0].crouchkeydown=0;
6216 player[0].drawkeydown=0;
6217 player[0].throwkeydown=0;
6220 if(!player[0].jumpkeydown)
6221 player[0].jumpclimb=0;
6230 facing=DoRotation(facing,-rotation2,0,0);
6231 facing=DoRotation(facing,0,0-rotation,0);
6236 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6238 if(Input::isKeyDown(forwardkey))
6239 viewer+=facing*multiplier*4;
6240 if(Input::isKeyDown(backkey))
6241 viewer-=facing*multiplier*4;
6242 if(Input::isKeyDown(leftkey))
6243 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6244 if(Input::isKeyDown(rightkey))
6245 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6246 if(Input::isKeyDown(jumpkey))
6247 viewer.y+=multiplier*4;
6248 if(Input::isKeyDown(crouchkey))
6249 viewer.y-=multiplier*4;
6250 if( Input::isKeyPressed(SDLK_1)||
6251 Input::isKeyPressed(SDLK_2)||
6252 Input::isKeyPressed(SDLK_3)||
6253 Input::isKeyPressed(SDLK_4)||
6254 Input::isKeyPressed(SDLK_5)||
6255 Input::isKeyPressed(SDLK_6)||
6256 Input::isKeyPressed(SDLK_7)||
6257 Input::isKeyPressed(SDLK_8)||
6258 Input::isKeyPressed(SDLK_9)||
6259 Input::isKeyPressed(SDLK_0)||
6260 Input::isKeyPressed(SDLK_MINUS)){
6262 if(Input::isKeyPressed(SDLK_1))whichend=1;
6263 if(Input::isKeyPressed(SDLK_2))whichend=2;
6264 if(Input::isKeyPressed(SDLK_3))whichend=3;
6265 if(Input::isKeyPressed(SDLK_4))whichend=4;
6266 if(Input::isKeyPressed(SDLK_5))whichend=5;
6267 if(Input::isKeyPressed(SDLK_6))whichend=6;
6268 if(Input::isKeyPressed(SDLK_7))whichend=7;
6269 if(Input::isKeyPressed(SDLK_8))whichend=8;
6270 if(Input::isKeyPressed(SDLK_9))whichend=9;
6271 if(Input::isKeyPressed(SDLK_0))whichend=0;
6272 if(Input::isKeyPressed(SDLK_MINUS))
6275 participantfocus[whichdialogue][indialogue]=whichend;
6276 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6277 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6280 participantfocus[whichdialogue][indialogue]=-1;
6282 if(player[participantfocus[whichdialogue][indialogue]].dead){
6287 dialoguecamera[whichdialogue][indialogue]=viewer;
6288 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6289 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6291 if(indialogue<numdialogueboxes[whichdialogue]){
6292 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6293 playdialogueboxsound();
6297 for(int j=0;j<numplayers;j++){
6298 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6301 //TODO: should these be KeyDown or KeyPressed?
6302 if( Input::isKeyDown(SDLK_KP1)||
6303 Input::isKeyDown(SDLK_KP2)||
6304 Input::isKeyDown(SDLK_KP3)||
6305 Input::isKeyDown(SDLK_KP4)||
6306 Input::isKeyDown(SDLK_KP5)||
6307 Input::isKeyDown(SDLK_KP6)||
6308 Input::isKeyDown(SDLK_KP7)||
6309 Input::isKeyDown(SDLK_KP8)||
6310 Input::isKeyDown(SDLK_KP9)||
6311 Input::isKeyDown(SDLK_KP0)){
6313 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6314 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6315 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6316 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6317 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6318 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6319 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6320 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6321 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6322 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6323 participantfacing[whichdialogue][indialogue][whichend]=facing;
6325 if(indialogue>=numdialogueboxes[whichdialogue]){
6332 pause_sound(whooshsound);
6333 viewer=dialoguecamera[whichdialogue][indialogue];
6334 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6335 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6336 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6337 if(dialoguetime>0.5)
6338 if( Input::isKeyPressed(SDLK_1)||
6339 Input::isKeyPressed(SDLK_2)||
6340 Input::isKeyPressed(SDLK_3)||
6341 Input::isKeyPressed(SDLK_4)||
6342 Input::isKeyPressed(SDLK_5)||
6343 Input::isKeyPressed(SDLK_6)||
6344 Input::isKeyPressed(SDLK_7)||
6345 Input::isKeyPressed(SDLK_8)||
6346 Input::isKeyPressed(SDLK_9)||
6347 Input::isKeyPressed(SDLK_0)||
6348 Input::isKeyPressed(SDLK_MINUS)||
6349 Input::isKeyPressed(attackkey)){
6351 if(indialogue<numdialogueboxes[whichdialogue]){
6352 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6353 playdialogueboxsound();
6354 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6355 hotspot[numhotspots]=player[0].coords;
6356 hotspotsize[numhotspots]=10;
6357 hotspottype[numhotspots]=-1;
6361 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6365 if(player[participantfocus[whichdialogue][indialogue]].dead){
6373 if(indialogue>=numdialogueboxes[whichdialogue]){
6377 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6380 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6383 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6385 for(int i=1;i<numplayers;i++){
6386 player[i].aitype = attacktypecutoff;
6393 if(!player[0].jumpkeydown){
6394 player[0].jumptogglekeydown=0;
6396 if(player[0].jumpkeydown&&
6397 player[0].targetanimation!=jumpupanim&&
6398 player[0].targetanimation!=jumpdownanim&&
6399 !player[0].isFlip())
6400 player[0].jumptogglekeydown=1;
6403 dialoguetime+=multiplier;
6404 hawkrotation+=multiplier*25;
6406 realhawkcoords.x=25;
6407 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6408 hawkcalldelay-=multiplier/2;
6410 if(hawkcalldelay<=0){
6411 emit_sound_at(hawksound, realhawkcoords);
6413 hawkcalldelay=16+abs(Random()%8);
6420 doPlayerCollisions();
6424 for(int k=0;k<numplayers;k++)
6425 if(k!=0&&player[k].immobile)
6426 player[k].coords=player[k].realoldcoords;
6428 for(int k=0;k<numplayers;k++){
6429 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6430 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6431 player[k].DoDamage(1000);
6437 static bool respawnkeydown;
6440 (Input::isKeyDown(SDLK_z)&&
6441 Input::isKeyDown(SDLK_LMETA)&&
6443 (Input::isKeyDown(jumpkey)&&
6447 targetlevel=whichlevel;
6451 if(!Input::isKeyDown(jumpkey))
6453 if(Input::isKeyDown(jumpkey))
6459 static bool movekey;
6462 for(int i=0;i<numplayers;i++){
6463 static float oldtargetrotation;
6464 if(!player[i].skeleton.free){
6465 oldtargetrotation=player[i].targetrotation;
6466 if(i==0&&indialogue==-1){
6467 //TODO: refactor repetitive code
6468 if(!animation[player[0].targetanimation].attack&&
6469 player[0].targetanimation!=staggerbackhighanim&&
6470 player[0].targetanimation!=staggerbackhardanim&&
6471 player[0].targetanimation!=crouchremoveknifeanim&&
6472 player[0].targetanimation!=removeknifeanim&&
6473 player[0].targetanimation!=backhandspringanim&&
6474 player[0].targetanimation!=dodgebackanim&&
6475 player[0].targetanimation!=walljumprightkickanim&&
6476 player[0].targetanimation!=walljumpleftkickanim){
6478 player[0].targetrotation=0;
6480 player[0].targetrotation=-rotation+180;
6486 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6490 facing=DoRotation(facing,-rotation2,0,0);
6491 facing=DoRotation(facing,0,0-rotation,0);
6494 player[0].lookrotation=-rotation;
6496 player[i].targetheadrotation=rotation;
6497 player[i].targetheadrotation2=rotation2;
6499 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6500 if(!animation[player[i].targetanimation].attack&&
6501 player[i].targetanimation!=staggerbackhighanim&&
6502 player[i].targetanimation!=staggerbackhardanim&&
6503 player[i].targetanimation!=crouchremoveknifeanim&&
6504 player[i].targetanimation!=removeknifeanim&&
6505 player[i].targetanimation!=backhandspringanim&&
6506 player[i].targetanimation!=dodgebackanim&&
6507 player[i].targetanimation!=walljumprightkickanim&&
6508 player[i].targetanimation!=walljumpleftkickanim){
6509 player[i].targetrotation=-player[i].lookrotation+180;
6515 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6517 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6518 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6520 player[i].targetheadrotation=player[i].lookrotation;
6521 player[i].targetheadrotation2=player[i].lookrotation2;
6524 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6525 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6531 player[i].avoidsomething=0;
6533 //avoid flaming things
6534 for(int j=0;j<objects.numobjects;j++)
6535 if(objects.onfire[j])
6536 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6537 if( findDistancefast(&player[i].coords,&objects.position[j])<
6538 findDistancefast(&player[i].coords,&player[0].coords)){
6539 player[i].collided=0;
6540 player[i].avoidcollided=1;
6541 if(player[i].avoidsomething==0||
6542 findDistancefast(&player[i].coords,&objects.position[j])<
6543 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6544 player[i].avoidwhere=objects.position[j];
6545 player[i].avoidsomething=1;
6549 //avoid flaming players
6550 for(int j=0;j<numplayers;j++)
6551 if(player[j].onfire)
6552 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6553 if( findDistancefast(&player[i].coords,&player[j].coords)<
6554 findDistancefast(&player[i].coords,&player[0].coords)){
6555 player[i].collided=0;
6556 player[i].avoidcollided=1;
6557 if(player[i].avoidsomething==0||
6558 findDistancefast(&player[i].coords,&player[j].coords)<
6559 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6560 player[i].avoidwhere=player[j].coords;
6561 player[i].avoidsomething=1;
6565 if(player[i].collided>.8)
6566 player[i].avoidcollided=0;
6570 if(animation[player[i].targetanimation].attack==reversed){
6571 //player[i].targetrotation=player[i].rotation;
6572 player[i].forwardkeydown=0;
6573 player[i].leftkeydown=0;
6574 player[i].backkeydown=0;
6575 player[i].rightkeydown=0;
6576 player[i].jumpkeydown=0;
6577 player[i].attackkeydown=0;
6578 //player[i].crouchkeydown=0;
6579 player[i].throwkeydown=0;
6583 player[i].forwardkeydown=0;
6584 player[i].leftkeydown=0;
6585 player[i].backkeydown=0;
6586 player[i].rightkeydown=0;
6587 player[i].jumpkeydown=0;
6588 player[i].crouchkeydown=0;
6589 player[i].drawkeydown=0;
6590 player[i].throwkeydown=0;
6593 if(player[i].collided<-.3)
6594 player[i].collided=-.3;
6595 if(player[i].collided>1)
6596 player[i].collided=1;
6597 player[i].collided-=multiplier*4;
6598 player[i].whichdirectiondelay-=multiplier;
6599 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6600 player[i].avoidcollided=-.3;
6601 player[i].whichdirection=abs(Random()%2);
6602 player[i].whichdirectiondelay=.4;
6604 if(player[i].avoidcollided>1)
6605 player[i].avoidcollided=1;
6606 player[i].avoidcollided-=multiplier/4;
6607 if(!player[i].skeleton.free){
6608 player[i].stunned-=multiplier;
6609 player[i].surprised-=multiplier;
6611 if(i!=0&&player[i].surprised<=0&&
6612 player[i].aitype==attacktypecutoff&&
6614 !player[i].skeleton.free&&
6615 animation[player[i].targetanimation].attack==neutral)
6618 if(!player[i].throwkeydown)
6619 player[i].throwtogglekeydown=0;
6622 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6623 if(player[i].weaponactive==-1&&
6624 player[i].num_weapons<2&&
6625 (player[i].isIdle()||
6626 player[i].isCrouch()||
6627 player[i].targetanimation==sneakanim||
6628 player[i].targetanimation==rollanim||
6629 player[i].targetanimation==backhandspringanim||
6630 player[i].isFlip()||
6631 player[i].isFlip()||
6632 player[i].aitype!=playercontrolled)){
6633 for(int j=0;j<weapons.size();j++){
6634 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6635 player[i].aitype==playercontrolled)&&
6636 weapons[j].owner==-1&&
6637 player[i].weaponactive==-1)
6638 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
6639 if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
6640 if(player[i].isCrouch()||
6641 player[i].targetanimation==sneakanim||
6643 player[i].isIdle()||
6644 player[i].aitype!=playercontrolled){
6645 player[i].throwtogglekeydown=1;
6646 setAnimation(i,crouchremoveknifeanim);
6647 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6648 player[i].hasvictim=0;
6650 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6651 player[i].throwtogglekeydown=1;
6652 player[i].hasvictim=0;
6654 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6655 player[i].aitype==playercontrolled)&&
6656 weapons[j].owner==-1||
6658 weapons[j].owner==player[i].victim->id)
6659 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
6660 if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
6661 if(weapons[j].getType()!=staff)
6662 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6664 player[i].weaponactive=0;
6665 weapons[j].owner=player[i].id;
6666 if(player[i].num_weapons>0)
6667 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6668 player[i].num_weapons++;
6669 player[i].weaponids[0]=j;
6672 }else if((player[i].isIdle()||
6673 player[i].isFlip()||
6674 player[i].aitype!=playercontrolled)&&
6675 findDistancefast(&player[i].coords,&weapons[j].position)<5&&
6676 player[i].coords.y<weapons[j].position.y){
6677 if(!player[i].isFlip()){
6678 player[i].throwtogglekeydown=1;
6679 setAnimation(i,removeknifeanim);
6680 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6682 if(player[i].isFlip()){
6683 player[i].throwtogglekeydown=1;
6684 player[i].hasvictim=0;
6686 for(int k=0;k<weapons.size();k++){
6687 if(player[i].weaponactive==-1)
6688 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
6689 player[i].aitype==playercontrolled)&&
6690 weapons[k].owner==-1||
6692 weapons[k].owner==player[i].victim->id)
6693 if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
6694 player[i].weaponactive==-1){
6695 if(weapons[k].getType()!=staff)
6696 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6698 player[i].weaponactive=0;
6699 weapons[k].owner=player[i].id;
6700 if(player[i].num_weapons>0)
6701 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6702 player[i].num_weapons++;
6703 player[i].weaponids[0]=k;
6710 if(player[i].isCrouch()||
6711 player[i].targetanimation==sneakanim||
6713 player[i].isIdle()||player[i].targetanimation==rollanim||
6714 player[i].targetanimation==backhandspringanim){
6716 for(int j=0;j<numplayers;j++){
6717 if(player[i].weaponactive==-1)
6719 if(player[j].num_weapons&&
6720 player[j].skeleton.free&&
6721 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6722 (((player[j].skeleton.forward.y<0&&
6723 player[j].weaponstuckwhere==0)||
6724 (player[j].skeleton.forward.y>0&&
6725 player[j].weaponstuckwhere==1))||
6726 player[j].weaponstuck==-1||
6727 player[j].num_weapons>1)){
6728 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6729 player[i].throwtogglekeydown=1;
6730 player[i].victim=&player[j];
6731 player[i].hasvictim=1;
6732 setAnimation(i,crouchremoveknifeanim);
6733 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6735 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6736 player[i].throwtogglekeydown=1;
6737 player[i].victim=&player[j];
6738 player[i].hasvictim=1;
6739 int k = player[j].weaponids[0];
6740 if(player[i].hasvictim){
6743 if(player[i].victim->weaponstuck!=-1){
6744 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6749 if(weapons[k].getType()!=staff)
6750 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6753 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6755 player[i].weaponactive=0;
6756 if(weapons[k].owner!=-1){
6757 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6758 else player[i].victim->num_weapons=1;
6760 player[i].victim->skeleton.longdead=0;
6761 player[i].victim->skeleton.free=1;
6762 player[i].victim->skeleton.broken=0;
6764 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6765 player[i].victim->skeleton.joints[l].velchange=0;
6766 player[i].victim->skeleton.joints[l].locked=0;
6772 Normalise(&relative);
6773 XYZ footvel,footpoint;
6775 footpoint=weapons[k].position;
6776 if(player[i].victim->weaponstuck!=-1){
6777 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6778 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6779 weapons[k].bloody=2;
6780 weapons[k].blooddrip=5;
6781 player[i].victim->weaponstuck=-1;
6782 player[i].victim->bloodloss+=2000;
6783 player[i].victim->DoDamage(2000);
6786 if(player[i].victim->num_weapons>0){
6787 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6788 if(player[i].victim->weaponids[0]==k)
6789 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6792 player[i].victim->weaponactive=-1;
6794 playerJoint(player[i].victim,abdomen).velocity+=relative*6;
6795 playerJoint(player[i].victim,neck).velocity+=relative*6;
6796 playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
6797 playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
6800 if(player[i].num_weapons>0){
6801 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6803 player[i].num_weapons++;
6804 player[i].weaponids[0]=k;
6811 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6812 if(weapons[player[i].weaponids[0]].getType()==knife){
6813 if(player[i].isIdle()||
6815 player[i].isCrouch()||
6816 player[i].targetanimation==sneakanim||
6819 for(int j=0;j<numplayers;j++){
6821 if(tutoriallevel!=1||tutorialstage==49)
6823 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6824 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6825 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6826 !player[j].skeleton.free&&
6827 -1==checkcollide(DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
6828 if(!player[i].isFlip()){
6829 player[i].throwtogglekeydown=1;
6830 player[i].victim=&player[j];
6831 setAnimation(i,knifethrowanim);
6832 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6833 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6835 if(player[i].isFlip()){
6836 if(player[i].weaponactive!=-1){
6837 player[i].throwtogglekeydown=1;
6838 player[i].victim=&player[j];
6840 weapons[player[i].weaponids[0]].owner=-1;
6841 aim=player[i].victim->coords+DoRotation(playerJoint(player[i].victim,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(playerJoint(i,righthand).position,0,player[i].rotation,0)*player[i].scale);
6844 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6846 weapons[player[i].weaponids[0]].velocity=aim*50;
6847 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
6848 weapons[player[i].weaponids[0]].missed=0;
6849 weapons[player[i].weaponids[0]].freetime=0;
6850 weapons[player[i].weaponids[0]].firstfree=1;
6851 weapons[player[i].weaponids[0]].physics=0;
6852 player[i].num_weapons--;
6853 if(player[i].num_weapons){
6854 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6856 player[i].weaponactive=-1;
6863 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6864 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6865 player[i].throwtogglekeydown=1;
6866 weapons[player[i].weaponids[0]].owner=-1;
6867 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
6868 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
6869 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
6870 weapons[player[i].weaponids[0]].missed=1;
6871 weapons[player[i].weaponids[0]].freetime=0;
6872 weapons[player[i].weaponids[0]].firstfree=1;
6873 weapons[player[i].weaponids[0]].physics=1;
6874 player[i].num_weapons--;
6875 if(player[i].num_weapons){
6876 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6877 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6880 player[i].weaponactive=-1;
6881 for(int j=0;j<numplayers;j++){
6882 player[j].wentforweapon=0;
6890 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
6891 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6892 player[i].num_weapons==2&&
6893 player[i].weaponactive==-1&&
6894 player[i].isIdle()||
6896 player[i].weaponactive!=-1&&
6899 if(player[i].weaponactive!=-1)
6900 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
6902 if(isgood&&player[i].creature!=wolftype){
6903 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6904 setAnimation(i,drawrightanim);
6905 player[i].drawtogglekeydown=1;
6907 if((player[i].isIdle()||
6908 (player[i].aitype!=playercontrolled&&
6909 player[0].weaponactive!=-1&&
6910 player[i].isRun()))&&
6911 player[i].num_weapons&&
6912 weapons[player[i].weaponids[0]].getType()==sword){
6913 setAnimation(i,drawleftanim);
6914 player[i].drawtogglekeydown=1;
6916 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6917 setAnimation(i,crouchdrawrightanim);
6918 player[i].drawtogglekeydown=1;
6925 if(player[i].weaponactive!=-1) {
6926 if (player[i].isCrouch()&&
6927 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
6929 player[i].onterrain&&
6930 player[i].num_weapons&&
6931 player[i].attackkeydown&&
6932 musictype!=stream_fighttheme) {
6933 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
6934 setAnimation(i,crouchstabanim);
6935 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
6936 setAnimation(i,swordgroundstabanim);
6937 player[i].hasvictim=0;
6941 if(!player[i].drawkeydown)
6942 player[i].drawtogglekeydown=0;
6949 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
6951 absflatfacing=flatfacing;
6954 player[i].forwardkeydown=0;
6955 player[i].leftkeydown=0;
6956 player[i].backkeydown=0;
6957 player[i].rightkeydown=0;
6958 player[i].jumpkeydown=0;
6959 player[i].crouchkeydown=0;
6960 player[i].drawkeydown=0;
6961 player[i].throwkeydown=0;
6965 if(!animation[player[i].targetanimation].attack&&
6966 player[i].targetanimation!=staggerbackhighanim&&
6967 player[i].targetanimation!=staggerbackhardanim&&
6968 player[i].targetanimation!=backhandspringanim&&
6969 player[i].targetanimation!=dodgebackanim){
6970 if(!player[i].forwardkeydown)
6971 player[i].forwardstogglekeydown=0;
6972 if(player[i].crouchkeydown){
6976 player[i].superruntoggle=1;
6978 for(int j=0;j<numplayers;j++)
6979 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
6980 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
6981 player[i].superruntoggle=0;
6985 for(int j=0;j<numplayers;j++){
6986 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
6987 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
6988 player[j].victim==&player[i]&&
6989 (player[j].targetanimation==sweepanim||
6990 player[j].targetanimation==upunchanim||
6991 player[j].targetanimation==wolfslapanim||
6992 ((player[j].targetanimation==swordslashanim||
6993 player[j].targetanimation==knifeslashstartanim||
6994 player[j].targetanimation==staffhitanim||
6995 player[j].targetanimation==staffspinhitanim)&&
6996 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7005 player[target].Reverse();
7006 player[i].lowreversaldelay=.5;
7008 if(player[i].isIdle()){
7009 setAnimation(i,player[i].getCrouch());
7010 player[i].transspeed=10;
7012 if(player[i].isRun()||
7013 (player[i].isStop()&&
7014 (player[i].leftkeydown||
7015 player[i].rightkeydown||
7016 player[i].forwardkeydown||
7017 player[i].backkeydown))){
7018 setAnimation(i,rollanim);
7019 player[i].transspeed=20;
7022 if(!player[i].crouchkeydown){
7024 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7026 if(player[i].isCrouch()){
7028 for(int j=0;j<numplayers;j++){
7030 !player[j].skeleton.free&&
7032 player[i].highreversaldelay<=0){
7033 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7034 player[j].victim==&player[i]&&
7035 (player[j].targetanimation==spinkickanim)&&
7036 player[i].isCrouch()){
7045 player[target].Reverse();
7046 player[i].highreversaldelay=.5;
7048 if(player[i].isCrouch()){
7049 if(!player[i].wasCrouch()){
7050 player[i].currentanimation=player[i].getCrouch();
7051 player[i].currentframe=0;
7053 setAnimation(i,player[i].getIdle());
7054 player[i].transspeed=10;
7057 if(player[i].targetanimation==sneakanim){
7058 setAnimation(i,player[i].getIdle());
7059 player[i].transspeed=10;
7062 if(player[i].forwardkeydown){
7063 if(player[i].isIdle()||
7064 (player[i].isStop()&&
7065 player[i].targetrotation==player[i].rotation)||
7066 (player[i].isLanding()&&
7067 player[i].targetframe>0&&
7068 !player[i].jumpkeydown)||
7069 (player[i].isLandhard()&&
7070 player[i].targetframe>0&&
7071 !player[i].jumpkeydown&&
7072 player[i].crouchkeydown)){
7073 if(player[i].aitype==passivetype)
7074 setAnimation(i,walkanim);
7076 setAnimation(i,player[i].getRun());
7078 if(player[i].isCrouch()){
7079 player[i].targetanimation=sneakanim;
7080 if(player[i].wasCrouch())
7082 player[i].targetframe=0;
7084 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7085 setAnimation(i,climbanim);
7086 player[i].targetframe=1;
7087 player[i].jumpclimb=1;
7089 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7090 player[i].velocity+=absflatfacing*5*multiplier;
7092 player[i].forwardstogglekeydown=1;
7095 if (player[i].rightkeydown){
7096 if(player[i].isIdle()||
7097 (player[i].isStop()&&
7098 player[i].targetrotation==player[i].rotation)||
7099 (player[i].isLanding()&&
7100 player[i].targetframe>0&&
7101 !player[i].jumpkeydown)||
7102 (player[i].isLandhard()&&
7103 player[i].targetframe>0&&
7104 !player[i].jumpkeydown&&
7105 player[i].crouchkeydown)){
7106 setAnimation(i,player[i].getRun());
7108 if(player[i].isCrouch()){
7109 player[i].targetanimation=sneakanim;
7110 if(player[i].wasCrouch())
7112 player[i].targetframe=0;
7114 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7115 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7117 player[i].targetrotation-=90;
7118 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7119 if(player[i].backkeydown)player[i].targetrotation-=45;
7122 if ( player[i].leftkeydown){
7123 if(player[i].isIdle()||
7124 (player[i].isStop()&&
7125 player[i].targetrotation==player[i].rotation)||
7126 (player[i].isLanding()&&
7127 player[i].targetframe>0&&
7128 !player[i].jumpkeydown)||
7129 (player[i].isLandhard()&&
7130 player[i].targetframe>0&&
7131 !player[i].jumpkeydown&&
7132 player[i].crouchkeydown)){
7133 setAnimation(i,player[i].getRun());
7135 if(player[i].isCrouch()){
7136 player[i].targetanimation=sneakanim;
7137 if(player[i].wasCrouch())
7139 player[i].targetframe=0;
7141 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7142 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7144 player[i].targetrotation+=90;
7145 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7146 if(player[i].backkeydown)player[i].targetrotation+=45;
7149 if(player[i].backkeydown){
7150 if(player[i].isIdle()||
7151 (player[i].isStop()&&
7152 player[i].targetrotation==player[i].rotation)||
7153 (player[i].isLanding()&&
7154 player[i].targetframe>0&&
7155 !player[i].jumpkeydown)||
7156 (player[i].isLandhard()&&
7157 player[i].targetframe>0&&
7158 !player[i].jumpkeydown&&
7159 player[i].crouchkeydown)){
7160 setAnimation(i,player[i].getRun());
7162 if(player[i].isCrouch()){
7163 player[i].targetanimation=sneakanim;
7164 if(player[i].wasCrouch())
7166 player[i].targetframe=0;
7168 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7169 player[i].velocity-=absflatfacing*5*multiplier;
7171 if(player[i].targetanimation==hanganim){
7172 player[i].currentanimation=jumpdownanim;
7173 player[i].targetanimation=jumpdownanim;
7175 player[i].currentframe=0;
7176 player[i].targetframe=1;
7177 player[i].velocity=0;
7178 player[i].velocity.y+=gravity;
7179 player[i].coords.y-=1.4;
7180 player[i].grabdelay=1;
7182 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7183 player[i].targetrotation+=180;
7186 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7187 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7189 player[i].targetanimation==walkanim||
7190 player[i].isCrouch()||
7191 player[i].targetanimation==sneakanim)&&
7192 player[i].jumppower>1)&&
7193 ((player[i].targetanimation!=rabbitrunninganim&&
7194 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7195 player[i].jumpstart=0;
7196 setAnimation(i,jumpupanim);
7197 player[i].rotation=player[i].targetrotation;
7198 player[i].transspeed=20;
7199 player[i].FootLand(0,1);
7200 player[i].FootLand(1,1);
7204 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7206 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7207 if(!movekey)player[i].velocity=0;
7212 for(int j=0;j<numplayers;j++){
7213 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7214 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7215 player[j].victim==&player[i]&&
7216 (player[j].targetanimation==sweepanim)){
7217 if(target>=0)target=-1;
7222 if(target>=0)player[i].velocity.y=1;
7223 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7224 player[i].velocity.y=7;
7225 player[i].crouchtogglekeydown=1;
7227 else player[i].velocity.y=5;
7229 if(mousejump&&i==0&&debugmode){
7230 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7231 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7234 player[i].coords.y+=.2;
7235 player[i].jumppower-=1;
7238 emit_sound_at(whooshsound, player[i].coords, 128.);
7240 emit_sound_at(jumpsound, player[i].coords, 128.);
7242 if((player[i].isIdle())&&player[i].jumppower>1){
7243 setAnimation(i,player[i].getLanding());
7244 player[i].targetframe=2;
7245 player[i].landhard=0;
7246 player[i].jumpstart=1;
7247 player[i].tempdeltav=deltav;
7249 if(player[i].targetanimation==jumpupanim&&
7253 player[i].aitype!=playercontrolled)){
7254 if(player[i].jumppower>multiplier*6){
7255 player[i].velocity.y+=multiplier*6;
7256 player[i].jumppower-=multiplier*6;
7258 if(player[i].jumppower<=multiplier*6){
7259 player[i].velocity.y+=player[i].jumppower;
7260 player[i].jumppower=0;
7263 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7267 if(player[i].isRun()||player[i].targetanimation==walkanim)
7268 setAnimation(i,player[i].getStop());
7269 if(player[i].targetanimation==sneakanim){
7270 player[i].targetanimation=player[i].getCrouch();
7271 if(player[i].currentanimation==sneakanim)
7273 player[i].targetframe=0;
7276 if(player[i].targetanimation==walkanim&&
7277 (player[i].aitype==attacktypecutoff||
7278 player[i].aitype==searchtype||
7279 (player[i].aitype==passivetype&&
7280 player[i].numwaypoints<=1)))
7281 setAnimation(i,player[i].getStop());
7282 if(player[i].isRun()&&(player[i].aitype==passivetype))
7283 setAnimation(i,player[i].getStop());
7286 if(player[i].targetanimation==rollanim)
7287 player[i].targetrotation=oldtargetrotation;
7291 for(int k=0;k<numplayers;k++){
7292 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7293 if(player[k].rotation>player[k].targetrotation)
7294 player[k].rotation-=360;
7296 player[k].rotation+=360;
7299 //stop to turn in right direction
7300 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7301 setAnimation(k,player[k].getStop());
7303 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7304 player[k].targettilt=0;
7306 if(player[k].targetanimation!=jumpupanim&&
7307 player[k].targetanimation!=backhandspringanim&&
7308 player[k].targetanimation!=jumpdownanim&&
7309 !player[k].isFlip()){
7310 player[k].targettilt=0;
7311 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7312 player[k].jumppower=0;
7313 player[k].jumppower+=multiplier*7;
7314 if(player[k].isCrouch())
7315 player[k].jumppower+=multiplier*7;
7316 if(player[k].jumppower>5)
7317 player[k].jumppower=5;
7320 if(player[k].isRun())
7321 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7323 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7324 player[k].grabdelay-=multiplier;
7328 for(int k=0;k<numplayers;k++){
7329 player[k].DoAnimations();
7330 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7331 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7337 for(int j=numenvsounds-1;j>=0;j--){
7338 envsoundlife[j]-=multiplier;
7339 if(envsoundlife[j]<0){
7341 envsoundlife[j]=envsoundlife[numenvsounds];
7342 envsound[j]=envsound[numenvsounds];
7346 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7348 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7350 if(tutoriallevel==1){
7367 if(tutorialstage>=51)
7368 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7369 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7370 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7372 emit_stream_np(stream_menutheme);
7381 if(tutorialstage<51)
7382 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7383 emit_sound_at(fireendsound, player[0].coords);
7385 player[0].coords=(oldtemp+oldtemp2)/2;
7389 if(tutorialstage>=14&&tutorialstage<50)
7390 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7391 emit_sound_at(fireendsound, player[1].coords);
7393 for(int i=0;i<player[1].skeleton.num_joints;i++){
7395 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7396 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7397 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;
7398 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7399 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7403 player[1].coords=(oldtemp+oldtemp2)/2;
7404 for(int i=0;i<player[1].skeleton.num_joints;i++){
7405 player[1].skeleton.joints[i].velocity=0;
7407 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7408 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7409 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;
7410 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7411 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7419 static float gLoc[3];
7423 static float vel[3];
7424 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7425 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7426 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7428 //Set orientation with forward and up vectors
7429 static XYZ upvector;
7433 upvector=DoRotation(upvector,-rotation2+90,0,0);
7434 upvector=DoRotation(upvector,0,0-rotation,0);
7439 facing=DoRotation(facing,-rotation2,0,0);
7440 facing=DoRotation(facing,0,0-rotation,0);
7443 static float ori[6];
7447 ori[3] = -upvector.x;
7448 ori[4] = upvector.y;
7449 ori[5] = -upvector.z;
7451 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7458 if(Input::isKeyPressed(SDLK_F1))
7462 void Game::TickOnce(){
7464 rotation+=multiplier*5;
7466 if(directing||indialogue==-1) {
7467 rotation+=deltah*.7;
7469 rotation2+=deltav*.7;
7471 rotation2-=deltav*.7;
7479 void Game::TickOnceAfter(){
7480 static XYZ colviewer;
7481 static XYZ coltarget;
7485 static float changedelay;
7486 static bool alldead;
7487 static float unseendelay;
7488 static float cameraspeed;
7492 if(environment==snowyenvironment)
7493 leveltheme=stream_snowtheme;
7494 if(environment==grassyenvironment)
7495 leveltheme=stream_grasstheme;
7496 if(environment==desertenvironment)
7497 leveltheme=stream_deserttheme;
7501 musictype=leveltheme;
7502 for(int i=0;i<numplayers;i++){
7503 if((player[i].aitype==attacktypecutoff||
7504 player[i].aitype==getweapontype||
7505 player[i].aitype==gethelptype||
7506 player[i].aitype==searchtype)&&
7507 !player[i].dead/*&&player[i].surprised<=0*/&&
7508 (player[i].targetanimation!=sneakattackedanim&&
7509 player[i].targetanimation!=knifesneakattackedanim&&
7510 player[i].targetanimation!=swordsneakattackedanim)){
7511 musictype=stream_fighttheme;
7516 musictype=stream_menutheme;
7519 if(musictype==stream_fighttheme)
7522 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7523 unseendelay-=multiplier;
7525 musictype=stream_fighttheme;
7530 musictype=stream_menutheme;
7538 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7539 emit_sound_np(alarmsound);
7540 musicselected=musictype;
7542 if(musicselected==leveltheme)
7543 musicvolume[0]+=multiplier*450;
7545 musicvolume[0]-=multiplier*450;
7546 if(musicselected==stream_fighttheme)
7547 musicvolume[1]+=multiplier*450;
7549 musicvolume[1]-=multiplier*450;
7550 if(musicselected==stream_menutheme)
7551 musicvolume[2]+=multiplier*450;
7553 musicvolume[2]-=multiplier*450;
7555 for(int i=0;i<3;i++){
7556 if(musicvolume[i]<0)
7558 if(musicvolume[i]>512)
7562 if(musicvolume[2]>128&&!loading&&!mainmenu)
7566 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7567 emit_stream_np(leveltheme, musicvolume[0]);
7568 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7569 emit_stream_np(stream_fighttheme, musicvolume[1]);
7570 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7571 emit_stream_np(stream_menutheme, musicvolume[2]);
7572 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7573 pause_sound(leveltheme);
7574 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7575 pause_sound(stream_fighttheme);
7576 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7577 pause_sound(stream_menutheme);
7579 if(musicvolume[0]!=oldmusicvolume[0])
7580 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7581 if(musicvolume[1]!=oldmusicvolume[1])
7582 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7583 if(musicvolume[2]!=oldmusicvolume[2])
7584 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7586 for(int i=0;i<3;i++)
7587 oldmusicvolume[i]=musicvolume[i];
7589 pause_sound(leveltheme);
7590 pause_sound(stream_fighttheme);
7591 pause_sound(stream_menutheme);
7593 for(int i=0;i<4;i++){
7594 oldmusicvolume[i]=0;
7600 for(int i=0;i<numhotspots;i++){
7601 if(hotspottype[i]>10&&hotspottype[i]<20){
7602 if(player[hotspottype[i]-10].dead==0)
7604 else if(killhotspot==2)
7613 for(int i=0;i<numhotspots;i++)
7614 if(hotspottype[i]==-1)
7615 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7619 for(int i=1;i<numplayers;i++)
7620 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7622 if(numalarmed>maxalarmed)
7623 maxalarmed=numalarmed;
7625 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7626 if(player[0].dead&&changedelay<=0){
7628 targetlevel=whichlevel;
7631 for(int i=1;i<numplayers;i++)
7632 if(!player[i].dead&&player[i].howactive<typedead1)
7636 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7638 targetlevel=whichlevel+1;
7639 if(targetlevel>numchallengelevels-1)targetlevel=0;
7641 if(winhotspot||windialogue){
7643 targetlevel=whichlevel+1;
7644 if(targetlevel>numchallengelevels-1)targetlevel=0;
7650 targetlevel=whichlevel+1;
7651 if(targetlevel>numchallengelevels-1)targetlevel=0;
7654 if(changedelay>0&&!player[0].dead&&!won) {
7655 //high scores, awards, win
7657 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7660 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7676 if(!editorenabled&&gameon&&!mainmenu) {
7677 if(changedelay!=-999)
7678 changedelay-=multiplier/7;
7680 targetlevel=whichlevel;
7681 if(loading==2&&!campaign){
7684 fireSound(firestartsound);
7686 if(!player[0].dead&&targetlevel!=whichlevel)
7687 startbonustotal=bonustotal;
7689 Loadlevel(whichlevel);
7691 Loadlevel(targetlevel);
7697 if(loading==2&&targetlevel==whichlevel){
7701 fireSound(firestartsound);
7703 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
7709 if(changedelay<=-999&&
7713 (alldead&&maptype==mapkilleveryone)||
7717 if((player[0].dead||
7718 (alldead&&maptype==mapkilleveryone)||
7723 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7733 // campaignchoosenext determines what to do when the level is complete:
7734 // 0 = load next level
7735 // 1 = go back to level select screen
7736 // 2 = stealthload next level
7737 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
7738 if(campaignlevels[actuallevel].nextlevel.empty())
7740 } else if(mainmenu==0&&winfreeze) {
7741 stealthloading = (campaignlevels[actuallevel].choosenext==2);
7743 if(!stealthloading){
7744 fireSound(firestartsound);
7759 actuallevel=campaignlevels[actuallevel].nextlevel.front();
7762 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
7766 pause_sound(stream_menutheme);
7777 oldmusictype=musictype;
7783 facing=DoRotation(facing,-rotation2,0,0);
7784 facing=DoRotation(facing,0,0-rotation,0);
7785 viewerfacing=facing;
7788 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;
7789 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;
7791 if(player[0].skeleton.free){
7792 for(int i=0;i<player[0].skeleton.num_joints;i++){
7793 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7794 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7798 if(player[0].skeleton.free!=2&&!autocam){
7800 if(findLengthfast(&player[0].velocity)>400){
7801 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7803 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7804 coltarget=target-cameraloc;
7805 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7807 Normalise(&coltarget);
7808 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7809 else cameraloc=cameraloc+coltarget*multiplier*8;
7811 if(editorenabled)cameraloc=target;
7812 cameradist+=multiplier*5;
7813 if(cameradist>2.3)cameradist=2.3;
7814 viewer=cameraloc-facing*cameradist;
7816 coltarget=cameraloc;
7817 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7818 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7819 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7820 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7822 coltarget=cameraloc;
7823 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7825 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7826 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7827 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7829 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7833 cameradist=findDistance(&viewer,&target);
7834 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7835 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7836 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7839 if(player[0].skeleton.free!=2&&autocam){
7841 if(findLengthfast(&player[0].velocity)>400){
7842 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7844 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7845 cameradist+=multiplier*5;
7846 if(cameradist>3.3)cameradist=3.3;
7847 coltarget=target-cameraloc;
7848 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7849 else if(findLengthfast(&coltarget)>1)
7851 Normalise(&coltarget);
7852 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7853 else cameraloc=cameraloc+coltarget*multiplier*8;
7855 if(editorenabled)cameraloc=target;
7858 coltarget=cameraloc;
7859 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7860 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7861 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7862 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7864 coltarget=cameraloc;
7865 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7867 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7868 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7869 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7871 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7875 cameradist=findDistance(&viewer,&target);
7876 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7877 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7878 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7881 if(camerashake>.8)camerashake=.8;
7882 //if(woozy>10)woozy=10;
7883 //woozy+=multiplier;
7885 if(player[0].dead)camerashake=0;
7886 if(player[0].dead)woozy=0;
7887 camerashake-=multiplier*2;
7888 blackout-=multiplier*2;
7889 //if(player[0].isCrouch())woozy-=multiplier*8;
7890 if(camerashake<0)camerashake=0;
7891 if(blackout<0)blackout=0;
7892 //if(woozy<0)woozy=0;
7894 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7895 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7896 viewer.z+=(float)(Random()%100)*.0005*camerashake;