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.type[player[0].weaponids[j]]);
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.type[player[j].weaponids[k]]);
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 char *cmd)
1106 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1108 for (i = 0; i < n_cmds; i++)
1109 if (stripfx(cmd, cmd_names[i]))
1111 cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
1114 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1117 /********************> Tick() <*****/
1118 extern bool save_image(const char * fname);
1119 void Screenshot (void)
1122 time_t t = time(NULL);
1123 struct tm *tme = localtime(&t);
1124 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);
1127 mkdir("Screenshots");
1129 mkdir("Screenshots", S_IRWXU);
1135 void Game::SetUpLighting(){
1136 if(environment==snowyenvironment)
1137 light.setColors(.65,.65,.7,.4,.4,.44);
1138 if(environment==desertenvironment)
1139 light.setColors(.95,.95,.95,.4,.35,.3);
1140 if(environment==grassyenvironment)
1141 light.setColors(.95,.95,1,.4,.4,.44);
1143 light.setColors(1,1,1,.4,.4,.4);
1145 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1146 light.color[0]*=(skyboxlightr+average)/2;
1147 light.color[1]*=(skyboxlightg+average)/2;
1148 light.color[2]*=(skyboxlightb+average)/2;
1149 light.ambient[0]*=(skyboxlightr+average)/2;
1150 light.ambient[1]*=(skyboxlightg+average)/2;
1151 light.ambient[2]*=(skyboxlightb+average)/2;
1154 int Game::findPathDist(int start,int end){
1155 int smallestcount,count,connected;
1156 int last,last2,last3,last4;
1160 for(int i=0;i<50;i++){
1166 while(last!=end&&count<30){
1168 for(int j=0;j<numpathpoints;j++){
1169 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1172 if(numpathpointconnect[j])
1173 for(int k=0;k<numpathpointconnect[j];k++){
1174 if(pathpointconnect[j][k]==last)connected=1;
1177 if(numpathpointconnect[last])
1178 for(int k=0;k<numpathpointconnect[last];k++){
1179 if(pathpointconnect[last][k]==j)connected=1;
1182 if(closest==-1||Random()%2==0){
1193 if(count<smallestcount)smallestcount=count;
1195 return smallestcount;
1198 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1199 static XYZ colpoint,colviewer,coltarget;
1200 static float minx,minz,maxx,maxz,miny,maxy;
1202 minx=min(startpoint.x,endpoint.x)-1;
1203 miny=min(startpoint.y,endpoint.y)-1;
1204 minz=min(startpoint.z,endpoint.z)-1;
1205 maxx=max(startpoint.x,endpoint.x)+1;
1206 maxy=max(startpoint.y,endpoint.y)+1;
1207 maxz=max(startpoint.z,endpoint.z)+1;
1209 for(int i=0;i<objects.numobjects;i++){
1210 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1211 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1212 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1213 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1214 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1215 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1216 if( objects.type[i]!=treeleavestype&&
1217 objects.type[i]!=bushtype&&
1218 objects.type[i]!=firetype){
1219 colviewer=startpoint;
1221 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1226 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1231 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1232 static XYZ colpoint,colviewer,coltarget;
1233 static float minx,minz,maxx,maxz,miny,maxy;
1234 static int i; //FIXME: see below
1236 minx=min(startpoint.x,endpoint.x)-1;
1237 miny=min(startpoint.y,endpoint.y)-1;
1238 minz=min(startpoint.z,endpoint.z)-1;
1239 maxx=max(startpoint.x,endpoint.x)+1;
1240 maxy=max(startpoint.y,endpoint.y)+1;
1241 maxz=max(startpoint.z,endpoint.z)+1;
1244 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1245 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1246 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1247 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1248 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1249 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1250 if( objects.type[what]!=treeleavestype&&
1251 objects.type[what]!=bushtype&&
1252 objects.type[what]!=firetype){
1253 colviewer=startpoint;
1256 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1261 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1266 void Game::Setenvironment(int which)
1270 LOG(" Setting environment...");
1272 float temptexdetail;
1275 pause_sound(stream_snowtheme);
1276 pause_sound(stream_grasstheme);
1277 pause_sound(stream_deserttheme);
1278 pause_sound(stream_wind);
1279 pause_sound(stream_desertambient);
1282 if(environment==snowyenvironment){
1286 emit_stream_np(stream_wind);
1288 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1289 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1290 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1291 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1293 footstepsound = footstepsn1;
1294 footstepsound2 = footstepsn2;
1295 footstepsound3 = footstepst1;
1296 footstepsound4 = footstepst2;
1298 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1300 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1302 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1307 temptexdetail=texdetail;
1308 if(texdetail>1)texdetail=4;
1309 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1310 ":Data:Textures:Skybox(snow):Left.jpg",
1311 ":Data:Textures:Skybox(snow):Back.jpg",
1312 ":Data:Textures:Skybox(snow):Right.jpg",
1313 ":Data:Textures:Skybox(snow):Up.jpg",
1314 ":Data:Textures:Skybox(snow):Down.jpg");
1319 texdetail=temptexdetail;
1320 } else if(environment==desertenvironment){
1323 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1324 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1325 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1326 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1330 emit_stream_np(stream_desertambient);
1332 footstepsound = footstepsn1;
1333 footstepsound2 = footstepsn2;
1334 footstepsound3 = footstepsn1;
1335 footstepsound4 = footstepsn2;
1337 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1339 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1341 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1345 temptexdetail=texdetail;
1346 if(texdetail>1)texdetail=4;
1347 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1348 ":Data:Textures:Skybox(sand):Left.jpg",
1349 ":Data:Textures:Skybox(sand):Back.jpg",
1350 ":Data:Textures:Skybox(sand):Right.jpg",
1351 ":Data:Textures:Skybox(sand):Up.jpg",
1352 ":Data:Textures:Skybox(sand):Down.jpg");
1357 texdetail=temptexdetail;
1358 } else if(environment==grassyenvironment){
1361 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1362 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1363 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1364 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1367 emit_stream_np(stream_wind, 100.);
1369 footstepsound = footstepgr1;
1370 footstepsound2 = footstepgr2;
1371 footstepsound3 = footstepst1;
1372 footstepsound4 = footstepst2;
1374 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1376 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1378 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1382 temptexdetail=texdetail;
1383 if(texdetail>1)texdetail=4;
1384 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1385 ":Data:Textures:Skybox(grass):Left.jpg",
1386 ":Data:Textures:Skybox(grass):Back.jpg",
1387 ":Data:Textures:Skybox(grass):Right.jpg",
1388 ":Data:Textures:Skybox(grass):Up.jpg",
1389 ":Data:Textures:Skybox(grass):Down.jpg");
1393 texdetail=temptexdetail;
1395 temptexdetail=texdetail;
1397 terrain.load(":Data:Textures:heightmap.png");
1399 texdetail=temptexdetail;
1402 void Game::Loadlevel(int which){
1408 Loadlevel("tutorial");
1409 }else if(which >= 0 && which <= 15){
1411 snprintf(buf, 32, "map%d", which + 1); // challenges
1414 Loadlevel("mapsave");
1417 void Game::Loadlevel(const char *name){
1418 cout << "loading level " << name << "…" << endl;
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 tfile=fopen( FixedFN, "rb" );
1464 pause_sound(stream_firesound);
1470 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1474 for(int i=0;i<20;i++)
1475 dialoguegonethrough[i]=0;
1484 difficulty=accountactive->getDifficulty();
1503 for(int i=0;i<100;i++)
1523 bonustotal=startbonustotal;
1528 emit_sound_np(consolesuccesssound);
1533 if(!stealthloading){
1534 terrain.numdecals=0;
1535 Sprite::deleteSprites();
1536 for(int i=0;i<objects.numobjects;i++)
1537 objects.model[i].numdecals=0;
1539 int j=objects.numobjects;
1540 for(int i=0;i<j;i++){
1541 objects.DeleteObject(0);
1546 for(int i=0;i<subdivision;i++)
1547 for(int j=0;j<subdivision;j++)
1548 terrain.patchobjectnum[i][j]=0;
1553 weapons.numweapons=0;
1555 funpackf(tfile, "Bi", &mapvers);
1557 funpackf(tfile, "Bi", &indemo);
1561 funpackf(tfile, "Bi", &maptype);
1563 maptype=mapkilleveryone;
1565 funpackf(tfile, "Bi", &hostile);
1569 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1575 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1583 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1585 skyboxlightr=skyboxr;
1586 skyboxlightg=skyboxg;
1587 skyboxlightb=skyboxb;
1590 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);
1592 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1593 player[0].originalcoords=player[0].coords;
1594 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1595 for(int j=0;j<player[0].num_weapons;j++){
1596 player[0].weaponids[j]=weapons.numweapons;
1597 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1598 weapons.owner[weapons.numweapons]=0;
1599 weapons.numweapons++;
1605 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1606 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1607 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1608 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1610 funpackf(tfile, "Bi", &player[0].numclothes);
1613 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1615 player[0].whichskin=0;
1616 player[0].creature=rabbittype;
1619 player[0].lastattack=-1;
1620 player[0].lastattack2=-1;
1621 player[0].lastattack3=-1;
1625 funpackf(tfile, "Bi", &numdialogues);
1626 for(int k=0;k<numdialogues;k++){
1627 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1628 funpackf(tfile, "Bi", &dialoguetype[k]);
1629 for(int l=0;l<10;l++){
1630 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1631 funpackf(tfile, "Bf", &participantrotation[k][l]);
1633 for(int l=0;l<numdialogueboxes[k];l++){
1634 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1635 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1636 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1637 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1638 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1640 funpackf(tfile, "Bi",&templength);
1641 if(templength>128||templength<=0)
1644 for(m=0;m<templength;m++){
1645 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1646 if(dialoguetext[k][l][m]=='\0')
1649 dialoguetext[k][l][m] = 0;
1651 funpackf(tfile, "Bi",&templength);
1652 if(templength>64||templength<=0)templength=64;
1653 for(m=0;m<templength;m++){
1654 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1655 if(dialoguename[k][l][m]=='\0')
1658 dialoguename[k][l][m] = 0;
1659 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1660 funpackf(tfile, "Bi", &participantfocus[k][l]);
1661 funpackf(tfile, "Bi", &participantaction[k][l]);
1664 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1666 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1672 for(int k=0;k<player[0].numclothes;k++){
1673 funpackf(tfile, "Bi", &templength);
1674 for(int l=0;l<templength;l++)
1675 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1676 player[0].clothes[k][templength]='\0';
1677 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1680 funpackf(tfile, "Bi", &environment);
1682 funpackf(tfile, "Bi", &objects.numobjects);
1683 for(int i=0;i<objects.numobjects;i++){
1684 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]);
1685 if(objects.type[i]==treeleavestype)
1686 objects.scale[i]=objects.scale[i-1];
1690 funpackf(tfile, "Bi", &numhotspots);
1691 for(int i=0;i<numhotspots;i++){
1692 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1693 funpackf(tfile, "Bi", &templength);
1695 for(int l=0;l<templength;l++)
1696 funpackf(tfile, "Bb", &hotspottext[i][l]);
1697 hotspottext[i][templength]='\0';
1698 if(hotspottype[i]==-111)
1707 if(!stealthloading){
1709 for(int i=0;i<objects.numobjects;i++)
1710 objects.center+=objects.position[i];
1711 objects.center/=objects.numobjects;
1717 float maxdistance=0;
1719 //~ int whichclosest;
1720 for(int i=0;i<objects.numobjects;i++){
1721 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1722 if(tempdist>maxdistance){
1724 maxdistance=tempdist;
1727 objects.radius=fast_sqrt(maxdistance);
1732 //mapcenter=objects.center;
1733 //mapradius=objects.radius;
1735 funpackf(tfile, "Bi", &numplayers);
1736 int howmanyremoved=0;
1737 bool removeanother=0;
1738 if(numplayers>1&&numplayers<maxplayers){
1739 for(int i=1;i<numplayers;i++){
1744 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);
1746 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1748 player[i-howmanyremoved].howactive=typeactive;
1750 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1752 player[i-howmanyremoved].scale=-1;
1754 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1756 player[i-howmanyremoved].immobile=0;
1758 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1760 player[i-howmanyremoved].rotation=0;
1761 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1762 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1767 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1768 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1769 player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1770 funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1771 weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1772 weapons.numweapons++;
1775 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1776 //player[i-howmanyremoved].numwaypoints=10;
1777 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1778 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1779 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1780 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1782 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1784 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1787 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1788 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1789 player[i-howmanyremoved].waypoint=0;
1791 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1792 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1793 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1794 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1797 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1804 if(player[i-howmanyremoved].creature==wolftype){
1805 player[i-howmanyremoved].proportionhead=1.1*headprop;
1806 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1807 player[i-howmanyremoved].proportionarms=1.1*armprop;
1808 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1811 if(player[i-howmanyremoved].creature==rabbittype){
1812 player[i-howmanyremoved].proportionhead=1.2*headprop;
1813 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1814 player[i-howmanyremoved].proportionarms=1.00*armprop;
1815 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1816 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1819 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1820 if(player[i-howmanyremoved].numclothes){
1821 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1823 funpackf(tfile, "Bi", &templength);
1824 for(int l=0;l<templength;l++)
1825 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1826 player[i-howmanyremoved].clothes[k][templength]='\0';
1827 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1836 numplayers-=howmanyremoved;
1837 funpackf(tfile, "Bi", &numpathpoints);
1838 if(numpathpoints>30||numpathpoints<0)
1840 for(int j=0;j<numpathpoints;j++){
1841 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1842 for(int k=0;k<numpathpointconnect[j];k++){
1843 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1849 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1852 if(environment!=oldenvironment)
1853 Setenvironment(environment);
1854 oldenvironment=environment;
1856 if(!stealthloading){
1857 int j=objects.numobjects;
1858 objects.numobjects=0;
1859 for(int i=0;i<j;i++){
1860 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1865 terrain.DoShadows();
1868 objects.DoShadows();
1875 if(numplayers>maxplayers-1)
1876 numplayers=maxplayers-1;
1877 for(int i=0;i<numplayers;i++){
1883 if(i==0||player[i].scale<0)
1885 player[i].skeleton.free=0;
1886 player[i].skeleton.id=i;
1888 player[i].creature=rabbittype;
1889 if(player[i].creature!=wolftype){
1890 player[i].skeleton.Load(
1891 (char *)":Data:Skeleton:Basic Figure",
1892 (char *)":Data:Skeleton:Basic Figurelow",
1893 (char *)":Data:Skeleton:Rabbitbelt",
1894 (char *)":Data:Models:Body.solid",
1895 (char *)":Data:Models:Body2.solid",
1896 (char *)":Data:Models:Body3.solid",
1897 (char *)":Data:Models:Body4.solid",
1898 (char *)":Data:Models:Body5.solid",
1899 (char *)":Data:Models:Body6.solid",
1900 (char *)":Data:Models:Body7.solid",
1901 (char *)":Data:Models:Bodylow.solid",
1902 (char *)":Data:Models:Belt.solid",0);
1904 if(player[i].creature!=wolftype){
1905 player[i].skeleton.Load(
1906 (char *)":Data:Skeleton:Basic Figure",
1907 (char *)":Data:Skeleton:Basic Figurelow",
1908 (char *)":Data:Skeleton:Rabbitbelt",
1909 (char *)":Data:Models:Body.solid",
1910 (char *)":Data:Models:Body2.solid",
1911 (char *)":Data:Models:Body3.solid",
1912 (char *)":Data:Models:Body4.solid",
1913 (char *)":Data:Models:Body5.solid",
1914 (char *)":Data:Models:Body6.solid",
1915 (char *)":Data:Models:Body7.solid",
1916 (char *)":Data:Models:Bodylow.solid",
1917 (char *)":Data:Models:Belt.solid",1);
1918 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1920 if(player[i].creature==wolftype){
1921 player[i].skeleton.Load(
1922 (char *)":Data:Skeleton:Basic Figure Wolf",
1923 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1924 (char *)":Data:Skeleton:Rabbitbelt",
1925 (char *)":Data:Models:Wolf.solid",
1926 (char *)":Data:Models:Wolf2.solid",
1927 (char *)":Data:Models:Wolf3.solid",
1928 (char *)":Data:Models:Wolf4.solid",
1929 (char *)":Data:Models:Wolf5.solid",
1930 (char *)":Data:Models:Wolf6.solid",
1931 (char *)":Data:Models:Wolf7.solid",
1932 (char *)":Data:Models:Wolflow.solid",
1933 (char *)":Data:Models:Belt.solid",0);
1939 //~ texsize=512*512*3/texdetail/texdetail;
1941 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1943 if(player[i].numclothes){
1944 for(int j=0;j<player[i].numclothes;j++){
1945 tintr=player[i].clothestintr[j];
1946 tintg=player[i].clothestintg[j];
1947 tintb=player[i].clothestintb[j];
1948 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1950 player[i].DoMipmaps();
1953 player[i].currentanimation=bounceidleanim;
1954 player[i].targetanimation=bounceidleanim;
1955 player[i].currentframe=0;
1956 player[i].targetframe=1;
1958 player[i].speed=1+(float)(Random()%100)/1000;
1960 player[i].speed-=.2;
1962 player[i].speed-=.1;
1964 player[i].velocity=0;
1965 player[i].oldcoords=player[i].coords;
1966 player[i].realoldcoords=player[i].coords;
1969 player[i].skeleton.id=i;
1970 player[i].updatedelay=0;
1971 player[i].normalsupdatedelay=0;
1973 player[i].aitype=passivetype;
1974 player[i].madskills=0;
1977 player[i].proportionhead=1.2;
1978 player[i].proportionbody=1.05;
1979 player[i].proportionarms=1.00;
1980 player[i].proportionlegs=1.1;
1981 player[i].proportionlegs.y=1.05;
1983 player[i].headless=0;
1984 player[i].currentoffset=0;
1985 player[i].targetoffset=0;
1987 player[i].damagetolerance=200;
1989 if(player[i].creature==wolftype){
1990 if(i==0||player[i].scale<0)
1991 player[i].scale=.23;
1992 player[i].damagetolerance=300;
1998 player[i].proportionhead.z=0;
1999 player[i].proportionbody.z=0;
2000 player[i].proportionarms.z=0;
2001 player[i].proportionlegs.z=0;
2004 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2006 player[i].headmorphness=0;
2007 player[i].targetheadmorphness=1;
2008 player[i].headmorphstart=0;
2009 player[i].headmorphend=0;
2011 player[i].pausetime=0;
2014 player[i].jumppower=5;
2016 player[i].permanentdamage=0;
2017 player[i].superpermanentdamage=0;
2019 player[i].forwardkeydown=0;
2020 player[i].leftkeydown=0;
2021 player[i].backkeydown=0;
2022 player[i].rightkeydown=0;
2023 player[i].jumpkeydown=0;
2024 player[i].crouchkeydown=0;
2025 player[i].throwkeydown=0;
2027 player[i].collided=-10;
2029 player[i].bloodloss=0;
2030 player[i].weaponactive=-1;
2031 player[i].weaponstuck=-1;
2032 player[i].bleeding=0;
2033 player[i].deathbleeding=0;
2034 player[i].stunned=0;
2035 player[i].hasvictim=0;
2036 player[i].wentforweapon=0;
2039 player[0].aitype=playercontrolled;
2040 player[0].weaponactive=-1;
2043 player[0].power=1/.9;
2046 player[0].power=1/.8;
2049 player[0].damagetolerance=250;
2051 player[0].damagetolerance=300;
2053 player[0].armorhead*=1.5;
2055 player[0].armorhigh*=1.5;
2057 player[0].armorlow*=1.5;
2058 cameraloc=player[0].coords;
2060 rotation=player[0].rotation;
2062 hawkcoords=player[0].coords;
2067 for(int i=0;i<weapons.numweapons;i++){
2068 weapons.bloody[i]=0;
2069 weapons.blooddrip[i]=0;
2070 weapons.blooddripdelay[i]=0;
2071 weapons.onfire[i]=0;
2072 weapons.flamedelay[i]=0;
2073 weapons.damage[i]=0;
2074 if(weapons.type[i]==sword){
2075 weapons.mass[i]=1.5;
2076 weapons.tipmass[i]=1;
2077 weapons.length[i]=.8;
2079 if(weapons.type[i]==staff){
2081 weapons.tipmass[i]=1;
2082 weapons.length[i]=1.5;
2084 if(weapons.type[i]==knife){
2086 weapons.tipmass[i]=1.2;
2087 weapons.length[i]=.25;
2089 weapons.position[i]=-1000;
2090 weapons.tippoint[i]=-1000;
2093 LOG("Starting background music...");
2095 OPENAL_StopSound(OPENAL_ALL);
2096 if(environment==snowyenvironment){
2098 emit_stream_np(stream_wind);
2099 }else if(environment==desertenvironment){
2101 emit_stream_np(stream_desertambient);
2102 }else if(environment==grassyenvironment){
2104 emit_stream_np(stream_wind, 100.);
2106 oldmusicvolume[0]=0;
2107 oldmusicvolume[1]=0;
2108 oldmusicvolume[2]=0;
2109 oldmusicvolume[3]=0;
2119 void Game::doTutorial(){
2120 if(tutorialstagetime>tutorialmaxtime){
2123 if(tutorialstage<=1){
2128 switch(tutorialstage){
2134 tutorialmaxtime=600;
2136 tutorialmaxtime=1000;
2138 tutorialmaxtime=600;
2140 tutorialmaxtime=600;
2142 tutorialmaxtime=600;
2144 tutorialmaxtime=600;
2146 tutorialmaxtime=600;
2150 tutorialmaxtime=1000;
2152 tutorialmaxtime=1000;
2167 player[1].coords=(temp+temp2)/2;
2169 emit_sound_at(fireendsound, player[1].coords);
2171 for(int i=0;i<player[1].skeleton.num_joints;i++){
2173 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2174 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2175 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;
2176 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2177 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2182 tutorialmaxtime=500;
2184 tutorialmaxtime=500;
2186 tutorialmaxtime=500;
2188 tutorialmaxtime=500;
2191 //tutorialmaxtime=500;
2193 tutorialmaxtime=500;
2195 tutorialmaxtime=500;
2202 tutorialmaxtime=500;
2204 tutorialmaxtime=500;
2206 tutorialmaxtime=500;
2208 tutorialmaxtime=500;
2215 player[1].aitype=attacktypecutoff;
2217 tutorialmaxtime=400;
2219 tutorialmaxtime=400;
2220 player[0].escapednum=0;
2225 player[1].aitype=passivetype;
2231 tutorialmaxtime=400;
2234 player[1].aitype=attacktypecutoff;
2236 tutorialmaxtime=400;
2238 tutorialmaxtime=400;
2243 player[1].aitype=passivetype;
2250 player[1].aitype=attacktypecutoff;
2255 player[1].aitype=passivetype;
2267 weapons.owner[weapons.numweapons]=-1;
2268 weapons.type[weapons.numweapons]=knife;
2269 weapons.damage[weapons.numweapons]=0;
2270 weapons.mass[weapons.numweapons]=1;
2271 weapons.tipmass[weapons.numweapons]=1.2;
2272 weapons.length[weapons.numweapons]=.25;
2273 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2274 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2276 weapons.velocity[weapons.numweapons]=0.1;
2277 weapons.tipvelocity[weapons.numweapons]=0.1;
2278 weapons.missed[weapons.numweapons]=1;
2279 weapons.hitsomething[weapons.numweapons]=0;
2280 weapons.freetime[weapons.numweapons]=0;
2281 weapons.firstfree[weapons.numweapons]=1;
2282 weapons.physics[weapons.numweapons]=1;
2284 weapons.numweapons++;
2287 tutorialmaxtime=300;
2289 tutorialmaxtime=300;
2293 tutorialmaxtime=300;
2296 player[0].weaponactive=-1;
2297 player[0].num_weapons=0;
2298 player[1].weaponactive=0;
2299 player[1].num_weapons=1;
2300 player[1].weaponids[0]=0;
2304 player[1].aitype=attacktypecutoff;
2306 tutorialmaxtime=300;
2309 player[0].weaponactive=-1;
2310 player[0].num_weapons=0;
2311 player[1].weaponactive=0;
2312 player[1].num_weapons=1;
2313 player[1].weaponids[0]=0;
2315 tutorialmaxtime=300;
2318 player[0].weaponactive=-1;
2319 player[0].num_weapons=0;
2320 player[1].weaponactive=0;
2321 player[1].num_weapons=1;
2322 player[1].weaponids[0]=0;
2324 weapons.type[0]=sword;
2326 tutorialmaxtime=300;
2339 weapons.owner[weapons.numweapons]=-1;
2340 weapons.type[weapons.numweapons]=sword;
2341 weapons.damage[weapons.numweapons]=0;
2342 weapons.mass[weapons.numweapons]=1;
2343 weapons.tipmass[weapons.numweapons]=1.2;
2344 weapons.length[weapons.numweapons]=.25;
2345 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2346 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2348 weapons.velocity[weapons.numweapons]=0.1;
2349 weapons.tipvelocity[weapons.numweapons]=0.1;
2350 weapons.missed[weapons.numweapons]=1;
2351 weapons.hitsomething[weapons.numweapons]=0;
2352 weapons.freetime[weapons.numweapons]=0;
2353 weapons.firstfree[weapons.numweapons]=1;
2354 weapons.physics[weapons.numweapons]=1;
2358 player[0].weaponactive=0;
2359 player[0].num_weapons=1;
2360 player[0].weaponids[0]=1;
2361 player[1].weaponactive=0;
2362 player[1].num_weapons=1;
2363 player[1].weaponids[0]=0;
2365 weapons.numweapons++;
2370 player[1].aitype=passivetype;
2376 player[0].weaponactive=0;
2377 player[0].num_weapons=1;
2378 player[0].weaponids[0]=1;
2379 player[1].weaponactive=0;
2380 player[1].num_weapons=1;
2381 player[1].weaponids[0]=0;
2383 if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
2384 else weapons.type[0]=staff;
2386 weapons.numweapons++;
2390 player[1].aitype=passivetype;
2392 tutorialmaxtime=200;
2394 weapons.position[1]=1000;
2395 weapons.tippoint[1]=1000;
2397 weapons.numweapons=1;
2399 player[1].weaponactive=-1;
2400 player[1].num_weapons=0;
2401 player[0].weaponactive=0;
2402 player[0].num_weapons=1;
2403 player[0].weaponids[0]=0;
2405 weapons.type[0]=knife;
2407 weapons.numweapons++;
2412 emit_sound_at(fireendsound, player[1].coords);
2414 for(int i=0;i<player[1].skeleton.num_joints;i++){
2416 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2417 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2418 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;
2419 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2420 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2424 player[1].num_weapons=0;
2425 player[1].weaponstuck=-1;
2426 player[1].weaponactive=-1;
2428 weapons.numweapons=0;
2430 weapons.owner[0]=-1;
2431 weapons.velocity[0]=0.1;
2432 weapons.tipvelocity[0]=-0.1;
2433 weapons.missed[0]=1;
2434 weapons.hitsomething[0]=0;
2435 weapons.freetime[0]=0;
2436 weapons.firstfree[0]=1;
2437 weapons.physics[0]=1;
2440 tutorialmaxtime=80000;
2441 break; default: break;
2443 if(tutorialstage<=51)tutorialstagetime=0;
2447 if(tutorialstagetime<tutorialmaxtime-3){
2448 switch(tutorialstage){
2449 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2450 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2451 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2452 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2453 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2454 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2455 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2456 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2457 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2458 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2459 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2460 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2461 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2462 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2463 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2464 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2465 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2466 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2467 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2468 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2469 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2471 if(player[0].escapednum==2){
2475 player[1].aitype=passivetype;
2477 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2478 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2480 if(animation[player[0].targetanimation].attack==reversal){
2484 player[1].aitype=passivetype;
2486 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2487 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2488 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2489 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2490 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2491 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2492 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2493 break; default: break;
2495 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2498 if(tutorialstagetime==tutorialmaxtime-3){
2499 emit_sound_np(consolesuccesssound);
2502 if(tutorialsuccess>=1){
2503 if(tutorialstage==34||tutorialstage==35)
2504 tutorialstagetime=tutorialmaxtime-1;
2508 if(tutorialstage<14||tutorialstage>=50){
2509 player[1].coords.y=300;
2510 player[1].velocity=0;
2514 void Game::doDebugKeys(){
2515 float headprop,bodyprop,armprop,legprop;
2517 if(Input::isKeyPressed(SDLK_h)){
2518 player[0].damagetolerance=200000;
2521 player[0].permanentdamage=0;
2522 player[0].superpermanentdamage=0;
2525 if(Input::isKeyPressed(SDLK_j)){
2529 Setenvironment(environment);
2532 if(Input::isKeyPressed(SDLK_c)){
2533 cameramode=1-cameramode;
2536 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2537 if(player[0].num_weapons>0){
2538 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
2539 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
2540 else weapons.type[player[0].weaponids[0]]=sword;
2541 if(weapons.type[player[0].weaponids[0]]==sword){
2542 weapons.mass[player[0].weaponids[0]]=1.5;
2543 weapons.tipmass[player[0].weaponids[0]]=1;
2544 weapons.length[player[0].weaponids[0]]=.8;
2546 if(weapons.type[player[0].weaponids[0]]==staff){
2547 weapons.mass[player[0].weaponids[0]]=2;
2548 weapons.tipmass[player[0].weaponids[0]]=1;
2549 weapons.length[player[0].weaponids[0]]=1.5;
2552 if(weapons.type[player[0].weaponids[0]]==knife){
2553 weapons.mass[player[0].weaponids[0]]=1;
2554 weapons.tipmass[player[0].weaponids[0]]=1.2;
2555 weapons.length[player[0].weaponids[0]]=.25;
2560 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2562 float closestdist=-1;
2565 for(int i=1;i<numplayers;i++){
2566 distance=findDistancefast(&player[i].coords,&player[0].coords);
2567 if(closestdist==-1||distance<closestdist){
2568 closestdist=distance;
2573 if(player[closest].num_weapons){
2574 if(weapons.type[player[closest].weaponids[0]]==sword)
2575 weapons.type[player[closest].weaponids[0]]=staff;
2576 else if(weapons.type[player[closest].weaponids[0]]==staff)
2577 weapons.type[player[closest].weaponids[0]]=knife;
2578 else weapons.type[player[closest].weaponids[0]]=sword;
2579 if(weapons.type[player[closest].weaponids[0]]==sword){
2580 weapons.mass[player[closest].weaponids[0]]=1.5;
2581 weapons.tipmass[player[closest].weaponids[0]]=1;
2582 weapons.length[player[closest].weaponids[0]]=.8;
2584 if(weapons.type[player[0].weaponids[0]]==staff){
2585 weapons.mass[player[0].weaponids[0]]=2;
2586 weapons.tipmass[player[0].weaponids[0]]=1;
2587 weapons.length[player[0].weaponids[0]]=1.5;
2589 if(weapons.type[player[closest].weaponids[0]]==knife){
2590 weapons.mass[player[closest].weaponids[0]]=1;
2591 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2592 weapons.length[player[closest].weaponids[0]]=.25;
2595 if(!player[closest].num_weapons){
2596 player[closest].weaponids[0]=weapons.numweapons;
2597 weapons.owner[weapons.numweapons]=closest;
2598 weapons.type[weapons.numweapons]=knife;
2599 weapons.damage[weapons.numweapons]=0;
2600 weapons.numweapons++;
2601 player[closest].num_weapons=1;
2602 if(weapons.type[player[closest].weaponids[0]]==sword){
2603 weapons.mass[player[closest].weaponids[0]]=1.5;
2604 weapons.tipmass[player[closest].weaponids[0]]=1;
2605 weapons.length[player[closest].weaponids[0]]=.8;
2607 if(weapons.type[player[closest].weaponids[0]]==knife){
2608 weapons.mass[player[closest].weaponids[0]]=1;
2609 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2610 weapons.length[player[closest].weaponids[0]]=.25;
2616 if(Input::isKeyDown(SDLK_u)){
2618 float closestdist=-1;
2621 for(int i=1;i<numplayers;i++){
2622 distance=findDistancefast(&player[i].coords,&player[0].coords);
2623 if(closestdist==-1||distance<closestdist){
2624 closestdist=distance;
2628 player[closest].rotation+=multiplier*50;
2629 player[closest].targetrotation=player[closest].rotation;
2633 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2635 float closestdist=-1;
2638 for(int i=1;i<numplayers;i++){
2639 distance=findDistancefast(&player[i].coords,&player[0].coords);
2640 if(closestdist==-1||distance<closestdist){
2641 closestdist=distance;
2645 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2648 player[closest].whichskin++;
2649 if(player[closest].whichskin>9)
2650 player[closest].whichskin=0;
2651 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2652 player[closest].whichskin=0;
2654 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2655 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2658 if(player[closest].numclothes){
2659 for(int i=0;i<player[closest].numclothes;i++){
2660 tintr=player[closest].clothestintr[i];
2661 tintg=player[closest].clothestintg[i];
2662 tintb=player[closest].clothestintb[i];
2663 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2665 player[closest].DoMipmaps();
2669 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2671 float closestdist=-1;
2674 for(int i=1;i<numplayers;i++){
2675 distance=findDistancefast(&player[i].coords,&player[0].coords);
2676 if(closestdist==-1||distance<closestdist){
2677 closestdist=distance;
2682 if(player[closest].creature==wolftype){
2683 headprop=player[closest].proportionhead.x/1.1;
2684 bodyprop=player[closest].proportionbody.x/1.1;
2685 armprop=player[closest].proportionarms.x/1.1;
2686 legprop=player[closest].proportionlegs.x/1.1;
2689 if(player[closest].creature==rabbittype){
2690 headprop=player[closest].proportionhead.x/1.2;
2691 bodyprop=player[closest].proportionbody.x/1.05;
2692 armprop=player[closest].proportionarms.x/1.00;
2693 legprop=player[closest].proportionlegs.x/1.1;
2697 if(player[closest].creature==rabbittype){
2698 player[closest].skeleton.id=closest;
2699 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);
2700 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2701 player[closest].whichskin=0;
2702 player[closest].creature=wolftype;
2704 player[closest].proportionhead=1.1;
2705 player[closest].proportionbody=1.1;
2706 player[closest].proportionarms=1.1;
2707 player[closest].proportionlegs=1.1;
2708 player[closest].proportionlegs.y=1.1;
2709 player[closest].scale=.23*5*player[0].scale;
2711 player[closest].damagetolerance=300;
2715 player[closest].skeleton.id=closest;
2716 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);
2717 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2718 player[closest].whichskin=0;
2719 player[closest].creature=rabbittype;
2721 player[closest].proportionhead=1.2;
2722 player[closest].proportionbody=1.05;
2723 player[closest].proportionarms=1.00;
2724 player[closest].proportionlegs=1.1;
2725 player[closest].proportionlegs.y=1.05;
2726 player[closest].scale=.2*5*player[0].scale;
2728 player[closest].damagetolerance=200;
2731 if(player[closest].creature==wolftype){
2732 player[closest].proportionhead=1.1*headprop;
2733 player[closest].proportionbody=1.1*bodyprop;
2734 player[closest].proportionarms=1.1*armprop;
2735 player[closest].proportionlegs=1.1*legprop;
2738 if(player[closest].creature==rabbittype){
2739 player[closest].proportionhead=1.2*headprop;
2740 player[closest].proportionbody=1.05*bodyprop;
2741 player[closest].proportionarms=1.00*armprop;
2742 player[closest].proportionlegs=1.1*legprop;
2743 player[closest].proportionlegs.y=1.05*legprop;
2749 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2755 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2757 float closestdist=-1;
2759 XYZ flatfacing2,flatvelocity2;
2762 for(int i=1;i<numplayers;i++){
2763 distance=findDistancefast(&player[i].coords,&player[0].coords);
2764 if(distance<144&&!player[i].headless)
2765 if(closestdist==-1||distance<closestdist){
2766 closestdist=distance;
2768 blah = player[i].coords;
2773 XYZ headspurtdirection;
2774 //int i = player[closest].skeleton.jointlabels[head];
2775 Joint& headjoint=playerJoint(closest,head);
2776 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2777 if(!player[closest].skeleton.free)
2778 flatvelocity2=player[closest].velocity;
2779 if(player[closest].skeleton.free)
2780 flatvelocity2=headjoint.velocity;
2781 if(!player[closest].skeleton.free)
2782 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;
2783 if(player[closest].skeleton.free)
2784 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2785 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2786 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2787 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2788 headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
2789 Normalise(&headspurtdirection);
2790 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2791 flatvelocity2+=headspurtdirection*8;
2792 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2794 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2796 emit_sound_at(splattersound, blah);
2797 emit_sound_at(breaksound2, blah, 100.);
2799 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2800 player[closest].RagDoll(0);
2801 player[closest].dead=2;
2802 player[closest].headless=1;
2803 player[closest].DoBloodBig(3,165);
2809 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2811 float closestdist=-1;
2813 XYZ flatfacing2,flatvelocity2;
2816 for(int i=1;i<numplayers;i++){
2817 distance=findDistancefast(&player[i].coords,&player[0].coords);
2819 if(closestdist==-1||distance<closestdist){
2820 closestdist=distance;
2822 blah=player[i].coords;
2827 emit_sound_at(splattersound, blah);
2829 emit_sound_at(breaksound2, blah);
2831 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2832 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2833 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2834 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;
2835 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2836 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2837 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2838 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2839 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2840 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2841 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2844 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2845 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2846 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2847 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;
2848 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2849 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2850 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2851 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2852 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2853 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2856 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2857 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2858 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2859 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;
2860 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2861 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2862 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2863 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2864 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2865 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2868 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2869 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2870 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2871 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;
2872 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2873 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2874 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2875 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2876 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2877 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2881 for(int j=0;j<numplayers; j++){
2883 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2884 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2885 if(player[j].skeleton.free==2)
2886 player[j].skeleton.free=1;
2887 player[j].skeleton.longdead=0;
2888 player[j].RagDoll(0);
2889 for(int i=0;i<player[j].skeleton.num_joints; i++){
2890 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2891 if(findDistancefast(&temppos,&player[closest].coords)<25){
2892 flatvelocity2=temppos-player[closest].coords;
2893 Normalise(&flatvelocity2);
2894 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2901 player[closest].DoDamage(10000);
2902 player[closest].RagDoll(0);
2903 player[closest].dead=2;
2904 player[closest].coords=20;
2905 player[closest].skeleton.free=2;
2912 if(Input::isKeyPressed(SDLK_f)){
2913 player[0].onfire=1-player[0].onfire;
2914 if(player[0].onfire){
2915 player[0].CatchFire();
2917 if(!player[0].onfire){
2918 emit_sound_at(fireendsound, player[0].coords);
2919 pause_sound(stream_firesound);
2923 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2924 //if(!player[0].skeleton.free)player[0].damage+=500;
2925 player[0].RagDoll(0);
2926 //player[0].spurt=1;
2927 //player[0].DoDamage(1000);
2929 emit_sound_at(whooshsound, player[0].coords, 128.);
2932 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2933 for(int i=0;i<objects.numobjects;i++){
2934 if(objects.type[i]==treeleavestype){
2935 objects.scale[i]*=.9;
2940 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2941 editorenabled=1-editorenabled;
2943 player[0].damagetolerance=100000;
2945 player[0].damagetolerance=200;
2947 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2948 player[0].permanentdamage=0;
2949 player[0].superpermanentdamage=0;
2950 player[0].bloodloss=0;
2951 player[0].deathbleeding=0;
2955 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2957 if(targetlevel>numchallengelevels-1)
2964 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2966 float closestdist=-1;
2969 for(int i=1;i<numplayers;i++){
2970 distance=findDistancefast(&player[i].coords,&player[0].coords);
2971 if(closestdist==-1||distance<closestdist){
2972 closestdist=distance;
2976 if(closestdist>0&&closest>=0){
2977 //player[closest]=player[numplayers-1];
2978 //player[closest].skeleton=player[numplayers-1].skeleton;
2983 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2985 float closestdist=-1;
2988 for(int i=1;i<max_objects;i++){
2989 distance=findDistancefast(&objects.position[i],&player[0].coords);
2990 if(closestdist==-1||distance<closestdist){
2991 closestdist=distance;
2995 if(closestdist>0&&closest>=0){
2996 objects.position[closest].y-=500;
3000 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3002 //if(drawmode>2)drawmode=0;
3003 if(objects.numobjects<max_objects-1){
3005 boxcoords.x=player[0].coords.x;
3006 boxcoords.z=player[0].coords.z;
3007 boxcoords.y=player[0].coords.y-3;
3008 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3009 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3010 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3011 float temprotat,temprotat2;
3012 temprotat=editorrotation;
3013 temprotat2=editorrotation2;
3014 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3015 if(temprotat2<0)temprotat2=Random()%360;
3017 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3018 if(editortype==treetrunktype)
3019 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
3023 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3024 if(numplayers<maxplayers-1){
3025 player[numplayers].scale=.2*5*player[0].scale;
3026 player[numplayers].creature=rabbittype;
3027 player[numplayers].howactive=editoractive;
3028 player[numplayers].skeleton.id=numplayers;
3029 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);
3031 //texsize=512*512*3/texdetail/texdetail;
3032 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3033 //player[numplayers].skeleton.skinText.resize(texsize);
3035 int k=abs(Random()%2)+1;
3037 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3038 player[numplayers].whichskin=0;
3041 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3042 player[numplayers].whichskin=1;
3045 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3046 player[numplayers].whichskin=2;
3049 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
3050 player[numplayers].power=1;
3051 player[numplayers].speedmult=1;
3052 player[numplayers].currentanimation=bounceidleanim;
3053 player[numplayers].targetanimation=bounceidleanim;
3054 player[numplayers].currentframe=0;
3055 player[numplayers].targetframe=1;
3056 player[numplayers].target=0;
3057 player[numplayers].bled=0;
3058 player[numplayers].speed=1+(float)(Random()%100)/1000;
3060 player[numplayers].targetrotation=player[0].targetrotation;
3061 player[numplayers].rotation=player[0].rotation;
3063 player[numplayers].velocity=0;
3064 player[numplayers].coords=player[0].coords;
3065 player[numplayers].oldcoords=player[numplayers].coords;
3066 player[numplayers].realoldcoords=player[numplayers].coords;
3068 player[numplayers].id=numplayers;
3069 player[numplayers].skeleton.id=numplayers;
3070 player[numplayers].updatedelay=0;
3071 player[numplayers].normalsupdatedelay=0;
3073 player[numplayers].aitype=passivetype;
3075 if(player[0].creature==wolftype){
3076 headprop=player[0].proportionhead.x/1.1;
3077 bodyprop=player[0].proportionbody.x/1.1;
3078 armprop=player[0].proportionarms.x/1.1;
3079 legprop=player[0].proportionlegs.x/1.1;
3082 if(player[0].creature==rabbittype){
3083 headprop=player[0].proportionhead.x/1.2;
3084 bodyprop=player[0].proportionbody.x/1.05;
3085 armprop=player[0].proportionarms.x/1.00;
3086 legprop=player[0].proportionlegs.x/1.1;
3089 if(player[numplayers].creature==wolftype){
3090 player[numplayers].proportionhead=1.1*headprop;
3091 player[numplayers].proportionbody=1.1*bodyprop;
3092 player[numplayers].proportionarms=1.1*armprop;
3093 player[numplayers].proportionlegs=1.1*legprop;
3096 if(player[numplayers].creature==rabbittype){
3097 player[numplayers].proportionhead=1.2*headprop;
3098 player[numplayers].proportionbody=1.05*bodyprop;
3099 player[numplayers].proportionarms=1.00*armprop;
3100 player[numplayers].proportionlegs=1.1*legprop;
3101 player[numplayers].proportionlegs.y=1.05*legprop;
3104 player[numplayers].headless=0;
3105 player[numplayers].onfire=0;
3108 player[numplayers].proportionhead.z=0;
3109 player[numplayers].proportionbody.z=0;
3110 player[numplayers].proportionarms.z=0;
3111 player[numplayers].proportionlegs.z=0;
3114 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3116 player[numplayers].damagetolerance=200;
3118 player[numplayers].protectionhead=player[0].protectionhead;
3119 player[numplayers].protectionhigh=player[0].protectionhigh;
3120 player[numplayers].protectionlow=player[0].protectionlow;
3121 player[numplayers].armorhead=player[0].armorhead;
3122 player[numplayers].armorhigh=player[0].armorhigh;
3123 player[numplayers].armorlow=player[0].armorlow;
3124 player[numplayers].metalhead=player[0].metalhead;
3125 player[numplayers].metalhigh=player[0].metalhigh;
3126 player[numplayers].metallow=player[0].metallow;
3128 player[numplayers].immobile=player[0].immobile;
3130 player[numplayers].numclothes=player[0].numclothes;
3131 if(player[numplayers].numclothes)
3132 for(int i=0;i<player[numplayers].numclothes;i++){
3133 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3134 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3135 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3136 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3137 tintr=player[numplayers].clothestintr[i];
3138 tintg=player[numplayers].clothestintg[i];
3139 tintb=player[numplayers].clothestintb[i];
3140 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3142 if(player[numplayers].numclothes){
3143 player[numplayers].DoMipmaps();
3146 player[numplayers].power=player[0].power;
3147 player[numplayers].speedmult=player[0].speedmult;
3149 player[numplayers].damage=0;
3150 player[numplayers].permanentdamage=0;
3151 player[numplayers].superpermanentdamage=0;
3152 player[numplayers].deathbleeding=0;
3153 player[numplayers].bleeding=0;
3154 player[numplayers].numwaypoints=0;
3155 player[numplayers].waypoint=0;
3156 player[numplayers].jumppath=0;
3157 player[numplayers].weaponstuck=-1;
3158 player[numplayers].weaponactive=-1;
3159 player[numplayers].num_weapons=0;
3160 player[numplayers].bloodloss=0;
3161 player[numplayers].dead=0;
3163 player[numplayers].loaded=1;
3169 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3170 if(player[numplayers-1].numwaypoints<90){
3171 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3172 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3173 player[numplayers-1].numwaypoints++;
3177 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3178 if(numpathpoints<30){
3179 bool connected,alreadyconnected;
3182 for(int i=0;i<numpathpoints;i++){
3183 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3185 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3186 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3188 if(!alreadyconnected){
3189 numpathpointconnect[pathpointselected]++;
3191 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3197 pathpoint[numpathpoints-1]=player[0].coords;
3198 numpathpointconnect[numpathpoints-1]=0;
3199 if(numpathpoints>1&&pathpointselected!=-1){
3200 numpathpointconnect[pathpointselected]++;
3201 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3203 pathpointselected=numpathpoints-1;
3208 if(Input::isKeyPressed(SDLK_PERIOD)){
3209 pathpointselected++;
3210 if(pathpointselected>=numpathpoints)
3211 pathpointselected=-1;
3213 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3214 pathpointselected--;
3215 if(pathpointselected<=-2)
3216 pathpointselected=numpathpoints-1;
3218 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3219 if(pathpointselected!=-1){
3221 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3222 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3223 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3224 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3226 for(int i=0;i<numpathpoints;i++){
3227 for(int j=0;j<numpathpointconnect[i];j++){
3228 if(pathpointconnect[i][j]==pathpointselected){
3229 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3230 numpathpointconnect[i]--;
3232 if(pathpointconnect[i][j]==numpathpoints){
3233 pathpointconnect[i][j]=pathpointselected;
3237 pathpointselected=numpathpoints-1;
3241 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3243 if(editortype==treeleavestype||editortype==10)editortype--;
3244 if(editortype<0)editortype=firetype;
3247 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3249 if(editortype==treeleavestype||editortype==10)editortype++;
3250 if(editortype>firetype)editortype=0;
3253 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3254 editorrotation-=multiplier*100;
3255 if(editorrotation<-.01)editorrotation=-.01;
3258 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3259 editorrotation+=multiplier*100;
3262 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3263 editorsize+=multiplier;
3266 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3267 editorsize-=multiplier;
3268 if(editorsize<.1)editorsize=.1;
3272 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3273 mapradius-=multiplier*10;
3276 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3277 mapradius+=multiplier*10;
3279 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3280 editorrotation2+=multiplier*100;
3283 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3284 editorrotation2-=multiplier*100;
3285 if(editorrotation2<-.01)editorrotation2=-.01;
3287 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3289 float closestdist=-1;
3291 for(int i=0;i<objects.numobjects;i++){
3292 distance=findDistancefast(&objects.position[i],&player[0].coords);
3293 if(closestdist==-1||distance<closestdist){
3294 closestdist=distance;
3298 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3304 void Game::doJumpReversals(){
3305 for(int k=0;k<numplayers;k++)
3306 for(int i=k;i<numplayers;i++){
3308 if( player[k].skeleton.free==0&&
3309 player[i].skeleton.oldfree==0&&
3310 (player[i].targetanimation==jumpupanim||
3311 player[k].targetanimation==jumpupanim)&&
3312 (player[i].aitype==playercontrolled||
3313 player[k].aitype==playercontrolled)&&
3314 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3315 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3316 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3317 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3318 //TODO: refactor two huge similar ifs
3319 if(player[i].targetanimation==jumpupanim&&
3320 player[k].targetanimation!=getupfrombackanim&&
3321 player[k].targetanimation!=getupfromfrontanim&&
3322 animation[player[k].targetanimation].height==middleheight&&
3323 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3324 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3325 player[k].aitype!=playercontrolled)){
3326 player[i].victim=&player[k];
3327 player[i].velocity=0;
3328 player[i].currentanimation=jumpreversedanim;
3329 player[i].targetanimation=jumpreversedanim;
3330 player[i].currentframe=0;
3331 player[i].targetframe=1;
3332 player[i].targettilt2=0;
3333 player[k].victim=&player[i];
3334 player[k].velocity=0;
3335 player[k].currentanimation=jumpreversalanim;
3336 player[k].targetanimation=jumpreversalanim;
3337 player[k].currentframe=0;
3338 player[k].targetframe=1;
3339 player[k].targettilt2=0;
3340 if(player[i].coords.y<player[k].coords.y+1){
3341 player[i].currentanimation=rabbitkickreversedanim;
3342 player[i].targetanimation=rabbitkickreversedanim;
3343 player[i].currentframe=1;
3344 player[i].targetframe=2;
3345 player[k].currentanimation=rabbitkickreversalanim;
3346 player[k].targetanimation=rabbitkickreversalanim;
3347 player[k].currentframe=1;
3348 player[k].targetframe=2;
3351 player[k].oldcoords=player[k].coords;
3352 player[i].coords=player[k].coords;
3353 player[k].targetrotation=player[i].targetrotation;
3354 player[k].rotation=player[i].targetrotation;
3355 if(player[k].aitype==attacktypecutoff)
3356 player[k].stunned=.5;
3358 if(player[k].targetanimation==jumpupanim&&
3359 player[i].targetanimation!=getupfrombackanim&&
3360 player[i].targetanimation!=getupfromfrontanim&&
3361 animation[player[i].targetanimation].height==middleheight&&
3362 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3363 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3364 player[i].aitype!=playercontrolled)){
3365 player[k].victim=&player[i];
3366 player[k].velocity=0;
3367 player[k].currentanimation=jumpreversedanim;
3368 player[k].targetanimation=jumpreversedanim;
3369 player[k].currentframe=0;
3370 player[k].targetframe=1;
3371 player[k].targettilt2=0;
3372 player[i].victim=&player[k];
3373 player[i].velocity=0;
3374 player[i].currentanimation=jumpreversalanim;
3375 player[i].targetanimation=jumpreversalanim;
3376 player[i].currentframe=0;
3377 player[i].targetframe=1;
3378 player[i].targettilt2=0;
3379 if(player[k].coords.y<player[i].coords.y+1){
3380 player[k].targetanimation=rabbitkickreversedanim;
3381 player[k].currentanimation=rabbitkickreversedanim;
3382 player[i].currentanimation=rabbitkickreversalanim;
3383 player[i].targetanimation=rabbitkickreversalanim;
3384 player[k].currentframe=1;
3385 player[k].targetframe=2;
3386 player[i].currentframe=1;
3387 player[i].targetframe=2;
3390 player[i].oldcoords=player[i].coords;
3391 player[k].coords=player[i].coords;
3392 player[i].targetrotation=player[k].targetrotation;
3393 player[i].rotation=player[k].targetrotation;
3394 if(player[i].aitype==attacktypecutoff)
3395 player[i].stunned=.5;
3402 void Game::doAerialAcrobatics(){
3403 static XYZ facing,flatfacing;
3404 for(int k=0;k<numplayers;k++){
3405 player[k].turnspeed=500;
3407 if((player[k].isRun()&&
3408 ((player[k].targetrotation!=rabbitrunninganim&&
3409 player[k].targetrotation!=wolfrunninganim)||
3410 player[k].targetframe==4))||
3411 player[k].targetanimation==removeknifeanim||
3412 player[k].targetanimation==crouchremoveknifeanim||
3413 player[k].targetanimation==flipanim||
3414 player[k].targetanimation==fightsidestep||
3415 player[k].targetanimation==walkanim){
3416 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3420 if(player[k].isStop()||
3421 player[k].isLanding()||
3422 player[k].targetanimation==staggerbackhighanim||
3423 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3424 player[k].targetanimation==staggerbackhardanim||
3425 player[k].targetanimation==backhandspringanim||
3426 player[k].targetanimation==dodgebackanim||
3427 player[k].targetanimation==rollanim||
3428 (animation[player[k].targetanimation].attack&&
3429 player[k].targetanimation!=rabbitkickanim&&
3430 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3431 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3432 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3435 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3436 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3439 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3440 player[k].DoStuff();
3441 if(player[k].immobile&&k!=0)
3442 player[k].coords=player[k].realoldcoords;
3444 //if player's position has changed (?)
3445 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3446 !player[k].skeleton.free&&
3447 player[k].targetanimation!=climbanim&&
3448 player[k].targetanimation!=hanganim){
3449 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3453 if(player[k].collide<-.3)
3454 player[k].collide=-.3;
3455 if(player[k].collide>1)
3456 player[k].collide=1;
3457 player[k].collide-=multiplier*30;
3460 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3462 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3463 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3464 if(objects.type[i]!=rocktype||
3465 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3466 objects.position[i].y>player[k].coords.y){
3467 lowpoint=player[k].coords;
3468 if(player[k].targetanimation!=jumpupanim&&
3469 player[k].targetanimation!=jumpdownanim&&
3470 !player[k].isFlip())
3474 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3475 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3476 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3477 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3478 flatfacing=lowpoint-player[k].coords;
3479 player[k].coords=lowpoint;
3480 player[k].coords.y-=1.3;
3481 player[k].collide=1;
3484 //TODO: refactor four similar blocks
3485 if(player[k].aitype==playercontrolled&&
3486 (player[k].targetanimation==jumpupanim||
3487 player[k].targetanimation==jumpdownanim||
3488 player[k].isFlip())&&
3489 !player[k].jumptogglekeydown&&
3490 player[k].jumpkeydown){
3491 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3492 XYZ tempcoords1=lowpoint;
3493 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3494 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3495 setAnimation(k,walljumpleftanim);
3496 emit_sound_at(movewhooshsound, player[k].coords);
3498 pause_sound(whooshsound);
3500 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3501 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3502 if(lowpointtarget.z<0)
3503 player[k].rotation=180-player[k].rotation;
3504 player[k].targetrotation=player[k].rotation;
3505 player[k].lowrotation=player[k].rotation;
3511 lowpoint=tempcoords1;
3512 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3513 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3514 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3515 setAnimation(k,walljumprightanim);
3516 emit_sound_at(movewhooshsound, player[k].coords);
3517 if(k==0)pause_sound(whooshsound);
3519 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3520 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3521 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3522 player[k].targetrotation=player[k].rotation;
3523 player[k].lowrotation=player[k].rotation;
3524 if(k==0)numwallflipped++;
3528 lowpoint=tempcoords1;
3529 lowpointtarget=lowpoint+player[k].facing*2;
3530 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3531 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3532 setAnimation(k,walljumpbackanim);
3533 emit_sound_at(movewhooshsound, player[k].coords);
3534 if(k==0)pause_sound(whooshsound);
3536 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3537 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3538 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3539 player[k].targetrotation=player[k].rotation;
3540 player[k].lowrotation=player[k].rotation;
3541 if(k==0)numwallflipped++;
3545 lowpoint=tempcoords1;
3546 lowpointtarget=lowpoint-player[k].facing*2;
3547 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3548 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3549 setAnimation(k,walljumpfrontanim);
3550 emit_sound_at(movewhooshsound, player[k].coords);
3551 if(k==0)pause_sound(whooshsound);
3553 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3554 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3555 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3556 player[k].rotation+=180;
3557 player[k].targetrotation=player[k].rotation;
3558 player[k].lowrotation=player[k].rotation;
3559 if(k==0)numwallflipped++;
3567 else if(objects.type[i]==rocktype){
3568 lowpoint2=player[k].coords;
3569 lowpoint=player[k].coords;
3571 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3572 player[k].coords=colpoint;
3573 player[k].collide=1;
3576 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3577 //flipped into a rock
3578 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3579 player[k].RagDoll(0);
3581 if(player[k].targetanimation==jumpupanim){
3582 player[k].jumppower=-4;
3583 player[k].targetanimation=player[k].getIdle();
3586 player[k].targetframe=0;
3587 player[k].onterrain=1;
3589 if(player[k].id==0){
3590 pause_sound(whooshsound);
3591 OPENAL_SetVolume(channels[whooshsound], 0);
3595 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3596 if(player[k].isFlip())
3597 player[k].jumppower=-4;
3598 player[k].targetanimation=player[k].getLanding();
3599 emit_sound_at(landsound, player[k].coords, 128.);
3601 envsound[numenvsounds]=player[k].coords;
3602 envsoundvol[numenvsounds]=16;
3603 envsoundlife[numenvsounds]=.4;
3613 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3614 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3615 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3616 lowpoint=player[k].coords;
3618 if(objects.type[i]!=rocktype)
3619 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3620 if(player[k].targetanimation!=jumpupanim&&
3621 player[k].targetanimation!=jumpdownanim&&
3622 player[k].onterrain)
3623 player[k].avoidcollided=1;
3624 player[k].coords=lowpoint;
3625 player[k].coords.y-=1.35;
3626 player[k].collide=1;
3628 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3629 (player[k].currentanimation!=climbanim&&
3630 player[k].currentanimation!=hanganim&&
3631 !player[k].isWallJump()||
3632 player[k].targetanimation==jumpupanim||
3633 player[k].targetanimation==jumpdownanim)){
3634 lowpoint=player[k].coords;
3635 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3636 lowpoint=player[k].coords;
3640 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3641 lowpointtarget=lowpoint+facing*1.4;
3642 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3644 lowpoint=player[k].coords;
3646 lowpointtarget=lowpoint+facing*1.4;
3648 lowpointtarget2=lowpointtarget;
3650 lowpointtarget3=lowpointtarget;
3652 lowpointtarget4=lowpointtarget;
3654 lowpointtarget5=lowpointtarget;
3656 lowpointtarget6=lowpointtarget;
3658 lowpointtarget7=lowpoint;
3660 lowpointtarget2.x+=.1;
3662 lowpointtarget3.z+=.1;
3664 lowpointtarget4.x-=.1;
3666 lowpointtarget5.z-=.1;
3668 lowpointtarget6.y+=45/13;
3669 lowpointtarget6+=facing*.6;
3670 lowpointtarget7.y+=90/13;
3671 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3672 if(objects.friction[i]>.5)
3674 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3675 player[k].collided=1;
3676 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3677 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3678 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3679 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3680 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3681 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3682 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3683 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3684 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3685 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3686 for(int j=0;j<45;j++){
3687 lowpoint=player[k].coords;
3688 lowpoint.y+=(float)j/13;
3689 lowpointtarget=lowpoint+facing*1.4;
3690 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3691 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3692 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3694 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3695 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3696 lowpoint=player[k].coords;
3697 lowpoint.y+=(float)j/13;
3698 lowpointtarget=lowpoint+facing*1.3;
3699 flatfacing=player[k].coords;
3700 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3701 player[k].coords.y=lowpointtarget.y-.07;
3702 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3704 if(j>10||!player[k].isRun()){
3705 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3707 pause_sound(whooshsound);
3709 emit_sound_at(jumpsound, player[k].coords, 128.);
3711 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3712 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3713 if(lowpointtarget.z<0)
3714 player[k].rotation=180-player[k].rotation;
3715 player[k].targetrotation=player[k].rotation;
3716 player[k].lowrotation=player[k].rotation;
3718 //player[k].velocity=lowpointtarget*.03;
3719 player[k].velocity=0;
3722 if(player[k].targetanimation==jumpupanim){
3723 player[k].targetanimation=climbanim;
3724 player[k].jumppower=0;
3725 player[k].jumpclimb=1;
3727 player[k].transspeed=6;
3729 player[k].targetframe=1;
3732 setAnimation(k,hanganim);
3733 player[k].jumppower=0;
3745 if(player[k].collide<=0){
3747 if(!player[k].onterrain&&
3748 player[k].targetanimation!=jumpupanim&&
3749 player[k].targetanimation!=jumpdownanim&&
3750 player[k].targetanimation!=climbanim&&
3751 player[k].targetanimation!=hanganim&&
3752 !player[k].isWallJump()&&
3753 !player[k].isFlip()){
3754 if(player[k].currentanimation!=climbanim&&
3755 player[k].currentanimation!=tempanim&&
3756 player[k].targetanimation!=backhandspringanim&&
3757 (player[k].targetanimation!=rollanim||
3758 player[k].targetframe<2||
3759 player[k].targetframe>6)){
3760 //stagger off ledge (?)
3761 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3762 player[k].RagDoll(0);
3763 setAnimation(k,jumpdownanim);
3766 emit_sound_at(whooshsound, player[k].coords, 128.);
3769 player[k].velocity.y+=gravity;
3773 player[k].realoldcoords=player[k].coords;
3777 void Game::doAttacks(){
3778 static XYZ relative;
3779 static int randattack;
3780 static bool playerrealattackkeydown=0;
3782 if(!Input::isKeyDown(attackkey))
3785 player[0].attackkeydown=0;
3787 playerrealattackkeydown=0;
3789 playerrealattackkeydown=Input::isKeyDown(attackkey);
3790 if((player[0].parriedrecently<=0||
3791 player[0].weaponactive==-1)&&
3794 player[0].lastattack!=swordslashanim&&
3795 player[0].lastattack!=knifeslashstartanim&&
3796 player[0].lastattack!=staffhitanim&&
3797 player[0].lastattack!=staffspinhitanim)))
3798 player[0].attackkeydown=Input::isKeyDown(attackkey);
3799 if(Input::isKeyDown(attackkey)&&
3801 !player[0].backkeydown){
3802 for(int k=0;k<numplayers;k++){
3803 if((player[k].targetanimation==swordslashanim||
3804 player[k].targetanimation==staffhitanim||
3805 player[k].targetanimation==staffspinhitanim)&&
3806 player[0].currentanimation!=dodgebackanim&&
3807 !player[k].skeleton.free)
3808 player[k].Reverse();
3812 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3814 for(int k=0;k<numplayers;k++){
3815 if(indialogue!=-1)player[k].attackkeydown=0;
3816 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3817 if(player[k].aitype!=playercontrolled)
3818 player[k].victim=&player[0];
3819 //attack key pressed
3820 if(player[k].attackkeydown){
3822 if(player[k].backkeydown&&
3823 player[k].targetanimation!=backhandspringanim&&
3824 (player[k].isIdle()||
3825 player[k].isStop()||
3827 player[k].targetanimation==walkanim)){
3828 if(player[k].jumppower<=1){
3829 player[k].jumppower-=2;
3831 for(int i=0;i<numplayers;i++){
3833 if(player[i].targetanimation==swordslashanim||
3834 player[i].targetanimation==knifeslashstartanim||
3835 player[i].targetanimation==staffhitanim||
3836 player[i].targetanimation==staffspinhitanim)
3837 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3838 setAnimation(k,dodgebackanim);
3839 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3840 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3843 if(player[k].targetanimation!=dodgebackanim){
3844 if(k==0)numflipped++;
3845 setAnimation(k,backhandspringanim);
3846 player[k].targetrotation=-rotation+180;
3847 if(player[k].leftkeydown)
3848 player[k].targetrotation-=45;
3849 if(player[k].rightkeydown)
3850 player[k].targetrotation+=45;
3851 player[k].rotation=player[k].targetrotation;
3852 player[k].jumppower-=2;
3857 if(!animation[player[k].targetanimation].attack&&
3858 !player[k].backkeydown&&
3859 (player[k].isIdle()||
3861 player[k].targetanimation==walkanim||
3862 player[k].targetanimation==sneakanim||
3863 player[k].isCrouch())){
3864 const int attackweapon=player[k].weaponactive==-1?0:weapons.type[player[k].weaponids[player[k].weaponactive]];
3865 //normal attacks (?)
3866 player[k].hasvictim=0;
3868 for(int i=0;i<numplayers;i++){
3869 if(i==k||!(k==0||i==0))continue;
3870 if(!player[k].hasvictim)
3871 if(animation[player[k].targetanimation].attack!=reversal){
3873 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3875 !player[i].skeleton.free&&
3876 player[i].howactive<typedead1&&
3877 player[i].targetanimation!=jumpreversedanim&&
3878 player[i].targetanimation!=rabbitkickreversedanim&&
3879 player[i].targetanimation!=rabbitkickanim&&
3880 player[k].targetanimation!=rabbitkickanim&&
3881 player[i].targetanimation!=getupfrombackanim&&
3882 (player[i].targetanimation!=staggerbackhighanim&&
3883 (player[i].targetanimation!=staggerbackhardanim||
3884 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3885 player[i].targetanimation!=jumpdownanim&&
3886 player[i].targetanimation!=jumpupanim&&
3887 player[i].targetanimation!=getupfromfrontanim){
3888 player[k].victim=&player[i];
3889 player[k].hasvictim=1;
3890 if(player[k].aitype==playercontrolled){ //human player
3892 if(distance<2.5*sq(player[k].scale*5)&&
3893 player[k].crouchkeydown&&
3894 animation[player[i].targetanimation].height!=lowheight)
3895 player[k].targetanimation=sweepanim;
3897 else if(distance<1.5*sq(player[k].scale*5)&&
3898 animation[player[i].targetanimation].height!=lowheight&&
3899 !player[k].forwardkeydown&&
3900 !player[k].leftkeydown&&
3901 !player[k].rightkeydown&&
3902 !player[k].crouchkeydown&&
3905 player[k].targetanimation=winduppunchanim;
3907 else if(distance<2.5*sq(player[k].scale*5)&&
3908 animation[player[i].targetanimation].height!=lowheight&&
3909 !player[k].forwardkeydown&&
3910 !player[k].leftkeydown&&
3911 !player[k].rightkeydown&&
3912 !player[k].crouchkeydown&&
3914 player[k].targetanimation=upunchanim;
3916 else if(distance<2.5*sq(player[k].scale*5)&&
3917 player[i].staggerdelay>0&&
3918 attackweapon==knife&&
3919 player[i].bloodloss>player[i].damagetolerance/2)
3920 player[k].targetanimation=knifefollowanim;
3922 else if(distance<2.5*sq(player[k].scale*5)&&
3923 animation[player[i].targetanimation].height!=lowheight&&
3924 !player[k].forwardkeydown&&
3925 !player[k].leftkeydown&&
3926 !player[k].rightkeydown&&
3927 !player[k].crouchkeydown&&
3928 attackweapon==knife&&
3929 player[k].weaponmissdelay<=0)
3930 player[k].targetanimation=knifeslashstartanim;
3932 else if(distance<4.5*sq(player[k].scale*5)&&
3933 animation[player[i].targetanimation].height!=lowheight&&
3934 !player[k].crouchkeydown&&
3935 attackweapon==sword&&
3936 player[k].weaponmissdelay<=0)
3937 player[k].targetanimation=swordslashanim;
3939 else if(distance<4.5*sq(player[k].scale*5)&&
3940 animation[player[i].targetanimation].height!=lowheight&&
3941 !player[k].crouchkeydown&&
3942 attackweapon==staff&&
3943 player[k].weaponmissdelay<=0&&
3944 !player[k].leftkeydown&&
3945 !player[k].rightkeydown&&
3946 !player[k].forwardkeydown)
3947 player[k].targetanimation=staffhitanim;
3949 else if(distance<4.5*sq(player[k].scale*5)&&
3950 animation[player[i].targetanimation].height!=lowheight&&
3951 !player[k].crouchkeydown&&
3952 attackweapon==staff&&
3953 player[k].weaponmissdelay<=0)
3954 player[k].targetanimation=staffspinhitanim;
3956 else if(distance<2.5*sq(player[k].scale*5)&&
3957 animation[player[i].targetanimation].height!=lowheight)
3958 player[k].targetanimation=spinkickanim;
3960 else if(distance<2.5*sq(player[k].scale*5)&&
3961 animation[player[i].targetanimation].height==lowheight&&
3962 animation[player[k].targetanimation].attack!=normalattack)
3963 player[k].targetanimation=lowkickanim;
3964 } else { //AI player
3965 if(distance<4.5*sq(player[k].scale*5)){
3966 randattack=abs(Random()%5);
3967 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3969 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3970 player[k].targetanimation=sweepanim;
3972 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3974 player[k].targetanimation=upunchanim;
3976 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3977 player[k].targetanimation=spinkickanim;
3979 else if(animation[player[i].targetanimation].height==lowheight)
3980 player[k].targetanimation=lowkickanim;
3984 if((tutoriallevel!=1||!attackweapon)&&
3985 distance<2.5*sq(player[k].scale*5)&&
3987 animation[player[i].targetanimation].height!=lowheight)
3988 player[k].targetanimation=sweepanim;
3990 else if(distance<2.5*sq(player[k].scale*5)&&
3991 attackweapon==knife&&
3992 player[k].weaponmissdelay<=0)
3993 player[k].targetanimation=knifeslashstartanim;
3995 else if(!(player[0].victim==&player[i]&&
3996 player[0].hasvictim&&
3997 player[0].targetanimation==swordslashanim)&&
3998 attackweapon==sword&&
3999 player[k].weaponmissdelay<=0)
4000 player[k].targetanimation=swordslashanim;
4002 else if(!(player[0].victim==&player[i]&&
4003 player[0].hasvictim&&
4004 player[0].targetanimation==swordslashanim)&&
4005 attackweapon==staff&&
4006 player[k].weaponmissdelay<=0&&
4008 player[k].targetanimation=staffhitanim;
4010 else if(!(player[0].victim==&player[i]&&
4011 player[0].hasvictim&&
4012 player[0].targetanimation==swordslashanim)&&
4013 attackweapon==staff&&
4014 player[k].weaponmissdelay<=0&&
4016 player[k].targetanimation=staffspinhitanim;
4018 else if((tutoriallevel!=1||!attackweapon)&&
4019 distance<2.5*sq(player[k].scale*5)&&
4021 animation[player[i].targetanimation].height!=lowheight)
4022 player[k].targetanimation=spinkickanim;
4024 else if(distance<2.5*sq(player[k].scale*5)&&
4025 animation[player[i].targetanimation].height==lowheight&&
4026 animation[player[k].targetanimation].attack!=normalattack)
4027 player[k].targetanimation=lowkickanim;
4031 //upunch becomes wolfslap
4032 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
4033 player[k].targetanimation=wolfslapanim;
4036 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4037 player[i].howactive<typedead1&&
4038 distance<1.5*sq(player[k].scale*5)&&
4039 !player[i].skeleton.free&&
4040 player[i].targetanimation!=getupfrombackanim&&
4041 player[i].targetanimation!=getupfromfrontanim&&
4042 (player[i].stunned>0&&player[k].madskills||
4043 player[i].surprised>0||
4044 player[i].aitype==passivetype||
4045 attackweapon&&player[i].stunned>0)&&
4046 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4049 player[k].currentanimation=sneakattackanim;
4050 player[k].targetanimation=sneakattackanim;
4051 player[i].currentanimation=sneakattackedanim;
4052 player[i].targetanimation=sneakattackedanim;
4053 player[k].oldcoords=player[k].coords;
4054 player[k].coords=player[i].coords;
4057 if(attackweapon==knife){
4058 player[k].currentanimation=knifesneakattackanim;
4059 player[k].targetanimation=knifesneakattackanim;
4060 player[i].currentanimation=knifesneakattackedanim;
4061 player[i].targetanimation=knifesneakattackedanim;
4062 player[i].oldcoords=player[i].coords;
4063 player[i].coords=player[k].coords;
4066 if(attackweapon==sword){
4067 player[k].currentanimation=swordsneakattackanim;
4068 player[k].targetanimation=swordsneakattackanim;
4069 player[i].currentanimation=swordsneakattackedanim;
4070 player[i].targetanimation=swordsneakattackedanim;
4071 player[i].oldcoords=player[i].coords;
4072 player[i].coords=player[k].coords;
4074 if(attackweapon!=staff){
4075 player[k].victim=&player[i];
4076 player[k].hasvictim=1;
4077 player[i].targettilt2=0;
4078 player[i].targetframe=1;
4079 player[i].currentframe=0;
4081 player[i].velocity=0;
4082 player[k].targettilt2=player[i].targettilt2;
4083 player[k].currentframe=player[i].currentframe;
4084 player[k].targetframe=player[i].targetframe;
4085 player[k].target=player[i].target;
4086 player[k].velocity=0;
4087 player[k].targetrotation=player[i].rotation;
4088 player[k].rotation=player[i].rotation;
4089 player[i].targetrotation=player[i].rotation;
4092 if(animation[player[k].targetanimation].attack==normalattack&&
4093 player[k].victim==&player[i]&&
4094 (!player[i].skeleton.free)){
4096 player[k].targetframe=0;
4099 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4100 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4101 player[k].lastattack3=player[k].lastattack2;
4102 player[k].lastattack2=player[k].lastattack;
4103 player[k].lastattack=player[k].targetanimation;
4105 if(player[k].targetanimation==knifefollowanim&&
4106 player[k].victim==&player[i]){
4108 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4109 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4110 player[k].victim=&player[i];
4111 player[k].hasvictim=1;
4112 player[i].targetanimation=knifefollowedanim;
4113 player[i].currentanimation=knifefollowedanim;
4114 player[i].targettilt2=0;
4115 player[i].targettilt2=player[k].targettilt2;
4116 player[i].targetframe=1;
4117 player[i].currentframe=0;
4119 player[i].velocity=0;
4120 player[k].currentanimation=knifefollowanim;
4121 player[k].targetanimation=knifefollowanim;
4122 player[k].targettilt2=player[i].targettilt2;
4123 player[k].currentframe=player[i].currentframe;
4124 player[k].targetframe=player[i].targetframe;
4125 player[k].target=player[i].target;
4126 player[k].velocity=0;
4127 player[k].oldcoords=player[k].coords;
4128 player[i].coords=player[k].coords;
4129 player[i].targetrotation=player[k].targetrotation;
4130 player[i].rotation=player[k].targetrotation;
4131 player[k].rotation=player[k].targetrotation;
4132 player[i].rotation=player[k].targetrotation;
4136 const bool hasstaff=attackweapon==staff;
4137 if(k==0&&numplayers>1)
4138 for(int i=0;i<numplayers;i++){
4140 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4141 animation[player[k].targetanimation].attack==neutral){
4142 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4143 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4144 if(player[i].skeleton.free)
4145 if(distance<3.5*sq(player[k].scale*5)&&
4147 player[i].skeleton.longdead>1000||
4151 (player[i].skeleton.longdead>2000||
4152 player[i].damage>player[i].damagetolerance/8||
4153 player[i].bloodloss>player[i].damagetolerance/2)&&
4154 distance<1.5*sq(player[k].scale*5)))){
4155 player[k].victim=&player[i];
4156 player[k].hasvictim=1;
4157 if(attackweapon&&tutoriallevel!=1){
4159 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4160 player[k].targetanimation=crouchstabanim;
4162 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4163 player[k].targetanimation=swordgroundstabanim;
4165 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4166 player[k].targetanimation=staffgroundsmashanim;
4169 player[k].crouchkeydown&&
4170 player[k].targetanimation!=crouchstabanim&&
4173 player[i].skeleton.free&&
4174 player[i].skeleton.longdead>1000){
4175 player[k].targetanimation=killanim;
4176 //TODO: refactor this out, what does it do?
4177 for(int j=0;j<terrain.numdecals;j++){
4178 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4179 terrain.decalalivetime[j]<2)
4180 terrain.DeleteDecal(j);
4182 for(int l=0;l<objects.numobjects;l++){
4183 if(objects.model[l].type==decalstype)
4184 for(int j=0;j<objects.model[l].numdecals;j++){
4185 if((objects.model[l].decaltype[j]==blooddecal||
4186 objects.model[l].decaltype[j]==blooddecalslow)&&
4187 objects.model[l].decalalivetime[j]<2)
4188 objects.model[l].DeleteDecal(j);
4192 if(!player[i].dead||musictype!=2)
4194 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4195 player[k].staggerdelay<=0&&
4197 player[i].skeleton.longdead<300&&
4198 player[k].lastattack!=spinkickanim&&
4199 player[i].skeleton.free)&&
4200 (!player[i].dead||musictype!=stream_fighttheme)){
4201 player[k].targetanimation=dropkickanim;
4202 for(int j=0;j<terrain.numdecals;j++){
4203 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4204 terrain.decalalivetime[j]<2){
4205 terrain.DeleteDecal(j);
4208 for(int l=0;l<objects.numobjects;l++){
4209 if(objects.model[l].type==decalstype)
4210 for(int j=0;j<objects.model[l].numdecals;j++){
4211 if((objects.model[l].decaltype[j]==blooddecal||
4212 objects.model[l].decaltype[j]==blooddecalslow)&&
4213 objects.model[l].decalalivetime[j]<2){
4214 objects.model[l].DeleteDecal(j);
4220 if(animation[player[k].targetanimation].attack==normalattack&&
4221 player[k].victim==&player[i]&&
4222 (!player[i].skeleton.free||
4223 player[k].targetanimation==killanim||
4224 player[k].targetanimation==crouchstabanim||
4225 player[k].targetanimation==swordgroundstabanim||
4226 player[k].targetanimation==staffgroundsmashanim||
4227 player[k].targetanimation==dropkickanim)){
4229 player[k].targetframe=0;
4232 XYZ targetpoint=player[i].coords;
4233 if(player[k].targetanimation==crouchstabanim||
4234 player[k].targetanimation==swordgroundstabanim||
4235 player[k].targetanimation==staffgroundsmashanim){
4236 targetpoint+=(playerJoint(i,abdomen).position+
4237 playerJoint(i,neck).position)/2*
4240 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4241 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4243 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4244 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4247 if(player[k].targetanimation==staffgroundsmashanim)
4248 player[k].targettilt2+=10;
4250 player[k].lastattack3=player[k].lastattack2;
4251 player[k].lastattack2=player[k].lastattack;
4252 player[k].lastattack=player[k].targetanimation;
4254 if(player[k].targetanimation==swordgroundstabanim){
4255 player[k].targetrotation+=30;
4260 if(!player[k].hasvictim){
4262 for(int i=0;i<numplayers;i++){
4263 if(i==k||!(i==0||k==0))continue;
4264 if(!player[i].skeleton.free){
4265 if(player[k].hasvictim){
4266 if(findDistancefast(&player[k].coords,&player[i].coords)<
4267 findDistancefast(&player[k].coords,&player[k].victim->coords))
4268 player[k].victim=&player[i];
4270 player[k].victim=&player[i];
4271 player[k].hasvictim=1;
4276 if(player[k].aitype==playercontrolled)
4278 if(player[k].attackkeydown&&
4280 player[k].wasRun()&&
4281 ((player[k].hasvictim&&
4282 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4283 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4284 !player[k].victim->skeleton.free&&
4285 player[k].victim->targetanimation!=getupfrombackanim&&
4286 player[k].victim->targetanimation!=getupfromfrontanim&&
4287 animation[player[k].victim->targetanimation].height!=lowheight&&
4288 player[k].aitype!=playercontrolled&& //wat???
4289 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4290 player[k].rabbitkickenabled)||
4291 player[k].jumpkeydown)){
4293 setAnimation(k,rabbitkickanim);
4296 if(animation[player[k].targetanimation].attack&&k==0){
4298 switch(attackweapon){
4299 case 0: numunarmedattack++; break;
4300 case knife: numknifeattack++; break;
4301 case sword: numswordattack++; break;
4302 case staff: numstaffattack++; break;
4311 void Game::doPlayerCollisions(){
4312 static XYZ rotatetarget;
4313 static float collisionradius;
4315 for(int k=0;k<numplayers;k++)
4316 for(int i=k+1;i<numplayers;i++){
4317 //neither player is part of a reversal
4318 if((animation[player[i].targetanimation].attack!=reversed&&
4319 animation[player[i].targetanimation].attack!=reversal&&
4320 animation[player[k].targetanimation].attack!=reversed&&
4321 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4322 if((animation[player[i].currentanimation].attack!=reversed&&
4323 animation[player[i].currentanimation].attack!=reversal&&
4324 animation[player[k].currentanimation].attack!=reversed&&
4325 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4326 //neither is sleeping
4327 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4328 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4329 //in same patch, neither is climbing
4330 if(player[i].whichpatchx==player[k].whichpatchx&&
4331 player[i].whichpatchz==player[k].whichpatchz&&
4332 player[k].skeleton.oldfree==player[k].skeleton.free&&
4333 player[i].skeleton.oldfree==player[i].skeleton.free&&
4334 player[i].targetanimation!=climbanim&&
4335 player[i].targetanimation!=hanganim&&
4336 player[k].targetanimation!=climbanim&&
4337 player[k].targetanimation!=hanganim)
4338 //players are close (bounding box test)
4339 if(player[i].coords.y>player[k].coords.y-3)
4340 if(player[i].coords.y<player[k].coords.y+3)
4341 if(player[i].coords.x>player[k].coords.x-3)
4342 if(player[i].coords.x<player[k].coords.x+3)
4343 if(player[i].coords.z>player[k].coords.z-3)
4344 if(player[i].coords.z<player[k].coords.z+3){
4345 //spread fire from player to player
4346 if(findDistancefast(&player[i].coords,&player[k].coords)
4347 <3*sq((player[i].scale+player[k].scale)*2.5)){
4348 if(player[i].onfire||player[k].onfire){
4349 if(!player[i].onfire)player[i].CatchFire();
4350 if(!player[k].onfire)player[k].CatchFire();
4354 XYZ tempcoords1=player[i].coords;
4355 XYZ tempcoords2=player[k].coords;
4356 if(!player[i].skeleton.oldfree)
4357 tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
4358 if(!player[k].skeleton.oldfree)
4359 tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
4360 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4361 if(player[0].hasvictim)
4362 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4364 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4365 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4366 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4367 //jump down on a dead body
4370 if(player[0].targetanimation==jumpdownanim&&
4371 !player[0].skeleton.oldfree&&
4372 !player[0].skeleton.free&&
4373 player[l].skeleton.oldfree&&
4374 player[l].skeleton.free&&
4376 player[0].lastcollide<=0&&
4377 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4378 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4379 player[0].coords.y=player[l].coords.y;
4380 player[l].velocity=player[0].velocity;
4381 player[l].skeleton.free=0;
4382 player[l].rotation=0;
4383 player[l].RagDoll(0);
4384 player[l].DoDamage(20);
4386 player[l].skeleton.longdead=0;
4387 player[0].lastcollide=1;
4391 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4392 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4393 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4394 rotatetarget=player[k].velocity-player[i].velocity;
4395 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4396 player[i].skeleton.free)&&
4397 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4398 player[k].skeleton.free))
4399 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4400 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4401 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4403 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4404 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4405 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4406 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4407 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4409 if( (i!=0||player[i].skeleton.free)&&
4410 (k!=0||player[k].skeleton.free)||
4411 (animation[player[i].targetanimation].height==highheight&&
4412 animation[player[k].targetanimation].height==highheight)){
4413 if(tutoriallevel!=1){
4414 emit_sound_at(heavyimpactsound, player[i].coords);
4417 player[i].RagDoll(0);
4418 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4419 award_bonus(0, aimbonus);
4421 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4422 player[k].RagDoll(0);
4423 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4424 award_bonus(0, aimbonus); // Huh, again?
4426 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4428 for(int j=0;j<player[i].skeleton.num_joints;j++){
4429 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4431 for(int j=0;j<player[k].skeleton.num_joints;j++){
4432 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4437 if( (animation[player[i].targetanimation].attack==neutral||
4438 animation[player[i].targetanimation].attack==normalattack)&&
4439 (animation[player[k].targetanimation].attack==neutral||
4440 animation[player[k].targetanimation].attack==normalattack)){
4442 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4443 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4444 rotatetarget=player[k].coords-player[i].coords;
4445 Normalise(&rotatetarget);
4446 player[k].coords=(player[k].coords+player[i].coords)/2;
4447 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4448 *sq((player[i].scale+player[k].scale)*2.5);
4449 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4450 if(player[k].howactive==typeactive||hostile)
4451 if(player[k].isIdle()){
4452 if(player[k].howactive<typesleeping)
4453 setAnimation(k,player[k].getStop());
4454 else if(player[k].howactive==typesleeping)
4455 setAnimation(k,getupfromfrontanim);
4457 player[k].howactive=typeactive;
4459 if(player[i].howactive==typeactive||hostile)
4460 if(player[i].isIdle()){
4461 if(player[i].howactive<typesleeping)
4462 setAnimation(i,player[k].getStop());
4464 setAnimation(i,getupfromfrontanim);
4466 player[i].howactive=typeactive;
4469 //jump down on player
4471 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4472 !player[i].isCrouch()&&
4473 player[i].targetanimation!=rollanim&&
4474 !player[k].skeleton.oldfree&&!
4475 player[k].skeleton.free&&
4476 player[k].lastcollide<=0&&
4477 player[k].velocity.y<-10){
4478 player[i].velocity=player[k].velocity;
4479 player[k].velocity=player[k].velocity*-.5;
4480 player[k].velocity.y=player[i].velocity.y;
4481 player[i].DoDamage(20);
4482 player[i].RagDoll(0);
4483 player[k].lastcollide=1;
4484 award_bonus(k, AboveBonus);
4486 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4487 !player[k].isCrouch()&&
4488 player[k].targetanimation!=rollanim&&
4489 !player[i].skeleton.oldfree&&
4490 !player[i].skeleton.free&&
4491 player[i].lastcollide<=0&&
4492 player[i].velocity.y<-10){
4493 player[k].velocity=player[i].velocity;
4494 player[i].velocity=player[i].velocity*-.3;
4495 player[i].velocity.y=player[k].velocity.y;
4496 player[k].DoDamage(20);
4497 player[k].RagDoll(0);
4498 player[i].lastcollide=1;
4499 award_bonus(i, AboveBonus);
4505 player[i].CheckKick();
4506 player[k].CheckKick();
4512 void Game::doAI(int i){
4513 static bool connected;
4514 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4515 player[i].jumpclimb=0;
4516 //disable movement in editor
4518 player[i].stunned=1;
4521 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4522 player[0].coords.y>player[i].coords.y+2&&
4523 !player[0].onterrain)
4527 if(player[i].aitype==pathfindtype){
4528 if(player[i].finalpathfindpoint==-1){
4529 float closestdistance;
4535 for(int j=0;j<numpathpoints;j++)
4536 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4537 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4539 player[i].finaltarget=pathpoint[j];
4541 player[i].finalpathfindpoint=closest;
4542 for(int j=0;j<numpathpoints;j++)
4543 for(int k=0;k<numpathpointconnect[j];k++){
4544 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4545 if(sq(tempdist)<closestdistance)
4546 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4547 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4548 closestdistance=sq(tempdist);
4550 player[i].finaltarget=colpoint;
4553 player[i].finalpathfindpoint=closest;
4556 if(player[i].targetpathfindpoint==-1){
4557 float closestdistance;
4563 if(player[i].lastpathfindpoint==-1){
4564 for(int j=0;j<numpathpoints;j++){
4565 if(j!=player[i].lastpathfindpoint)
4566 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4567 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4571 player[i].targetpathfindpoint=closest;
4572 for(int j=0;j<numpathpoints;j++)
4573 if(j!=player[i].lastpathfindpoint)
4574 for(int k=0;k<numpathpointconnect[j];k++){
4575 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4576 if(sq(tempdist)<closestdistance){
4577 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4578 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4579 closestdistance=sq(tempdist);
4584 player[i].targetpathfindpoint=closest;
4588 for(int j=0;j<numpathpoints;j++)
4589 if(j!=player[i].lastpathfindpoint&&
4590 j!=player[i].lastpathfindpoint2&&
4591 j!=player[i].lastpathfindpoint3&&
4592 j!=player[i].lastpathfindpoint4){
4594 if(numpathpointconnect[j])
4595 for(int k=0;k<numpathpointconnect[j];k++)
4596 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4599 if(numpathpointconnect[player[i].lastpathfindpoint])
4600 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4601 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4604 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4605 if(closest==-1||tempdist<closestdistance){
4606 closestdistance=tempdist;
4611 player[i].targetpathfindpoint=closest;
4614 player[i].losupdatedelay-=multiplier;
4616 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4617 player[i].lookrotation=player[i].targetrotation;
4619 //reached target point
4620 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4621 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4622 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4623 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4624 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4625 if(player[i].lastpathfindpoint2==-1)
4626 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4627 if(player[i].lastpathfindpoint3==-1)
4628 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4629 if(player[i].lastpathfindpoint4==-1)
4630 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4631 player[i].targetpathfindpoint=-1;
4633 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4634 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4635 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4636 player[i].lastpathfindpoint==player[i].finalpathfindpoint){
4637 player[i].aitype=passivetype;
4640 player[i].forwardkeydown=1;
4641 player[i].leftkeydown=0;
4642 player[i].backkeydown=0;
4643 player[i].rightkeydown=0;
4644 player[i].crouchkeydown=0;
4645 player[i].attackkeydown=0;
4646 player[i].throwkeydown=0;
4648 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
4649 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4651 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4652 player[i].jumpkeydown=0;
4653 if((player[i].collided>.8&&player[i].jumppower>=5))
4654 player[i].jumpkeydown=1;
4656 if((tutoriallevel!=1||cananger)&&
4659 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4660 player[i].occluded<25){
4661 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4662 animation[player[0].targetanimation].height!=lowheight&&
4664 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4665 player[i].aitype=attacktypecutoff;
4666 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4667 animation[player[0].targetanimation].height==highheight&&
4669 player[i].aitype=attacktypecutoff;
4671 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4672 player[i].losupdatedelay=.2;
4673 for(int j=0;j<numplayers;j++)
4674 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4675 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4676 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4677 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4678 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4679 if(!player[j].isWallJump()&&-1==checkcollide(
4680 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
4681 *player[i].scale+player[i].coords,
4682 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
4683 *player[j].scale+player[j].coords)||
4684 (player[j].targetanimation==hanganim&&
4685 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4686 player[i].aitype=searchtype;
4687 player[i].lastchecktime=12;
4688 player[i].lastseen=player[j].coords;
4689 player[i].lastseentime=12;
4693 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4694 if(player[i].creature!=wolftype){
4695 player[i].stunned=.6;
4696 player[i].surprised=.6;
4700 if(player[i].aitype!=passivetype&&leveltime>.5)
4701 player[i].howactive=typeactive;
4703 if(player[i].aitype==passivetype){
4704 player[i].aiupdatedelay-=multiplier;
4705 player[i].losupdatedelay-=multiplier;
4706 player[i].lastseentime+=multiplier;
4707 player[i].pausetime-=multiplier;
4708 if(player[i].lastseentime>1)
4709 player[i].lastseentime=1;
4711 if(player[i].aiupdatedelay<0){
4712 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4713 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4714 player[i].lookrotation=player[i].targetrotation;
4715 player[i].aiupdatedelay=.05;
4717 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4718 if(player[i].waypointtype[player[i].waypoint]==wppause)
4719 player[i].pausetime=4;
4720 player[i].waypoint++;
4721 if(player[i].waypoint>player[i].numwaypoints-1)
4722 player[i].waypoint=0;
4727 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4728 player[i].forwardkeydown=1;
4730 player[i].forwardkeydown=0;
4731 player[i].leftkeydown=0;
4732 player[i].backkeydown=0;
4733 player[i].rightkeydown=0;
4734 player[i].crouchkeydown=0;
4735 player[i].attackkeydown=0;
4736 player[i].throwkeydown=0;
4738 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4739 if(!player[i].avoidsomething)
4740 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4742 XYZ leftpos,rightpos;
4743 float leftdist,rightdist;
4744 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4745 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4746 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4747 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4748 if(leftdist<rightdist)
4749 player[i].targetrotation+=90;
4751 player[i].targetrotation-=90;
4755 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4756 player[i].jumpkeydown=0;
4757 if((player[i].collided>.8&&player[i].jumppower>=5))
4758 player[i].jumpkeydown=1;
4763 if(player[i].howactive<=typesleeping)
4764 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4765 for(int j=0;j<numenvsounds;j++){
4766 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4767 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4768 2*(vol+vol*(player[i].creature==rabbittype)*3))
4769 player[i].aitype=attacktypecutoff;
4772 if(player[i].aitype!=passivetype){
4773 if(player[i].howactive==typesleeping)
4774 setAnimation(i,getupfromfrontanim);
4775 player[i].howactive=typeactive;
4779 if(player[i].howactive<typesleeping&&
4780 ((tutoriallevel!=1||cananger)&&hostile)&&
4782 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4783 player[i].occluded<25){
4784 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4785 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4786 player[i].aitype=attacktypecutoff;
4787 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4788 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4789 player[i].aitype=attacktypecutoff;
4792 if(player[i].creature==wolftype){
4794 for(int j=0;j<numplayers;j++){
4795 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4796 float smelldistance=50;
4797 if(j==0&&player[j].num_weapons>0){
4798 if(weapons.bloody[player[j].weaponids[0]])
4800 if(player[j].num_weapons==2)
4801 if(weapons.bloody[player[j].weaponids[1]])
4806 windsmell=windvector;
4807 Normalise(&windsmell);
4808 windsmell=windsmell*2+player[j].coords;
4809 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4810 player[i].aitype=attacktypecutoff;
4815 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4816 player[i].losupdatedelay=.2;
4817 for(int j=0;j<numplayers;j++){
4818 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4819 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4820 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4821 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4822 if((-1==checkcollide(
4823 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4824 player[i].scale+player[i].coords,
4825 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
4826 player[j].scale+player[j].coords)&&
4827 !player[j].isWallJump())||
4828 (player[j].targetanimation==hanganim&&
4829 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4830 player[i].lastseentime-=.2;
4831 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4832 player[i].lastseentime-=.4;
4834 player[i].lastseentime-=.6;
4836 if(player[i].lastseentime<=0){
4837 player[i].aitype=searchtype;
4838 player[i].lastchecktime=12;
4839 player[i].lastseen=player[j].coords;
4840 player[i].lastseentime=12;
4847 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4848 if(player[i].creature!=wolftype){
4849 player[i].stunned=.6;
4850 player[i].surprised=.6;
4852 if(player[i].creature==wolftype){
4853 player[i].stunned=.47;
4854 player[i].surprised=.47;
4862 if(player[i].aitype==searchtype){
4863 player[i].aiupdatedelay-=multiplier;
4864 player[i].losupdatedelay-=multiplier;
4865 if(!player[i].pause)
4866 player[i].lastseentime-=multiplier;
4867 player[i].lastchecktime-=multiplier;
4869 if(player[i].isRun()&&!player[i].onground){
4870 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4871 XYZ test2=player[i].coords+player[i].facing;
4873 XYZ test=player[i].coords+player[i].facing;
4875 j=checkcollide(test2,test,player[i].laststanding);
4877 j=checkcollide(test2,test);
4879 player[i].velocity=0;
4880 setAnimation(i,player[i].getStop());
4881 player[i].targetrotation+=180;
4882 player[i].stunned=.5;
4883 //player[i].aitype=passivetype;
4884 player[i].aitype=pathfindtype;
4885 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4886 player[i].finalpathfindpoint=-1;
4887 player[i].targetpathfindpoint=-1;
4888 player[i].lastpathfindpoint=-1;
4889 player[i].lastpathfindpoint2=-1;
4890 player[i].lastpathfindpoint3=-1;
4891 player[i].lastpathfindpoint4=-1;
4893 else player[i].laststanding=j;
4896 //check out last seen location
4897 if(player[i].aiupdatedelay<0){
4898 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4899 player[i].lookrotation=player[i].targetrotation;
4900 player[i].aiupdatedelay=.05;
4901 player[i].forwardkeydown=1;
4903 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4904 player[i].forwardkeydown=0;
4905 player[i].aiupdatedelay=1;
4906 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4907 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4908 player[i].lastchecktime=3;
4911 player[i].leftkeydown=0;
4912 player[i].backkeydown=0;
4913 player[i].rightkeydown=0;
4914 player[i].crouchkeydown=0;
4915 player[i].attackkeydown=0;
4916 player[i].throwkeydown=0;
4918 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4919 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4921 XYZ leftpos,rightpos;
4922 float leftdist,rightdist;
4923 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4924 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4925 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4926 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4927 if(leftdist<rightdist)player[i].targetrotation+=90;
4928 else player[i].targetrotation-=90;
4932 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4933 player[i].jumpkeydown=0;
4934 if((player[i].collided>.8&&player[i].jumppower>=5))
4935 player[i].jumpkeydown=1;
4937 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4938 for(int k=0;k<numenvsounds;k++){
4939 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4940 player[i].aitype=attacktypecutoff;
4944 if(!player[0].dead&&
4945 player[i].losupdatedelay<0&&
4947 player[i].occluded<2&&
4948 ((tutoriallevel!=1||cananger)&&hostile)){
4949 player[i].losupdatedelay=.2;
4950 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4951 player[i].aitype=attacktypecutoff;
4952 player[i].lastseentime=1;
4954 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4955 //TODO: factor out canSeePlayer()
4956 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4957 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4959 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4960 player[i].scale+player[i].coords,
4961 DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
4962 player[0].scale+player[0].coords)==-1)||
4963 (player[0].targetanimation==hanganim&&normaldotproduct(
4964 player[0].facing,player[i].coords-player[0].coords)<0)){
4965 /* //TODO: changed j to 0 on a whim, make sure this is correct
4966 (player[j].targetanimation==hanganim&&normaldotproduct(
4967 player[j].facing,player[i].coords-player[j].coords)<0)
4969 player[i].aitype=attacktypecutoff;
4970 player[i].lastseentime=1;
4974 if(player[i].lastseentime<0){
4975 //player[i].aitype=passivetype;
4977 player[i].aitype=pathfindtype;
4978 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4979 player[i].finalpathfindpoint=-1;
4980 player[i].targetpathfindpoint=-1;
4981 player[i].lastpathfindpoint=-1;
4982 player[i].lastpathfindpoint2=-1;
4983 player[i].lastpathfindpoint3=-1;
4984 player[i].lastpathfindpoint4=-1;
4988 if(player[i].aitype!=gethelptype)
4989 player[i].runninghowlong=0;
4991 //get help from buddies
4992 if(player[i].aitype==gethelptype){
4993 player[i].runninghowlong+=multiplier;
4994 player[i].aiupdatedelay-=multiplier;
4996 if(player[i].aiupdatedelay<0||player[i].ally==0){
4997 player[i].aiupdatedelay=.2;
5000 //TODO: factor out closest search somehow
5001 if(!player[i].ally){
5003 float closestdist=-1;
5004 for(int k=0;k<numplayers;k++){
5005 if(k!=i&&k!=0&&!player[k].dead&&
5006 player[k].howactive<typedead1&&
5007 !player[k].skeleton.free&&
5008 player[k].aitype==passivetype){
5009 float distance=findDistancefast(&player[i].coords,&player[k].coords);
5010 if(closestdist==-1||distance<closestdist){
5011 closestdist=distance;
5018 player[i].ally=closest;
5021 player[i].lastseen=player[0].coords;
5022 player[i].lastseentime=12;
5026 player[i].lastchecktime=12;
5028 XYZ facing=player[i].coords;
5029 XYZ flatfacing=player[player[i].ally].coords;
5030 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5031 flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
5032 if(-1!=checkcollide(facing,flatfacing))
5033 player[i].lastseentime-=.1;
5035 //no available ally, run back to player
5036 if(player[i].ally<=0||
5037 player[player[i].ally].skeleton.free||
5038 player[player[i].ally].aitype!=passivetype||
5039 player[i].lastseentime<=0){
5040 player[i].aitype=searchtype;
5041 player[i].lastseentime=12;
5045 if(player[i].ally>0){
5046 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5047 player[i].lookrotation=player[i].targetrotation;
5048 player[i].aiupdatedelay=.05;
5049 player[i].forwardkeydown=1;
5051 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
5052 player[i].aitype=searchtype;
5053 player[i].lastseentime=12;
5054 player[player[i].ally].aitype=searchtype;
5055 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5056 player[player[i].ally].lastseen=player[i].lastseen;
5057 player[player[i].ally].lastseentime=player[i].lastseentime;
5058 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5062 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5063 if(!player[i].avoidsomething)
5064 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5066 XYZ leftpos,rightpos;
5067 float leftdist,rightdist;
5068 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5069 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5070 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5071 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5072 if(leftdist<rightdist)
5073 player[i].targetrotation+=90;
5075 player[i].targetrotation-=90;
5080 player[i].leftkeydown=0;
5081 player[i].backkeydown=0;
5082 player[i].rightkeydown=0;
5083 player[i].crouchkeydown=0;
5084 player[i].attackkeydown=0;
5086 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5087 player[i].jumpkeydown=0;
5088 if(player[i].collided>.8&&player[i].jumppower>=5)
5089 player[i].jumpkeydown=1;
5092 //retreiving a weapon on the ground
5093 if(player[i].aitype==getweapontype){
5094 player[i].aiupdatedelay-=multiplier;
5095 player[i].lastchecktime-=multiplier;
5097 if(player[i].aiupdatedelay<0){
5098 player[i].aiupdatedelay=.2;
5101 if(player[i].ally<0){
5103 float closestdist=-1;
5104 for(int k=0;k<weapons.numweapons;k++)
5105 if(weapons.owner[k]==-1){
5106 float distance=findDistancefast(&player[i].coords,&weapons.position[k]);
5107 if(closestdist==-1||distance<closestdist){
5108 closestdist=distance;
5114 player[i].ally=closest;
5119 player[i].lastseentime=12;
5121 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5122 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5123 player[i].aitype=attacktypecutoff;
5124 player[i].lastseentime=1;
5127 if(player[i].ally>=0){
5128 if(weapons.owner[player[i].ally]!=-1||
5129 findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
5130 player[i].aitype=attacktypecutoff;
5131 player[i].lastseentime=1;
5133 //TODO: factor these out as moveToward()
5134 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[player[i].ally]);
5135 player[i].lookrotation=player[i].targetrotation;
5136 player[i].aiupdatedelay=.05;
5137 player[i].forwardkeydown=1;
5140 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5141 if(!player[i].avoidsomething)
5142 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5144 XYZ leftpos,rightpos;
5145 float leftdist,rightdist;
5146 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5147 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5148 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5149 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5150 if(leftdist<rightdist)
5151 player[i].targetrotation+=90;
5153 player[i].targetrotation-=90;
5158 player[i].leftkeydown=0;
5159 player[i].backkeydown=0;
5160 player[i].rightkeydown=0;
5161 player[i].attackkeydown=0;
5162 player[i].throwkeydown=1;
5163 player[i].crouchkeydown=0;
5164 if(player[i].targetanimation!=crouchremoveknifeanim&&
5165 player[i].targetanimation!=removeknifeanim)
5166 player[i].throwtogglekeydown=0;
5167 player[i].drawkeydown=0;
5169 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5170 player[i].jumpkeydown=0;
5171 if((player[i].collided>.8&&player[i].jumppower>=5))
5172 player[i].jumpkeydown=1;
5175 if(player[i].aitype==attacktypecutoff){
5176 player[i].aiupdatedelay-=multiplier;
5177 //dodge or reverse rabbit kicks, knife throws, flips
5178 if(player[i].damage<player[i].damagetolerance*2/3)
5179 if((player[0].targetanimation==rabbitkickanim||
5180 player[0].targetanimation==knifethrowanim||
5181 (player[0].isFlip()&&
5182 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5183 !player[0].skeleton.free&&
5184 (player[i].aiupdatedelay<.1)){
5185 player[i].attackkeydown=0;
5186 if(player[i].isIdle())
5187 player[i].crouchkeydown=1;
5188 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5189 if(weapons.type[player[0].weaponids[0]]==knife){
5190 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5191 if(abs(Random()%2==0))
5192 setAnimation(i,backhandspringanim);
5194 setAnimation(i,rollanim);
5195 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5196 player[i].wentforweapon=0;
5198 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5199 setAnimation(i,flipanim);
5202 player[i].forwardkeydown=0;
5203 player[i].aiupdatedelay=.02;
5205 //get confused by flips
5206 if(player[0].isFlip()&&
5207 !player[0].skeleton.free&&
5208 player[0].targetanimation!=walljumprightkickanim&&
5209 player[0].targetanimation!=walljumpleftkickanim){
5210 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5211 if((1-player[i].damage/player[i].damagetolerance)>.5)
5212 player[i].stunned=1;
5214 //go for weapon on the ground
5215 if(player[i].wentforweapon<3)
5216 for(int k=0;k<weapons.numweapons;k++)
5217 if(player[i].creature!=wolftype)
5218 if(player[i].num_weapons==0&&
5219 weapons.owner[k]==-1&&
5220 weapons.velocity[i].x==0&&
5221 weapons.velocity[i].z==0&&
5222 weapons.velocity[i].y==0){
5223 if(findDistancefast(&player[i].coords,&weapons.position[k])<16){
5224 player[i].wentforweapon++;
5225 player[i].lastchecktime=6;
5226 player[i].aitype=getweapontype;
5230 //dodge/reverse walljump kicks
5231 if(player[i].damage<player[i].damagetolerance/2)
5232 if(animation[player[i].targetanimation].height!=highheight)
5233 if(player[i].damage<player[i].damagetolerance*.5&&
5234 ((player[0].targetanimation==walljumprightkickanim||
5235 player[0].targetanimation==walljumpleftkickanim)&&
5236 ((player[i].aiupdatedelay<.15&&
5238 (player[i].aiupdatedelay<.08&&
5240 player[i].crouchkeydown=1;
5242 //walked off a ledge (?)
5243 if(player[i].isRun()&&!player[i].onground)
5244 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5245 XYZ test2=player[i].coords+player[i].facing;
5247 XYZ test=player[i].coords+player[i].facing;
5249 j=checkcollide(test2,test,player[i].laststanding);
5251 j=checkcollide(test2,test);
5253 player[i].velocity=0;
5254 setAnimation(i,player[i].getStop());
5255 player[i].targetrotation+=180;
5256 player[i].stunned=.5;
5257 player[i].aitype=pathfindtype;
5258 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5259 player[i].finalpathfindpoint=-1;
5260 player[i].targetpathfindpoint=-1;
5261 player[i].lastpathfindpoint=-1;
5262 player[i].lastpathfindpoint2=-1;
5263 player[i].lastpathfindpoint3=-1;
5264 player[i].lastpathfindpoint4=-1;
5266 player[i].laststanding=j;
5268 //lose sight of player in the air (?)
5269 if(player[0].coords.y>player[i].coords.y+5&&
5270 animation[player[0].targetanimation].height!=highheight&&
5271 !player[0].onterrain){
5272 player[i].aitype=pathfindtype;
5273 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5274 player[i].finalpathfindpoint=-1;
5275 player[i].targetpathfindpoint=-1;
5276 player[i].lastpathfindpoint=-1;
5277 player[i].lastpathfindpoint2=-1;
5278 player[i].lastpathfindpoint3=-1;
5279 player[i].lastpathfindpoint4=-1;
5281 //it's time to think (?)
5282 if(player[i].aiupdatedelay<0&&
5283 !animation[player[i].targetanimation].attack&&
5284 player[i].targetanimation!=staggerbackhighanim&&
5285 player[i].targetanimation!=staggerbackhardanim&&
5286 player[i].targetanimation!=backhandspringanim&&
5287 player[i].targetanimation!=dodgebackanim){
5289 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5290 player[i].drawkeydown=Random()%2;
5292 player[i].drawkeydown=0;
5293 player[i].rabbitkickenabled=Random()%2;
5295 XYZ rotatetarget=player[0].coords+player[0].velocity;
5296 XYZ targetpoint=player[0].coords;
5297 if(findDistancefast(&player[0].coords,&player[i].coords)<
5298 findDistancefast(&rotatetarget,&player[i].coords))
5299 targetpoint+=player[0].velocity*
5300 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5301 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5302 player[i].lookrotation=player[i].targetrotation;
5303 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5305 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5306 player[i].forwardkeydown=1;
5307 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5308 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5309 player[0].weaponactive!=-1)
5310 player[i].forwardkeydown=1;
5311 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5312 player[i].forwardkeydown=1;
5314 player[i].forwardkeydown=0;
5315 //chill out around the corpse
5317 player[i].forwardkeydown=0;
5319 player[i].forwardkeydown=1;
5320 if(Random()%100==0){
5321 player[i].aitype=pathfindtype;
5322 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5323 player[i].finalpathfindpoint=-1;
5324 player[i].targetpathfindpoint=-1;
5325 player[i].lastpathfindpoint=-1;
5326 player[i].lastpathfindpoint2=-1;
5327 player[i].lastpathfindpoint3=-1;
5328 player[i].lastpathfindpoint4=-1;
5331 player[i].leftkeydown=0;
5332 player[i].backkeydown=0;
5333 player[i].rightkeydown=0;
5334 player[i].crouchkeydown=0;
5335 player[i].throwkeydown=0;
5337 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5338 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5340 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5341 player[i].attackkeydown=1;
5343 player[i].attackkeydown=0;
5344 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5345 player[i].attackkeydown=0;
5348 if(player[i].aitype!=playercontrolled&&
5349 (player[i].isIdle()||
5350 player[i].isCrouch()||
5351 player[i].isRun())){
5353 for(int j=0;j<numplayers;j++)
5354 if(j!=i&&!player[j].skeleton.free&&
5355 player[j].hasvictim&&
5356 (tutoriallevel==1&&reversaltrain||
5357 Random()%2==0&&difficulty==2||
5358 Random()%4==0&&difficulty==1||
5359 Random()%8==0&&difficulty==0||
5360 player[j].lastattack2==player[j].targetanimation&&
5361 player[j].lastattack3==player[j].targetanimation&&
5362 (Random()%2==0||difficulty==2)||
5363 (player[i].isIdle()||player[i].isRun())&&
5364 player[j].weaponactive!=-1||
5365 player[j].targetanimation==swordslashanim&&
5366 player[i].weaponactive!=-1||
5367 player[j].targetanimation==staffhitanim||
5368 player[j].targetanimation==staffspinhitanim))
5369 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5370 player[j].victim==&player[i]&&
5371 (player[j].targetanimation==sweepanim||
5372 player[j].targetanimation==spinkickanim||
5373 player[j].targetanimation==staffhitanim||
5374 player[j].targetanimation==staffspinhitanim||
5375 player[j].targetanimation==winduppunchanim||
5376 player[j].targetanimation==upunchanim||
5377 player[j].targetanimation==wolfslapanim||
5378 player[j].targetanimation==knifeslashstartanim||
5379 player[j].targetanimation==swordslashanim&&
5380 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5381 player[i].weaponactive!=-1))){
5388 player[target].Reverse();
5391 if(player[i].collided<1)
5392 player[i].jumpkeydown=0;
5393 if(player[i].collided>.8&&player[i].jumppower>=5||
5394 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5395 player[i].onterrain&&
5396 player[i].creature==rabbittype)
5397 player[i].jumpkeydown=1;
5398 //TODO: why are we controlling the human?
5399 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5400 player[0].jumpkeydown=0;
5401 if(player[0].targetanimation==jumpdownanim&&
5402 findDistancefast(&player[0].coords,&player[i].coords)<40)
5403 player[i].crouchkeydown=1;
5404 if(player[i].jumpkeydown)
5405 player[i].attackkeydown=0;
5407 if(tutoriallevel==1)
5409 player[i].attackkeydown=0;
5412 XYZ facing=player[i].coords;
5413 XYZ flatfacing=player[0].coords;
5414 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5415 flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
5416 if(player[i].occluded>=2)
5417 if(-1!=checkcollide(facing,flatfacing)){
5418 if(!player[i].pause)
5419 player[i].lastseentime-=.2;
5420 if(player[i].lastseentime<=0&&
5421 (player[i].creature!=wolftype||
5422 player[i].weaponstuck==-1)){
5423 player[i].aitype=searchtype;
5424 player[i].lastchecktime=12;
5425 player[i].lastseen=player[0].coords;
5426 player[i].lastseentime=12;
5429 player[i].lastseentime=1;
5432 if(animation[player[0].targetanimation].height==highheight&&
5433 (player[i].aitype==attacktypecutoff||
5434 player[i].aitype==searchtype))
5435 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5436 XYZ test=player[0].coords;
5438 if(-1==checkcollide(player[0].coords,test))
5439 player[i].stunned=1;
5442 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5443 player[i].stunned>0||
5444 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5446 player[i].lastseentime=1;
5447 player[i].targetrotation=player[i].rotation;
5448 player[i].forwardkeydown=0;
5449 player[i].leftkeydown=0;
5450 player[i].backkeydown=0;
5451 player[i].rightkeydown=0;
5452 player[i].jumpkeydown=0;
5453 player[i].attackkeydown=0;
5454 player[i].crouchkeydown=0;
5455 player[i].throwkeydown=0;
5463 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5466 if(player[i].aitype==attacktypecutoff){
5467 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5468 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5469 }else if(player[i].howactive>=typesleeping){
5470 player[i].targetheadrotation=player[i].targetrotation;
5471 player[i].targetheadrotation2=0;
5473 if(player[i].interestdelay<=0){
5474 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5475 player[i].headtarget=player[i].coords;
5476 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5477 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5478 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5479 player[i].headtarget+=player[i].facing*1.5;
5481 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5482 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5488 Values of mainmenu :
5490 2 Menu pause (resume/end game)
5492 4 Controls configuration menu
5493 5 Main game menu (choose level or challenge)
5494 6 Deleting user menu
5495 7 User managment menu (select/add)
5496 8 Choose difficulty menu
5497 9 Challenge level selection menu
5498 10 End of the campaign congratulation (is that really a menu?)
5499 11 Same that 9 ??? => unused
5500 18 stereo configuration
5503 void Game::MenuTick(){
5506 // some specific case where we do something even if the left mouse button is not pressed.
5507 if((mainmenu==5) && (endgame==2)) {
5508 accountactive->endGame();
5513 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
5514 stereoseparation-=0.001;
5516 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5522 if(gameon) { //resume
5524 pause_sound(stream_menutheme);
5525 resume_stream(leveltheme);
5527 fireSound(firestartsound);
5529 mainmenu=(accountactive?5:7);
5537 if(newdetail>2) newdetail=detail;
5538 if(newdetail<0) newdetail=detail;
5539 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5540 if(newscreenwidth<0) newscreenwidth=screenwidth;
5541 if(newscreenheight>3000) newscreenheight=screenheight;
5542 if(newscreenheight<0) newscreenheight=screenheight;
5547 if(gameon){ //end game
5552 pause_sound(stream_menutheme);
5559 bool isCustomResolution,found;
5562 extern SDL_Rect **resolutions;
5563 isCustomResolution = true;
5565 for(int i = 0; (!found) && (resolutions[i]); i++) {
5566 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5567 isCustomResolution = false;
5569 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5571 if(resolutions[i] != NULL) {
5572 newscreenwidth = (int) resolutions[i]->w;
5573 newscreenheight = (int) resolutions[i]->h;
5574 } else if(isCustomResolution){
5575 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5576 newscreenwidth = (int) resolutions[0]->w;
5577 newscreenheight = (int) resolutions[0]->h;
5579 newscreenwidth = screenwidth;
5580 newscreenheight = screenheight;
5583 newscreenwidth = (int) resolutions[0]->w;
5584 newscreenheight = (int) resolutions[0]->h;
5591 newscreenwidth = (int) resolutions[0]->w;
5592 newscreenheight = (int) resolutions[0]->h;
5597 if(newdetail>2) newdetail=0;
5601 if(bloodtoggle>2) bloodtoggle=0;
5605 if(difficulty>2) difficulty=0;
5608 ismotionblur = !ismotionblur;
5614 musictoggle = !musictoggle;
5617 emit_stream_np(stream_menutheme);
5619 pause_sound(leveltheme);
5620 pause_sound(stream_fighttheme);
5621 pause_sound(stream_menutheme);
5623 for(int i=0;i<4;i++){
5624 oldmusicvolume[i]=0;
5639 SaveSettings(*this);
5640 mainmenu=gameon?2:1;
5643 invertmouse = !invertmouse;
5646 usermousesensitivity+=.2;
5647 if(usermousesensitivity>2) usermousesensitivity=.2;
5651 if(volume>1.0001f) volume=0;
5652 OPENAL_SetSFXMasterVolume((int)(volume*255));
5657 newstereomode = stereomode;
5662 showdamagebar = !showdamagebar;
5669 if(selected<9 && keyselect==-1)
5683 if((selected-NB_CAMPAIGN_MENU_ITEM-1 >= accountactive->getCampaignChoicesMade())) {
5693 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-1-accountactive->getCampaignChoicesMade();
5696 Loadlevel(campaignmapname[campaignchoicewhich[whichchoice]]);
5700 pause_sound(stream_menutheme);
5717 pause_sound(stream_menutheme);
5726 mainmenu=(gameon?2:1);
5732 vector<string> campaigns = ListCampaigns();
5733 vector<string>::iterator c;
5734 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5735 if(!campaigns.empty())
5736 accountactive->setCurrentCampaign(campaigns.front());
5739 if(c==campaigns.end())
5740 c=campaigns.begin();
5741 accountactive->setCurrentCampaign(*c);
5744 if(Mainmenuitems[7])
5745 glDeleteTextures(1,&Mainmenuitems[7]);
5746 ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
5748 LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
5750 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
5759 accountactive = Account::destroy(accountactive);
5761 } else if(selected==2) {
5768 if(selected==0 && Account::getNbAccounts()<8){
5770 } else if (selected < Account::getNbAccounts()+1) {
5773 accountactive=Account::get(selected-1);
5774 } else if (selected == Account::getNbAccounts()+1) {
5777 for(int j=0;j<255;j++){
5778 displaytext[0][j]=0;
5789 accountactive->setDifficulty(selected);
5793 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5801 targetlevel=selected;
5802 if(firstload)TickOnceAfter();
5803 if(!firstload)LoadStuff();
5804 else Loadlevel(selected);
5809 pause_sound(stream_menutheme);
5811 if(selected==numchallengelevels){
5826 stereoseparation+=0.001;
5830 newstereomode = (StereoMode)(newstereomode + 1);
5831 while(!CanInitStereo(newstereomode)){
5832 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5833 newstereomode = (StereoMode)(newstereomode + 1);
5834 if(newstereomode >= stereoCount)
5835 newstereomode = stereoNone;
5837 } else if(selected==2) {
5838 stereoreverse = !stereoreverse;
5839 } else if(selected==3) {
5843 stereomode = newstereomode;
5844 InitStereo(stereomode);
5851 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5854 SaveSettings(*this);
5858 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5861 inputText(displaytext[0],&displayselected,&displaychars[0]);
5862 if(!waiting) { // the input as finished
5863 if(displaychars[0]){ // with enter
5864 accountactive = Account::add(string(displaytext[0]));
5870 fireSound(firestartsound);
5872 for(int i=0;i<255;i++){
5873 displaytext[0][i]=0;
5882 displayblinkdelay-=multiplier;
5883 if(displayblinkdelay<=0){
5884 displayblinkdelay=.3;
5885 displayblink=1-displayblink;
5891 static XYZ facing,flatfacing;
5894 for(int i=0;i<15;i++){
5895 displaytime[i]+=multiplier;
5898 keyboardfrozen=false;
5901 if(Input::isKeyPressed(SDLK_F6)){
5902 if(Input::isKeyDown(SDLK_LSHIFT))
5905 stereoreverse=false;
5908 printf("Stereo reversed\n");
5910 printf("Stereo unreversed\n");
5913 if(Input::isKeyDown(SDLK_F7)){
5914 if(Input::isKeyDown(SDLK_LSHIFT))
5915 stereoseparation -= 0.001;
5917 stereoseparation -= 0.010;
5918 printf("Stereo decreased increased to %f\n", stereoseparation);
5921 if(Input::isKeyDown(SDLK_F8)){
5922 if(Input::isKeyDown(SDLK_LSHIFT))
5923 stereoseparation += 0.001;
5925 stereoseparation += 0.010;
5926 printf("Stereo separation increased to %f\n", stereoseparation);
5930 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5931 if(tutorialstage!=51)
5932 tutorialstagetime=tutorialmaxtime;
5933 emit_sound_np(consolefailsound, 128.);
5937 Values of mainmenu :
5939 2 Menu pause (resume/end game)
5941 4 Controls configuration menu
5942 5 Main game menu (choose level or challenge)
5943 6 Deleting user menu
5944 7 User managment menu (select/add)
5945 8 Choose difficulty menu
5946 9 Challenge level selection menu
5947 10 End of the campaign congratulation (is that really a menu?)
5948 11 Same that 9 ??? => unused
5949 18 stereo configuration
5954 if(mainmenu&&endgame==1)
5956 //go to level select after completing a campaign level
5957 if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1) {
5964 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5965 emit_stream_np(stream_menutheme);
5966 pause_sound(leveltheme);
5970 //escape key pressed
5971 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5972 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5973 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
5975 if(mainmenu==0&&!winfreeze)
5977 else if(mainmenu==1||mainmenu==2){
5978 mainmenu=0; //unpause
5981 if(musictoggle&&(mainmenu==1||mainmenu==2)){
5982 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5983 emit_stream_np(stream_menutheme);
5984 pause_sound(leveltheme);
5986 //on resume, play level music
5988 pause_sound(stream_menutheme);
5989 resume_stream(leveltheme);
5991 //finished with settings menu
5993 SaveSettings(*this);
5996 if(mainmenu>=3&&mainmenu!=8){
6003 mainmenu=gameon?2:1; break;
6006 case 6: case 7: case 9: case 10:
6017 if(hostile==1)hostiletime+=multiplier;
6019 if(!winfreeze)leveltime+=multiplier;
6022 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6025 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6029 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6033 inputText(displaytext[0],&displayselected,&displaychars[0]);
6035 if(displaychars[0]){
6036 for(int j=0;j<255;j++)
6037 displaytext[0][j]=0;
6044 displayblinkdelay-=multiplier;
6045 if(displayblinkdelay<=0){
6046 displayblinkdelay=.3;
6047 displayblink=1-displayblink;
6051 keyboardfrozen=true;
6053 if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){
6056 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6065 if(console&&!Input::isKeyDown(SDLK_LMETA)){
6066 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6069 if(consolechars[0]>0){
6070 consoletext[0][consolechars[0]]=' ';
6071 cmd_dispatch(this, consoletext[0]);
6072 for(int k=14;k>=1;k--){
6073 for(int j=0;j<255;j++)
6074 consoletext[k][j]=consoletext[k-1][j];
6075 consolechars[k]=consolechars[k-1];
6077 for(int j=0;j<255;j++)
6078 consoletext[0][j]=0;
6084 consoleblinkdelay-=multiplier;
6085 if(consoleblinkdelay<=0){
6086 consoleblinkdelay=.3;
6087 consoleblink=1-consoleblink;
6093 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6096 SaveSettings(*this);
6100 static int oldwinfreeze;
6101 if(winfreeze&&!oldwinfreeze){
6102 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6103 emit_sound_np(consolesuccesssound);
6106 oldwinfreeze=winfreeze;
6110 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6113 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6117 } else if(winfreeze) {
6125 //TODO: what is this test?
6126 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6131 talkdelay-=multiplier;
6133 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6134 for(int i=0;i<numdialogues;i++){
6135 int realdialoguetype;
6137 if(dialoguetype[i]>49){
6138 realdialoguetype=dialoguetype[i]-50;
6141 else if(dialoguetype[i]>39){
6142 realdialoguetype=dialoguetype[i]-40;
6145 else if(dialoguetype[i]>29){
6146 realdialoguetype=dialoguetype[i]-30;
6149 else if(dialoguetype[i]>19){
6150 realdialoguetype=dialoguetype[i]-20;
6153 else if(dialoguetype[i]>9){
6154 realdialoguetype=dialoguetype[i]-10;
6158 realdialoguetype=dialoguetype[i];
6161 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6162 realdialoguetype<numplayers&&
6163 realdialoguetype>0&&
6164 (dialoguegonethrough[i]==0||!special)&&
6165 (special||Input::isKeyPressed(attackkey))){
6166 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6167 player[realdialoguetype].howactive>=typedead1||
6168 dialoguetype[i]>40&&dialoguetype[i]<50){
6170 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6171 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6172 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6173 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6174 player[participantfocus[whichdialogue][j]].velocity=0;
6175 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6176 player[participantfocus[whichdialogue][j]].targetframe=0;
6181 dialoguegonethrough[i]++;
6182 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6183 playdialogueboxsound();
6189 windvar+=multiplier;
6190 smoketex+=multiplier;
6191 tutorialstagetime+=multiplier;
6194 static float hotspotvisual[40];
6198 for(int i=0;i<numhotspots;i++)
6199 hotspotvisual[i]-=multiplier/320;
6201 for(int i=0;i<numhotspots;i++){
6202 //if(hotspottype[i]<=10)
6203 while(hotspotvisual[i]<0){
6205 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6206 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6207 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6208 hotspotsprite+=hotspot[i];
6209 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6210 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6214 for(int i=0;i<numhotspots;i++){
6215 if(hotspottype[i]<=10&&hotspottype[i]>0){
6216 hotspot[i]=player[hotspottype[i]].coords;
6227 if(tutoriallevel!=1){
6230 bonus!=spinecrusher&&
6231 bonus!=tracheotomy&&
6234 emit_sound_np(consolesuccesssound);
6236 } else if(bonustime==0){
6237 emit_sound_np(fireendsound);
6240 if(bonus!=solidhit&&
6242 bonus!=threexcombo&&
6247 bonusnum[bonus]+=0.15;
6250 bonusvalue/=bonusnum[bonus];
6251 bonustotal+=bonusvalue;
6253 bonustime+=multiplier;
6256 if(environment==snowyenvironment){
6257 precipdelay-=multiplier;
6258 while(precipdelay<0){
6262 XYZ footvel,footpoint;
6265 footpoint=viewer+viewerfacing*6;
6266 footpoint.y+=((float)abs(Random()%1200))/100-6;
6267 footpoint.x+=((float)abs(Random()%1200))/100-6;
6268 footpoint.z+=((float)abs(Random()%1200))/100-6;
6269 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6274 doAerialAcrobatics();
6277 static XYZ oldviewer;
6281 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6282 player[0].leftkeydown=Input::isKeyDown(leftkey);
6283 player[0].backkeydown=Input::isKeyDown(backkey);
6284 player[0].rightkeydown=Input::isKeyDown(rightkey);
6285 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6286 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6287 player[0].drawkeydown=Input::isKeyDown(drawkey);
6288 player[0].throwkeydown=Input::isKeyDown(throwkey);
6292 player[0].forwardkeydown=0;
6293 player[0].leftkeydown=0;
6294 player[0].backkeydown=0;
6295 player[0].rightkeydown=0;
6296 player[0].jumpkeydown=0;
6297 player[0].crouchkeydown=0;
6298 player[0].drawkeydown=0;
6299 player[0].throwkeydown=0;
6302 if(!player[0].jumpkeydown)
6303 player[0].jumpclimb=0;
6312 facing=DoRotation(facing,-rotation2,0,0);
6313 facing=DoRotation(facing,0,0-rotation,0);
6318 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6320 if(Input::isKeyDown(forwardkey))
6321 viewer+=facing*multiplier*4;
6322 if(Input::isKeyDown(backkey))
6323 viewer-=facing*multiplier*4;
6324 if(Input::isKeyDown(leftkey))
6325 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6326 if(Input::isKeyDown(rightkey))
6327 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6328 if(Input::isKeyDown(jumpkey))
6329 viewer.y+=multiplier*4;
6330 if(Input::isKeyDown(crouchkey))
6331 viewer.y-=multiplier*4;
6332 if( Input::isKeyPressed(SDLK_1)||
6333 Input::isKeyPressed(SDLK_2)||
6334 Input::isKeyPressed(SDLK_3)||
6335 Input::isKeyPressed(SDLK_4)||
6336 Input::isKeyPressed(SDLK_5)||
6337 Input::isKeyPressed(SDLK_6)||
6338 Input::isKeyPressed(SDLK_7)||
6339 Input::isKeyPressed(SDLK_8)||
6340 Input::isKeyPressed(SDLK_9)||
6341 Input::isKeyPressed(SDLK_0)||
6342 Input::isKeyPressed(SDLK_MINUS)){
6344 if(Input::isKeyPressed(SDLK_1))whichend=1;
6345 if(Input::isKeyPressed(SDLK_2))whichend=2;
6346 if(Input::isKeyPressed(SDLK_3))whichend=3;
6347 if(Input::isKeyPressed(SDLK_4))whichend=4;
6348 if(Input::isKeyPressed(SDLK_5))whichend=5;
6349 if(Input::isKeyPressed(SDLK_6))whichend=6;
6350 if(Input::isKeyPressed(SDLK_7))whichend=7;
6351 if(Input::isKeyPressed(SDLK_8))whichend=8;
6352 if(Input::isKeyPressed(SDLK_9))whichend=9;
6353 if(Input::isKeyPressed(SDLK_0))whichend=0;
6354 if(Input::isKeyPressed(SDLK_MINUS))
6357 participantfocus[whichdialogue][indialogue]=whichend;
6358 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6359 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6362 participantfocus[whichdialogue][indialogue]=-1;
6364 if(player[participantfocus[whichdialogue][indialogue]].dead){
6369 dialoguecamera[whichdialogue][indialogue]=viewer;
6370 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6371 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6373 if(indialogue<numdialogueboxes[whichdialogue]){
6374 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6375 playdialogueboxsound();
6379 for(int j=0;j<numplayers;j++){
6380 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6383 //TODO: should these be KeyDown or KeyPressed?
6384 if( Input::isKeyDown(SDLK_KP1)||
6385 Input::isKeyDown(SDLK_KP2)||
6386 Input::isKeyDown(SDLK_KP3)||
6387 Input::isKeyDown(SDLK_KP4)||
6388 Input::isKeyDown(SDLK_KP5)||
6389 Input::isKeyDown(SDLK_KP6)||
6390 Input::isKeyDown(SDLK_KP7)||
6391 Input::isKeyDown(SDLK_KP8)||
6392 Input::isKeyDown(SDLK_KP9)||
6393 Input::isKeyDown(SDLK_KP0)){
6395 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6396 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6397 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6398 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6399 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6400 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6401 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6402 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6403 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6404 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6405 participantfacing[whichdialogue][indialogue][whichend]=facing;
6407 if(indialogue>=numdialogueboxes[whichdialogue]){
6414 pause_sound(whooshsound);
6415 viewer=dialoguecamera[whichdialogue][indialogue];
6416 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6417 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6418 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6419 if(dialoguetime>0.5)
6420 if( Input::isKeyPressed(SDLK_1)||
6421 Input::isKeyPressed(SDLK_2)||
6422 Input::isKeyPressed(SDLK_3)||
6423 Input::isKeyPressed(SDLK_4)||
6424 Input::isKeyPressed(SDLK_5)||
6425 Input::isKeyPressed(SDLK_6)||
6426 Input::isKeyPressed(SDLK_7)||
6427 Input::isKeyPressed(SDLK_8)||
6428 Input::isKeyPressed(SDLK_9)||
6429 Input::isKeyPressed(SDLK_0)||
6430 Input::isKeyPressed(SDLK_MINUS)||
6431 Input::isKeyPressed(attackkey)){
6433 if(indialogue<numdialogueboxes[whichdialogue]){
6434 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6435 playdialogueboxsound();
6436 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6437 hotspot[numhotspots]=player[0].coords;
6438 hotspotsize[numhotspots]=10;
6439 hotspottype[numhotspots]=-1;
6443 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6447 if(player[participantfocus[whichdialogue][indialogue]].dead){
6455 if(indialogue>=numdialogueboxes[whichdialogue]){
6459 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6462 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6465 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6467 for(int i=1;i<numplayers;i++){
6468 player[i].aitype = attacktypecutoff;
6475 if(!player[0].jumpkeydown){
6476 player[0].jumptogglekeydown=0;
6478 if(player[0].jumpkeydown&&
6479 player[0].targetanimation!=jumpupanim&&
6480 player[0].targetanimation!=jumpdownanim&&
6481 !player[0].isFlip())
6482 player[0].jumptogglekeydown=1;
6485 dialoguetime+=multiplier;
6486 hawkrotation+=multiplier*25;
6488 realhawkcoords.x=25;
6489 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6490 hawkcalldelay-=multiplier/2;
6492 if(hawkcalldelay<=0){
6493 emit_sound_at(hawksound, realhawkcoords);
6495 hawkcalldelay=16+abs(Random()%8);
6502 doPlayerCollisions();
6506 for(int k=0;k<numplayers;k++)
6507 if(k!=0&&player[k].immobile)
6508 player[k].coords=player[k].realoldcoords;
6510 for(int k=0;k<numplayers;k++){
6511 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6512 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6513 player[k].DoDamage(1000);
6519 static bool respawnkeydown;
6522 (Input::isKeyDown(SDLK_z)&&
6523 Input::isKeyDown(SDLK_LMETA)&&
6525 (Input::isKeyDown(jumpkey)&&
6529 targetlevel=whichlevel;
6533 if(!Input::isKeyDown(jumpkey))
6535 if(Input::isKeyDown(jumpkey))
6541 static bool movekey;
6544 for(int i=0;i<numplayers;i++){
6545 static float oldtargetrotation;
6546 if(!player[i].skeleton.free){
6547 oldtargetrotation=player[i].targetrotation;
6548 if(i==0&&indialogue==-1){
6549 //TODO: refactor repetitive code
6550 if(!animation[player[0].targetanimation].attack&&
6551 player[0].targetanimation!=staggerbackhighanim&&
6552 player[0].targetanimation!=staggerbackhardanim&&
6553 player[0].targetanimation!=crouchremoveknifeanim&&
6554 player[0].targetanimation!=removeknifeanim&&
6555 player[0].targetanimation!=backhandspringanim&&
6556 player[0].targetanimation!=dodgebackanim&&
6557 player[0].targetanimation!=walljumprightkickanim&&
6558 player[0].targetanimation!=walljumpleftkickanim){
6560 player[0].targetrotation=0;
6562 player[0].targetrotation=-rotation+180;
6568 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6572 facing=DoRotation(facing,-rotation2,0,0);
6573 facing=DoRotation(facing,0,0-rotation,0);
6576 player[0].lookrotation=-rotation;
6578 player[i].targetheadrotation=rotation;
6579 player[i].targetheadrotation2=rotation2;
6581 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6582 if(!animation[player[i].targetanimation].attack&&
6583 player[i].targetanimation!=staggerbackhighanim&&
6584 player[i].targetanimation!=staggerbackhardanim&&
6585 player[i].targetanimation!=crouchremoveknifeanim&&
6586 player[i].targetanimation!=removeknifeanim&&
6587 player[i].targetanimation!=backhandspringanim&&
6588 player[i].targetanimation!=dodgebackanim&&
6589 player[i].targetanimation!=walljumprightkickanim&&
6590 player[i].targetanimation!=walljumpleftkickanim){
6591 player[i].targetrotation=-player[i].lookrotation+180;
6597 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6599 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6600 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6602 player[i].targetheadrotation=player[i].lookrotation;
6603 player[i].targetheadrotation2=player[i].lookrotation2;
6606 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6607 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6613 player[i].avoidsomething=0;
6615 //avoid flaming things
6616 for(int j=0;j<objects.numobjects;j++)
6617 if(objects.onfire[j])
6618 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6619 if( findDistancefast(&player[i].coords,&objects.position[j])<
6620 findDistancefast(&player[i].coords,&player[0].coords)){
6621 player[i].collided=0;
6622 player[i].avoidcollided=1;
6623 if(player[i].avoidsomething==0||
6624 findDistancefast(&player[i].coords,&objects.position[j])<
6625 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6626 player[i].avoidwhere=objects.position[j];
6627 player[i].avoidsomething=1;
6631 //avoid flaming players
6632 for(int j=0;j<numplayers;j++)
6633 if(player[j].onfire)
6634 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6635 if( findDistancefast(&player[i].coords,&player[j].coords)<
6636 findDistancefast(&player[i].coords,&player[0].coords)){
6637 player[i].collided=0;
6638 player[i].avoidcollided=1;
6639 if(player[i].avoidsomething==0||
6640 findDistancefast(&player[i].coords,&player[j].coords)<
6641 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6642 player[i].avoidwhere=player[j].coords;
6643 player[i].avoidsomething=1;
6647 if(player[i].collided>.8)
6648 player[i].avoidcollided=0;
6652 if(animation[player[i].targetanimation].attack==reversed){
6653 //player[i].targetrotation=player[i].rotation;
6654 player[i].forwardkeydown=0;
6655 player[i].leftkeydown=0;
6656 player[i].backkeydown=0;
6657 player[i].rightkeydown=0;
6658 player[i].jumpkeydown=0;
6659 player[i].attackkeydown=0;
6660 //player[i].crouchkeydown=0;
6661 player[i].throwkeydown=0;
6665 player[i].forwardkeydown=0;
6666 player[i].leftkeydown=0;
6667 player[i].backkeydown=0;
6668 player[i].rightkeydown=0;
6669 player[i].jumpkeydown=0;
6670 player[i].crouchkeydown=0;
6671 player[i].drawkeydown=0;
6672 player[i].throwkeydown=0;
6675 if(player[i].collided<-.3)
6676 player[i].collided=-.3;
6677 if(player[i].collided>1)
6678 player[i].collided=1;
6679 player[i].collided-=multiplier*4;
6680 player[i].whichdirectiondelay-=multiplier;
6681 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6682 player[i].avoidcollided=-.3;
6683 player[i].whichdirection=abs(Random()%2);
6684 player[i].whichdirectiondelay=.4;
6686 if(player[i].avoidcollided>1)
6687 player[i].avoidcollided=1;
6688 player[i].avoidcollided-=multiplier/4;
6689 if(!player[i].skeleton.free){
6690 player[i].stunned-=multiplier;
6691 player[i].surprised-=multiplier;
6693 if(i!=0&&player[i].surprised<=0&&
6694 player[i].aitype==attacktypecutoff&&
6696 !player[i].skeleton.free&&
6697 animation[player[i].targetanimation].attack==neutral)
6700 if(!player[i].throwkeydown)
6701 player[i].throwtogglekeydown=0;
6704 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6705 if(player[i].weaponactive==-1&&
6706 player[i].num_weapons<2&&
6707 (player[i].isIdle()||
6708 player[i].isCrouch()||
6709 player[i].targetanimation==sneakanim||
6710 player[i].targetanimation==rollanim||
6711 player[i].targetanimation==backhandspringanim||
6712 player[i].isFlip()||
6713 player[i].isFlip()||
6714 player[i].aitype!=playercontrolled)){
6715 for(int j=0;j<weapons.numweapons;j++){
6716 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6717 player[i].aitype==playercontrolled)&&
6718 weapons.owner[j]==-1&&
6719 player[i].weaponactive==-1)
6720 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
6721 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
6722 if(player[i].isCrouch()||
6723 player[i].targetanimation==sneakanim||
6725 player[i].isIdle()||
6726 player[i].aitype!=playercontrolled){
6727 player[i].throwtogglekeydown=1;
6728 setAnimation(i,crouchremoveknifeanim);
6729 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6730 player[i].hasvictim=0;
6732 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6733 player[i].throwtogglekeydown=1;
6734 player[i].hasvictim=0;
6736 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6737 player[i].aitype==playercontrolled)&&
6738 weapons.owner[j]==-1||
6740 weapons.owner[j]==player[i].victim->id)
6741 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1)
6742 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
6743 if(weapons.type[j]!=staff)
6744 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6746 player[i].weaponactive=0;
6747 weapons.owner[j]=player[i].id;
6748 if(player[i].num_weapons>0)
6749 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6750 player[i].num_weapons++;
6751 player[i].weaponids[0]=j;
6754 }else if((player[i].isIdle()||
6755 player[i].isFlip()||
6756 player[i].aitype!=playercontrolled)&&
6757 findDistancefast(&player[i].coords,&weapons.position[j])<5&&
6758 player[i].coords.y<weapons.position[j].y){
6759 if(!player[i].isFlip()){
6760 player[i].throwtogglekeydown=1;
6761 setAnimation(i,removeknifeanim);
6762 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6764 if(player[i].isFlip()){
6765 player[i].throwtogglekeydown=1;
6766 player[i].hasvictim=0;
6768 for(int k=0;k<weapons.numweapons;k++){
6769 if(player[i].weaponactive==-1)
6770 if((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0||
6771 player[i].aitype==playercontrolled)&&
6772 weapons.owner[k]==-1||
6774 weapons.owner[k]==player[i].victim->id)
6775 if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&
6776 player[i].weaponactive==-1){
6777 if(weapons.type[k]!=staff)
6778 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6780 player[i].weaponactive=0;
6781 weapons.owner[k]=player[i].id;
6782 if(player[i].num_weapons>0)
6783 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6784 player[i].num_weapons++;
6785 player[i].weaponids[0]=k;
6792 if(player[i].isCrouch()||
6793 player[i].targetanimation==sneakanim||
6795 player[i].isIdle()||player[i].targetanimation==rollanim||
6796 player[i].targetanimation==backhandspringanim){
6798 for(int j=0;j<numplayers;j++){
6799 if(player[i].weaponactive==-1)
6801 if(player[j].num_weapons&&
6802 player[j].skeleton.free&&
6803 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6804 (((player[j].skeleton.forward.y<0&&
6805 player[j].weaponstuckwhere==0)||
6806 (player[j].skeleton.forward.y>0&&
6807 player[j].weaponstuckwhere==1))||
6808 player[j].weaponstuck==-1||
6809 player[j].num_weapons>1)){
6810 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6811 player[i].throwtogglekeydown=1;
6812 player[i].victim=&player[j];
6813 player[i].hasvictim=1;
6814 setAnimation(i,crouchremoveknifeanim);
6815 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6817 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6818 player[i].throwtogglekeydown=1;
6819 player[i].victim=&player[j];
6820 player[i].hasvictim=1;
6821 int k = player[j].weaponids[0];
6822 if(player[i].hasvictim){
6825 if(player[i].victim->weaponstuck!=-1){
6826 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6831 if(weapons.type[k]!=staff)
6832 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6835 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6837 player[i].weaponactive=0;
6838 if(weapons.owner[k]!=-1){
6839 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6840 else player[i].victim->num_weapons=1;
6842 player[i].victim->skeleton.longdead=0;
6843 player[i].victim->skeleton.free=1;
6844 player[i].victim->skeleton.broken=0;
6846 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6847 player[i].victim->skeleton.joints[l].velchange=0;
6848 player[i].victim->skeleton.joints[l].locked=0;
6854 Normalise(&relative);
6855 XYZ footvel,footpoint;
6857 footpoint=weapons.position[k];
6858 if(player[i].victim->weaponstuck!=-1){
6859 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6860 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6861 weapons.bloody[k]=2;
6862 weapons.blooddrip[k]=5;
6863 player[i].victim->weaponstuck=-1;
6864 player[i].victim->bloodloss+=2000;
6865 player[i].victim->DoDamage(2000);
6868 if(player[i].victim->num_weapons>0){
6869 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6870 if(player[i].victim->weaponids[0]==k)
6871 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6874 player[i].victim->weaponactive=-1;
6876 playerJoint(player[i].victim,abdomen).velocity+=relative*6;
6877 playerJoint(player[i].victim,neck).velocity+=relative*6;
6878 playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
6879 playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
6882 if(player[i].num_weapons>0){
6883 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6885 player[i].num_weapons++;
6886 player[i].weaponids[0]=k;
6893 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6894 if(weapons.type[player[i].weaponids[0]]==knife){
6895 if(player[i].isIdle()||
6897 player[i].isCrouch()||
6898 player[i].targetanimation==sneakanim||
6901 for(int j=0;j<numplayers;j++){
6903 if(tutoriallevel!=1||tutorialstage==49)
6905 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6906 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6907 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6908 !player[j].skeleton.free&&
6909 -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)){
6910 if(!player[i].isFlip()){
6911 player[i].throwtogglekeydown=1;
6912 player[i].victim=&player[j];
6913 setAnimation(i,knifethrowanim);
6914 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6915 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6917 if(player[i].isFlip()){
6918 if(player[i].weaponactive!=-1){
6919 player[i].throwtogglekeydown=1;
6920 player[i].victim=&player[j];
6922 weapons.owner[player[i].weaponids[0]]=-1;
6923 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);
6926 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6928 weapons.velocity[player[i].weaponids[0]]=aim*50;
6929 weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
6930 weapons.missed[player[i].weaponids[0]]=0;
6931 weapons.freetime[player[i].weaponids[0]]=0;
6932 weapons.firstfree[player[i].weaponids[0]]=1;
6933 weapons.physics[player[i].weaponids[0]]=0;
6934 player[i].num_weapons--;
6935 if(player[i].num_weapons){
6936 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6938 player[i].weaponactive=-1;
6945 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6946 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6947 player[i].throwtogglekeydown=1;
6948 weapons.owner[player[i].weaponids[0]]=-1;
6949 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
6950 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
6951 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
6952 weapons.missed[player[i].weaponids[0]]=1;
6953 weapons.freetime[player[i].weaponids[0]]=0;
6954 weapons.firstfree[player[i].weaponids[0]]=1;
6955 weapons.physics[player[i].weaponids[0]]=1;
6956 player[i].num_weapons--;
6957 if(player[i].num_weapons){
6958 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6959 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6962 player[i].weaponactive=-1;
6963 for(int j=0;j<numplayers;j++){
6964 player[j].wentforweapon=0;
6972 if(i==0||!player[0].dead||player[i].weaponactive!=-1)
6973 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6974 player[i].num_weapons==2&&
6975 player[i].weaponactive==-1&&
6976 player[i].isIdle()||
6978 player[i].weaponactive!=-1&&
6981 if(player[i].weaponactive!=-1)
6982 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)
6984 if(isgood&&player[i].creature!=wolftype){
6985 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6986 setAnimation(i,drawrightanim);
6987 player[i].drawtogglekeydown=1;
6989 if((player[i].isIdle()||
6990 (player[i].aitype!=playercontrolled&&
6991 player[0].weaponactive!=-1&&
6992 player[i].isRun()))&&
6993 player[i].num_weapons&&
6994 weapons.type[player[i].weaponids[0]]==sword){
6995 setAnimation(i,drawleftanim);
6996 player[i].drawtogglekeydown=1;
6998 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6999 setAnimation(i,crouchdrawrightanim);
7000 player[i].drawtogglekeydown=1;
7005 if(player[i].isCrouch()&&
7006 weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7008 player[i].onterrain&&
7009 player[i].num_weapons&&
7010 player[i].weaponactive!=-1&&
7011 player[i].attackkeydown){
7012 if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7013 player[i].onterrain&&
7014 bloodtoggle&&musictype!=stream_fighttheme){
7015 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)
7016 setAnimation(i,crouchstabanim);
7017 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)
7018 setAnimation(i,swordgroundstabanim);
7019 player[i].hasvictim=0;
7020 //player[i].attacktogglekeydown=1;
7024 if(!player[i].drawkeydown)
7025 player[i].drawtogglekeydown=0;
7032 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7034 else absflatfacing=flatfacing;
7037 player[i].forwardkeydown=0;
7038 player[i].leftkeydown=0;
7039 player[i].backkeydown=0;
7040 player[i].rightkeydown=0;
7041 player[i].jumpkeydown=0;
7042 player[i].crouchkeydown=0;
7043 player[i].drawkeydown=0;
7044 player[i].throwkeydown=0;
7048 if(!animation[player[i].targetanimation].attack&&
7049 player[i].targetanimation!=staggerbackhighanim&&
7050 player[i].targetanimation!=staggerbackhardanim&&
7051 player[i].targetanimation!=backhandspringanim&&
7052 player[i].targetanimation!=dodgebackanim){
7053 if(!player[i].forwardkeydown)
7054 player[i].forwardstogglekeydown=0;
7055 if(player[i].crouchkeydown){
7059 player[i].superruntoggle=1;
7061 for(int j=0;j<numplayers;j++)
7062 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7063 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7064 player[i].superruntoggle=0;
7068 for(int j=0;j<numplayers;j++){
7069 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7070 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7071 player[j].victim==&player[i]&&
7072 (player[j].targetanimation==sweepanim||
7073 player[j].targetanimation==upunchanim||
7074 player[j].targetanimation==wolfslapanim||
7075 ((player[j].targetanimation==swordslashanim||
7076 player[j].targetanimation==knifeslashstartanim||
7077 player[j].targetanimation==staffhitanim||
7078 player[j].targetanimation==staffspinhitanim)&&
7079 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7088 player[target].Reverse();
7089 player[i].lowreversaldelay=.5;
7091 if(player[i].isIdle()){
7092 setAnimation(i,player[i].getCrouch());
7093 player[i].transspeed=10;
7095 if(player[i].isRun()||
7096 (player[i].isStop()&&
7097 (player[i].leftkeydown||
7098 player[i].rightkeydown||
7099 player[i].forwardkeydown||
7100 player[i].backkeydown))){
7101 setAnimation(i,rollanim);
7102 player[i].transspeed=20;
7105 if(!player[i].crouchkeydown){
7107 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7109 if(player[i].isCrouch()){
7111 for(int j=0;j<numplayers;j++){
7113 !player[j].skeleton.free&&
7115 player[i].highreversaldelay<=0){
7116 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7117 player[j].victim==&player[i]&&
7118 (player[j].targetanimation==spinkickanim)&&
7119 player[i].isCrouch()){
7128 player[target].Reverse();
7129 player[i].highreversaldelay=.5;
7131 if(player[i].isCrouch()){
7132 if(!player[i].wasCrouch()){
7133 player[i].currentanimation=player[i].getCrouch();
7134 player[i].currentframe=0;
7136 setAnimation(i,player[i].getIdle());
7137 player[i].transspeed=10;
7140 if(player[i].targetanimation==sneakanim){
7141 setAnimation(i,player[i].getIdle());
7142 player[i].transspeed=10;
7145 if(player[i].forwardkeydown){
7146 if(player[i].isIdle()||
7147 (player[i].isStop()&&
7148 player[i].targetrotation==player[i].rotation)||
7149 (player[i].isLanding()&&
7150 player[i].targetframe>0&&
7151 !player[i].jumpkeydown)||
7152 (player[i].isLandhard()&&
7153 player[i].targetframe>0&&
7154 !player[i].jumpkeydown&&
7155 player[i].crouchkeydown)){
7156 if(player[i].aitype==passivetype)
7157 setAnimation(i,walkanim);
7159 setAnimation(i,player[i].getRun());
7161 if(player[i].isCrouch()){
7162 player[i].targetanimation=sneakanim;
7163 if(player[i].wasCrouch())
7165 player[i].targetframe=0;
7167 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7168 setAnimation(i,climbanim);
7169 player[i].targetframe=1;
7170 player[i].jumpclimb=1;
7172 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7173 player[i].velocity+=absflatfacing*5*multiplier;
7175 player[i].forwardstogglekeydown=1;
7178 if (player[i].rightkeydown){
7179 if(player[i].isIdle()||
7180 (player[i].isStop()&&
7181 player[i].targetrotation==player[i].rotation)||
7182 (player[i].isLanding()&&
7183 player[i].targetframe>0&&
7184 !player[i].jumpkeydown)||
7185 (player[i].isLandhard()&&
7186 player[i].targetframe>0&&
7187 !player[i].jumpkeydown&&
7188 player[i].crouchkeydown)){
7189 setAnimation(i,player[i].getRun());
7191 if(player[i].isCrouch()){
7192 player[i].targetanimation=sneakanim;
7193 if(player[i].wasCrouch())
7195 player[i].targetframe=0;
7197 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7198 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7200 player[i].targetrotation-=90;
7201 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7202 if(player[i].backkeydown)player[i].targetrotation-=45;
7205 if ( player[i].leftkeydown){
7206 if(player[i].isIdle()||
7207 (player[i].isStop()&&
7208 player[i].targetrotation==player[i].rotation)||
7209 (player[i].isLanding()&&
7210 player[i].targetframe>0&&
7211 !player[i].jumpkeydown)||
7212 (player[i].isLandhard()&&
7213 player[i].targetframe>0&&
7214 !player[i].jumpkeydown&&
7215 player[i].crouchkeydown)){
7216 setAnimation(i,player[i].getRun());
7218 if(player[i].isCrouch()){
7219 player[i].targetanimation=sneakanim;
7220 if(player[i].wasCrouch())
7222 player[i].targetframe=0;
7224 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7225 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7227 player[i].targetrotation+=90;
7228 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7229 if(player[i].backkeydown)player[i].targetrotation+=45;
7232 if(player[i].backkeydown){
7233 if(player[i].isIdle()||
7234 (player[i].isStop()&&
7235 player[i].targetrotation==player[i].rotation)||
7236 (player[i].isLanding()&&
7237 player[i].targetframe>0&&
7238 !player[i].jumpkeydown)||
7239 (player[i].isLandhard()&&
7240 player[i].targetframe>0&&
7241 !player[i].jumpkeydown&&
7242 player[i].crouchkeydown)){
7243 setAnimation(i,player[i].getRun());
7245 if(player[i].isCrouch()){
7246 player[i].targetanimation=sneakanim;
7247 if(player[i].wasCrouch())
7249 player[i].targetframe=0;
7251 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7252 player[i].velocity-=absflatfacing*5*multiplier;
7254 if(player[i].targetanimation==hanganim){
7255 player[i].currentanimation=jumpdownanim;
7256 player[i].targetanimation=jumpdownanim;
7258 player[i].currentframe=0;
7259 player[i].targetframe=1;
7260 player[i].velocity=0;
7261 player[i].velocity.y+=gravity;
7262 player[i].coords.y-=1.4;
7263 player[i].grabdelay=1;
7265 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7266 player[i].targetrotation+=180;
7269 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7270 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7272 player[i].targetanimation==walkanim||
7273 player[i].isCrouch()||
7274 player[i].targetanimation==sneakanim)&&
7275 player[i].jumppower>1)&&
7276 ((player[i].targetanimation!=rabbitrunninganim&&
7277 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7278 player[i].jumpstart=0;
7279 setAnimation(i,jumpupanim);
7280 player[i].rotation=player[i].targetrotation;
7281 player[i].transspeed=20;
7282 player[i].FootLand(0,1);
7283 player[i].FootLand(1,1);
7287 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7289 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7290 if(!movekey)player[i].velocity=0;
7295 for(int j=0;j<numplayers;j++){
7296 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7297 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7298 player[j].victim==&player[i]&&
7299 (player[j].targetanimation==sweepanim)){
7300 if(target>=0)target=-1;
7305 if(target>=0)player[i].velocity.y=1;
7306 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7307 player[i].velocity.y=7;
7308 player[i].crouchtogglekeydown=1;
7310 else player[i].velocity.y=5;
7312 if(mousejump&&i==0&&debugmode){
7313 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7314 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7317 player[i].coords.y+=.2;
7318 player[i].jumppower-=1;
7321 emit_sound_at(whooshsound, player[i].coords, 128.);
7323 emit_sound_at(jumpsound, player[i].coords, 128.);
7325 if((player[i].isIdle())&&player[i].jumppower>1){
7326 setAnimation(i,player[i].getLanding());
7327 player[i].targetframe=2;
7328 player[i].landhard=0;
7329 player[i].jumpstart=1;
7330 player[i].tempdeltav=deltav;
7332 if(player[i].targetanimation==jumpupanim&&
7336 player[i].aitype!=playercontrolled)){
7337 if(player[i].jumppower>multiplier*6){
7338 player[i].velocity.y+=multiplier*6;
7339 player[i].jumppower-=multiplier*6;
7341 if(player[i].jumppower<=multiplier*6){
7342 player[i].velocity.y+=player[i].jumppower;
7343 player[i].jumppower=0;
7346 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7350 if(player[i].isRun()||player[i].targetanimation==walkanim)
7351 setAnimation(i,player[i].getStop());
7352 if(player[i].targetanimation==sneakanim){
7353 player[i].targetanimation=player[i].getCrouch();
7354 if(player[i].currentanimation==sneakanim)
7356 player[i].targetframe=0;
7359 if(player[i].targetanimation==walkanim&&
7360 (player[i].aitype==attacktypecutoff||
7361 player[i].aitype==searchtype||
7362 (player[i].aitype==passivetype&&
7363 player[i].numwaypoints<=1)))
7364 setAnimation(i,player[i].getStop());
7365 if(player[i].isRun()&&(player[i].aitype==passivetype))
7366 setAnimation(i,player[i].getStop());
7369 if(player[i].targetanimation==rollanim)
7370 player[i].targetrotation=oldtargetrotation;
7374 for(int k=0;k<numplayers;k++){
7375 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7376 if(player[k].rotation>player[k].targetrotation)
7377 player[k].rotation-=360;
7379 player[k].rotation+=360;
7382 //stop to turn in right direction
7383 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7384 setAnimation(k,player[k].getStop());
7386 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7387 player[k].targettilt=0;
7389 if(player[k].targetanimation!=jumpupanim&&
7390 player[k].targetanimation!=backhandspringanim&&
7391 player[k].targetanimation!=jumpdownanim&&
7392 !player[k].isFlip()){
7393 player[k].targettilt=0;
7394 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7395 player[k].jumppower=0;
7396 player[k].jumppower+=multiplier*7;
7397 if(player[k].isCrouch())
7398 player[k].jumppower+=multiplier*7;
7399 if(player[k].jumppower>5)
7400 player[k].jumppower=5;
7403 if(player[k].isRun())
7404 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7406 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7407 player[k].grabdelay-=multiplier;
7411 for(int k=0;k<numplayers;k++){
7412 player[k].DoAnimations();
7413 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7414 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7420 for(int j=numenvsounds-1;j>=0;j--){
7421 envsoundlife[j]-=multiplier;
7422 if(envsoundlife[j]<0){
7424 envsoundlife[j]=envsoundlife[numenvsounds];
7425 envsound[j]=envsound[numenvsounds];
7429 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7431 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7433 if(tutoriallevel==1){
7450 if(tutorialstage>=51)
7451 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7452 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7453 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7455 emit_stream_np(stream_menutheme);
7464 if(tutorialstage<51)
7465 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7466 emit_sound_at(fireendsound, player[0].coords);
7468 player[0].coords=(oldtemp+oldtemp2)/2;
7472 if(tutorialstage>=14&&tutorialstage<50)
7473 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7474 emit_sound_at(fireendsound, player[1].coords);
7476 for(int i=0;i<player[1].skeleton.num_joints;i++){
7478 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7479 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7480 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;
7481 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7482 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7486 player[1].coords=(oldtemp+oldtemp2)/2;
7487 for(int i=0;i<player[1].skeleton.num_joints;i++){
7488 player[1].skeleton.joints[i].velocity=0;
7490 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7491 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7492 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;
7493 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7494 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7502 static float gLoc[3];
7506 static float vel[3];
7507 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7508 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7509 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7511 //Set orientation with forward and up vectors
7512 static XYZ upvector;
7516 upvector=DoRotation(upvector,-rotation2+90,0,0);
7517 upvector=DoRotation(upvector,0,0-rotation,0);
7522 facing=DoRotation(facing,-rotation2,0,0);
7523 facing=DoRotation(facing,0,0-rotation,0);
7526 static float ori[6];
7530 ori[3] = -upvector.x;
7531 ori[4] = upvector.y;
7532 ori[5] = -upvector.z;
7534 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7541 if(Input::isKeyPressed(SDLK_F1))
7545 void Game::TickOnce(){
7547 rotation+=multiplier*5;
7549 if(directing||indialogue==-1) {
7550 rotation+=deltah*.7;
7552 rotation2+=deltav*.7;
7554 rotation2-=deltav*.7;
7562 void Game::TickOnceAfter(){
7563 static XYZ colviewer;
7564 static XYZ coltarget;
7568 static float changedelay;
7569 static bool alldead;
7570 static float unseendelay;
7571 static float cameraspeed;
7575 if(environment==snowyenvironment)
7576 leveltheme=stream_snowtheme;
7577 if(environment==grassyenvironment)
7578 leveltheme=stream_grasstheme;
7579 if(environment==desertenvironment)
7580 leveltheme=stream_deserttheme;
7584 musictype=leveltheme;
7585 for(int i=0;i<numplayers;i++){
7586 if((player[i].aitype==attacktypecutoff||
7587 player[i].aitype==getweapontype||
7588 player[i].aitype==gethelptype||
7589 player[i].aitype==searchtype)&&
7590 !player[i].dead/*&&player[i].surprised<=0*/&&
7591 (player[i].targetanimation!=sneakattackedanim&&
7592 player[i].targetanimation!=knifesneakattackedanim&&
7593 player[i].targetanimation!=swordsneakattackedanim)){
7594 musictype=stream_fighttheme;
7599 musictype=stream_menutheme;
7602 if(musictype==stream_fighttheme)
7605 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7606 unseendelay-=multiplier;
7608 musictype=stream_fighttheme;
7613 musictype=stream_menutheme;
7621 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7622 emit_sound_np(alarmsound);
7623 musicselected=musictype;
7625 if(musicselected==leveltheme)
7626 musicvolume[0]+=multiplier*450;
7628 musicvolume[0]-=multiplier*450;
7629 if(musicselected==stream_fighttheme)
7630 musicvolume[1]+=multiplier*450;
7632 musicvolume[1]-=multiplier*450;
7633 if(musicselected==stream_menutheme)
7634 musicvolume[2]+=multiplier*450;
7636 musicvolume[2]-=multiplier*450;
7638 for(int i=0;i<3;i++){
7639 if(musicvolume[i]<0)
7641 if(musicvolume[i]>512)
7645 if(musicvolume[2]>128&&!loading&&!mainmenu)
7649 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7650 emit_stream_np(leveltheme, musicvolume[0]);
7651 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7652 emit_stream_np(stream_fighttheme, musicvolume[1]);
7653 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7654 emit_stream_np(stream_menutheme, musicvolume[2]);
7655 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7656 pause_sound(leveltheme);
7657 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7658 pause_sound(stream_fighttheme);
7659 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7660 pause_sound(stream_menutheme);
7662 if(musicvolume[0]!=oldmusicvolume[0])
7663 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7664 if(musicvolume[1]!=oldmusicvolume[1])
7665 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7666 if(musicvolume[2]!=oldmusicvolume[2])
7667 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7669 for(int i=0;i<3;i++)
7670 oldmusicvolume[i]=musicvolume[i];
7672 pause_sound(leveltheme);
7673 pause_sound(stream_fighttheme);
7674 pause_sound(stream_menutheme);
7676 for(int i=0;i<4;i++){
7677 oldmusicvolume[i]=0;
7683 for(int i=0;i<numhotspots;i++){
7684 if(hotspottype[i]>10&&hotspottype[i]<20){
7685 if(player[hotspottype[i]-10].dead==0)
7687 else if(killhotspot==2)
7696 for(int i=0;i<numhotspots;i++)
7697 if(hotspottype[i]==-1)
7698 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7702 for(int i=1;i<numplayers;i++)
7703 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7705 if(numalarmed>maxalarmed)
7706 maxalarmed=numalarmed;
7708 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7709 if(player[0].dead&&changedelay<=0){
7711 targetlevel=whichlevel;
7714 for(int i=1;i<numplayers;i++)
7715 if(!player[i].dead&&player[i].howactive<typedead1)
7719 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7721 targetlevel=whichlevel+1;
7722 if(targetlevel>numchallengelevels-1)targetlevel=0;
7724 if(winhotspot||windialogue){
7726 targetlevel=whichlevel+1;
7727 if(targetlevel>numchallengelevels-1)targetlevel=0;
7733 targetlevel=whichlevel+1;
7734 if(targetlevel>numchallengelevels-1)targetlevel=0;
7737 if(changedelay>0&&!player[0].dead&&!won) {
7738 //high scores, awards, win
7740 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7743 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7759 if(!editorenabled&&gameon&&!mainmenu) {
7760 if(changedelay!=-999)
7761 changedelay-=multiplier/7;
7763 targetlevel=whichlevel;
7764 if(loading==2&&!campaign){
7767 fireSound(firestartsound);
7769 if(!player[0].dead&&targetlevel!=whichlevel)
7770 startbonustotal=bonustotal;
7772 Loadlevel(whichlevel);
7774 Loadlevel(targetlevel);
7780 if(loading==2&&targetlevel==whichlevel){
7784 fireSound(firestartsound);
7786 Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);
7792 if(changedelay<=-999&&
7796 (alldead&&maptype==mapkilleveryone)||
7800 if((player[0].dead||
7801 (alldead&&maptype==mapkilleveryone)||
7806 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7816 // campaignchoosenext determines what to do when the level is complete:
7817 // 0 = load next level
7818 // 1 = go back to level select screen
7819 // 2 = stealthload next level
7820 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
7821 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0)
7823 } else if(mainmenu==0&&winfreeze) {
7824 stealthloading = (campaignchoosenext[campaignchoicewhich[whichchoice]]==2);
7826 if(!stealthloading){
7827 fireSound(firestartsound);
7844 Loadlevel(campaignmapname[campaignchoicewhich[0]]);
7848 pause_sound(stream_menutheme);
7859 oldmusictype=musictype;
7865 facing=DoRotation(facing,-rotation2,0,0);
7866 facing=DoRotation(facing,0,0-rotation,0);
7867 viewerfacing=facing;
7870 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;
7871 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;
7873 if(player[0].skeleton.free){
7874 for(int i=0;i<player[0].skeleton.num_joints;i++){
7875 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7876 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7880 if(player[0].skeleton.free!=2&&!autocam){
7882 if(findLengthfast(&player[0].velocity)>400){
7883 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7885 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7886 coltarget=target-cameraloc;
7887 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7889 Normalise(&coltarget);
7890 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7891 else cameraloc=cameraloc+coltarget*multiplier*8;
7893 if(editorenabled)cameraloc=target;
7894 cameradist+=multiplier*5;
7895 if(cameradist>2.3)cameradist=2.3;
7896 viewer=cameraloc-facing*cameradist;
7898 coltarget=cameraloc;
7899 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7900 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7901 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7902 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7904 coltarget=cameraloc;
7905 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7907 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7908 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7909 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7911 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7915 cameradist=findDistance(&viewer,&target);
7916 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7917 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7918 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7921 if(player[0].skeleton.free!=2&&autocam){
7923 if(findLengthfast(&player[0].velocity)>400){
7924 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7926 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7927 cameradist+=multiplier*5;
7928 if(cameradist>3.3)cameradist=3.3;
7929 coltarget=target-cameraloc;
7930 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7931 else if(findLengthfast(&coltarget)>1)
7933 Normalise(&coltarget);
7934 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7935 else cameraloc=cameraloc+coltarget*multiplier*8;
7937 if(editorenabled)cameraloc=target;
7940 coltarget=cameraloc;
7941 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7942 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7943 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7944 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7946 coltarget=cameraloc;
7947 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7949 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7950 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7951 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7953 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7957 cameradist=findDistance(&viewer,&target);
7958 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7959 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7960 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7963 if(camerashake>.8)camerashake=.8;
7964 //if(woozy>10)woozy=10;
7965 //woozy+=multiplier;
7967 if(player[0].dead)camerashake=0;
7968 if(player[0].dead)woozy=0;
7969 camerashake-=multiplier*2;
7970 blackout-=multiplier*2;
7971 //if(player[0].isCrouch())woozy-=multiplier*8;
7972 if(camerashake<0)camerashake=0;
7973 if(blackout<0)blackout=0;
7974 //if(woozy<0)woozy=0;
7976 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7977 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7978 viewer.z+=(float)(Random()%100)*.0005*camerashake;