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);
1414 Loadlevel("mapsave");
1417 void Game::Loadlevel(const char *name){
1420 static const char *pfx = ":Data:Maps:";
1423 float headprop,legprop,armprop,bodyprop;
1427 LOG(std::string("Loading level...") + name);
1439 if(tutoriallevel!=-1)
1444 if(tutoriallevel==1)
1446 if(tutorialstage==0){
1447 tutorialstagetime=0;
1451 pause_sound(whooshsound);
1452 pause_sound(stream_firesound);
1454 // Change the map filename into something that is os specific
1455 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1456 sprintf(buf, "%s%s", pfx, name);
1457 const char *FixedFN = ConvertFileName(buf);
1461 tfile=fopen( FixedFN, "rb" );
1463 pause_sound(stream_firesound);
1469 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1473 for(int i=0;i<20;i++)
1474 dialoguegonethrough[i]=0;
1483 difficulty=accountactive->getDifficulty();
1502 for(int i=0;i<100;i++)
1522 bonustotal=startbonustotal;
1527 emit_sound_np(consolesuccesssound);
1532 if(!stealthloading){
1533 terrain.numdecals=0;
1534 Sprite::deleteSprites();
1535 for(int i=0;i<objects.numobjects;i++)
1536 objects.model[i].numdecals=0;
1538 int j=objects.numobjects;
1539 for(int i=0;i<j;i++){
1540 objects.DeleteObject(0);
1545 for(int i=0;i<subdivision;i++)
1546 for(int j=0;j<subdivision;j++)
1547 terrain.patchobjectnum[i][j]=0;
1552 weapons.numweapons=0;
1554 funpackf(tfile, "Bi", &mapvers);
1556 funpackf(tfile, "Bi", &indemo);
1560 funpackf(tfile, "Bi", &maptype);
1562 maptype=mapkilleveryone;
1564 funpackf(tfile, "Bi", &hostile);
1568 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1574 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1582 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1584 skyboxlightr=skyboxr;
1585 skyboxlightg=skyboxg;
1586 skyboxlightb=skyboxb;
1589 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);
1591 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1592 player[0].originalcoords=player[0].coords;
1593 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1594 for(int j=0;j<player[0].num_weapons;j++){
1595 player[0].weaponids[j]=weapons.numweapons;
1596 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1597 weapons.owner[weapons.numweapons]=0;
1598 weapons.numweapons++;
1604 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1605 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1606 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1607 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1609 funpackf(tfile, "Bi", &player[0].numclothes);
1612 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1614 player[0].whichskin=0;
1615 player[0].creature=rabbittype;
1618 player[0].lastattack=-1;
1619 player[0].lastattack2=-1;
1620 player[0].lastattack3=-1;
1624 funpackf(tfile, "Bi", &numdialogues);
1625 for(int k=0;k<numdialogues;k++){
1626 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1627 funpackf(tfile, "Bi", &dialoguetype[k]);
1628 for(int l=0;l<10;l++){
1629 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1630 funpackf(tfile, "Bf", &participantrotation[k][l]);
1632 for(int l=0;l<numdialogueboxes[k];l++){
1633 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1634 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1635 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1636 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1637 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1639 funpackf(tfile, "Bi",&templength);
1640 if(templength>128||templength<=0)
1643 for(m=0;m<templength;m++){
1644 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1645 if(dialoguetext[k][l][m]=='\0')
1648 dialoguetext[k][l][m] = 0;
1650 funpackf(tfile, "Bi",&templength);
1651 if(templength>64||templength<=0)templength=64;
1652 for(m=0;m<templength;m++){
1653 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1654 if(dialoguename[k][l][m]=='\0')
1657 dialoguename[k][l][m] = 0;
1658 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1659 funpackf(tfile, "Bi", &participantfocus[k][l]);
1660 funpackf(tfile, "Bi", &participantaction[k][l]);
1663 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1665 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1671 for(int k=0;k<player[0].numclothes;k++){
1672 funpackf(tfile, "Bi", &templength);
1673 for(int l=0;l<templength;l++)
1674 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1675 player[0].clothes[k][templength]='\0';
1676 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1679 funpackf(tfile, "Bi", &environment);
1681 funpackf(tfile, "Bi", &objects.numobjects);
1682 for(int i=0;i<objects.numobjects;i++){
1683 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]);
1684 if(objects.type[i]==treeleavestype)
1685 objects.scale[i]=objects.scale[i-1];
1689 funpackf(tfile, "Bi", &numhotspots);
1690 for(int i=0;i<numhotspots;i++){
1691 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1692 funpackf(tfile, "Bi", &templength);
1694 for(int l=0;l<templength;l++)
1695 funpackf(tfile, "Bb", &hotspottext[i][l]);
1696 hotspottext[i][templength]='\0';
1697 if(hotspottype[i]==-111)
1706 if(!stealthloading){
1708 for(int i=0;i<objects.numobjects;i++)
1709 objects.center+=objects.position[i];
1710 objects.center/=objects.numobjects;
1716 float maxdistance=0;
1718 //~ int whichclosest;
1719 for(int i=0;i<objects.numobjects;i++){
1720 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1721 if(tempdist>maxdistance){
1723 maxdistance=tempdist;
1726 objects.radius=fast_sqrt(maxdistance);
1731 //mapcenter=objects.center;
1732 //mapradius=objects.radius;
1734 funpackf(tfile, "Bi", &numplayers);
1735 int howmanyremoved=0;
1736 bool removeanother=0;
1737 if(numplayers>1&&numplayers<maxplayers){
1738 for(int i=1;i<numplayers;i++){
1743 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);
1745 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1747 player[i-howmanyremoved].howactive=typeactive;
1749 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1751 player[i-howmanyremoved].scale=-1;
1753 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1755 player[i-howmanyremoved].immobile=0;
1757 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1759 player[i-howmanyremoved].rotation=0;
1760 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1761 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1766 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1767 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1768 player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1769 funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1770 weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1771 weapons.numweapons++;
1774 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1775 //player[i-howmanyremoved].numwaypoints=10;
1776 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1777 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1778 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1779 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1781 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1783 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1786 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1787 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1788 player[i-howmanyremoved].waypoint=0;
1790 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1791 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1792 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1793 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1796 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1803 if(player[i-howmanyremoved].creature==wolftype){
1804 player[i-howmanyremoved].proportionhead=1.1*headprop;
1805 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1806 player[i-howmanyremoved].proportionarms=1.1*armprop;
1807 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1810 if(player[i-howmanyremoved].creature==rabbittype){
1811 player[i-howmanyremoved].proportionhead=1.2*headprop;
1812 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1813 player[i-howmanyremoved].proportionarms=1.00*armprop;
1814 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1815 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1818 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1819 if(player[i-howmanyremoved].numclothes){
1820 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1822 funpackf(tfile, "Bi", &templength);
1823 for(int l=0;l<templength;l++)
1824 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1825 player[i-howmanyremoved].clothes[k][templength]='\0';
1826 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1835 numplayers-=howmanyremoved;
1836 funpackf(tfile, "Bi", &numpathpoints);
1837 if(numpathpoints>30||numpathpoints<0)
1839 for(int j=0;j<numpathpoints;j++){
1840 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1841 for(int k=0;k<numpathpointconnect[j];k++){
1842 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1848 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1851 if(environment!=oldenvironment)
1852 Setenvironment(environment);
1853 oldenvironment=environment;
1855 if(!stealthloading){
1856 int j=objects.numobjects;
1857 objects.numobjects=0;
1858 for(int i=0;i<j;i++){
1859 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1864 terrain.DoShadows();
1867 objects.DoShadows();
1874 if(numplayers>maxplayers-1)
1875 numplayers=maxplayers-1;
1876 for(int i=0;i<numplayers;i++){
1882 if(i==0||player[i].scale<0)
1884 player[i].skeleton.free=0;
1885 player[i].skeleton.id=i;
1887 player[i].creature=rabbittype;
1888 if(player[i].creature!=wolftype){
1889 player[i].skeleton.Load(
1890 (char *)":Data:Skeleton:Basic Figure",
1891 (char *)":Data:Skeleton:Basic Figurelow",
1892 (char *)":Data:Skeleton:Rabbitbelt",
1893 (char *)":Data:Models:Body.solid",
1894 (char *)":Data:Models:Body2.solid",
1895 (char *)":Data:Models:Body3.solid",
1896 (char *)":Data:Models:Body4.solid",
1897 (char *)":Data:Models:Body5.solid",
1898 (char *)":Data:Models:Body6.solid",
1899 (char *)":Data:Models:Body7.solid",
1900 (char *)":Data:Models:Bodylow.solid",
1901 (char *)":Data:Models:Belt.solid",0);
1903 if(player[i].creature!=wolftype){
1904 player[i].skeleton.Load(
1905 (char *)":Data:Skeleton:Basic Figure",
1906 (char *)":Data:Skeleton:Basic Figurelow",
1907 (char *)":Data:Skeleton:Rabbitbelt",
1908 (char *)":Data:Models:Body.solid",
1909 (char *)":Data:Models:Body2.solid",
1910 (char *)":Data:Models:Body3.solid",
1911 (char *)":Data:Models:Body4.solid",
1912 (char *)":Data:Models:Body5.solid",
1913 (char *)":Data:Models:Body6.solid",
1914 (char *)":Data:Models:Body7.solid",
1915 (char *)":Data:Models:Bodylow.solid",
1916 (char *)":Data:Models:Belt.solid",1);
1917 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1919 if(player[i].creature==wolftype){
1920 player[i].skeleton.Load(
1921 (char *)":Data:Skeleton:Basic Figure Wolf",
1922 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1923 (char *)":Data:Skeleton:Rabbitbelt",
1924 (char *)":Data:Models:Wolf.solid",
1925 (char *)":Data:Models:Wolf2.solid",
1926 (char *)":Data:Models:Wolf3.solid",
1927 (char *)":Data:Models:Wolf4.solid",
1928 (char *)":Data:Models:Wolf5.solid",
1929 (char *)":Data:Models:Wolf6.solid",
1930 (char *)":Data:Models:Wolf7.solid",
1931 (char *)":Data:Models:Wolflow.solid",
1932 (char *)":Data:Models:Belt.solid",0);
1938 //~ texsize=512*512*3/texdetail/texdetail;
1940 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1942 if(player[i].numclothes){
1943 for(int j=0;j<player[i].numclothes;j++){
1944 tintr=player[i].clothestintr[j];
1945 tintg=player[i].clothestintg[j];
1946 tintb=player[i].clothestintb[j];
1947 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1949 player[i].DoMipmaps();
1952 player[i].currentanimation=bounceidleanim;
1953 player[i].targetanimation=bounceidleanim;
1954 player[i].currentframe=0;
1955 player[i].targetframe=1;
1957 player[i].speed=1+(float)(Random()%100)/1000;
1959 player[i].speed-=.2;
1961 player[i].speed-=.1;
1963 player[i].velocity=0;
1964 player[i].oldcoords=player[i].coords;
1965 player[i].realoldcoords=player[i].coords;
1968 player[i].skeleton.id=i;
1969 player[i].updatedelay=0;
1970 player[i].normalsupdatedelay=0;
1972 player[i].aitype=passivetype;
1973 player[i].madskills=0;
1976 player[i].proportionhead=1.2;
1977 player[i].proportionbody=1.05;
1978 player[i].proportionarms=1.00;
1979 player[i].proportionlegs=1.1;
1980 player[i].proportionlegs.y=1.05;
1982 player[i].headless=0;
1983 player[i].currentoffset=0;
1984 player[i].targetoffset=0;
1986 player[i].damagetolerance=200;
1988 if(player[i].creature==wolftype){
1989 if(i==0||player[i].scale<0)
1990 player[i].scale=.23;
1991 player[i].damagetolerance=300;
1997 player[i].proportionhead.z=0;
1998 player[i].proportionbody.z=0;
1999 player[i].proportionarms.z=0;
2000 player[i].proportionlegs.z=0;
2003 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2005 player[i].headmorphness=0;
2006 player[i].targetheadmorphness=1;
2007 player[i].headmorphstart=0;
2008 player[i].headmorphend=0;
2010 player[i].pausetime=0;
2013 player[i].jumppower=5;
2015 player[i].permanentdamage=0;
2016 player[i].superpermanentdamage=0;
2018 player[i].forwardkeydown=0;
2019 player[i].leftkeydown=0;
2020 player[i].backkeydown=0;
2021 player[i].rightkeydown=0;
2022 player[i].jumpkeydown=0;
2023 player[i].crouchkeydown=0;
2024 player[i].throwkeydown=0;
2026 player[i].collided=-10;
2028 player[i].bloodloss=0;
2029 player[i].weaponactive=-1;
2030 player[i].weaponstuck=-1;
2031 player[i].bleeding=0;
2032 player[i].deathbleeding=0;
2033 player[i].stunned=0;
2034 player[i].hasvictim=0;
2035 player[i].wentforweapon=0;
2038 player[0].aitype=playercontrolled;
2039 player[0].weaponactive=-1;
2042 player[0].power=1/.9;
2045 player[0].power=1/.8;
2048 player[0].damagetolerance=250;
2050 player[0].damagetolerance=300;
2052 player[0].armorhead*=1.5;
2054 player[0].armorhigh*=1.5;
2056 player[0].armorlow*=1.5;
2057 cameraloc=player[0].coords;
2059 rotation=player[0].rotation;
2061 hawkcoords=player[0].coords;
2066 for(int i=0;i<weapons.numweapons;i++){
2067 weapons.bloody[i]=0;
2068 weapons.blooddrip[i]=0;
2069 weapons.blooddripdelay[i]=0;
2070 weapons.onfire[i]=0;
2071 weapons.flamedelay[i]=0;
2072 weapons.damage[i]=0;
2073 if(weapons.type[i]==sword){
2074 weapons.mass[i]=1.5;
2075 weapons.tipmass[i]=1;
2076 weapons.length[i]=.8;
2078 if(weapons.type[i]==staff){
2080 weapons.tipmass[i]=1;
2081 weapons.length[i]=1.5;
2083 if(weapons.type[i]==knife){
2085 weapons.tipmass[i]=1.2;
2086 weapons.length[i]=.25;
2088 weapons.position[i]=-1000;
2089 weapons.tippoint[i]=-1000;
2092 LOG("Starting background music...");
2094 OPENAL_StopSound(OPENAL_ALL);
2095 if(environment==snowyenvironment){
2097 emit_stream_np(stream_wind);
2098 }else if(environment==desertenvironment){
2100 emit_stream_np(stream_desertambient);
2101 }else if(environment==grassyenvironment){
2103 emit_stream_np(stream_wind, 100.);
2105 oldmusicvolume[0]=0;
2106 oldmusicvolume[1]=0;
2107 oldmusicvolume[2]=0;
2108 oldmusicvolume[3]=0;
2118 void Game::doTutorial(){
2119 if(tutorialstagetime>tutorialmaxtime){
2122 if(tutorialstage<=1){
2127 switch(tutorialstage){
2133 tutorialmaxtime=600;
2135 tutorialmaxtime=1000;
2137 tutorialmaxtime=600;
2139 tutorialmaxtime=600;
2141 tutorialmaxtime=600;
2143 tutorialmaxtime=600;
2145 tutorialmaxtime=600;
2149 tutorialmaxtime=1000;
2151 tutorialmaxtime=1000;
2166 player[1].coords=(temp+temp2)/2;
2168 emit_sound_at(fireendsound, player[1].coords);
2170 for(int i=0;i<player[1].skeleton.num_joints;i++){
2172 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2173 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2174 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;
2175 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2176 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2181 tutorialmaxtime=500;
2183 tutorialmaxtime=500;
2185 tutorialmaxtime=500;
2187 tutorialmaxtime=500;
2190 //tutorialmaxtime=500;
2192 tutorialmaxtime=500;
2194 tutorialmaxtime=500;
2201 tutorialmaxtime=500;
2203 tutorialmaxtime=500;
2205 tutorialmaxtime=500;
2207 tutorialmaxtime=500;
2214 player[1].aitype=attacktypecutoff;
2216 tutorialmaxtime=400;
2218 tutorialmaxtime=400;
2219 player[0].escapednum=0;
2224 player[1].aitype=passivetype;
2230 tutorialmaxtime=400;
2233 player[1].aitype=attacktypecutoff;
2235 tutorialmaxtime=400;
2237 tutorialmaxtime=400;
2242 player[1].aitype=passivetype;
2249 player[1].aitype=attacktypecutoff;
2254 player[1].aitype=passivetype;
2266 weapons.owner[weapons.numweapons]=-1;
2267 weapons.type[weapons.numweapons]=knife;
2268 weapons.damage[weapons.numweapons]=0;
2269 weapons.mass[weapons.numweapons]=1;
2270 weapons.tipmass[weapons.numweapons]=1.2;
2271 weapons.length[weapons.numweapons]=.25;
2272 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2273 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2275 weapons.velocity[weapons.numweapons]=0.1;
2276 weapons.tipvelocity[weapons.numweapons]=0.1;
2277 weapons.missed[weapons.numweapons]=1;
2278 weapons.hitsomething[weapons.numweapons]=0;
2279 weapons.freetime[weapons.numweapons]=0;
2280 weapons.firstfree[weapons.numweapons]=1;
2281 weapons.physics[weapons.numweapons]=1;
2283 weapons.numweapons++;
2286 tutorialmaxtime=300;
2288 tutorialmaxtime=300;
2292 tutorialmaxtime=300;
2295 player[0].weaponactive=-1;
2296 player[0].num_weapons=0;
2297 player[1].weaponactive=0;
2298 player[1].num_weapons=1;
2299 player[1].weaponids[0]=0;
2303 player[1].aitype=attacktypecutoff;
2305 tutorialmaxtime=300;
2308 player[0].weaponactive=-1;
2309 player[0].num_weapons=0;
2310 player[1].weaponactive=0;
2311 player[1].num_weapons=1;
2312 player[1].weaponids[0]=0;
2314 tutorialmaxtime=300;
2317 player[0].weaponactive=-1;
2318 player[0].num_weapons=0;
2319 player[1].weaponactive=0;
2320 player[1].num_weapons=1;
2321 player[1].weaponids[0]=0;
2323 weapons.type[0]=sword;
2325 tutorialmaxtime=300;
2338 weapons.owner[weapons.numweapons]=-1;
2339 weapons.type[weapons.numweapons]=sword;
2340 weapons.damage[weapons.numweapons]=0;
2341 weapons.mass[weapons.numweapons]=1;
2342 weapons.tipmass[weapons.numweapons]=1.2;
2343 weapons.length[weapons.numweapons]=.25;
2344 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2345 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2347 weapons.velocity[weapons.numweapons]=0.1;
2348 weapons.tipvelocity[weapons.numweapons]=0.1;
2349 weapons.missed[weapons.numweapons]=1;
2350 weapons.hitsomething[weapons.numweapons]=0;
2351 weapons.freetime[weapons.numweapons]=0;
2352 weapons.firstfree[weapons.numweapons]=1;
2353 weapons.physics[weapons.numweapons]=1;
2357 player[0].weaponactive=0;
2358 player[0].num_weapons=1;
2359 player[0].weaponids[0]=1;
2360 player[1].weaponactive=0;
2361 player[1].num_weapons=1;
2362 player[1].weaponids[0]=0;
2364 weapons.numweapons++;
2369 player[1].aitype=passivetype;
2375 player[0].weaponactive=0;
2376 player[0].num_weapons=1;
2377 player[0].weaponids[0]=1;
2378 player[1].weaponactive=0;
2379 player[1].num_weapons=1;
2380 player[1].weaponids[0]=0;
2382 if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
2383 else weapons.type[0]=staff;
2385 weapons.numweapons++;
2389 player[1].aitype=passivetype;
2391 tutorialmaxtime=200;
2393 weapons.position[1]=1000;
2394 weapons.tippoint[1]=1000;
2396 weapons.numweapons=1;
2398 player[1].weaponactive=-1;
2399 player[1].num_weapons=0;
2400 player[0].weaponactive=0;
2401 player[0].num_weapons=1;
2402 player[0].weaponids[0]=0;
2404 weapons.type[0]=knife;
2406 weapons.numweapons++;
2411 emit_sound_at(fireendsound, player[1].coords);
2413 for(int i=0;i<player[1].skeleton.num_joints;i++){
2415 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2416 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2417 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;
2418 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2419 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2423 player[1].num_weapons=0;
2424 player[1].weaponstuck=-1;
2425 player[1].weaponactive=-1;
2427 weapons.numweapons=0;
2429 weapons.owner[0]=-1;
2430 weapons.velocity[0]=0.1;
2431 weapons.tipvelocity[0]=-0.1;
2432 weapons.missed[0]=1;
2433 weapons.hitsomething[0]=0;
2434 weapons.freetime[0]=0;
2435 weapons.firstfree[0]=1;
2436 weapons.physics[0]=1;
2439 tutorialmaxtime=80000;
2440 break; default: break;
2442 if(tutorialstage<=51)tutorialstagetime=0;
2446 if(tutorialstagetime<tutorialmaxtime-3){
2447 switch(tutorialstage){
2448 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2449 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2450 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2451 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2452 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2453 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2454 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2455 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2456 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2457 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2458 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2459 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2460 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2461 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2462 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2463 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2464 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2465 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2466 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2467 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2468 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2470 if(player[0].escapednum==2){
2474 player[1].aitype=passivetype;
2476 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2477 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2479 if(animation[player[0].targetanimation].attack==reversal){
2483 player[1].aitype=passivetype;
2485 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2486 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2487 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2488 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2489 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2490 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2491 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2492 break; default: break;
2494 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2497 if(tutorialstagetime==tutorialmaxtime-3){
2498 emit_sound_np(consolesuccesssound);
2501 if(tutorialsuccess>=1){
2502 if(tutorialstage==34||tutorialstage==35)
2503 tutorialstagetime=tutorialmaxtime-1;
2507 if(tutorialstage<14||tutorialstage>=50){
2508 player[1].coords.y=300;
2509 player[1].velocity=0;
2513 void Game::doDebugKeys(){
2514 float headprop,bodyprop,armprop,legprop;
2516 if(Input::isKeyPressed(SDLK_h)){
2517 player[0].damagetolerance=200000;
2520 player[0].permanentdamage=0;
2521 player[0].superpermanentdamage=0;
2524 if(Input::isKeyPressed(SDLK_j)){
2528 Setenvironment(environment);
2531 if(Input::isKeyPressed(SDLK_c)){
2532 cameramode=1-cameramode;
2535 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2536 if(player[0].num_weapons>0){
2537 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
2538 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
2539 else weapons.type[player[0].weaponids[0]]=sword;
2540 if(weapons.type[player[0].weaponids[0]]==sword){
2541 weapons.mass[player[0].weaponids[0]]=1.5;
2542 weapons.tipmass[player[0].weaponids[0]]=1;
2543 weapons.length[player[0].weaponids[0]]=.8;
2545 if(weapons.type[player[0].weaponids[0]]==staff){
2546 weapons.mass[player[0].weaponids[0]]=2;
2547 weapons.tipmass[player[0].weaponids[0]]=1;
2548 weapons.length[player[0].weaponids[0]]=1.5;
2551 if(weapons.type[player[0].weaponids[0]]==knife){
2552 weapons.mass[player[0].weaponids[0]]=1;
2553 weapons.tipmass[player[0].weaponids[0]]=1.2;
2554 weapons.length[player[0].weaponids[0]]=.25;
2559 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2561 float closestdist=-1;
2564 for(int i=1;i<numplayers;i++){
2565 distance=findDistancefast(&player[i].coords,&player[0].coords);
2566 if(closestdist==-1||distance<closestdist){
2567 closestdist=distance;
2572 if(player[closest].num_weapons){
2573 if(weapons.type[player[closest].weaponids[0]]==sword)
2574 weapons.type[player[closest].weaponids[0]]=staff;
2575 else if(weapons.type[player[closest].weaponids[0]]==staff)
2576 weapons.type[player[closest].weaponids[0]]=knife;
2577 else weapons.type[player[closest].weaponids[0]]=sword;
2578 if(weapons.type[player[closest].weaponids[0]]==sword){
2579 weapons.mass[player[closest].weaponids[0]]=1.5;
2580 weapons.tipmass[player[closest].weaponids[0]]=1;
2581 weapons.length[player[closest].weaponids[0]]=.8;
2583 if(weapons.type[player[0].weaponids[0]]==staff){
2584 weapons.mass[player[0].weaponids[0]]=2;
2585 weapons.tipmass[player[0].weaponids[0]]=1;
2586 weapons.length[player[0].weaponids[0]]=1.5;
2588 if(weapons.type[player[closest].weaponids[0]]==knife){
2589 weapons.mass[player[closest].weaponids[0]]=1;
2590 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2591 weapons.length[player[closest].weaponids[0]]=.25;
2594 if(!player[closest].num_weapons){
2595 player[closest].weaponids[0]=weapons.numweapons;
2596 weapons.owner[weapons.numweapons]=closest;
2597 weapons.type[weapons.numweapons]=knife;
2598 weapons.damage[weapons.numweapons]=0;
2599 weapons.numweapons++;
2600 player[closest].num_weapons=1;
2601 if(weapons.type[player[closest].weaponids[0]]==sword){
2602 weapons.mass[player[closest].weaponids[0]]=1.5;
2603 weapons.tipmass[player[closest].weaponids[0]]=1;
2604 weapons.length[player[closest].weaponids[0]]=.8;
2606 if(weapons.type[player[closest].weaponids[0]]==knife){
2607 weapons.mass[player[closest].weaponids[0]]=1;
2608 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2609 weapons.length[player[closest].weaponids[0]]=.25;
2615 if(Input::isKeyDown(SDLK_u)){
2617 float closestdist=-1;
2620 for(int i=1;i<numplayers;i++){
2621 distance=findDistancefast(&player[i].coords,&player[0].coords);
2622 if(closestdist==-1||distance<closestdist){
2623 closestdist=distance;
2627 player[closest].rotation+=multiplier*50;
2628 player[closest].targetrotation=player[closest].rotation;
2632 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2634 float closestdist=-1;
2637 for(int i=1;i<numplayers;i++){
2638 distance=findDistancefast(&player[i].coords,&player[0].coords);
2639 if(closestdist==-1||distance<closestdist){
2640 closestdist=distance;
2644 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2647 player[closest].whichskin++;
2648 if(player[closest].whichskin>9)
2649 player[closest].whichskin=0;
2650 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2651 player[closest].whichskin=0;
2653 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2654 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2657 if(player[closest].numclothes){
2658 for(int i=0;i<player[closest].numclothes;i++){
2659 tintr=player[closest].clothestintr[i];
2660 tintg=player[closest].clothestintg[i];
2661 tintb=player[closest].clothestintb[i];
2662 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2664 player[closest].DoMipmaps();
2668 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2670 float closestdist=-1;
2673 for(int i=1;i<numplayers;i++){
2674 distance=findDistancefast(&player[i].coords,&player[0].coords);
2675 if(closestdist==-1||distance<closestdist){
2676 closestdist=distance;
2681 if(player[closest].creature==wolftype){
2682 headprop=player[closest].proportionhead.x/1.1;
2683 bodyprop=player[closest].proportionbody.x/1.1;
2684 armprop=player[closest].proportionarms.x/1.1;
2685 legprop=player[closest].proportionlegs.x/1.1;
2688 if(player[closest].creature==rabbittype){
2689 headprop=player[closest].proportionhead.x/1.2;
2690 bodyprop=player[closest].proportionbody.x/1.05;
2691 armprop=player[closest].proportionarms.x/1.00;
2692 legprop=player[closest].proportionlegs.x/1.1;
2696 if(player[closest].creature==rabbittype){
2697 player[closest].skeleton.id=closest;
2698 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);
2699 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2700 player[closest].whichskin=0;
2701 player[closest].creature=wolftype;
2703 player[closest].proportionhead=1.1;
2704 player[closest].proportionbody=1.1;
2705 player[closest].proportionarms=1.1;
2706 player[closest].proportionlegs=1.1;
2707 player[closest].proportionlegs.y=1.1;
2708 player[closest].scale=.23*5*player[0].scale;
2710 player[closest].damagetolerance=300;
2714 player[closest].skeleton.id=closest;
2715 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);
2716 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2717 player[closest].whichskin=0;
2718 player[closest].creature=rabbittype;
2720 player[closest].proportionhead=1.2;
2721 player[closest].proportionbody=1.05;
2722 player[closest].proportionarms=1.00;
2723 player[closest].proportionlegs=1.1;
2724 player[closest].proportionlegs.y=1.05;
2725 player[closest].scale=.2*5*player[0].scale;
2727 player[closest].damagetolerance=200;
2730 if(player[closest].creature==wolftype){
2731 player[closest].proportionhead=1.1*headprop;
2732 player[closest].proportionbody=1.1*bodyprop;
2733 player[closest].proportionarms=1.1*armprop;
2734 player[closest].proportionlegs=1.1*legprop;
2737 if(player[closest].creature==rabbittype){
2738 player[closest].proportionhead=1.2*headprop;
2739 player[closest].proportionbody=1.05*bodyprop;
2740 player[closest].proportionarms=1.00*armprop;
2741 player[closest].proportionlegs=1.1*legprop;
2742 player[closest].proportionlegs.y=1.05*legprop;
2748 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2754 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2756 float closestdist=-1;
2758 XYZ flatfacing2,flatvelocity2;
2761 for(int i=1;i<numplayers;i++){
2762 distance=findDistancefast(&player[i].coords,&player[0].coords);
2763 if(distance<144&&!player[i].headless)
2764 if(closestdist==-1||distance<closestdist){
2765 closestdist=distance;
2767 blah = player[i].coords;
2772 XYZ headspurtdirection;
2773 //int i = player[closest].skeleton.jointlabels[head];
2774 Joint& headjoint=playerJoint(closest,head);
2775 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2776 if(!player[closest].skeleton.free)
2777 flatvelocity2=player[closest].velocity;
2778 if(player[closest].skeleton.free)
2779 flatvelocity2=headjoint.velocity;
2780 if(!player[closest].skeleton.free)
2781 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;
2782 if(player[closest].skeleton.free)
2783 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2784 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2785 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2786 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2787 headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
2788 Normalise(&headspurtdirection);
2789 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2790 flatvelocity2+=headspurtdirection*8;
2791 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2793 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2795 emit_sound_at(splattersound, blah);
2796 emit_sound_at(breaksound2, blah, 100.);
2798 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2799 player[closest].RagDoll(0);
2800 player[closest].dead=2;
2801 player[closest].headless=1;
2802 player[closest].DoBloodBig(3,165);
2808 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2810 float closestdist=-1;
2812 XYZ flatfacing2,flatvelocity2;
2815 for(int i=1;i<numplayers;i++){
2816 distance=findDistancefast(&player[i].coords,&player[0].coords);
2818 if(closestdist==-1||distance<closestdist){
2819 closestdist=distance;
2821 blah=player[i].coords;
2826 emit_sound_at(splattersound, blah);
2828 emit_sound_at(breaksound2, blah);
2830 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2831 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2832 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2833 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;
2834 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2835 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2836 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2837 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2838 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2839 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2840 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2843 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2844 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2845 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2846 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;
2847 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2848 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2849 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2850 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2851 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2852 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2855 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2856 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2857 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2858 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;
2859 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2860 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2861 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2862 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2863 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2864 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2867 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2868 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2869 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2870 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;
2871 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2872 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2873 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2874 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2875 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2876 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2880 for(int j=0;j<numplayers; j++){
2882 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2883 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2884 if(player[j].skeleton.free==2)
2885 player[j].skeleton.free=1;
2886 player[j].skeleton.longdead=0;
2887 player[j].RagDoll(0);
2888 for(int i=0;i<player[j].skeleton.num_joints; i++){
2889 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2890 if(findDistancefast(&temppos,&player[closest].coords)<25){
2891 flatvelocity2=temppos-player[closest].coords;
2892 Normalise(&flatvelocity2);
2893 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2900 player[closest].DoDamage(10000);
2901 player[closest].RagDoll(0);
2902 player[closest].dead=2;
2903 player[closest].coords=20;
2904 player[closest].skeleton.free=2;
2911 if(Input::isKeyPressed(SDLK_f)){
2912 player[0].onfire=1-player[0].onfire;
2913 if(player[0].onfire){
2914 player[0].CatchFire();
2916 if(!player[0].onfire){
2917 emit_sound_at(fireendsound, player[0].coords);
2918 pause_sound(stream_firesound);
2922 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2923 //if(!player[0].skeleton.free)player[0].damage+=500;
2924 player[0].RagDoll(0);
2925 //player[0].spurt=1;
2926 //player[0].DoDamage(1000);
2928 emit_sound_at(whooshsound, player[0].coords, 128.);
2931 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2932 for(int i=0;i<objects.numobjects;i++){
2933 if(objects.type[i]==treeleavestype){
2934 objects.scale[i]*=.9;
2939 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2940 editorenabled=1-editorenabled;
2942 player[0].damagetolerance=100000;
2944 player[0].damagetolerance=200;
2946 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2947 player[0].permanentdamage=0;
2948 player[0].superpermanentdamage=0;
2949 player[0].bloodloss=0;
2950 player[0].deathbleeding=0;
2954 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2956 if(targetlevel>numchallengelevels-1)
2963 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2965 float closestdist=-1;
2968 for(int i=1;i<numplayers;i++){
2969 distance=findDistancefast(&player[i].coords,&player[0].coords);
2970 if(closestdist==-1||distance<closestdist){
2971 closestdist=distance;
2975 if(closestdist>0&&closest>=0){
2976 //player[closest]=player[numplayers-1];
2977 //player[closest].skeleton=player[numplayers-1].skeleton;
2982 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2984 float closestdist=-1;
2987 for(int i=1;i<max_objects;i++){
2988 distance=findDistancefast(&objects.position[i],&player[0].coords);
2989 if(closestdist==-1||distance<closestdist){
2990 closestdist=distance;
2994 if(closestdist>0&&closest>=0){
2995 objects.position[closest].y-=500;
2999 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3001 //if(drawmode>2)drawmode=0;
3002 if(objects.numobjects<max_objects-1){
3004 boxcoords.x=player[0].coords.x;
3005 boxcoords.z=player[0].coords.z;
3006 boxcoords.y=player[0].coords.y-3;
3007 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3008 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3009 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3010 float temprotat,temprotat2;
3011 temprotat=editorrotation;
3012 temprotat2=editorrotation2;
3013 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3014 if(temprotat2<0)temprotat2=Random()%360;
3016 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3017 if(editortype==treetrunktype)
3018 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
3022 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3023 if(numplayers<maxplayers-1){
3024 player[numplayers].scale=.2*5*player[0].scale;
3025 player[numplayers].creature=rabbittype;
3026 player[numplayers].howactive=editoractive;
3027 player[numplayers].skeleton.id=numplayers;
3028 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);
3030 //texsize=512*512*3/texdetail/texdetail;
3031 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3032 //player[numplayers].skeleton.skinText.resize(texsize);
3034 int k=abs(Random()%2)+1;
3036 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3037 player[numplayers].whichskin=0;
3040 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3041 player[numplayers].whichskin=1;
3044 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3045 player[numplayers].whichskin=2;
3048 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
3049 player[numplayers].power=1;
3050 player[numplayers].speedmult=1;
3051 player[numplayers].currentanimation=bounceidleanim;
3052 player[numplayers].targetanimation=bounceidleanim;
3053 player[numplayers].currentframe=0;
3054 player[numplayers].targetframe=1;
3055 player[numplayers].target=0;
3056 player[numplayers].bled=0;
3057 player[numplayers].speed=1+(float)(Random()%100)/1000;
3059 player[numplayers].targetrotation=player[0].targetrotation;
3060 player[numplayers].rotation=player[0].rotation;
3062 player[numplayers].velocity=0;
3063 player[numplayers].coords=player[0].coords;
3064 player[numplayers].oldcoords=player[numplayers].coords;
3065 player[numplayers].realoldcoords=player[numplayers].coords;
3067 player[numplayers].id=numplayers;
3068 player[numplayers].skeleton.id=numplayers;
3069 player[numplayers].updatedelay=0;
3070 player[numplayers].normalsupdatedelay=0;
3072 player[numplayers].aitype=passivetype;
3074 if(player[0].creature==wolftype){
3075 headprop=player[0].proportionhead.x/1.1;
3076 bodyprop=player[0].proportionbody.x/1.1;
3077 armprop=player[0].proportionarms.x/1.1;
3078 legprop=player[0].proportionlegs.x/1.1;
3081 if(player[0].creature==rabbittype){
3082 headprop=player[0].proportionhead.x/1.2;
3083 bodyprop=player[0].proportionbody.x/1.05;
3084 armprop=player[0].proportionarms.x/1.00;
3085 legprop=player[0].proportionlegs.x/1.1;
3088 if(player[numplayers].creature==wolftype){
3089 player[numplayers].proportionhead=1.1*headprop;
3090 player[numplayers].proportionbody=1.1*bodyprop;
3091 player[numplayers].proportionarms=1.1*armprop;
3092 player[numplayers].proportionlegs=1.1*legprop;
3095 if(player[numplayers].creature==rabbittype){
3096 player[numplayers].proportionhead=1.2*headprop;
3097 player[numplayers].proportionbody=1.05*bodyprop;
3098 player[numplayers].proportionarms=1.00*armprop;
3099 player[numplayers].proportionlegs=1.1*legprop;
3100 player[numplayers].proportionlegs.y=1.05*legprop;
3103 player[numplayers].headless=0;
3104 player[numplayers].onfire=0;
3107 player[numplayers].proportionhead.z=0;
3108 player[numplayers].proportionbody.z=0;
3109 player[numplayers].proportionarms.z=0;
3110 player[numplayers].proportionlegs.z=0;
3113 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3115 player[numplayers].damagetolerance=200;
3117 player[numplayers].protectionhead=player[0].protectionhead;
3118 player[numplayers].protectionhigh=player[0].protectionhigh;
3119 player[numplayers].protectionlow=player[0].protectionlow;
3120 player[numplayers].armorhead=player[0].armorhead;
3121 player[numplayers].armorhigh=player[0].armorhigh;
3122 player[numplayers].armorlow=player[0].armorlow;
3123 player[numplayers].metalhead=player[0].metalhead;
3124 player[numplayers].metalhigh=player[0].metalhigh;
3125 player[numplayers].metallow=player[0].metallow;
3127 player[numplayers].immobile=player[0].immobile;
3129 player[numplayers].numclothes=player[0].numclothes;
3130 if(player[numplayers].numclothes)
3131 for(int i=0;i<player[numplayers].numclothes;i++){
3132 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3133 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3134 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3135 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3136 tintr=player[numplayers].clothestintr[i];
3137 tintg=player[numplayers].clothestintg[i];
3138 tintb=player[numplayers].clothestintb[i];
3139 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3141 if(player[numplayers].numclothes){
3142 player[numplayers].DoMipmaps();
3145 player[numplayers].power=player[0].power;
3146 player[numplayers].speedmult=player[0].speedmult;
3148 player[numplayers].damage=0;
3149 player[numplayers].permanentdamage=0;
3150 player[numplayers].superpermanentdamage=0;
3151 player[numplayers].deathbleeding=0;
3152 player[numplayers].bleeding=0;
3153 player[numplayers].numwaypoints=0;
3154 player[numplayers].waypoint=0;
3155 player[numplayers].jumppath=0;
3156 player[numplayers].weaponstuck=-1;
3157 player[numplayers].weaponactive=-1;
3158 player[numplayers].num_weapons=0;
3159 player[numplayers].bloodloss=0;
3160 player[numplayers].dead=0;
3162 player[numplayers].loaded=1;
3168 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3169 if(player[numplayers-1].numwaypoints<90){
3170 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3171 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3172 player[numplayers-1].numwaypoints++;
3176 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3177 if(numpathpoints<30){
3178 bool connected,alreadyconnected;
3181 for(int i=0;i<numpathpoints;i++){
3182 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3184 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3185 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3187 if(!alreadyconnected){
3188 numpathpointconnect[pathpointselected]++;
3190 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3196 pathpoint[numpathpoints-1]=player[0].coords;
3197 numpathpointconnect[numpathpoints-1]=0;
3198 if(numpathpoints>1&&pathpointselected!=-1){
3199 numpathpointconnect[pathpointselected]++;
3200 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3202 pathpointselected=numpathpoints-1;
3207 if(Input::isKeyPressed(SDLK_PERIOD)){
3208 pathpointselected++;
3209 if(pathpointselected>=numpathpoints)
3210 pathpointselected=-1;
3212 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3213 pathpointselected--;
3214 if(pathpointselected<=-2)
3215 pathpointselected=numpathpoints-1;
3217 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3218 if(pathpointselected!=-1){
3220 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3221 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3222 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3223 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3225 for(int i=0;i<numpathpoints;i++){
3226 for(int j=0;j<numpathpointconnect[i];j++){
3227 if(pathpointconnect[i][j]==pathpointselected){
3228 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3229 numpathpointconnect[i]--;
3231 if(pathpointconnect[i][j]==numpathpoints){
3232 pathpointconnect[i][j]=pathpointselected;
3236 pathpointselected=numpathpoints-1;
3240 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3242 if(editortype==treeleavestype||editortype==10)editortype--;
3243 if(editortype<0)editortype=firetype;
3246 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3248 if(editortype==treeleavestype||editortype==10)editortype++;
3249 if(editortype>firetype)editortype=0;
3252 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3253 editorrotation-=multiplier*100;
3254 if(editorrotation<-.01)editorrotation=-.01;
3257 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3258 editorrotation+=multiplier*100;
3261 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3262 editorsize+=multiplier;
3265 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3266 editorsize-=multiplier;
3267 if(editorsize<.1)editorsize=.1;
3271 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3272 mapradius-=multiplier*10;
3275 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3276 mapradius+=multiplier*10;
3278 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3279 editorrotation2+=multiplier*100;
3282 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3283 editorrotation2-=multiplier*100;
3284 if(editorrotation2<-.01)editorrotation2=-.01;
3286 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3288 float closestdist=-1;
3290 for(int i=0;i<objects.numobjects;i++){
3291 distance=findDistancefast(&objects.position[i],&player[0].coords);
3292 if(closestdist==-1||distance<closestdist){
3293 closestdist=distance;
3297 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3303 void Game::doJumpReversals(){
3304 for(int k=0;k<numplayers;k++)
3305 for(int i=k;i<numplayers;i++){
3307 if( player[k].skeleton.free==0&&
3308 player[i].skeleton.oldfree==0&&
3309 (player[i].targetanimation==jumpupanim||
3310 player[k].targetanimation==jumpupanim)&&
3311 (player[i].aitype==playercontrolled||
3312 player[k].aitype==playercontrolled)&&
3313 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3314 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3315 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3316 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3317 //TODO: refactor two huge similar ifs
3318 if(player[i].targetanimation==jumpupanim&&
3319 player[k].targetanimation!=getupfrombackanim&&
3320 player[k].targetanimation!=getupfromfrontanim&&
3321 animation[player[k].targetanimation].height==middleheight&&
3322 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3323 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3324 player[k].aitype!=playercontrolled)){
3325 player[i].victim=&player[k];
3326 player[i].velocity=0;
3327 player[i].currentanimation=jumpreversedanim;
3328 player[i].targetanimation=jumpreversedanim;
3329 player[i].currentframe=0;
3330 player[i].targetframe=1;
3331 player[i].targettilt2=0;
3332 player[k].victim=&player[i];
3333 player[k].velocity=0;
3334 player[k].currentanimation=jumpreversalanim;
3335 player[k].targetanimation=jumpreversalanim;
3336 player[k].currentframe=0;
3337 player[k].targetframe=1;
3338 player[k].targettilt2=0;
3339 if(player[i].coords.y<player[k].coords.y+1){
3340 player[i].currentanimation=rabbitkickreversedanim;
3341 player[i].targetanimation=rabbitkickreversedanim;
3342 player[i].currentframe=1;
3343 player[i].targetframe=2;
3344 player[k].currentanimation=rabbitkickreversalanim;
3345 player[k].targetanimation=rabbitkickreversalanim;
3346 player[k].currentframe=1;
3347 player[k].targetframe=2;
3350 player[k].oldcoords=player[k].coords;
3351 player[i].coords=player[k].coords;
3352 player[k].targetrotation=player[i].targetrotation;
3353 player[k].rotation=player[i].targetrotation;
3354 if(player[k].aitype==attacktypecutoff)
3355 player[k].stunned=.5;
3357 if(player[k].targetanimation==jumpupanim&&
3358 player[i].targetanimation!=getupfrombackanim&&
3359 player[i].targetanimation!=getupfromfrontanim&&
3360 animation[player[i].targetanimation].height==middleheight&&
3361 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3362 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3363 player[i].aitype!=playercontrolled)){
3364 player[k].victim=&player[i];
3365 player[k].velocity=0;
3366 player[k].currentanimation=jumpreversedanim;
3367 player[k].targetanimation=jumpreversedanim;
3368 player[k].currentframe=0;
3369 player[k].targetframe=1;
3370 player[k].targettilt2=0;
3371 player[i].victim=&player[k];
3372 player[i].velocity=0;
3373 player[i].currentanimation=jumpreversalanim;
3374 player[i].targetanimation=jumpreversalanim;
3375 player[i].currentframe=0;
3376 player[i].targetframe=1;
3377 player[i].targettilt2=0;
3378 if(player[k].coords.y<player[i].coords.y+1){
3379 player[k].targetanimation=rabbitkickreversedanim;
3380 player[k].currentanimation=rabbitkickreversedanim;
3381 player[i].currentanimation=rabbitkickreversalanim;
3382 player[i].targetanimation=rabbitkickreversalanim;
3383 player[k].currentframe=1;
3384 player[k].targetframe=2;
3385 player[i].currentframe=1;
3386 player[i].targetframe=2;
3389 player[i].oldcoords=player[i].coords;
3390 player[k].coords=player[i].coords;
3391 player[i].targetrotation=player[k].targetrotation;
3392 player[i].rotation=player[k].targetrotation;
3393 if(player[i].aitype==attacktypecutoff)
3394 player[i].stunned=.5;
3401 void Game::doAerialAcrobatics(){
3402 static XYZ facing,flatfacing;
3403 for(int k=0;k<numplayers;k++){
3404 player[k].turnspeed=500;
3406 if((player[k].isRun()&&
3407 ((player[k].targetrotation!=rabbitrunninganim&&
3408 player[k].targetrotation!=wolfrunninganim)||
3409 player[k].targetframe==4))||
3410 player[k].targetanimation==removeknifeanim||
3411 player[k].targetanimation==crouchremoveknifeanim||
3412 player[k].targetanimation==flipanim||
3413 player[k].targetanimation==fightsidestep||
3414 player[k].targetanimation==walkanim){
3415 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3419 if(player[k].isStop()||
3420 player[k].isLanding()||
3421 player[k].targetanimation==staggerbackhighanim||
3422 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3423 player[k].targetanimation==staggerbackhardanim||
3424 player[k].targetanimation==backhandspringanim||
3425 player[k].targetanimation==dodgebackanim||
3426 player[k].targetanimation==rollanim||
3427 (animation[player[k].targetanimation].attack&&
3428 player[k].targetanimation!=rabbitkickanim&&
3429 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3430 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3431 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3434 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3435 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3438 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3439 player[k].DoStuff();
3440 if(player[k].immobile&&k!=0)
3441 player[k].coords=player[k].realoldcoords;
3443 //if player's position has changed (?)
3444 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3445 !player[k].skeleton.free&&
3446 player[k].targetanimation!=climbanim&&
3447 player[k].targetanimation!=hanganim){
3448 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3452 if(player[k].collide<-.3)
3453 player[k].collide=-.3;
3454 if(player[k].collide>1)
3455 player[k].collide=1;
3456 player[k].collide-=multiplier*30;
3459 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3461 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3462 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3463 if(objects.type[i]!=rocktype||
3464 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3465 objects.position[i].y>player[k].coords.y){
3466 lowpoint=player[k].coords;
3467 if(player[k].targetanimation!=jumpupanim&&
3468 player[k].targetanimation!=jumpdownanim&&
3469 !player[k].isFlip())
3473 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3474 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3475 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3476 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3477 flatfacing=lowpoint-player[k].coords;
3478 player[k].coords=lowpoint;
3479 player[k].coords.y-=1.3;
3480 player[k].collide=1;
3483 //TODO: refactor four similar blocks
3484 if(player[k].aitype==playercontrolled&&
3485 (player[k].targetanimation==jumpupanim||
3486 player[k].targetanimation==jumpdownanim||
3487 player[k].isFlip())&&
3488 !player[k].jumptogglekeydown&&
3489 player[k].jumpkeydown){
3490 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3491 XYZ tempcoords1=lowpoint;
3492 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3493 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3494 setAnimation(k,walljumpleftanim);
3495 emit_sound_at(movewhooshsound, player[k].coords);
3497 pause_sound(whooshsound);
3499 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3500 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3501 if(lowpointtarget.z<0)
3502 player[k].rotation=180-player[k].rotation;
3503 player[k].targetrotation=player[k].rotation;
3504 player[k].lowrotation=player[k].rotation;
3510 lowpoint=tempcoords1;
3511 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3512 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3513 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3514 setAnimation(k,walljumprightanim);
3515 emit_sound_at(movewhooshsound, player[k].coords);
3516 if(k==0)pause_sound(whooshsound);
3518 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3519 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3520 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3521 player[k].targetrotation=player[k].rotation;
3522 player[k].lowrotation=player[k].rotation;
3523 if(k==0)numwallflipped++;
3527 lowpoint=tempcoords1;
3528 lowpointtarget=lowpoint+player[k].facing*2;
3529 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3530 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3531 setAnimation(k,walljumpbackanim);
3532 emit_sound_at(movewhooshsound, player[k].coords);
3533 if(k==0)pause_sound(whooshsound);
3535 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3536 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3537 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3538 player[k].targetrotation=player[k].rotation;
3539 player[k].lowrotation=player[k].rotation;
3540 if(k==0)numwallflipped++;
3544 lowpoint=tempcoords1;
3545 lowpointtarget=lowpoint-player[k].facing*2;
3546 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3547 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3548 setAnimation(k,walljumpfrontanim);
3549 emit_sound_at(movewhooshsound, player[k].coords);
3550 if(k==0)pause_sound(whooshsound);
3552 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3553 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3554 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3555 player[k].rotation+=180;
3556 player[k].targetrotation=player[k].rotation;
3557 player[k].lowrotation=player[k].rotation;
3558 if(k==0)numwallflipped++;
3566 else if(objects.type[i]==rocktype){
3567 lowpoint2=player[k].coords;
3568 lowpoint=player[k].coords;
3570 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3571 player[k].coords=colpoint;
3572 player[k].collide=1;
3575 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3576 //flipped into a rock
3577 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3578 player[k].RagDoll(0);
3580 if(player[k].targetanimation==jumpupanim){
3581 player[k].jumppower=-4;
3582 player[k].targetanimation=player[k].getIdle();
3585 player[k].targetframe=0;
3586 player[k].onterrain=1;
3588 if(player[k].id==0){
3589 pause_sound(whooshsound);
3590 OPENAL_SetVolume(channels[whooshsound], 0);
3594 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3595 if(player[k].isFlip())
3596 player[k].jumppower=-4;
3597 player[k].targetanimation=player[k].getLanding();
3598 emit_sound_at(landsound, player[k].coords, 128.);
3600 envsound[numenvsounds]=player[k].coords;
3601 envsoundvol[numenvsounds]=16;
3602 envsoundlife[numenvsounds]=.4;
3612 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3613 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3614 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3615 lowpoint=player[k].coords;
3617 if(objects.type[i]!=rocktype)
3618 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3619 if(player[k].targetanimation!=jumpupanim&&
3620 player[k].targetanimation!=jumpdownanim&&
3621 player[k].onterrain)
3622 player[k].avoidcollided=1;
3623 player[k].coords=lowpoint;
3624 player[k].coords.y-=1.35;
3625 player[k].collide=1;
3627 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3628 (player[k].currentanimation!=climbanim&&
3629 player[k].currentanimation!=hanganim&&
3630 !player[k].isWallJump()||
3631 player[k].targetanimation==jumpupanim||
3632 player[k].targetanimation==jumpdownanim)){
3633 lowpoint=player[k].coords;
3634 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3635 lowpoint=player[k].coords;
3639 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3640 lowpointtarget=lowpoint+facing*1.4;
3641 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3643 lowpoint=player[k].coords;
3645 lowpointtarget=lowpoint+facing*1.4;
3647 lowpointtarget2=lowpointtarget;
3649 lowpointtarget3=lowpointtarget;
3651 lowpointtarget4=lowpointtarget;
3653 lowpointtarget5=lowpointtarget;
3655 lowpointtarget6=lowpointtarget;
3657 lowpointtarget7=lowpoint;
3659 lowpointtarget2.x+=.1;
3661 lowpointtarget3.z+=.1;
3663 lowpointtarget4.x-=.1;
3665 lowpointtarget5.z-=.1;
3667 lowpointtarget6.y+=45/13;
3668 lowpointtarget6+=facing*.6;
3669 lowpointtarget7.y+=90/13;
3670 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3671 if(objects.friction[i]>.5)
3673 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3674 player[k].collided=1;
3675 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3676 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3677 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3678 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3679 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3680 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3681 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3682 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3683 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3684 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3685 for(int j=0;j<45;j++){
3686 lowpoint=player[k].coords;
3687 lowpoint.y+=(float)j/13;
3688 lowpointtarget=lowpoint+facing*1.4;
3689 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3690 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3691 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3693 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3694 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3695 lowpoint=player[k].coords;
3696 lowpoint.y+=(float)j/13;
3697 lowpointtarget=lowpoint+facing*1.3;
3698 flatfacing=player[k].coords;
3699 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3700 player[k].coords.y=lowpointtarget.y-.07;
3701 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3703 if(j>10||!player[k].isRun()){
3704 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3706 pause_sound(whooshsound);
3708 emit_sound_at(jumpsound, player[k].coords, 128.);
3710 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3711 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3712 if(lowpointtarget.z<0)
3713 player[k].rotation=180-player[k].rotation;
3714 player[k].targetrotation=player[k].rotation;
3715 player[k].lowrotation=player[k].rotation;
3717 //player[k].velocity=lowpointtarget*.03;
3718 player[k].velocity=0;
3721 if(player[k].targetanimation==jumpupanim){
3722 player[k].targetanimation=climbanim;
3723 player[k].jumppower=0;
3724 player[k].jumpclimb=1;
3726 player[k].transspeed=6;
3728 player[k].targetframe=1;
3731 setAnimation(k,hanganim);
3732 player[k].jumppower=0;
3744 if(player[k].collide<=0){
3746 if(!player[k].onterrain&&
3747 player[k].targetanimation!=jumpupanim&&
3748 player[k].targetanimation!=jumpdownanim&&
3749 player[k].targetanimation!=climbanim&&
3750 player[k].targetanimation!=hanganim&&
3751 !player[k].isWallJump()&&
3752 !player[k].isFlip()){
3753 if(player[k].currentanimation!=climbanim&&
3754 player[k].currentanimation!=tempanim&&
3755 player[k].targetanimation!=backhandspringanim&&
3756 (player[k].targetanimation!=rollanim||
3757 player[k].targetframe<2||
3758 player[k].targetframe>6)){
3759 //stagger off ledge (?)
3760 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3761 player[k].RagDoll(0);
3762 setAnimation(k,jumpdownanim);
3765 emit_sound_at(whooshsound, player[k].coords, 128.);
3768 player[k].velocity.y+=gravity;
3772 player[k].realoldcoords=player[k].coords;
3776 void Game::doAttacks(){
3777 static XYZ relative;
3778 static int randattack;
3779 static bool playerrealattackkeydown=0;
3781 if(!Input::isKeyDown(attackkey))
3784 player[0].attackkeydown=0;
3786 playerrealattackkeydown=0;
3788 playerrealattackkeydown=Input::isKeyDown(attackkey);
3789 if((player[0].parriedrecently<=0||
3790 player[0].weaponactive==-1)&&
3793 player[0].lastattack!=swordslashanim&&
3794 player[0].lastattack!=knifeslashstartanim&&
3795 player[0].lastattack!=staffhitanim&&
3796 player[0].lastattack!=staffspinhitanim)))
3797 player[0].attackkeydown=Input::isKeyDown(attackkey);
3798 if(Input::isKeyDown(attackkey)&&
3800 !player[0].backkeydown){
3801 for(int k=0;k<numplayers;k++){
3802 if((player[k].targetanimation==swordslashanim||
3803 player[k].targetanimation==staffhitanim||
3804 player[k].targetanimation==staffspinhitanim)&&
3805 player[0].currentanimation!=dodgebackanim&&
3806 !player[k].skeleton.free)
3807 player[k].Reverse();
3811 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3813 for(int k=0;k<numplayers;k++){
3814 if(indialogue!=-1)player[k].attackkeydown=0;
3815 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3816 if(player[k].aitype!=playercontrolled)
3817 player[k].victim=&player[0];
3818 //attack key pressed
3819 if(player[k].attackkeydown){
3821 if(player[k].backkeydown&&
3822 player[k].targetanimation!=backhandspringanim&&
3823 (player[k].isIdle()||
3824 player[k].isStop()||
3826 player[k].targetanimation==walkanim)){
3827 if(player[k].jumppower<=1){
3828 player[k].jumppower-=2;
3830 for(int i=0;i<numplayers;i++){
3832 if(player[i].targetanimation==swordslashanim||
3833 player[i].targetanimation==knifeslashstartanim||
3834 player[i].targetanimation==staffhitanim||
3835 player[i].targetanimation==staffspinhitanim)
3836 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3837 setAnimation(k,dodgebackanim);
3838 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3839 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3842 if(player[k].targetanimation!=dodgebackanim){
3843 if(k==0)numflipped++;
3844 setAnimation(k,backhandspringanim);
3845 player[k].targetrotation=-rotation+180;
3846 if(player[k].leftkeydown)
3847 player[k].targetrotation-=45;
3848 if(player[k].rightkeydown)
3849 player[k].targetrotation+=45;
3850 player[k].rotation=player[k].targetrotation;
3851 player[k].jumppower-=2;
3856 if(!animation[player[k].targetanimation].attack&&
3857 !player[k].backkeydown&&
3858 (player[k].isIdle()||
3860 player[k].targetanimation==walkanim||
3861 player[k].targetanimation==sneakanim||
3862 player[k].isCrouch())){
3863 const int attackweapon=player[k].weaponactive==-1?0:weapons.type[player[k].weaponids[player[k].weaponactive]];
3864 //normal attacks (?)
3865 player[k].hasvictim=0;
3867 for(int i=0;i<numplayers;i++){
3868 if(i==k||!(k==0||i==0))continue;
3869 if(!player[k].hasvictim)
3870 if(animation[player[k].targetanimation].attack!=reversal){
3872 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3874 !player[i].skeleton.free&&
3875 player[i].howactive<typedead1&&
3876 player[i].targetanimation!=jumpreversedanim&&
3877 player[i].targetanimation!=rabbitkickreversedanim&&
3878 player[i].targetanimation!=rabbitkickanim&&
3879 player[k].targetanimation!=rabbitkickanim&&
3880 player[i].targetanimation!=getupfrombackanim&&
3881 (player[i].targetanimation!=staggerbackhighanim&&
3882 (player[i].targetanimation!=staggerbackhardanim||
3883 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3884 player[i].targetanimation!=jumpdownanim&&
3885 player[i].targetanimation!=jumpupanim&&
3886 player[i].targetanimation!=getupfromfrontanim){
3887 player[k].victim=&player[i];
3888 player[k].hasvictim=1;
3889 if(player[k].aitype==playercontrolled){ //human player
3891 if(distance<2.5*sq(player[k].scale*5)&&
3892 player[k].crouchkeydown&&
3893 animation[player[i].targetanimation].height!=lowheight)
3894 player[k].targetanimation=sweepanim;
3896 else if(distance<1.5*sq(player[k].scale*5)&&
3897 animation[player[i].targetanimation].height!=lowheight&&
3898 !player[k].forwardkeydown&&
3899 !player[k].leftkeydown&&
3900 !player[k].rightkeydown&&
3901 !player[k].crouchkeydown&&
3904 player[k].targetanimation=winduppunchanim;
3906 else if(distance<2.5*sq(player[k].scale*5)&&
3907 animation[player[i].targetanimation].height!=lowheight&&
3908 !player[k].forwardkeydown&&
3909 !player[k].leftkeydown&&
3910 !player[k].rightkeydown&&
3911 !player[k].crouchkeydown&&
3913 player[k].targetanimation=upunchanim;
3915 else if(distance<2.5*sq(player[k].scale*5)&&
3916 player[i].staggerdelay>0&&
3917 attackweapon==knife&&
3918 player[i].bloodloss>player[i].damagetolerance/2)
3919 player[k].targetanimation=knifefollowanim;
3921 else if(distance<2.5*sq(player[k].scale*5)&&
3922 animation[player[i].targetanimation].height!=lowheight&&
3923 !player[k].forwardkeydown&&
3924 !player[k].leftkeydown&&
3925 !player[k].rightkeydown&&
3926 !player[k].crouchkeydown&&
3927 attackweapon==knife&&
3928 player[k].weaponmissdelay<=0)
3929 player[k].targetanimation=knifeslashstartanim;
3931 else if(distance<4.5*sq(player[k].scale*5)&&
3932 animation[player[i].targetanimation].height!=lowheight&&
3933 !player[k].crouchkeydown&&
3934 attackweapon==sword&&
3935 player[k].weaponmissdelay<=0)
3936 player[k].targetanimation=swordslashanim;
3938 else if(distance<4.5*sq(player[k].scale*5)&&
3939 animation[player[i].targetanimation].height!=lowheight&&
3940 !player[k].crouchkeydown&&
3941 attackweapon==staff&&
3942 player[k].weaponmissdelay<=0&&
3943 !player[k].leftkeydown&&
3944 !player[k].rightkeydown&&
3945 !player[k].forwardkeydown)
3946 player[k].targetanimation=staffhitanim;
3948 else if(distance<4.5*sq(player[k].scale*5)&&
3949 animation[player[i].targetanimation].height!=lowheight&&
3950 !player[k].crouchkeydown&&
3951 attackweapon==staff&&
3952 player[k].weaponmissdelay<=0)
3953 player[k].targetanimation=staffspinhitanim;
3955 else if(distance<2.5*sq(player[k].scale*5)&&
3956 animation[player[i].targetanimation].height!=lowheight)
3957 player[k].targetanimation=spinkickanim;
3959 else if(distance<2.5*sq(player[k].scale*5)&&
3960 animation[player[i].targetanimation].height==lowheight&&
3961 animation[player[k].targetanimation].attack!=normalattack)
3962 player[k].targetanimation=lowkickanim;
3963 } else { //AI player
3964 if(distance<4.5*sq(player[k].scale*5)){
3965 randattack=abs(Random()%5);
3966 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3968 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3969 player[k].targetanimation=sweepanim;
3971 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3973 player[k].targetanimation=upunchanim;
3975 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3976 player[k].targetanimation=spinkickanim;
3978 else if(animation[player[i].targetanimation].height==lowheight)
3979 player[k].targetanimation=lowkickanim;
3983 if((tutoriallevel!=1||!attackweapon)&&
3984 distance<2.5*sq(player[k].scale*5)&&
3986 animation[player[i].targetanimation].height!=lowheight)
3987 player[k].targetanimation=sweepanim;
3989 else if(distance<2.5*sq(player[k].scale*5)&&
3990 attackweapon==knife&&
3991 player[k].weaponmissdelay<=0)
3992 player[k].targetanimation=knifeslashstartanim;
3994 else if(!(player[0].victim==&player[i]&&
3995 player[0].hasvictim&&
3996 player[0].targetanimation==swordslashanim)&&
3997 attackweapon==sword&&
3998 player[k].weaponmissdelay<=0)
3999 player[k].targetanimation=swordslashanim;
4001 else if(!(player[0].victim==&player[i]&&
4002 player[0].hasvictim&&
4003 player[0].targetanimation==swordslashanim)&&
4004 attackweapon==staff&&
4005 player[k].weaponmissdelay<=0&&
4007 player[k].targetanimation=staffhitanim;
4009 else if(!(player[0].victim==&player[i]&&
4010 player[0].hasvictim&&
4011 player[0].targetanimation==swordslashanim)&&
4012 attackweapon==staff&&
4013 player[k].weaponmissdelay<=0&&
4015 player[k].targetanimation=staffspinhitanim;
4017 else if((tutoriallevel!=1||!attackweapon)&&
4018 distance<2.5*sq(player[k].scale*5)&&
4020 animation[player[i].targetanimation].height!=lowheight)
4021 player[k].targetanimation=spinkickanim;
4023 else if(distance<2.5*sq(player[k].scale*5)&&
4024 animation[player[i].targetanimation].height==lowheight&&
4025 animation[player[k].targetanimation].attack!=normalattack)
4026 player[k].targetanimation=lowkickanim;
4030 //upunch becomes wolfslap
4031 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
4032 player[k].targetanimation=wolfslapanim;
4035 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4036 player[i].howactive<typedead1&&
4037 distance<1.5*sq(player[k].scale*5)&&
4038 !player[i].skeleton.free&&
4039 player[i].targetanimation!=getupfrombackanim&&
4040 player[i].targetanimation!=getupfromfrontanim&&
4041 (player[i].stunned>0&&player[k].madskills||
4042 player[i].surprised>0||
4043 player[i].aitype==passivetype||
4044 attackweapon&&player[i].stunned>0)&&
4045 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4048 player[k].currentanimation=sneakattackanim;
4049 player[k].targetanimation=sneakattackanim;
4050 player[i].currentanimation=sneakattackedanim;
4051 player[i].targetanimation=sneakattackedanim;
4052 player[k].oldcoords=player[k].coords;
4053 player[k].coords=player[i].coords;
4056 if(attackweapon==knife){
4057 player[k].currentanimation=knifesneakattackanim;
4058 player[k].targetanimation=knifesneakattackanim;
4059 player[i].currentanimation=knifesneakattackedanim;
4060 player[i].targetanimation=knifesneakattackedanim;
4061 player[i].oldcoords=player[i].coords;
4062 player[i].coords=player[k].coords;
4065 if(attackweapon==sword){
4066 player[k].currentanimation=swordsneakattackanim;
4067 player[k].targetanimation=swordsneakattackanim;
4068 player[i].currentanimation=swordsneakattackedanim;
4069 player[i].targetanimation=swordsneakattackedanim;
4070 player[i].oldcoords=player[i].coords;
4071 player[i].coords=player[k].coords;
4073 if(attackweapon!=staff){
4074 player[k].victim=&player[i];
4075 player[k].hasvictim=1;
4076 player[i].targettilt2=0;
4077 player[i].targetframe=1;
4078 player[i].currentframe=0;
4080 player[i].velocity=0;
4081 player[k].targettilt2=player[i].targettilt2;
4082 player[k].currentframe=player[i].currentframe;
4083 player[k].targetframe=player[i].targetframe;
4084 player[k].target=player[i].target;
4085 player[k].velocity=0;
4086 player[k].targetrotation=player[i].rotation;
4087 player[k].rotation=player[i].rotation;
4088 player[i].targetrotation=player[i].rotation;
4091 if(animation[player[k].targetanimation].attack==normalattack&&
4092 player[k].victim==&player[i]&&
4093 (!player[i].skeleton.free)){
4095 player[k].targetframe=0;
4098 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4099 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4100 player[k].lastattack3=player[k].lastattack2;
4101 player[k].lastattack2=player[k].lastattack;
4102 player[k].lastattack=player[k].targetanimation;
4104 if(player[k].targetanimation==knifefollowanim&&
4105 player[k].victim==&player[i]){
4107 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4108 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4109 player[k].victim=&player[i];
4110 player[k].hasvictim=1;
4111 player[i].targetanimation=knifefollowedanim;
4112 player[i].currentanimation=knifefollowedanim;
4113 player[i].targettilt2=0;
4114 player[i].targettilt2=player[k].targettilt2;
4115 player[i].targetframe=1;
4116 player[i].currentframe=0;
4118 player[i].velocity=0;
4119 player[k].currentanimation=knifefollowanim;
4120 player[k].targetanimation=knifefollowanim;
4121 player[k].targettilt2=player[i].targettilt2;
4122 player[k].currentframe=player[i].currentframe;
4123 player[k].targetframe=player[i].targetframe;
4124 player[k].target=player[i].target;
4125 player[k].velocity=0;
4126 player[k].oldcoords=player[k].coords;
4127 player[i].coords=player[k].coords;
4128 player[i].targetrotation=player[k].targetrotation;
4129 player[i].rotation=player[k].targetrotation;
4130 player[k].rotation=player[k].targetrotation;
4131 player[i].rotation=player[k].targetrotation;
4135 const bool hasstaff=attackweapon==staff;
4136 if(k==0&&numplayers>1)
4137 for(int i=0;i<numplayers;i++){
4139 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4140 animation[player[k].targetanimation].attack==neutral){
4141 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4142 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4143 if(player[i].skeleton.free)
4144 if(distance<3.5*sq(player[k].scale*5)&&
4146 player[i].skeleton.longdead>1000||
4150 (player[i].skeleton.longdead>2000||
4151 player[i].damage>player[i].damagetolerance/8||
4152 player[i].bloodloss>player[i].damagetolerance/2)&&
4153 distance<1.5*sq(player[k].scale*5)))){
4154 player[k].victim=&player[i];
4155 player[k].hasvictim=1;
4156 if(attackweapon&&tutoriallevel!=1){
4158 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4159 player[k].targetanimation=crouchstabanim;
4161 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4162 player[k].targetanimation=swordgroundstabanim;
4164 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4165 player[k].targetanimation=staffgroundsmashanim;
4168 player[k].crouchkeydown&&
4169 player[k].targetanimation!=crouchstabanim&&
4172 player[i].skeleton.free&&
4173 player[i].skeleton.longdead>1000){
4174 player[k].targetanimation=killanim;
4175 //TODO: refactor this out, what does it do?
4176 for(int j=0;j<terrain.numdecals;j++){
4177 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4178 terrain.decalalivetime[j]<2)
4179 terrain.DeleteDecal(j);
4181 for(int l=0;l<objects.numobjects;l++){
4182 if(objects.model[l].type==decalstype)
4183 for(int j=0;j<objects.model[l].numdecals;j++){
4184 if((objects.model[l].decaltype[j]==blooddecal||
4185 objects.model[l].decaltype[j]==blooddecalslow)&&
4186 objects.model[l].decalalivetime[j]<2)
4187 objects.model[l].DeleteDecal(j);
4191 if(!player[i].dead||musictype!=2)
4193 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4194 player[k].staggerdelay<=0&&
4196 player[i].skeleton.longdead<300&&
4197 player[k].lastattack!=spinkickanim&&
4198 player[i].skeleton.free)&&
4199 (!player[i].dead||musictype!=stream_fighttheme)){
4200 player[k].targetanimation=dropkickanim;
4201 for(int j=0;j<terrain.numdecals;j++){
4202 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4203 terrain.decalalivetime[j]<2){
4204 terrain.DeleteDecal(j);
4207 for(int l=0;l<objects.numobjects;l++){
4208 if(objects.model[l].type==decalstype)
4209 for(int j=0;j<objects.model[l].numdecals;j++){
4210 if((objects.model[l].decaltype[j]==blooddecal||
4211 objects.model[l].decaltype[j]==blooddecalslow)&&
4212 objects.model[l].decalalivetime[j]<2){
4213 objects.model[l].DeleteDecal(j);
4219 if(animation[player[k].targetanimation].attack==normalattack&&
4220 player[k].victim==&player[i]&&
4221 (!player[i].skeleton.free||
4222 player[k].targetanimation==killanim||
4223 player[k].targetanimation==crouchstabanim||
4224 player[k].targetanimation==swordgroundstabanim||
4225 player[k].targetanimation==staffgroundsmashanim||
4226 player[k].targetanimation==dropkickanim)){
4228 player[k].targetframe=0;
4231 XYZ targetpoint=player[i].coords;
4232 if(player[k].targetanimation==crouchstabanim||
4233 player[k].targetanimation==swordgroundstabanim||
4234 player[k].targetanimation==staffgroundsmashanim){
4235 targetpoint+=(playerJoint(i,abdomen).position+
4236 playerJoint(i,neck).position)/2*
4239 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4240 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4242 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4243 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4246 if(player[k].targetanimation==staffgroundsmashanim)
4247 player[k].targettilt2+=10;
4249 player[k].lastattack3=player[k].lastattack2;
4250 player[k].lastattack2=player[k].lastattack;
4251 player[k].lastattack=player[k].targetanimation;
4253 if(player[k].targetanimation==swordgroundstabanim){
4254 player[k].targetrotation+=30;
4259 if(!player[k].hasvictim){
4261 for(int i=0;i<numplayers;i++){
4262 if(i==k||!(i==0||k==0))continue;
4263 if(!player[i].skeleton.free){
4264 if(player[k].hasvictim){
4265 if(findDistancefast(&player[k].coords,&player[i].coords)<
4266 findDistancefast(&player[k].coords,&player[k].victim->coords))
4267 player[k].victim=&player[i];
4269 player[k].victim=&player[i];
4270 player[k].hasvictim=1;
4275 if(player[k].aitype==playercontrolled)
4277 if(player[k].attackkeydown&&
4279 player[k].wasRun()&&
4280 ((player[k].hasvictim&&
4281 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4282 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4283 !player[k].victim->skeleton.free&&
4284 player[k].victim->targetanimation!=getupfrombackanim&&
4285 player[k].victim->targetanimation!=getupfromfrontanim&&
4286 animation[player[k].victim->targetanimation].height!=lowheight&&
4287 player[k].aitype!=playercontrolled&& //wat???
4288 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4289 player[k].rabbitkickenabled)||
4290 player[k].jumpkeydown)){
4292 setAnimation(k,rabbitkickanim);
4295 if(animation[player[k].targetanimation].attack&&k==0){
4297 switch(attackweapon){
4298 case 0: numunarmedattack++; break;
4299 case knife: numknifeattack++; break;
4300 case sword: numswordattack++; break;
4301 case staff: numstaffattack++; break;
4310 void Game::doPlayerCollisions(){
4311 static XYZ rotatetarget;
4312 static float collisionradius;
4314 for(int k=0;k<numplayers;k++)
4315 for(int i=k+1;i<numplayers;i++){
4316 //neither player is part of a reversal
4317 if((animation[player[i].targetanimation].attack!=reversed&&
4318 animation[player[i].targetanimation].attack!=reversal&&
4319 animation[player[k].targetanimation].attack!=reversed&&
4320 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4321 if((animation[player[i].currentanimation].attack!=reversed&&
4322 animation[player[i].currentanimation].attack!=reversal&&
4323 animation[player[k].currentanimation].attack!=reversed&&
4324 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4325 //neither is sleeping
4326 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4327 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4328 //in same patch, neither is climbing
4329 if(player[i].whichpatchx==player[k].whichpatchx&&
4330 player[i].whichpatchz==player[k].whichpatchz&&
4331 player[k].skeleton.oldfree==player[k].skeleton.free&&
4332 player[i].skeleton.oldfree==player[i].skeleton.free&&
4333 player[i].targetanimation!=climbanim&&
4334 player[i].targetanimation!=hanganim&&
4335 player[k].targetanimation!=climbanim&&
4336 player[k].targetanimation!=hanganim)
4337 //players are close (bounding box test)
4338 if(player[i].coords.y>player[k].coords.y-3)
4339 if(player[i].coords.y<player[k].coords.y+3)
4340 if(player[i].coords.x>player[k].coords.x-3)
4341 if(player[i].coords.x<player[k].coords.x+3)
4342 if(player[i].coords.z>player[k].coords.z-3)
4343 if(player[i].coords.z<player[k].coords.z+3){
4344 //spread fire from player to player
4345 if(findDistancefast(&player[i].coords,&player[k].coords)
4346 <3*sq((player[i].scale+player[k].scale)*2.5)){
4347 if(player[i].onfire||player[k].onfire){
4348 if(!player[i].onfire)player[i].CatchFire();
4349 if(!player[k].onfire)player[k].CatchFire();
4353 XYZ tempcoords1=player[i].coords;
4354 XYZ tempcoords2=player[k].coords;
4355 if(!player[i].skeleton.oldfree)
4356 tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
4357 if(!player[k].skeleton.oldfree)
4358 tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
4359 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4360 if(player[0].hasvictim)
4361 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4363 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4364 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4365 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4366 //jump down on a dead body
4369 if(player[0].targetanimation==jumpdownanim&&
4370 !player[0].skeleton.oldfree&&
4371 !player[0].skeleton.free&&
4372 player[l].skeleton.oldfree&&
4373 player[l].skeleton.free&&
4375 player[0].lastcollide<=0&&
4376 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4377 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4378 player[0].coords.y=player[l].coords.y;
4379 player[l].velocity=player[0].velocity;
4380 player[l].skeleton.free=0;
4381 player[l].rotation=0;
4382 player[l].RagDoll(0);
4383 player[l].DoDamage(20);
4385 player[l].skeleton.longdead=0;
4386 player[0].lastcollide=1;
4390 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4391 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4392 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4393 rotatetarget=player[k].velocity-player[i].velocity;
4394 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4395 player[i].skeleton.free)&&
4396 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4397 player[k].skeleton.free))
4398 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4399 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4400 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4402 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4403 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4404 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4405 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4406 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4408 if( (i!=0||player[i].skeleton.free)&&
4409 (k!=0||player[k].skeleton.free)||
4410 (animation[player[i].targetanimation].height==highheight&&
4411 animation[player[k].targetanimation].height==highheight)){
4412 if(tutoriallevel!=1){
4413 emit_sound_at(heavyimpactsound, player[i].coords);
4416 player[i].RagDoll(0);
4417 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4418 award_bonus(0, aimbonus);
4420 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4421 player[k].RagDoll(0);
4422 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4423 award_bonus(0, aimbonus); // Huh, again?
4425 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4427 for(int j=0;j<player[i].skeleton.num_joints;j++){
4428 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4430 for(int j=0;j<player[k].skeleton.num_joints;j++){
4431 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4436 if( (animation[player[i].targetanimation].attack==neutral||
4437 animation[player[i].targetanimation].attack==normalattack)&&
4438 (animation[player[k].targetanimation].attack==neutral||
4439 animation[player[k].targetanimation].attack==normalattack)){
4441 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4442 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4443 rotatetarget=player[k].coords-player[i].coords;
4444 Normalise(&rotatetarget);
4445 player[k].coords=(player[k].coords+player[i].coords)/2;
4446 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4447 *sq((player[i].scale+player[k].scale)*2.5);
4448 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4449 if(player[k].howactive==typeactive||hostile)
4450 if(player[k].isIdle()){
4451 if(player[k].howactive<typesleeping)
4452 setAnimation(k,player[k].getStop());
4453 else if(player[k].howactive==typesleeping)
4454 setAnimation(k,getupfromfrontanim);
4456 player[k].howactive=typeactive;
4458 if(player[i].howactive==typeactive||hostile)
4459 if(player[i].isIdle()){
4460 if(player[i].howactive<typesleeping)
4461 setAnimation(i,player[k].getStop());
4463 setAnimation(i,getupfromfrontanim);
4465 player[i].howactive=typeactive;
4468 //jump down on player
4470 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4471 !player[i].isCrouch()&&
4472 player[i].targetanimation!=rollanim&&
4473 !player[k].skeleton.oldfree&&!
4474 player[k].skeleton.free&&
4475 player[k].lastcollide<=0&&
4476 player[k].velocity.y<-10){
4477 player[i].velocity=player[k].velocity;
4478 player[k].velocity=player[k].velocity*-.5;
4479 player[k].velocity.y=player[i].velocity.y;
4480 player[i].DoDamage(20);
4481 player[i].RagDoll(0);
4482 player[k].lastcollide=1;
4483 award_bonus(k, AboveBonus);
4485 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4486 !player[k].isCrouch()&&
4487 player[k].targetanimation!=rollanim&&
4488 !player[i].skeleton.oldfree&&
4489 !player[i].skeleton.free&&
4490 player[i].lastcollide<=0&&
4491 player[i].velocity.y<-10){
4492 player[k].velocity=player[i].velocity;
4493 player[i].velocity=player[i].velocity*-.3;
4494 player[i].velocity.y=player[k].velocity.y;
4495 player[k].DoDamage(20);
4496 player[k].RagDoll(0);
4497 player[i].lastcollide=1;
4498 award_bonus(i, AboveBonus);
4504 player[i].CheckKick();
4505 player[k].CheckKick();
4511 void Game::doAI(int i){
4512 static bool connected;
4513 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4514 player[i].jumpclimb=0;
4515 //disable movement in editor
4517 player[i].stunned=1;
4520 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4521 player[0].coords.y>player[i].coords.y+2&&
4522 !player[0].onterrain)
4526 if(player[i].aitype==pathfindtype){
4527 if(player[i].finalpathfindpoint==-1){
4528 float closestdistance;
4534 for(int j=0;j<numpathpoints;j++)
4535 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4536 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4538 player[i].finaltarget=pathpoint[j];
4540 player[i].finalpathfindpoint=closest;
4541 for(int j=0;j<numpathpoints;j++)
4542 for(int k=0;k<numpathpointconnect[j];k++){
4543 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4544 if(sq(tempdist)<closestdistance)
4545 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4546 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4547 closestdistance=sq(tempdist);
4549 player[i].finaltarget=colpoint;
4552 player[i].finalpathfindpoint=closest;
4555 if(player[i].targetpathfindpoint==-1){
4556 float closestdistance;
4562 if(player[i].lastpathfindpoint==-1){
4563 for(int j=0;j<numpathpoints;j++){
4564 if(j!=player[i].lastpathfindpoint)
4565 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4566 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4570 player[i].targetpathfindpoint=closest;
4571 for(int j=0;j<numpathpoints;j++)
4572 if(j!=player[i].lastpathfindpoint)
4573 for(int k=0;k<numpathpointconnect[j];k++){
4574 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4575 if(sq(tempdist)<closestdistance){
4576 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4577 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4578 closestdistance=sq(tempdist);
4583 player[i].targetpathfindpoint=closest;
4587 for(int j=0;j<numpathpoints;j++)
4588 if(j!=player[i].lastpathfindpoint&&
4589 j!=player[i].lastpathfindpoint2&&
4590 j!=player[i].lastpathfindpoint3&&
4591 j!=player[i].lastpathfindpoint4){
4593 if(numpathpointconnect[j])
4594 for(int k=0;k<numpathpointconnect[j];k++)
4595 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4598 if(numpathpointconnect[player[i].lastpathfindpoint])
4599 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4600 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4603 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4604 if(closest==-1||tempdist<closestdistance){
4605 closestdistance=tempdist;
4610 player[i].targetpathfindpoint=closest;
4613 player[i].losupdatedelay-=multiplier;
4615 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4616 player[i].lookrotation=player[i].targetrotation;
4618 //reached target point
4619 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4620 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4621 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4622 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4623 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4624 if(player[i].lastpathfindpoint2==-1)
4625 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4626 if(player[i].lastpathfindpoint3==-1)
4627 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4628 if(player[i].lastpathfindpoint4==-1)
4629 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4630 player[i].targetpathfindpoint=-1;
4632 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4633 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4634 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4635 player[i].lastpathfindpoint==player[i].finalpathfindpoint){
4636 player[i].aitype=passivetype;
4639 player[i].forwardkeydown=1;
4640 player[i].leftkeydown=0;
4641 player[i].backkeydown=0;
4642 player[i].rightkeydown=0;
4643 player[i].crouchkeydown=0;
4644 player[i].attackkeydown=0;
4645 player[i].throwkeydown=0;
4647 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
4648 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4650 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4651 player[i].jumpkeydown=0;
4652 if((player[i].collided>.8&&player[i].jumppower>=5))
4653 player[i].jumpkeydown=1;
4655 if((tutoriallevel!=1||cananger)&&
4658 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4659 player[i].occluded<25){
4660 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4661 animation[player[0].targetanimation].height!=lowheight&&
4663 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4664 player[i].aitype=attacktypecutoff;
4665 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4666 animation[player[0].targetanimation].height==highheight&&
4668 player[i].aitype=attacktypecutoff;
4670 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4671 player[i].losupdatedelay=.2;
4672 for(int j=0;j<numplayers;j++)
4673 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4674 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4675 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4676 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4677 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4678 if(!player[j].isWallJump()&&-1==checkcollide(
4679 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
4680 *player[i].scale+player[i].coords,
4681 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
4682 *player[j].scale+player[j].coords)||
4683 (player[j].targetanimation==hanganim&&
4684 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4685 player[i].aitype=searchtype;
4686 player[i].lastchecktime=12;
4687 player[i].lastseen=player[j].coords;
4688 player[i].lastseentime=12;
4692 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4693 if(player[i].creature!=wolftype){
4694 player[i].stunned=.6;
4695 player[i].surprised=.6;
4699 if(player[i].aitype!=passivetype&&leveltime>.5)
4700 player[i].howactive=typeactive;
4702 if(player[i].aitype==passivetype){
4703 player[i].aiupdatedelay-=multiplier;
4704 player[i].losupdatedelay-=multiplier;
4705 player[i].lastseentime+=multiplier;
4706 player[i].pausetime-=multiplier;
4707 if(player[i].lastseentime>1)
4708 player[i].lastseentime=1;
4710 if(player[i].aiupdatedelay<0){
4711 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4712 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4713 player[i].lookrotation=player[i].targetrotation;
4714 player[i].aiupdatedelay=.05;
4716 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4717 if(player[i].waypointtype[player[i].waypoint]==wppause)
4718 player[i].pausetime=4;
4719 player[i].waypoint++;
4720 if(player[i].waypoint>player[i].numwaypoints-1)
4721 player[i].waypoint=0;
4726 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4727 player[i].forwardkeydown=1;
4729 player[i].forwardkeydown=0;
4730 player[i].leftkeydown=0;
4731 player[i].backkeydown=0;
4732 player[i].rightkeydown=0;
4733 player[i].crouchkeydown=0;
4734 player[i].attackkeydown=0;
4735 player[i].throwkeydown=0;
4737 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4738 if(!player[i].avoidsomething)
4739 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4741 XYZ leftpos,rightpos;
4742 float leftdist,rightdist;
4743 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4744 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4745 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4746 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4747 if(leftdist<rightdist)
4748 player[i].targetrotation+=90;
4750 player[i].targetrotation-=90;
4754 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4755 player[i].jumpkeydown=0;
4756 if((player[i].collided>.8&&player[i].jumppower>=5))
4757 player[i].jumpkeydown=1;
4762 if(player[i].howactive<=typesleeping)
4763 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4764 for(int j=0;j<numenvsounds;j++){
4765 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4766 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4767 2*(vol+vol*(player[i].creature==rabbittype)*3))
4768 player[i].aitype=attacktypecutoff;
4771 if(player[i].aitype!=passivetype){
4772 if(player[i].howactive==typesleeping)
4773 setAnimation(i,getupfromfrontanim);
4774 player[i].howactive=typeactive;
4778 if(player[i].howactive<typesleeping&&
4779 ((tutoriallevel!=1||cananger)&&hostile)&&
4781 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4782 player[i].occluded<25){
4783 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4784 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4785 player[i].aitype=attacktypecutoff;
4786 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4787 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4788 player[i].aitype=attacktypecutoff;
4791 if(player[i].creature==wolftype){
4793 for(int j=0;j<numplayers;j++){
4794 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4795 float smelldistance=50;
4796 if(j==0&&player[j].num_weapons>0){
4797 if(weapons.bloody[player[j].weaponids[0]])
4799 if(player[j].num_weapons==2)
4800 if(weapons.bloody[player[j].weaponids[1]])
4805 windsmell=windvector;
4806 Normalise(&windsmell);
4807 windsmell=windsmell*2+player[j].coords;
4808 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4809 player[i].aitype=attacktypecutoff;
4814 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4815 player[i].losupdatedelay=.2;
4816 for(int j=0;j<numplayers;j++){
4817 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4818 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4819 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4820 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4821 if((-1==checkcollide(
4822 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4823 player[i].scale+player[i].coords,
4824 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
4825 player[j].scale+player[j].coords)&&
4826 !player[j].isWallJump())||
4827 (player[j].targetanimation==hanganim&&
4828 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4829 player[i].lastseentime-=.2;
4830 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4831 player[i].lastseentime-=.4;
4833 player[i].lastseentime-=.6;
4835 if(player[i].lastseentime<=0){
4836 player[i].aitype=searchtype;
4837 player[i].lastchecktime=12;
4838 player[i].lastseen=player[j].coords;
4839 player[i].lastseentime=12;
4846 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4847 if(player[i].creature!=wolftype){
4848 player[i].stunned=.6;
4849 player[i].surprised=.6;
4851 if(player[i].creature==wolftype){
4852 player[i].stunned=.47;
4853 player[i].surprised=.47;
4861 if(player[i].aitype==searchtype){
4862 player[i].aiupdatedelay-=multiplier;
4863 player[i].losupdatedelay-=multiplier;
4864 if(!player[i].pause)
4865 player[i].lastseentime-=multiplier;
4866 player[i].lastchecktime-=multiplier;
4868 if(player[i].isRun()&&!player[i].onground){
4869 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4870 XYZ test2=player[i].coords+player[i].facing;
4872 XYZ test=player[i].coords+player[i].facing;
4874 j=checkcollide(test2,test,player[i].laststanding);
4876 j=checkcollide(test2,test);
4878 player[i].velocity=0;
4879 setAnimation(i,player[i].getStop());
4880 player[i].targetrotation+=180;
4881 player[i].stunned=.5;
4882 //player[i].aitype=passivetype;
4883 player[i].aitype=pathfindtype;
4884 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4885 player[i].finalpathfindpoint=-1;
4886 player[i].targetpathfindpoint=-1;
4887 player[i].lastpathfindpoint=-1;
4888 player[i].lastpathfindpoint2=-1;
4889 player[i].lastpathfindpoint3=-1;
4890 player[i].lastpathfindpoint4=-1;
4892 else player[i].laststanding=j;
4895 //check out last seen location
4896 if(player[i].aiupdatedelay<0){
4897 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4898 player[i].lookrotation=player[i].targetrotation;
4899 player[i].aiupdatedelay=.05;
4900 player[i].forwardkeydown=1;
4902 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4903 player[i].forwardkeydown=0;
4904 player[i].aiupdatedelay=1;
4905 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4906 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4907 player[i].lastchecktime=3;
4910 player[i].leftkeydown=0;
4911 player[i].backkeydown=0;
4912 player[i].rightkeydown=0;
4913 player[i].crouchkeydown=0;
4914 player[i].attackkeydown=0;
4915 player[i].throwkeydown=0;
4917 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4918 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4920 XYZ leftpos,rightpos;
4921 float leftdist,rightdist;
4922 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4923 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4924 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4925 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4926 if(leftdist<rightdist)player[i].targetrotation+=90;
4927 else player[i].targetrotation-=90;
4931 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4932 player[i].jumpkeydown=0;
4933 if((player[i].collided>.8&&player[i].jumppower>=5))
4934 player[i].jumpkeydown=1;
4936 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4937 for(int k=0;k<numenvsounds;k++){
4938 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4939 player[i].aitype=attacktypecutoff;
4943 if(!player[0].dead&&
4944 player[i].losupdatedelay<0&&
4946 player[i].occluded<2&&
4947 ((tutoriallevel!=1||cananger)&&hostile)){
4948 player[i].losupdatedelay=.2;
4949 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4950 player[i].aitype=attacktypecutoff;
4951 player[i].lastseentime=1;
4953 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4954 //TODO: factor out canSeePlayer()
4955 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4956 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4958 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
4959 player[i].scale+player[i].coords,
4960 DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
4961 player[0].scale+player[0].coords)==-1)||
4962 (player[0].targetanimation==hanganim&&normaldotproduct(
4963 player[0].facing,player[i].coords-player[0].coords)<0)){
4964 /* //TODO: changed j to 0 on a whim, make sure this is correct
4965 (player[j].targetanimation==hanganim&&normaldotproduct(
4966 player[j].facing,player[i].coords-player[j].coords)<0)
4968 player[i].aitype=attacktypecutoff;
4969 player[i].lastseentime=1;
4973 if(player[i].lastseentime<0){
4974 //player[i].aitype=passivetype;
4976 player[i].aitype=pathfindtype;
4977 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4978 player[i].finalpathfindpoint=-1;
4979 player[i].targetpathfindpoint=-1;
4980 player[i].lastpathfindpoint=-1;
4981 player[i].lastpathfindpoint2=-1;
4982 player[i].lastpathfindpoint3=-1;
4983 player[i].lastpathfindpoint4=-1;
4987 if(player[i].aitype!=gethelptype)
4988 player[i].runninghowlong=0;
4990 //get help from buddies
4991 if(player[i].aitype==gethelptype){
4992 player[i].runninghowlong+=multiplier;
4993 player[i].aiupdatedelay-=multiplier;
4995 if(player[i].aiupdatedelay<0||player[i].ally==0){
4996 player[i].aiupdatedelay=.2;
4999 //TODO: factor out closest search somehow
5000 if(!player[i].ally){
5002 float closestdist=-1;
5003 for(int k=0;k<numplayers;k++){
5004 if(k!=i&&k!=0&&!player[k].dead&&
5005 player[k].howactive<typedead1&&
5006 !player[k].skeleton.free&&
5007 player[k].aitype==passivetype){
5008 float distance=findDistancefast(&player[i].coords,&player[k].coords);
5009 if(closestdist==-1||distance<closestdist){
5010 closestdist=distance;
5017 player[i].ally=closest;
5020 player[i].lastseen=player[0].coords;
5021 player[i].lastseentime=12;
5025 player[i].lastchecktime=12;
5027 XYZ facing=player[i].coords;
5028 XYZ flatfacing=player[player[i].ally].coords;
5029 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5030 flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
5031 if(-1!=checkcollide(facing,flatfacing))
5032 player[i].lastseentime-=.1;
5034 //no available ally, run back to player
5035 if(player[i].ally<=0||
5036 player[player[i].ally].skeleton.free||
5037 player[player[i].ally].aitype!=passivetype||
5038 player[i].lastseentime<=0){
5039 player[i].aitype=searchtype;
5040 player[i].lastseentime=12;
5044 if(player[i].ally>0){
5045 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5046 player[i].lookrotation=player[i].targetrotation;
5047 player[i].aiupdatedelay=.05;
5048 player[i].forwardkeydown=1;
5050 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
5051 player[i].aitype=searchtype;
5052 player[i].lastseentime=12;
5053 player[player[i].ally].aitype=searchtype;
5054 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5055 player[player[i].ally].lastseen=player[i].lastseen;
5056 player[player[i].ally].lastseentime=player[i].lastseentime;
5057 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5061 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5062 if(!player[i].avoidsomething)
5063 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5065 XYZ leftpos,rightpos;
5066 float leftdist,rightdist;
5067 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5068 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5069 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5070 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5071 if(leftdist<rightdist)
5072 player[i].targetrotation+=90;
5074 player[i].targetrotation-=90;
5079 player[i].leftkeydown=0;
5080 player[i].backkeydown=0;
5081 player[i].rightkeydown=0;
5082 player[i].crouchkeydown=0;
5083 player[i].attackkeydown=0;
5085 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5086 player[i].jumpkeydown=0;
5087 if(player[i].collided>.8&&player[i].jumppower>=5)
5088 player[i].jumpkeydown=1;
5091 //retreiving a weapon on the ground
5092 if(player[i].aitype==getweapontype){
5093 player[i].aiupdatedelay-=multiplier;
5094 player[i].lastchecktime-=multiplier;
5096 if(player[i].aiupdatedelay<0){
5097 player[i].aiupdatedelay=.2;
5100 if(player[i].ally<0){
5102 float closestdist=-1;
5103 for(int k=0;k<weapons.numweapons;k++)
5104 if(weapons.owner[k]==-1){
5105 float distance=findDistancefast(&player[i].coords,&weapons.position[k]);
5106 if(closestdist==-1||distance<closestdist){
5107 closestdist=distance;
5113 player[i].ally=closest;
5118 player[i].lastseentime=12;
5120 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5121 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5122 player[i].aitype=attacktypecutoff;
5123 player[i].lastseentime=1;
5126 if(player[i].ally>=0){
5127 if(weapons.owner[player[i].ally]!=-1||
5128 findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
5129 player[i].aitype=attacktypecutoff;
5130 player[i].lastseentime=1;
5132 //TODO: factor these out as moveToward()
5133 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[player[i].ally]);
5134 player[i].lookrotation=player[i].targetrotation;
5135 player[i].aiupdatedelay=.05;
5136 player[i].forwardkeydown=1;
5139 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5140 if(!player[i].avoidsomething)
5141 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5143 XYZ leftpos,rightpos;
5144 float leftdist,rightdist;
5145 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5146 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5147 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5148 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5149 if(leftdist<rightdist)
5150 player[i].targetrotation+=90;
5152 player[i].targetrotation-=90;
5157 player[i].leftkeydown=0;
5158 player[i].backkeydown=0;
5159 player[i].rightkeydown=0;
5160 player[i].attackkeydown=0;
5161 player[i].throwkeydown=1;
5162 player[i].crouchkeydown=0;
5163 if(player[i].targetanimation!=crouchremoveknifeanim&&
5164 player[i].targetanimation!=removeknifeanim)
5165 player[i].throwtogglekeydown=0;
5166 player[i].drawkeydown=0;
5168 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5169 player[i].jumpkeydown=0;
5170 if((player[i].collided>.8&&player[i].jumppower>=5))
5171 player[i].jumpkeydown=1;
5174 if(player[i].aitype==attacktypecutoff){
5175 player[i].aiupdatedelay-=multiplier;
5176 //dodge or reverse rabbit kicks, knife throws, flips
5177 if(player[i].damage<player[i].damagetolerance*2/3)
5178 if((player[0].targetanimation==rabbitkickanim||
5179 player[0].targetanimation==knifethrowanim||
5180 (player[0].isFlip()&&
5181 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5182 !player[0].skeleton.free&&
5183 (player[i].aiupdatedelay<.1)){
5184 player[i].attackkeydown=0;
5185 if(player[i].isIdle())
5186 player[i].crouchkeydown=1;
5187 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5188 if(weapons.type[player[0].weaponids[0]]==knife){
5189 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5190 if(abs(Random()%2==0))
5191 setAnimation(i,backhandspringanim);
5193 setAnimation(i,rollanim);
5194 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5195 player[i].wentforweapon=0;
5197 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5198 setAnimation(i,flipanim);
5201 player[i].forwardkeydown=0;
5202 player[i].aiupdatedelay=.02;
5204 //get confused by flips
5205 if(player[0].isFlip()&&
5206 !player[0].skeleton.free&&
5207 player[0].targetanimation!=walljumprightkickanim&&
5208 player[0].targetanimation!=walljumpleftkickanim){
5209 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5210 if((1-player[i].damage/player[i].damagetolerance)>.5)
5211 player[i].stunned=1;
5213 //go for weapon on the ground
5214 if(player[i].wentforweapon<3)
5215 for(int k=0;k<weapons.numweapons;k++)
5216 if(player[i].creature!=wolftype)
5217 if(player[i].num_weapons==0&&
5218 weapons.owner[k]==-1&&
5219 weapons.velocity[i].x==0&&
5220 weapons.velocity[i].z==0&&
5221 weapons.velocity[i].y==0){
5222 if(findDistancefast(&player[i].coords,&weapons.position[k])<16){
5223 player[i].wentforweapon++;
5224 player[i].lastchecktime=6;
5225 player[i].aitype=getweapontype;
5229 //dodge/reverse walljump kicks
5230 if(player[i].damage<player[i].damagetolerance/2)
5231 if(animation[player[i].targetanimation].height!=highheight)
5232 if(player[i].damage<player[i].damagetolerance*.5&&
5233 ((player[0].targetanimation==walljumprightkickanim||
5234 player[0].targetanimation==walljumpleftkickanim)&&
5235 ((player[i].aiupdatedelay<.15&&
5237 (player[i].aiupdatedelay<.08&&
5239 player[i].crouchkeydown=1;
5241 //walked off a ledge (?)
5242 if(player[i].isRun()&&!player[i].onground)
5243 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5244 XYZ test2=player[i].coords+player[i].facing;
5246 XYZ test=player[i].coords+player[i].facing;
5248 j=checkcollide(test2,test,player[i].laststanding);
5250 j=checkcollide(test2,test);
5252 player[i].velocity=0;
5253 setAnimation(i,player[i].getStop());
5254 player[i].targetrotation+=180;
5255 player[i].stunned=.5;
5256 player[i].aitype=pathfindtype;
5257 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5258 player[i].finalpathfindpoint=-1;
5259 player[i].targetpathfindpoint=-1;
5260 player[i].lastpathfindpoint=-1;
5261 player[i].lastpathfindpoint2=-1;
5262 player[i].lastpathfindpoint3=-1;
5263 player[i].lastpathfindpoint4=-1;
5265 player[i].laststanding=j;
5267 //lose sight of player in the air (?)
5268 if(player[0].coords.y>player[i].coords.y+5&&
5269 animation[player[0].targetanimation].height!=highheight&&
5270 !player[0].onterrain){
5271 player[i].aitype=pathfindtype;
5272 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5273 player[i].finalpathfindpoint=-1;
5274 player[i].targetpathfindpoint=-1;
5275 player[i].lastpathfindpoint=-1;
5276 player[i].lastpathfindpoint2=-1;
5277 player[i].lastpathfindpoint3=-1;
5278 player[i].lastpathfindpoint4=-1;
5280 //it's time to think (?)
5281 if(player[i].aiupdatedelay<0&&
5282 !animation[player[i].targetanimation].attack&&
5283 player[i].targetanimation!=staggerbackhighanim&&
5284 player[i].targetanimation!=staggerbackhardanim&&
5285 player[i].targetanimation!=backhandspringanim&&
5286 player[i].targetanimation!=dodgebackanim){
5288 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5289 player[i].drawkeydown=Random()%2;
5291 player[i].drawkeydown=0;
5292 player[i].rabbitkickenabled=Random()%2;
5294 XYZ rotatetarget=player[0].coords+player[0].velocity;
5295 XYZ targetpoint=player[0].coords;
5296 if(findDistancefast(&player[0].coords,&player[i].coords)<
5297 findDistancefast(&rotatetarget,&player[i].coords))
5298 targetpoint+=player[0].velocity*
5299 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5300 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5301 player[i].lookrotation=player[i].targetrotation;
5302 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5304 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5305 player[i].forwardkeydown=1;
5306 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5307 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5308 player[0].weaponactive!=-1)
5309 player[i].forwardkeydown=1;
5310 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5311 player[i].forwardkeydown=1;
5313 player[i].forwardkeydown=0;
5314 //chill out around the corpse
5316 player[i].forwardkeydown=0;
5318 player[i].forwardkeydown=1;
5319 if(Random()%100==0){
5320 player[i].aitype=pathfindtype;
5321 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5322 player[i].finalpathfindpoint=-1;
5323 player[i].targetpathfindpoint=-1;
5324 player[i].lastpathfindpoint=-1;
5325 player[i].lastpathfindpoint2=-1;
5326 player[i].lastpathfindpoint3=-1;
5327 player[i].lastpathfindpoint4=-1;
5330 player[i].leftkeydown=0;
5331 player[i].backkeydown=0;
5332 player[i].rightkeydown=0;
5333 player[i].crouchkeydown=0;
5334 player[i].throwkeydown=0;
5336 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5337 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5339 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5340 player[i].attackkeydown=1;
5342 player[i].attackkeydown=0;
5343 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5344 player[i].attackkeydown=0;
5347 if(player[i].aitype!=playercontrolled&&
5348 (player[i].isIdle()||
5349 player[i].isCrouch()||
5350 player[i].isRun())){
5352 for(int j=0;j<numplayers;j++)
5353 if(j!=i&&!player[j].skeleton.free&&
5354 player[j].hasvictim&&
5355 (tutoriallevel==1&&reversaltrain||
5356 Random()%2==0&&difficulty==2||
5357 Random()%4==0&&difficulty==1||
5358 Random()%8==0&&difficulty==0||
5359 player[j].lastattack2==player[j].targetanimation&&
5360 player[j].lastattack3==player[j].targetanimation&&
5361 (Random()%2==0||difficulty==2)||
5362 (player[i].isIdle()||player[i].isRun())&&
5363 player[j].weaponactive!=-1||
5364 player[j].targetanimation==swordslashanim&&
5365 player[i].weaponactive!=-1||
5366 player[j].targetanimation==staffhitanim||
5367 player[j].targetanimation==staffspinhitanim))
5368 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5369 player[j].victim==&player[i]&&
5370 (player[j].targetanimation==sweepanim||
5371 player[j].targetanimation==spinkickanim||
5372 player[j].targetanimation==staffhitanim||
5373 player[j].targetanimation==staffspinhitanim||
5374 player[j].targetanimation==winduppunchanim||
5375 player[j].targetanimation==upunchanim||
5376 player[j].targetanimation==wolfslapanim||
5377 player[j].targetanimation==knifeslashstartanim||
5378 player[j].targetanimation==swordslashanim&&
5379 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5380 player[i].weaponactive!=-1))){
5387 player[target].Reverse();
5390 if(player[i].collided<1)
5391 player[i].jumpkeydown=0;
5392 if(player[i].collided>.8&&player[i].jumppower>=5||
5393 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5394 player[i].onterrain&&
5395 player[i].creature==rabbittype)
5396 player[i].jumpkeydown=1;
5397 //TODO: why are we controlling the human?
5398 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5399 player[0].jumpkeydown=0;
5400 if(player[0].targetanimation==jumpdownanim&&
5401 findDistancefast(&player[0].coords,&player[i].coords)<40)
5402 player[i].crouchkeydown=1;
5403 if(player[i].jumpkeydown)
5404 player[i].attackkeydown=0;
5406 if(tutoriallevel==1)
5408 player[i].attackkeydown=0;
5411 XYZ facing=player[i].coords;
5412 XYZ flatfacing=player[0].coords;
5413 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5414 flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
5415 if(player[i].occluded>=2)
5416 if(-1!=checkcollide(facing,flatfacing)){
5417 if(!player[i].pause)
5418 player[i].lastseentime-=.2;
5419 if(player[i].lastseentime<=0&&
5420 (player[i].creature!=wolftype||
5421 player[i].weaponstuck==-1)){
5422 player[i].aitype=searchtype;
5423 player[i].lastchecktime=12;
5424 player[i].lastseen=player[0].coords;
5425 player[i].lastseentime=12;
5428 player[i].lastseentime=1;
5431 if(animation[player[0].targetanimation].height==highheight&&
5432 (player[i].aitype==attacktypecutoff||
5433 player[i].aitype==searchtype))
5434 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5435 XYZ test=player[0].coords;
5437 if(-1==checkcollide(player[0].coords,test))
5438 player[i].stunned=1;
5441 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5442 player[i].stunned>0||
5443 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5445 player[i].lastseentime=1;
5446 player[i].targetrotation=player[i].rotation;
5447 player[i].forwardkeydown=0;
5448 player[i].leftkeydown=0;
5449 player[i].backkeydown=0;
5450 player[i].rightkeydown=0;
5451 player[i].jumpkeydown=0;
5452 player[i].attackkeydown=0;
5453 player[i].crouchkeydown=0;
5454 player[i].throwkeydown=0;
5462 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5465 if(player[i].aitype==attacktypecutoff){
5466 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5467 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5468 }else if(player[i].howactive>=typesleeping){
5469 player[i].targetheadrotation=player[i].targetrotation;
5470 player[i].targetheadrotation2=0;
5472 if(player[i].interestdelay<=0){
5473 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5474 player[i].headtarget=player[i].coords;
5475 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5476 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5477 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5478 player[i].headtarget+=player[i].facing*1.5;
5480 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5481 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5487 Values of mainmenu :
5489 2 Menu pause (resume/end game)
5491 4 Controls configuration menu
5492 5 Main game menu (choose level or challenge)
5493 6 Deleting user menu
5494 7 User managment menu (select/add)
5495 8 Choose difficulty menu
5496 9 Challenge level selection menu
5497 10 End of the campaign congratulation (is that really a menu?)
5498 11 Same that 9 ??? => unused
5499 18 stereo configuration
5502 void Game::MenuTick(){
5505 // some specific case where we do something even if the left mouse button is not pressed.
5506 if((mainmenu==5) && (endgame==2)) {
5507 accountactive->endGame();
5512 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
5513 stereoseparation-=0.001;
5515 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5521 if(gameon) { //resume
5523 pause_sound(stream_menutheme);
5524 resume_stream(leveltheme);
5526 fireSound(firestartsound);
5528 mainmenu=(accountactive?5:7);
5536 if(newdetail>2) newdetail=detail;
5537 if(newdetail<0) newdetail=detail;
5538 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5539 if(newscreenwidth<0) newscreenwidth=screenwidth;
5540 if(newscreenheight>3000) newscreenheight=screenheight;
5541 if(newscreenheight<0) newscreenheight=screenheight;
5546 if(gameon){ //end game
5551 pause_sound(stream_menutheme);
5558 bool isCustomResolution,found;
5561 extern SDL_Rect **resolutions;
5562 isCustomResolution = true;
5564 for(int i = 0; (!found) && (resolutions[i]); i++) {
5565 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5566 isCustomResolution = false;
5568 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5570 if(resolutions[i] != NULL) {
5571 newscreenwidth = (int) resolutions[i]->w;
5572 newscreenheight = (int) resolutions[i]->h;
5573 } else if(isCustomResolution){
5574 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5575 newscreenwidth = (int) resolutions[0]->w;
5576 newscreenheight = (int) resolutions[0]->h;
5578 newscreenwidth = screenwidth;
5579 newscreenheight = screenheight;
5582 newscreenwidth = (int) resolutions[0]->w;
5583 newscreenheight = (int) resolutions[0]->h;
5590 newscreenwidth = (int) resolutions[0]->w;
5591 newscreenheight = (int) resolutions[0]->h;
5596 if(newdetail>2) newdetail=0;
5600 if(bloodtoggle>2) bloodtoggle=0;
5604 if(difficulty>2) difficulty=0;
5607 ismotionblur = !ismotionblur;
5613 musictoggle = !musictoggle;
5616 emit_stream_np(stream_menutheme);
5618 pause_sound(leveltheme);
5619 pause_sound(stream_fighttheme);
5620 pause_sound(stream_menutheme);
5622 for(int i=0;i<4;i++){
5623 oldmusicvolume[i]=0;
5638 SaveSettings(*this);
5639 mainmenu=gameon?2:1;
5642 invertmouse = !invertmouse;
5645 usermousesensitivity+=.2;
5646 if(usermousesensitivity>2) usermousesensitivity=.2;
5650 if(volume>1.0001f) volume=0;
5651 OPENAL_SetSFXMasterVolume((int)(volume*255));
5656 newstereomode = stereomode;
5661 showdamagebar = !showdamagebar;
5668 if(selected<9 && keyselect==-1)
5682 if((selected-NB_CAMPAIGN_MENU_ITEM-1 >= accountactive->getCampaignChoicesMade())) {
5692 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-1-accountactive->getCampaignChoicesMade();
5695 Loadlevel(campaignmapname[campaignchoicewhich[whichchoice]]);
5699 pause_sound(stream_menutheme);
5716 pause_sound(stream_menutheme);
5725 mainmenu=(gameon?2:1);
5731 vector<string> campaigns = ListCampaigns();
5732 vector<string>::iterator c;
5733 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5734 if(!campaigns.empty())
5735 accountactive->setCurrentCampaign(campaigns.front());
5738 if(c==campaigns.end())
5739 c=campaigns.begin();
5740 accountactive->setCurrentCampaign(*c);
5743 if(Mainmenuitems[7])
5744 glDeleteTextures(1,&Mainmenuitems[7]);
5745 ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
5747 LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
5749 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
5758 accountactive = Account::destroy(accountactive);
5760 } else if(selected==2) {
5767 if(selected==0 && Account::getNbAccounts()<8){
5769 } else if (selected < Account::getNbAccounts()+1) {
5772 accountactive=Account::get(selected-1);
5773 } else if (selected == Account::getNbAccounts()+1) {
5776 for(int j=0;j<255;j++){
5777 displaytext[0][j]=0;
5788 accountactive->setDifficulty(selected);
5792 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5800 targetlevel=selected;
5801 if(firstload)TickOnceAfter();
5802 if(!firstload)LoadStuff();
5803 else Loadlevel(selected);
5808 pause_sound(stream_menutheme);
5810 if(selected==numchallengelevels){
5825 stereoseparation+=0.001;
5829 newstereomode = (StereoMode)(newstereomode + 1);
5830 while(!CanInitStereo(newstereomode)){
5831 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5832 newstereomode = (StereoMode)(newstereomode + 1);
5833 if(newstereomode >= stereoCount)
5834 newstereomode = stereoNone;
5836 } else if(selected==2) {
5837 stereoreverse = !stereoreverse;
5838 } else if(selected==3) {
5842 stereomode = newstereomode;
5843 InitStereo(stereomode);
5850 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5853 SaveSettings(*this);
5857 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5860 inputText(displaytext[0],&displayselected,&displaychars[0]);
5861 if(!waiting) { // the input as finished
5862 if(displaychars[0]){ // with enter
5863 accountactive = Account::add(string(displaytext[0]));
5869 fireSound(firestartsound);
5871 for(int i=0;i<255;i++){
5872 displaytext[0][i]=0;
5881 displayblinkdelay-=multiplier;
5882 if(displayblinkdelay<=0){
5883 displayblinkdelay=.3;
5884 displayblink=1-displayblink;
5890 static XYZ facing,flatfacing;
5893 for(int i=0;i<15;i++){
5894 displaytime[i]+=multiplier;
5897 keyboardfrozen=false;
5900 if(Input::isKeyPressed(SDLK_F6)){
5901 if(Input::isKeyDown(SDLK_LSHIFT))
5904 stereoreverse=false;
5907 printf("Stereo reversed\n");
5909 printf("Stereo unreversed\n");
5912 if(Input::isKeyDown(SDLK_F7)){
5913 if(Input::isKeyDown(SDLK_LSHIFT))
5914 stereoseparation -= 0.001;
5916 stereoseparation -= 0.010;
5917 printf("Stereo decreased increased to %f\n", stereoseparation);
5920 if(Input::isKeyDown(SDLK_F8)){
5921 if(Input::isKeyDown(SDLK_LSHIFT))
5922 stereoseparation += 0.001;
5924 stereoseparation += 0.010;
5925 printf("Stereo separation increased to %f\n", stereoseparation);
5929 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5930 if(tutorialstage!=51)
5931 tutorialstagetime=tutorialmaxtime;
5932 emit_sound_np(consolefailsound, 128.);
5936 Values of mainmenu :
5938 2 Menu pause (resume/end game)
5940 4 Controls configuration menu
5941 5 Main game menu (choose level or challenge)
5942 6 Deleting user menu
5943 7 User managment menu (select/add)
5944 8 Choose difficulty menu
5945 9 Challenge level selection menu
5946 10 End of the campaign congratulation (is that really a menu?)
5947 11 Same that 9 ??? => unused
5948 18 stereo configuration
5953 if(mainmenu&&endgame==1)
5955 //go to level select after completing a campaign level
5956 if(campaign&&winfreeze&&mainmenu==0&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1) {
5963 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5964 emit_stream_np(stream_menutheme);
5965 pause_sound(leveltheme);
5969 //escape key pressed
5970 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5971 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5972 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
5974 if(mainmenu==0&&!winfreeze)
5976 else if(mainmenu==1||mainmenu==2){
5977 mainmenu=0; //unpause
5980 if(musictoggle&&(mainmenu==1||mainmenu==2)){
5981 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5982 emit_stream_np(stream_menutheme);
5983 pause_sound(leveltheme);
5985 //on resume, play level music
5987 pause_sound(stream_menutheme);
5988 resume_stream(leveltheme);
5990 //finished with settings menu
5992 SaveSettings(*this);
5995 if(mainmenu>=3&&mainmenu!=8){
6002 mainmenu=gameon?2:1; break;
6005 case 6: case 7: case 9: case 10:
6016 if(hostile==1)hostiletime+=multiplier;
6018 if(!winfreeze)leveltime+=multiplier;
6021 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6024 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6028 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6032 inputText(displaytext[0],&displayselected,&displaychars[0]);
6034 if(displaychars[0]){
6035 for(int j=0;j<255;j++)
6036 displaytext[0][j]=0;
6043 displayblinkdelay-=multiplier;
6044 if(displayblinkdelay<=0){
6045 displayblinkdelay=.3;
6046 displayblink=1-displayblink;
6050 keyboardfrozen=true;
6052 if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){
6055 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6064 if(console&&!Input::isKeyDown(SDLK_LMETA)){
6065 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6068 if(consolechars[0]>0){
6069 consoletext[0][consolechars[0]]=' ';
6070 cmd_dispatch(this, consoletext[0]);
6071 for(int k=14;k>=1;k--){
6072 for(int j=0;j<255;j++)
6073 consoletext[k][j]=consoletext[k-1][j];
6074 consolechars[k]=consolechars[k-1];
6076 for(int j=0;j<255;j++)
6077 consoletext[0][j]=0;
6083 consoleblinkdelay-=multiplier;
6084 if(consoleblinkdelay<=0){
6085 consoleblinkdelay=.3;
6086 consoleblink=1-consoleblink;
6092 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6095 SaveSettings(*this);
6099 static int oldwinfreeze;
6100 if(winfreeze&&!oldwinfreeze){
6101 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6102 emit_sound_np(consolesuccesssound);
6105 oldwinfreeze=winfreeze;
6109 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6112 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6116 } else if(winfreeze) {
6124 //TODO: what is this test?
6125 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6130 talkdelay-=multiplier;
6132 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6133 for(int i=0;i<numdialogues;i++){
6134 int realdialoguetype;
6136 if(dialoguetype[i]>49){
6137 realdialoguetype=dialoguetype[i]-50;
6140 else if(dialoguetype[i]>39){
6141 realdialoguetype=dialoguetype[i]-40;
6144 else if(dialoguetype[i]>29){
6145 realdialoguetype=dialoguetype[i]-30;
6148 else if(dialoguetype[i]>19){
6149 realdialoguetype=dialoguetype[i]-20;
6152 else if(dialoguetype[i]>9){
6153 realdialoguetype=dialoguetype[i]-10;
6157 realdialoguetype=dialoguetype[i];
6160 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6161 realdialoguetype<numplayers&&
6162 realdialoguetype>0&&
6163 (dialoguegonethrough[i]==0||!special)&&
6164 (special||Input::isKeyPressed(attackkey))){
6165 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6166 player[realdialoguetype].howactive>=typedead1||
6167 dialoguetype[i]>40&&dialoguetype[i]<50){
6169 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6170 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6171 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6172 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6173 player[participantfocus[whichdialogue][j]].velocity=0;
6174 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6175 player[participantfocus[whichdialogue][j]].targetframe=0;
6180 dialoguegonethrough[i]++;
6181 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6182 playdialogueboxsound();
6188 windvar+=multiplier;
6189 smoketex+=multiplier;
6190 tutorialstagetime+=multiplier;
6193 static float hotspotvisual[40];
6197 for(int i=0;i<numhotspots;i++)
6198 hotspotvisual[i]-=multiplier/320;
6200 for(int i=0;i<numhotspots;i++){
6201 //if(hotspottype[i]<=10)
6202 while(hotspotvisual[i]<0){
6204 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6205 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6206 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6207 hotspotsprite+=hotspot[i];
6208 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6209 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6213 for(int i=0;i<numhotspots;i++){
6214 if(hotspottype[i]<=10&&hotspottype[i]>0){
6215 hotspot[i]=player[hotspottype[i]].coords;
6226 if(tutoriallevel!=1){
6229 bonus!=spinecrusher&&
6230 bonus!=tracheotomy&&
6233 emit_sound_np(consolesuccesssound);
6235 } else if(bonustime==0){
6236 emit_sound_np(fireendsound);
6239 if(bonus!=solidhit&&
6241 bonus!=threexcombo&&
6246 bonusnum[bonus]+=0.15;
6249 bonusvalue/=bonusnum[bonus];
6250 bonustotal+=bonusvalue;
6252 bonustime+=multiplier;
6255 if(environment==snowyenvironment){
6256 precipdelay-=multiplier;
6257 while(precipdelay<0){
6261 XYZ footvel,footpoint;
6264 footpoint=viewer+viewerfacing*6;
6265 footpoint.y+=((float)abs(Random()%1200))/100-6;
6266 footpoint.x+=((float)abs(Random()%1200))/100-6;
6267 footpoint.z+=((float)abs(Random()%1200))/100-6;
6268 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6273 doAerialAcrobatics();
6276 static XYZ oldviewer;
6280 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6281 player[0].leftkeydown=Input::isKeyDown(leftkey);
6282 player[0].backkeydown=Input::isKeyDown(backkey);
6283 player[0].rightkeydown=Input::isKeyDown(rightkey);
6284 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6285 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6286 player[0].drawkeydown=Input::isKeyDown(drawkey);
6287 player[0].throwkeydown=Input::isKeyDown(throwkey);
6291 player[0].forwardkeydown=0;
6292 player[0].leftkeydown=0;
6293 player[0].backkeydown=0;
6294 player[0].rightkeydown=0;
6295 player[0].jumpkeydown=0;
6296 player[0].crouchkeydown=0;
6297 player[0].drawkeydown=0;
6298 player[0].throwkeydown=0;
6301 if(!player[0].jumpkeydown)
6302 player[0].jumpclimb=0;
6311 facing=DoRotation(facing,-rotation2,0,0);
6312 facing=DoRotation(facing,0,0-rotation,0);
6317 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6319 if(Input::isKeyDown(forwardkey))
6320 viewer+=facing*multiplier*4;
6321 if(Input::isKeyDown(backkey))
6322 viewer-=facing*multiplier*4;
6323 if(Input::isKeyDown(leftkey))
6324 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6325 if(Input::isKeyDown(rightkey))
6326 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6327 if(Input::isKeyDown(jumpkey))
6328 viewer.y+=multiplier*4;
6329 if(Input::isKeyDown(crouchkey))
6330 viewer.y-=multiplier*4;
6331 if( Input::isKeyPressed(SDLK_1)||
6332 Input::isKeyPressed(SDLK_2)||
6333 Input::isKeyPressed(SDLK_3)||
6334 Input::isKeyPressed(SDLK_4)||
6335 Input::isKeyPressed(SDLK_5)||
6336 Input::isKeyPressed(SDLK_6)||
6337 Input::isKeyPressed(SDLK_7)||
6338 Input::isKeyPressed(SDLK_8)||
6339 Input::isKeyPressed(SDLK_9)||
6340 Input::isKeyPressed(SDLK_0)||
6341 Input::isKeyPressed(SDLK_MINUS)){
6343 if(Input::isKeyPressed(SDLK_1))whichend=1;
6344 if(Input::isKeyPressed(SDLK_2))whichend=2;
6345 if(Input::isKeyPressed(SDLK_3))whichend=3;
6346 if(Input::isKeyPressed(SDLK_4))whichend=4;
6347 if(Input::isKeyPressed(SDLK_5))whichend=5;
6348 if(Input::isKeyPressed(SDLK_6))whichend=6;
6349 if(Input::isKeyPressed(SDLK_7))whichend=7;
6350 if(Input::isKeyPressed(SDLK_8))whichend=8;
6351 if(Input::isKeyPressed(SDLK_9))whichend=9;
6352 if(Input::isKeyPressed(SDLK_0))whichend=0;
6353 if(Input::isKeyPressed(SDLK_MINUS))
6356 participantfocus[whichdialogue][indialogue]=whichend;
6357 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6358 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6361 participantfocus[whichdialogue][indialogue]=-1;
6363 if(player[participantfocus[whichdialogue][indialogue]].dead){
6368 dialoguecamera[whichdialogue][indialogue]=viewer;
6369 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6370 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6372 if(indialogue<numdialogueboxes[whichdialogue]){
6373 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6374 playdialogueboxsound();
6378 for(int j=0;j<numplayers;j++){
6379 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6382 //TODO: should these be KeyDown or KeyPressed?
6383 if( Input::isKeyDown(SDLK_KP1)||
6384 Input::isKeyDown(SDLK_KP2)||
6385 Input::isKeyDown(SDLK_KP3)||
6386 Input::isKeyDown(SDLK_KP4)||
6387 Input::isKeyDown(SDLK_KP5)||
6388 Input::isKeyDown(SDLK_KP6)||
6389 Input::isKeyDown(SDLK_KP7)||
6390 Input::isKeyDown(SDLK_KP8)||
6391 Input::isKeyDown(SDLK_KP9)||
6392 Input::isKeyDown(SDLK_KP0)){
6394 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6395 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6396 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6397 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6398 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6399 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6400 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6401 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6402 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6403 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6404 participantfacing[whichdialogue][indialogue][whichend]=facing;
6406 if(indialogue>=numdialogueboxes[whichdialogue]){
6413 pause_sound(whooshsound);
6414 viewer=dialoguecamera[whichdialogue][indialogue];
6415 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6416 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6417 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6418 if(dialoguetime>0.5)
6419 if( Input::isKeyPressed(SDLK_1)||
6420 Input::isKeyPressed(SDLK_2)||
6421 Input::isKeyPressed(SDLK_3)||
6422 Input::isKeyPressed(SDLK_4)||
6423 Input::isKeyPressed(SDLK_5)||
6424 Input::isKeyPressed(SDLK_6)||
6425 Input::isKeyPressed(SDLK_7)||
6426 Input::isKeyPressed(SDLK_8)||
6427 Input::isKeyPressed(SDLK_9)||
6428 Input::isKeyPressed(SDLK_0)||
6429 Input::isKeyPressed(SDLK_MINUS)||
6430 Input::isKeyPressed(attackkey)){
6432 if(indialogue<numdialogueboxes[whichdialogue]){
6433 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6434 playdialogueboxsound();
6435 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6436 hotspot[numhotspots]=player[0].coords;
6437 hotspotsize[numhotspots]=10;
6438 hotspottype[numhotspots]=-1;
6442 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6446 if(player[participantfocus[whichdialogue][indialogue]].dead){
6454 if(indialogue>=numdialogueboxes[whichdialogue]){
6458 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6461 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6464 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6466 for(int i=1;i<numplayers;i++){
6467 player[i].aitype = attacktypecutoff;
6474 if(!player[0].jumpkeydown){
6475 player[0].jumptogglekeydown=0;
6477 if(player[0].jumpkeydown&&
6478 player[0].targetanimation!=jumpupanim&&
6479 player[0].targetanimation!=jumpdownanim&&
6480 !player[0].isFlip())
6481 player[0].jumptogglekeydown=1;
6484 dialoguetime+=multiplier;
6485 hawkrotation+=multiplier*25;
6487 realhawkcoords.x=25;
6488 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6489 hawkcalldelay-=multiplier/2;
6491 if(hawkcalldelay<=0){
6492 emit_sound_at(hawksound, realhawkcoords);
6494 hawkcalldelay=16+abs(Random()%8);
6501 doPlayerCollisions();
6505 for(int k=0;k<numplayers;k++)
6506 if(k!=0&&player[k].immobile)
6507 player[k].coords=player[k].realoldcoords;
6509 for(int k=0;k<numplayers;k++){
6510 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6511 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6512 player[k].DoDamage(1000);
6518 static bool respawnkeydown;
6521 (Input::isKeyDown(SDLK_z)&&
6522 Input::isKeyDown(SDLK_LMETA)&&
6524 (Input::isKeyDown(jumpkey)&&
6528 targetlevel=whichlevel;
6532 if(!Input::isKeyDown(jumpkey))
6534 if(Input::isKeyDown(jumpkey))
6540 static bool movekey;
6543 for(int i=0;i<numplayers;i++){
6544 static float oldtargetrotation;
6545 if(!player[i].skeleton.free){
6546 oldtargetrotation=player[i].targetrotation;
6547 if(i==0&&indialogue==-1){
6548 //TODO: refactor repetitive code
6549 if(!animation[player[0].targetanimation].attack&&
6550 player[0].targetanimation!=staggerbackhighanim&&
6551 player[0].targetanimation!=staggerbackhardanim&&
6552 player[0].targetanimation!=crouchremoveknifeanim&&
6553 player[0].targetanimation!=removeknifeanim&&
6554 player[0].targetanimation!=backhandspringanim&&
6555 player[0].targetanimation!=dodgebackanim&&
6556 player[0].targetanimation!=walljumprightkickanim&&
6557 player[0].targetanimation!=walljumpleftkickanim){
6559 player[0].targetrotation=0;
6561 player[0].targetrotation=-rotation+180;
6567 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6571 facing=DoRotation(facing,-rotation2,0,0);
6572 facing=DoRotation(facing,0,0-rotation,0);
6575 player[0].lookrotation=-rotation;
6577 player[i].targetheadrotation=rotation;
6578 player[i].targetheadrotation2=rotation2;
6580 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6581 if(!animation[player[i].targetanimation].attack&&
6582 player[i].targetanimation!=staggerbackhighanim&&
6583 player[i].targetanimation!=staggerbackhardanim&&
6584 player[i].targetanimation!=crouchremoveknifeanim&&
6585 player[i].targetanimation!=removeknifeanim&&
6586 player[i].targetanimation!=backhandspringanim&&
6587 player[i].targetanimation!=dodgebackanim&&
6588 player[i].targetanimation!=walljumprightkickanim&&
6589 player[i].targetanimation!=walljumpleftkickanim){
6590 player[i].targetrotation=-player[i].lookrotation+180;
6596 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6598 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6599 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6601 player[i].targetheadrotation=player[i].lookrotation;
6602 player[i].targetheadrotation2=player[i].lookrotation2;
6605 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6606 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6612 player[i].avoidsomething=0;
6614 //avoid flaming things
6615 for(int j=0;j<objects.numobjects;j++)
6616 if(objects.onfire[j])
6617 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6618 if( findDistancefast(&player[i].coords,&objects.position[j])<
6619 findDistancefast(&player[i].coords,&player[0].coords)){
6620 player[i].collided=0;
6621 player[i].avoidcollided=1;
6622 if(player[i].avoidsomething==0||
6623 findDistancefast(&player[i].coords,&objects.position[j])<
6624 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6625 player[i].avoidwhere=objects.position[j];
6626 player[i].avoidsomething=1;
6630 //avoid flaming players
6631 for(int j=0;j<numplayers;j++)
6632 if(player[j].onfire)
6633 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6634 if( findDistancefast(&player[i].coords,&player[j].coords)<
6635 findDistancefast(&player[i].coords,&player[0].coords)){
6636 player[i].collided=0;
6637 player[i].avoidcollided=1;
6638 if(player[i].avoidsomething==0||
6639 findDistancefast(&player[i].coords,&player[j].coords)<
6640 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6641 player[i].avoidwhere=player[j].coords;
6642 player[i].avoidsomething=1;
6646 if(player[i].collided>.8)
6647 player[i].avoidcollided=0;
6651 if(animation[player[i].targetanimation].attack==reversed){
6652 //player[i].targetrotation=player[i].rotation;
6653 player[i].forwardkeydown=0;
6654 player[i].leftkeydown=0;
6655 player[i].backkeydown=0;
6656 player[i].rightkeydown=0;
6657 player[i].jumpkeydown=0;
6658 player[i].attackkeydown=0;
6659 //player[i].crouchkeydown=0;
6660 player[i].throwkeydown=0;
6664 player[i].forwardkeydown=0;
6665 player[i].leftkeydown=0;
6666 player[i].backkeydown=0;
6667 player[i].rightkeydown=0;
6668 player[i].jumpkeydown=0;
6669 player[i].crouchkeydown=0;
6670 player[i].drawkeydown=0;
6671 player[i].throwkeydown=0;
6674 if(player[i].collided<-.3)
6675 player[i].collided=-.3;
6676 if(player[i].collided>1)
6677 player[i].collided=1;
6678 player[i].collided-=multiplier*4;
6679 player[i].whichdirectiondelay-=multiplier;
6680 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6681 player[i].avoidcollided=-.3;
6682 player[i].whichdirection=abs(Random()%2);
6683 player[i].whichdirectiondelay=.4;
6685 if(player[i].avoidcollided>1)
6686 player[i].avoidcollided=1;
6687 player[i].avoidcollided-=multiplier/4;
6688 if(!player[i].skeleton.free){
6689 player[i].stunned-=multiplier;
6690 player[i].surprised-=multiplier;
6692 if(i!=0&&player[i].surprised<=0&&
6693 player[i].aitype==attacktypecutoff&&
6695 !player[i].skeleton.free&&
6696 animation[player[i].targetanimation].attack==neutral)
6699 if(!player[i].throwkeydown)
6700 player[i].throwtogglekeydown=0;
6703 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6704 if(player[i].weaponactive==-1&&
6705 player[i].num_weapons<2&&
6706 (player[i].isIdle()||
6707 player[i].isCrouch()||
6708 player[i].targetanimation==sneakanim||
6709 player[i].targetanimation==rollanim||
6710 player[i].targetanimation==backhandspringanim||
6711 player[i].isFlip()||
6712 player[i].isFlip()||
6713 player[i].aitype!=playercontrolled)){
6714 for(int j=0;j<weapons.numweapons;j++){
6715 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6716 player[i].aitype==playercontrolled)&&
6717 weapons.owner[j]==-1&&
6718 player[i].weaponactive==-1)
6719 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
6720 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
6721 if(player[i].isCrouch()||
6722 player[i].targetanimation==sneakanim||
6724 player[i].isIdle()||
6725 player[i].aitype!=playercontrolled){
6726 player[i].throwtogglekeydown=1;
6727 setAnimation(i,crouchremoveknifeanim);
6728 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6729 player[i].hasvictim=0;
6731 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6732 player[i].throwtogglekeydown=1;
6733 player[i].hasvictim=0;
6735 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6736 player[i].aitype==playercontrolled)&&
6737 weapons.owner[j]==-1||
6739 weapons.owner[j]==player[i].victim->id)
6740 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1)
6741 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
6742 if(weapons.type[j]!=staff)
6743 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6745 player[i].weaponactive=0;
6746 weapons.owner[j]=player[i].id;
6747 if(player[i].num_weapons>0)
6748 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6749 player[i].num_weapons++;
6750 player[i].weaponids[0]=j;
6753 }else if((player[i].isIdle()||
6754 player[i].isFlip()||
6755 player[i].aitype!=playercontrolled)&&
6756 findDistancefast(&player[i].coords,&weapons.position[j])<5&&
6757 player[i].coords.y<weapons.position[j].y){
6758 if(!player[i].isFlip()){
6759 player[i].throwtogglekeydown=1;
6760 setAnimation(i,removeknifeanim);
6761 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6763 if(player[i].isFlip()){
6764 player[i].throwtogglekeydown=1;
6765 player[i].hasvictim=0;
6767 for(int k=0;k<weapons.numweapons;k++){
6768 if(player[i].weaponactive==-1)
6769 if((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0||
6770 player[i].aitype==playercontrolled)&&
6771 weapons.owner[k]==-1||
6773 weapons.owner[k]==player[i].victim->id)
6774 if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&
6775 player[i].weaponactive==-1){
6776 if(weapons.type[k]!=staff)
6777 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6779 player[i].weaponactive=0;
6780 weapons.owner[k]=player[i].id;
6781 if(player[i].num_weapons>0)
6782 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6783 player[i].num_weapons++;
6784 player[i].weaponids[0]=k;
6791 if(player[i].isCrouch()||
6792 player[i].targetanimation==sneakanim||
6794 player[i].isIdle()||player[i].targetanimation==rollanim||
6795 player[i].targetanimation==backhandspringanim){
6797 for(int j=0;j<numplayers;j++){
6798 if(player[i].weaponactive==-1)
6800 if(player[j].num_weapons&&
6801 player[j].skeleton.free&&
6802 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6803 (((player[j].skeleton.forward.y<0&&
6804 player[j].weaponstuckwhere==0)||
6805 (player[j].skeleton.forward.y>0&&
6806 player[j].weaponstuckwhere==1))||
6807 player[j].weaponstuck==-1||
6808 player[j].num_weapons>1)){
6809 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6810 player[i].throwtogglekeydown=1;
6811 player[i].victim=&player[j];
6812 player[i].hasvictim=1;
6813 setAnimation(i,crouchremoveknifeanim);
6814 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6816 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6817 player[i].throwtogglekeydown=1;
6818 player[i].victim=&player[j];
6819 player[i].hasvictim=1;
6820 int k = player[j].weaponids[0];
6821 if(player[i].hasvictim){
6824 if(player[i].victim->weaponstuck!=-1){
6825 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6830 if(weapons.type[k]!=staff)
6831 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6834 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6836 player[i].weaponactive=0;
6837 if(weapons.owner[k]!=-1){
6838 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6839 else player[i].victim->num_weapons=1;
6841 player[i].victim->skeleton.longdead=0;
6842 player[i].victim->skeleton.free=1;
6843 player[i].victim->skeleton.broken=0;
6845 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6846 player[i].victim->skeleton.joints[l].velchange=0;
6847 player[i].victim->skeleton.joints[l].locked=0;
6853 Normalise(&relative);
6854 XYZ footvel,footpoint;
6856 footpoint=weapons.position[k];
6857 if(player[i].victim->weaponstuck!=-1){
6858 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6859 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6860 weapons.bloody[k]=2;
6861 weapons.blooddrip[k]=5;
6862 player[i].victim->weaponstuck=-1;
6863 player[i].victim->bloodloss+=2000;
6864 player[i].victim->DoDamage(2000);
6867 if(player[i].victim->num_weapons>0){
6868 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6869 if(player[i].victim->weaponids[0]==k)
6870 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6873 player[i].victim->weaponactive=-1;
6875 playerJoint(player[i].victim,abdomen).velocity+=relative*6;
6876 playerJoint(player[i].victim,neck).velocity+=relative*6;
6877 playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
6878 playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
6881 if(player[i].num_weapons>0){
6882 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6884 player[i].num_weapons++;
6885 player[i].weaponids[0]=k;
6892 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6893 if(weapons.type[player[i].weaponids[0]]==knife){
6894 if(player[i].isIdle()||
6896 player[i].isCrouch()||
6897 player[i].targetanimation==sneakanim||
6900 for(int j=0;j<numplayers;j++){
6902 if(tutoriallevel!=1||tutorialstage==49)
6904 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6905 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6906 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6907 !player[j].skeleton.free&&
6908 -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)){
6909 if(!player[i].isFlip()){
6910 player[i].throwtogglekeydown=1;
6911 player[i].victim=&player[j];
6912 setAnimation(i,knifethrowanim);
6913 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6914 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6916 if(player[i].isFlip()){
6917 if(player[i].weaponactive!=-1){
6918 player[i].throwtogglekeydown=1;
6919 player[i].victim=&player[j];
6921 weapons.owner[player[i].weaponids[0]]=-1;
6922 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);
6925 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6927 weapons.velocity[player[i].weaponids[0]]=aim*50;
6928 weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
6929 weapons.missed[player[i].weaponids[0]]=0;
6930 weapons.freetime[player[i].weaponids[0]]=0;
6931 weapons.firstfree[player[i].weaponids[0]]=1;
6932 weapons.physics[player[i].weaponids[0]]=0;
6933 player[i].num_weapons--;
6934 if(player[i].num_weapons){
6935 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6937 player[i].weaponactive=-1;
6944 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6945 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6946 player[i].throwtogglekeydown=1;
6947 weapons.owner[player[i].weaponids[0]]=-1;
6948 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
6949 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
6950 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
6951 weapons.missed[player[i].weaponids[0]]=1;
6952 weapons.freetime[player[i].weaponids[0]]=0;
6953 weapons.firstfree[player[i].weaponids[0]]=1;
6954 weapons.physics[player[i].weaponids[0]]=1;
6955 player[i].num_weapons--;
6956 if(player[i].num_weapons){
6957 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6958 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6961 player[i].weaponactive=-1;
6962 for(int j=0;j<numplayers;j++){
6963 player[j].wentforweapon=0;
6971 if(i==0||!player[0].dead||player[i].weaponactive!=-1)
6972 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6973 player[i].num_weapons==2&&
6974 player[i].weaponactive==-1&&
6975 player[i].isIdle()||
6977 player[i].weaponactive!=-1&&
6980 if(player[i].weaponactive!=-1)
6981 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)
6983 if(isgood&&player[i].creature!=wolftype){
6984 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6985 setAnimation(i,drawrightanim);
6986 player[i].drawtogglekeydown=1;
6988 if((player[i].isIdle()||
6989 (player[i].aitype!=playercontrolled&&
6990 player[0].weaponactive!=-1&&
6991 player[i].isRun()))&&
6992 player[i].num_weapons&&
6993 weapons.type[player[i].weaponids[0]]==sword){
6994 setAnimation(i,drawleftanim);
6995 player[i].drawtogglekeydown=1;
6997 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6998 setAnimation(i,crouchdrawrightanim);
6999 player[i].drawtogglekeydown=1;
7004 if(player[i].isCrouch()&&
7005 weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7007 player[i].onterrain&&
7008 player[i].num_weapons&&
7009 player[i].weaponactive!=-1&&
7010 player[i].attackkeydown){
7011 if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7012 player[i].onterrain&&
7013 bloodtoggle&&musictype!=stream_fighttheme){
7014 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)
7015 setAnimation(i,crouchstabanim);
7016 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)
7017 setAnimation(i,swordgroundstabanim);
7018 player[i].hasvictim=0;
7019 //player[i].attacktogglekeydown=1;
7023 if(!player[i].drawkeydown)
7024 player[i].drawtogglekeydown=0;
7031 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7033 else absflatfacing=flatfacing;
7036 player[i].forwardkeydown=0;
7037 player[i].leftkeydown=0;
7038 player[i].backkeydown=0;
7039 player[i].rightkeydown=0;
7040 player[i].jumpkeydown=0;
7041 player[i].crouchkeydown=0;
7042 player[i].drawkeydown=0;
7043 player[i].throwkeydown=0;
7047 if(!animation[player[i].targetanimation].attack&&
7048 player[i].targetanimation!=staggerbackhighanim&&
7049 player[i].targetanimation!=staggerbackhardanim&&
7050 player[i].targetanimation!=backhandspringanim&&
7051 player[i].targetanimation!=dodgebackanim){
7052 if(!player[i].forwardkeydown)
7053 player[i].forwardstogglekeydown=0;
7054 if(player[i].crouchkeydown){
7058 player[i].superruntoggle=1;
7060 for(int j=0;j<numplayers;j++)
7061 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7062 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7063 player[i].superruntoggle=0;
7067 for(int j=0;j<numplayers;j++){
7068 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7069 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7070 player[j].victim==&player[i]&&
7071 (player[j].targetanimation==sweepanim||
7072 player[j].targetanimation==upunchanim||
7073 player[j].targetanimation==wolfslapanim||
7074 ((player[j].targetanimation==swordslashanim||
7075 player[j].targetanimation==knifeslashstartanim||
7076 player[j].targetanimation==staffhitanim||
7077 player[j].targetanimation==staffspinhitanim)&&
7078 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7087 player[target].Reverse();
7088 player[i].lowreversaldelay=.5;
7090 if(player[i].isIdle()){
7091 setAnimation(i,player[i].getCrouch());
7092 player[i].transspeed=10;
7094 if(player[i].isRun()||
7095 (player[i].isStop()&&
7096 (player[i].leftkeydown||
7097 player[i].rightkeydown||
7098 player[i].forwardkeydown||
7099 player[i].backkeydown))){
7100 setAnimation(i,rollanim);
7101 player[i].transspeed=20;
7104 if(!player[i].crouchkeydown){
7106 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7108 if(player[i].isCrouch()){
7110 for(int j=0;j<numplayers;j++){
7112 !player[j].skeleton.free&&
7114 player[i].highreversaldelay<=0){
7115 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7116 player[j].victim==&player[i]&&
7117 (player[j].targetanimation==spinkickanim)&&
7118 player[i].isCrouch()){
7127 player[target].Reverse();
7128 player[i].highreversaldelay=.5;
7130 if(player[i].isCrouch()){
7131 if(!player[i].wasCrouch()){
7132 player[i].currentanimation=player[i].getCrouch();
7133 player[i].currentframe=0;
7135 setAnimation(i,player[i].getIdle());
7136 player[i].transspeed=10;
7139 if(player[i].targetanimation==sneakanim){
7140 setAnimation(i,player[i].getIdle());
7141 player[i].transspeed=10;
7144 if(player[i].forwardkeydown){
7145 if(player[i].isIdle()||
7146 (player[i].isStop()&&
7147 player[i].targetrotation==player[i].rotation)||
7148 (player[i].isLanding()&&
7149 player[i].targetframe>0&&
7150 !player[i].jumpkeydown)||
7151 (player[i].isLandhard()&&
7152 player[i].targetframe>0&&
7153 !player[i].jumpkeydown&&
7154 player[i].crouchkeydown)){
7155 if(player[i].aitype==passivetype)
7156 setAnimation(i,walkanim);
7158 setAnimation(i,player[i].getRun());
7160 if(player[i].isCrouch()){
7161 player[i].targetanimation=sneakanim;
7162 if(player[i].wasCrouch())
7164 player[i].targetframe=0;
7166 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7167 setAnimation(i,climbanim);
7168 player[i].targetframe=1;
7169 player[i].jumpclimb=1;
7171 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7172 player[i].velocity+=absflatfacing*5*multiplier;
7174 player[i].forwardstogglekeydown=1;
7177 if (player[i].rightkeydown){
7178 if(player[i].isIdle()||
7179 (player[i].isStop()&&
7180 player[i].targetrotation==player[i].rotation)||
7181 (player[i].isLanding()&&
7182 player[i].targetframe>0&&
7183 !player[i].jumpkeydown)||
7184 (player[i].isLandhard()&&
7185 player[i].targetframe>0&&
7186 !player[i].jumpkeydown&&
7187 player[i].crouchkeydown)){
7188 setAnimation(i,player[i].getRun());
7190 if(player[i].isCrouch()){
7191 player[i].targetanimation=sneakanim;
7192 if(player[i].wasCrouch())
7194 player[i].targetframe=0;
7196 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7197 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7199 player[i].targetrotation-=90;
7200 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7201 if(player[i].backkeydown)player[i].targetrotation-=45;
7204 if ( player[i].leftkeydown){
7205 if(player[i].isIdle()||
7206 (player[i].isStop()&&
7207 player[i].targetrotation==player[i].rotation)||
7208 (player[i].isLanding()&&
7209 player[i].targetframe>0&&
7210 !player[i].jumpkeydown)||
7211 (player[i].isLandhard()&&
7212 player[i].targetframe>0&&
7213 !player[i].jumpkeydown&&
7214 player[i].crouchkeydown)){
7215 setAnimation(i,player[i].getRun());
7217 if(player[i].isCrouch()){
7218 player[i].targetanimation=sneakanim;
7219 if(player[i].wasCrouch())
7221 player[i].targetframe=0;
7223 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7224 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7226 player[i].targetrotation+=90;
7227 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7228 if(player[i].backkeydown)player[i].targetrotation+=45;
7231 if(player[i].backkeydown){
7232 if(player[i].isIdle()||
7233 (player[i].isStop()&&
7234 player[i].targetrotation==player[i].rotation)||
7235 (player[i].isLanding()&&
7236 player[i].targetframe>0&&
7237 !player[i].jumpkeydown)||
7238 (player[i].isLandhard()&&
7239 player[i].targetframe>0&&
7240 !player[i].jumpkeydown&&
7241 player[i].crouchkeydown)){
7242 setAnimation(i,player[i].getRun());
7244 if(player[i].isCrouch()){
7245 player[i].targetanimation=sneakanim;
7246 if(player[i].wasCrouch())
7248 player[i].targetframe=0;
7250 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7251 player[i].velocity-=absflatfacing*5*multiplier;
7253 if(player[i].targetanimation==hanganim){
7254 player[i].currentanimation=jumpdownanim;
7255 player[i].targetanimation=jumpdownanim;
7257 player[i].currentframe=0;
7258 player[i].targetframe=1;
7259 player[i].velocity=0;
7260 player[i].velocity.y+=gravity;
7261 player[i].coords.y-=1.4;
7262 player[i].grabdelay=1;
7264 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7265 player[i].targetrotation+=180;
7268 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7269 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7271 player[i].targetanimation==walkanim||
7272 player[i].isCrouch()||
7273 player[i].targetanimation==sneakanim)&&
7274 player[i].jumppower>1)&&
7275 ((player[i].targetanimation!=rabbitrunninganim&&
7276 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7277 player[i].jumpstart=0;
7278 setAnimation(i,jumpupanim);
7279 player[i].rotation=player[i].targetrotation;
7280 player[i].transspeed=20;
7281 player[i].FootLand(0,1);
7282 player[i].FootLand(1,1);
7286 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7288 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7289 if(!movekey)player[i].velocity=0;
7294 for(int j=0;j<numplayers;j++){
7295 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7296 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7297 player[j].victim==&player[i]&&
7298 (player[j].targetanimation==sweepanim)){
7299 if(target>=0)target=-1;
7304 if(target>=0)player[i].velocity.y=1;
7305 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7306 player[i].velocity.y=7;
7307 player[i].crouchtogglekeydown=1;
7309 else player[i].velocity.y=5;
7311 if(mousejump&&i==0&&debugmode){
7312 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7313 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7316 player[i].coords.y+=.2;
7317 player[i].jumppower-=1;
7320 emit_sound_at(whooshsound, player[i].coords, 128.);
7322 emit_sound_at(jumpsound, player[i].coords, 128.);
7324 if((player[i].isIdle())&&player[i].jumppower>1){
7325 setAnimation(i,player[i].getLanding());
7326 player[i].targetframe=2;
7327 player[i].landhard=0;
7328 player[i].jumpstart=1;
7329 player[i].tempdeltav=deltav;
7331 if(player[i].targetanimation==jumpupanim&&
7335 player[i].aitype!=playercontrolled)){
7336 if(player[i].jumppower>multiplier*6){
7337 player[i].velocity.y+=multiplier*6;
7338 player[i].jumppower-=multiplier*6;
7340 if(player[i].jumppower<=multiplier*6){
7341 player[i].velocity.y+=player[i].jumppower;
7342 player[i].jumppower=0;
7345 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7349 if(player[i].isRun()||player[i].targetanimation==walkanim)
7350 setAnimation(i,player[i].getStop());
7351 if(player[i].targetanimation==sneakanim){
7352 player[i].targetanimation=player[i].getCrouch();
7353 if(player[i].currentanimation==sneakanim)
7355 player[i].targetframe=0;
7358 if(player[i].targetanimation==walkanim&&
7359 (player[i].aitype==attacktypecutoff||
7360 player[i].aitype==searchtype||
7361 (player[i].aitype==passivetype&&
7362 player[i].numwaypoints<=1)))
7363 setAnimation(i,player[i].getStop());
7364 if(player[i].isRun()&&(player[i].aitype==passivetype))
7365 setAnimation(i,player[i].getStop());
7368 if(player[i].targetanimation==rollanim)
7369 player[i].targetrotation=oldtargetrotation;
7373 for(int k=0;k<numplayers;k++){
7374 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7375 if(player[k].rotation>player[k].targetrotation)
7376 player[k].rotation-=360;
7378 player[k].rotation+=360;
7381 //stop to turn in right direction
7382 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7383 setAnimation(k,player[k].getStop());
7385 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7386 player[k].targettilt=0;
7388 if(player[k].targetanimation!=jumpupanim&&
7389 player[k].targetanimation!=backhandspringanim&&
7390 player[k].targetanimation!=jumpdownanim&&
7391 !player[k].isFlip()){
7392 player[k].targettilt=0;
7393 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7394 player[k].jumppower=0;
7395 player[k].jumppower+=multiplier*7;
7396 if(player[k].isCrouch())
7397 player[k].jumppower+=multiplier*7;
7398 if(player[k].jumppower>5)
7399 player[k].jumppower=5;
7402 if(player[k].isRun())
7403 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7405 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7406 player[k].grabdelay-=multiplier;
7410 for(int k=0;k<numplayers;k++){
7411 player[k].DoAnimations();
7412 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7413 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7419 for(int j=numenvsounds-1;j>=0;j--){
7420 envsoundlife[j]-=multiplier;
7421 if(envsoundlife[j]<0){
7423 envsoundlife[j]=envsoundlife[numenvsounds];
7424 envsound[j]=envsound[numenvsounds];
7428 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7430 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7432 if(tutoriallevel==1){
7449 if(tutorialstage>=51)
7450 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7451 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7452 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7454 emit_stream_np(stream_menutheme);
7463 if(tutorialstage<51)
7464 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7465 emit_sound_at(fireendsound, player[0].coords);
7467 player[0].coords=(oldtemp+oldtemp2)/2;
7471 if(tutorialstage>=14&&tutorialstage<50)
7472 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7473 emit_sound_at(fireendsound, player[1].coords);
7475 for(int i=0;i<player[1].skeleton.num_joints;i++){
7477 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7478 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7479 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;
7480 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7481 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7485 player[1].coords=(oldtemp+oldtemp2)/2;
7486 for(int i=0;i<player[1].skeleton.num_joints;i++){
7487 player[1].skeleton.joints[i].velocity=0;
7489 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7490 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7491 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;
7492 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7493 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7501 static float gLoc[3];
7505 static float vel[3];
7506 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7507 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7508 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7510 //Set orientation with forward and up vectors
7511 static XYZ upvector;
7515 upvector=DoRotation(upvector,-rotation2+90,0,0);
7516 upvector=DoRotation(upvector,0,0-rotation,0);
7521 facing=DoRotation(facing,-rotation2,0,0);
7522 facing=DoRotation(facing,0,0-rotation,0);
7525 static float ori[6];
7529 ori[3] = -upvector.x;
7530 ori[4] = upvector.y;
7531 ori[5] = -upvector.z;
7533 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7540 if(Input::isKeyPressed(SDLK_F1))
7544 void Game::TickOnce(){
7546 rotation+=multiplier*5;
7548 if(directing||indialogue==-1) {
7549 rotation+=deltah*.7;
7551 rotation2+=deltav*.7;
7553 rotation2-=deltav*.7;
7561 void Game::TickOnceAfter(){
7562 static XYZ colviewer;
7563 static XYZ coltarget;
7567 static float changedelay;
7568 static bool alldead;
7569 static float unseendelay;
7570 static float cameraspeed;
7574 if(environment==snowyenvironment)
7575 leveltheme=stream_snowtheme;
7576 if(environment==grassyenvironment)
7577 leveltheme=stream_grasstheme;
7578 if(environment==desertenvironment)
7579 leveltheme=stream_deserttheme;
7583 musictype=leveltheme;
7584 for(int i=0;i<numplayers;i++){
7585 if((player[i].aitype==attacktypecutoff||
7586 player[i].aitype==getweapontype||
7587 player[i].aitype==gethelptype||
7588 player[i].aitype==searchtype)&&
7589 !player[i].dead/*&&player[i].surprised<=0*/&&
7590 (player[i].targetanimation!=sneakattackedanim&&
7591 player[i].targetanimation!=knifesneakattackedanim&&
7592 player[i].targetanimation!=swordsneakattackedanim)){
7593 musictype=stream_fighttheme;
7598 musictype=stream_menutheme;
7601 if(musictype==stream_fighttheme)
7604 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7605 unseendelay-=multiplier;
7607 musictype=stream_fighttheme;
7612 musictype=stream_menutheme;
7620 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7621 emit_sound_np(alarmsound);
7622 musicselected=musictype;
7624 if(musicselected==leveltheme)
7625 musicvolume[0]+=multiplier*450;
7627 musicvolume[0]-=multiplier*450;
7628 if(musicselected==stream_fighttheme)
7629 musicvolume[1]+=multiplier*450;
7631 musicvolume[1]-=multiplier*450;
7632 if(musicselected==stream_menutheme)
7633 musicvolume[2]+=multiplier*450;
7635 musicvolume[2]-=multiplier*450;
7637 for(int i=0;i<3;i++){
7638 if(musicvolume[i]<0)
7640 if(musicvolume[i]>512)
7644 if(musicvolume[2]>128&&!loading&&!mainmenu)
7648 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7649 emit_stream_np(leveltheme, musicvolume[0]);
7650 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7651 emit_stream_np(stream_fighttheme, musicvolume[1]);
7652 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7653 emit_stream_np(stream_menutheme, musicvolume[2]);
7654 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7655 pause_sound(leveltheme);
7656 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7657 pause_sound(stream_fighttheme);
7658 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7659 pause_sound(stream_menutheme);
7661 if(musicvolume[0]!=oldmusicvolume[0])
7662 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7663 if(musicvolume[1]!=oldmusicvolume[1])
7664 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7665 if(musicvolume[2]!=oldmusicvolume[2])
7666 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7668 for(int i=0;i<3;i++)
7669 oldmusicvolume[i]=musicvolume[i];
7671 pause_sound(leveltheme);
7672 pause_sound(stream_fighttheme);
7673 pause_sound(stream_menutheme);
7675 for(int i=0;i<4;i++){
7676 oldmusicvolume[i]=0;
7682 for(int i=0;i<numhotspots;i++){
7683 if(hotspottype[i]>10&&hotspottype[i]<20){
7684 if(player[hotspottype[i]-10].dead==0)
7686 else if(killhotspot==2)
7695 for(int i=0;i<numhotspots;i++)
7696 if(hotspottype[i]==-1)
7697 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7701 for(int i=1;i<numplayers;i++)
7702 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7704 if(numalarmed>maxalarmed)
7705 maxalarmed=numalarmed;
7707 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7708 if(player[0].dead&&changedelay<=0){
7710 targetlevel=whichlevel;
7713 for(int i=1;i<numplayers;i++)
7714 if(!player[i].dead&&player[i].howactive<typedead1)
7718 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7720 targetlevel=whichlevel+1;
7721 if(targetlevel>numchallengelevels-1)targetlevel=0;
7723 if(winhotspot||windialogue){
7725 targetlevel=whichlevel+1;
7726 if(targetlevel>numchallengelevels-1)targetlevel=0;
7732 targetlevel=whichlevel+1;
7733 if(targetlevel>numchallengelevels-1)targetlevel=0;
7736 if(changedelay>0&&!player[0].dead&&!won) {
7737 //high scores, awards, win
7739 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7742 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7758 if(!editorenabled&&gameon&&!mainmenu) {
7759 if(changedelay!=-999)
7760 changedelay-=multiplier/7;
7762 targetlevel=whichlevel;
7763 if(loading==2&&!campaign){
7766 fireSound(firestartsound);
7768 if(!player[0].dead&&targetlevel!=whichlevel)
7769 startbonustotal=bonustotal;
7771 Loadlevel(whichlevel);
7773 Loadlevel(targetlevel);
7779 if(loading==2&&targetlevel==whichlevel){
7783 fireSound(firestartsound);
7785 Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);
7791 if(changedelay<=-999&&
7795 (alldead&&maptype==mapkilleveryone)||
7799 if((player[0].dead||
7800 (alldead&&maptype==mapkilleveryone)||
7805 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7815 // campaignchoosenext determines what to do when the level is complete:
7816 // 0 = load next level
7817 // 1 = go back to level select screen
7818 // 2 = stealthload next level
7819 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
7820 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0)
7822 } else if(mainmenu==0&&winfreeze) {
7823 stealthloading = (campaignchoosenext[campaignchoicewhich[whichchoice]]==2);
7825 if(!stealthloading){
7826 fireSound(firestartsound);
7843 Loadlevel(campaignmapname[campaignchoicewhich[0]]);
7847 pause_sound(stream_menutheme);
7858 oldmusictype=musictype;
7864 facing=DoRotation(facing,-rotation2,0,0);
7865 facing=DoRotation(facing,0,0-rotation,0);
7866 viewerfacing=facing;
7869 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;
7870 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;
7872 if(player[0].skeleton.free){
7873 for(int i=0;i<player[0].skeleton.num_joints;i++){
7874 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7875 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7879 if(player[0].skeleton.free!=2&&!autocam){
7881 if(findLengthfast(&player[0].velocity)>400){
7882 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7884 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7885 coltarget=target-cameraloc;
7886 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7888 Normalise(&coltarget);
7889 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7890 else cameraloc=cameraloc+coltarget*multiplier*8;
7892 if(editorenabled)cameraloc=target;
7893 cameradist+=multiplier*5;
7894 if(cameradist>2.3)cameradist=2.3;
7895 viewer=cameraloc-facing*cameradist;
7897 coltarget=cameraloc;
7898 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7899 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7900 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7901 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7903 coltarget=cameraloc;
7904 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7906 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7907 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7908 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7910 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7914 cameradist=findDistance(&viewer,&target);
7915 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7916 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7917 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7920 if(player[0].skeleton.free!=2&&autocam){
7922 if(findLengthfast(&player[0].velocity)>400){
7923 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7925 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7926 cameradist+=multiplier*5;
7927 if(cameradist>3.3)cameradist=3.3;
7928 coltarget=target-cameraloc;
7929 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7930 else if(findLengthfast(&coltarget)>1)
7932 Normalise(&coltarget);
7933 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7934 else cameraloc=cameraloc+coltarget*multiplier*8;
7936 if(editorenabled)cameraloc=target;
7939 coltarget=cameraloc;
7940 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7941 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7942 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7943 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7945 coltarget=cameraloc;
7946 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7948 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7949 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7950 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7952 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7956 cameradist=findDistance(&viewer,&target);
7957 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7958 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7959 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7962 if(camerashake>.8)camerashake=.8;
7963 //if(woozy>10)woozy=10;
7964 //woozy+=multiplier;
7966 if(player[0].dead)camerashake=0;
7967 if(player[0].dead)woozy=0;
7968 camerashake-=multiplier*2;
7969 blackout-=multiplier*2;
7970 //if(player[0].isCrouch())woozy-=multiplier*8;
7971 if(camerashake<0)camerashake=0;
7972 if(blackout<0)blackout=0;
7973 //if(woozy<0)woozy=0;
7975 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7976 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7977 viewer.z+=(float)(Random()%100)*.0005*camerashake;