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"
41 // Added more evilness needed for MSVC
43 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
44 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
48 extern float multiplier;
50 extern int environment;
51 extern Terrain terrain;
52 extern float screenwidth,screenheight;
55 extern float texdetail;
56 extern Objects objects;
58 extern float slomodelay;
59 extern bool floatjump;
62 extern float camerashake;
64 extern float blackout;
65 extern bool cellophane;
66 extern bool musictoggle;
67 extern int difficulty;
68 extern int bloodtoggle;
69 extern bool invertmouse;
71 extern float precipdelay;
72 extern XYZ viewerfacing;
73 extern bool ambientsound;
74 extern bool mousejump;
75 extern float viewdistance;
77 extern bool keyboardfrozen;
78 extern bool loadingstuff;
79 extern XYZ windvector;
80 extern bool debugmode;
81 static int leveltheme;
83 extern bool visibleloading;
84 extern XYZ envsound[30];
85 extern float envsoundvol[30];
86 extern int numenvsounds;
87 extern float envsoundlife[30];
88 extern float usermousesensitivity;
89 extern bool ismotionblur;
90 extern bool showdamagebar; // (des)activate the damage bar
92 extern float tintr,tintg,tintb;
93 extern bool skyboxtexture;
97 extern float skyboxlightr;
98 extern float skyboxlightg;
99 extern float skyboxlightb;
100 extern float fadestart;
101 extern float slomospeed;
102 extern float slomofreq;
103 extern int tutoriallevel;
104 extern float smoketex;
105 extern float tutorialstagetime;
106 extern int tutorialstage;
107 extern float tutorialmaxtime;
108 extern float tutorialsuccess;
109 extern bool againbonus;
110 extern bool reversaltrain;
111 extern bool canattack;
112 extern bool cananger;
113 extern float damagedealt;
115 extern int editoractive;
116 extern int editorpathtype;
118 extern float hostiletime;
120 extern bool gamestarted;
122 extern int numhotspots;
123 extern int winhotspot;
124 extern int windialogue;
125 extern int killhotspot;
126 extern XYZ hotspot[40];
127 extern int hotspottype[40];
128 extern float hotspotsize[40];
129 extern char hotspottext[40][256];
130 extern int currenthotspot;
134 extern bool stillloading;
135 extern bool winfreeze;
137 extern bool campaign;
139 static const char *rabbitskin[] = {
140 ":Data:Textures:Fur3.jpg",
141 ":Data:Textures:Fur.jpg",
142 ":Data:Textures:Fur2.jpg",
143 ":Data:Textures:Lynx.jpg",
144 ":Data:Textures:Otter.jpg",
145 ":Data:Textures:Opal.jpg",
146 ":Data:Textures:Sable.jpg",
147 ":Data:Textures:Chocolate.jpg",
148 ":Data:Textures:BW2.jpg",
149 ":Data:Textures:WB2.jpg"
152 static const char *wolfskin[] = {
153 ":Data:Textures:Wolf.jpg",
154 ":Data:Textures:Darkwolf.jpg",
155 ":Data:Textures:Snowwolf.jpg"
158 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
159 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
161 static const char **creatureskin[] = {rabbitskin, wolfskin};
163 /* Return true if PFX is a prefix of STR (case-insensitive). */
164 static bool stripfx(const char *str, const char *pfx)
166 return !strncasecmp(str, pfx, strlen(pfx));
169 static const char *cmd_names[] = {
170 #define DECLARE_COMMAND(cmd) #cmd " ",
171 #include "ConsoleCmds.h"
172 #undef DECLARE_COMMAND
175 typedef void (*console_handler)(Game *game, const char *args);
177 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
178 #include "ConsoleCmds.h"
179 #undef DECLARE_COMMAND
181 static console_handler cmd_handlers[] = {
182 #define DECLARE_COMMAND(cmd) ch_##cmd,
183 #include "ConsoleCmds.h"
184 #undef DECLARE_COMMAND
189 // added utility functions -sf17k =============================================================
191 //TODO: try to hide these variables completely with a better interface
192 inline void setAnimation(int playerid,int animation){
193 player[playerid].targetanimation=animation;
194 player[playerid].targetframe=0;
195 player[playerid].target=0;
198 //TODO: this is incorrect but I'm afraid to change it and break something,
199 //probably causes quirky behavior that I might want to preserve
200 inline float roughDirection(XYZ vec){
202 float angle=-asin(-vec.x)*180/M_PI;
207 inline float roughDirectionTo(XYZ start, XYZ end){
208 return roughDirection(end-start);
211 //TODO: gotta be a better way
212 inline float pitch(XYZ vec){
214 return -asin(vec.y)*180/M_PI;
216 inline float pitchTo(XYZ start, XYZ end){
217 return pitch(end-start);
220 //change these to a Person method
221 inline Joint& playerJoint(int playerid, int bodypart){
222 return player[playerid].skeleton.joints[player[playerid].skeleton.jointlabels[bodypart]]; }
223 inline Joint& playerJoint(Person* pplayer, int bodypart){
224 return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; }
226 inline float sq(float n){ return n*n; }
228 inline float stepTowardf(float from, float to, float by){
229 if(fabs(from-to)<by) return to;
230 else if(from>to) return from-by;
234 void playdialogueboxsound(){
236 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
237 temppos=temppos-viewer;
242 switch(dialogueboxsound[whichdialogue][indialogue]){
243 case -6: sound=alarmsound; break;
244 case -4: sound=consolefailsound; break;
245 case -3: sound=consolesuccesssound; break;
246 case -2: sound=firestartsound; break;
247 case -1: sound=fireendsound; break;
248 case 1: sound=rabbitchitter; break;
249 case 2: sound=rabbitchitter2; break;
250 case 3: sound=rabbitpainsound; break;
251 case 4: sound=rabbitpain1sound; break;
252 case 5: sound=rabbitattacksound; break;
253 case 6: sound=rabbitattack2sound; break;
254 case 7: sound=rabbitattack3sound; break;
255 case 8: sound=rabbitattack4sound; break;
256 case 9: sound=growlsound; break;
257 case 10: sound=growl2sound; break;
258 case 11: sound=snarlsound; break;
259 case 12: sound=snarl2sound; break;
260 case 13: sound=barksound; break;
261 case 14: sound=bark2sound; break;
262 case 15: sound=bark3sound; break;
263 case 16: sound=barkgrowlsound; break;
267 emit_sound_at(sound, temppos);
270 // end added utility functions ================================================================
274 static void ch_quit(Game *game, const char *args)
279 static void ch_map(Game *game, const char *args)
281 game->Loadlevel(args);
282 game->whichlevel = -2;
286 static void ch_save(Game *game, const char *args){
288 snprintf(buf, 63, ":Data:Maps:%s", args);
293 tfile=fopen( ConvertFileName(buf), "wb" );
294 fpackf(tfile, "Bi", mapvers);
295 fpackf(tfile, "Bi", maptype);
296 fpackf(tfile, "Bi", hostile);
297 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
298 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
299 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
300 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
301 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
302 if(player[0].num_weapons>0&&player[0].num_weapons<5)
303 for(int j=0;j<player[0].num_weapons;j++)
304 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
306 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
307 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
308 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
309 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
311 fpackf(tfile, "Bi", player[0].numclothes);
313 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
315 fpackf(tfile, "Bi", numdialogues);
317 for(int k=0;k<numdialogues;k++){
318 fpackf(tfile, "Bi", numdialogueboxes[k]);
319 fpackf(tfile, "Bi", dialoguetype[k]);
320 for(int l=0;l<10;l++){
321 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
322 fpackf(tfile, "Bf", participantrotation[k][l]);
324 for(int l=0;l<numdialogueboxes[k];l++){
325 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
326 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
327 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
328 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
329 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
331 int templength=strlen(dialoguetext[k][l]);
332 fpackf(tfile, "Bi",(templength));
333 for(int m=0;m<templength;m++){
334 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
335 if(dialoguetext[k][l][m]=='\0')
339 templength=strlen(dialoguename[k][l]);
340 fpackf(tfile, "Bi",templength);
341 for(int m=0;m<templength;m++){
342 fpackf(tfile, "Bb", dialoguename[k][l][m]);
343 if(dialoguename[k][l][m]=='\0')
347 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
348 fpackf(tfile, "Bi", participantfocus[k][l]);
349 fpackf(tfile, "Bi", participantaction[k][l]);
351 for(int m=0;m<10;m++)
352 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
354 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
358 for(int k=0;k<player[0].numclothes;k++){
359 int templength=strlen(player[0].clothes[k]);
360 fpackf(tfile, "Bi", templength);
361 for(int l=0;l<templength;l++)
362 fpackf(tfile, "Bb", player[0].clothes[k][l]);
363 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
366 fpackf(tfile, "Bi", environment);
368 fpackf(tfile, "Bi", objects.numobjects);
370 for(int k=0;k<objects.numobjects;k++)
371 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
372 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
374 fpackf(tfile, "Bi", numhotspots);
375 for(int i=0;i<numhotspots;i++){
376 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
377 int templength=strlen(hotspottext[i]);
378 fpackf(tfile, "Bi",templength);
379 for(int l=0;l<templength;l++)
380 fpackf(tfile, "Bb", hotspottext[i][l]);
383 fpackf(tfile, "Bi", numplayers);
384 if(numplayers<maxplayers)
385 for(int j=1;j<numplayers;j++){
386 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
387 player[j].coords.x, player[j].coords.y, player[j].coords.z,
388 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
389 if(player[j].num_weapons<5)
390 for(int k=0;k<player[j].num_weapons;k++)
391 fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
392 if(player[j].numwaypoints<30){
393 fpackf(tfile, "Bi", player[j].numwaypoints);
394 for(int k=0;k<player[j].numwaypoints;k++){
395 fpackf(tfile, "Bf", player[j].waypoints[k].x);
396 fpackf(tfile, "Bf", player[j].waypoints[k].y);
397 fpackf(tfile, "Bf", player[j].waypoints[k].z);
398 fpackf(tfile, "Bi", player[j].waypointtype[k]);
400 fpackf(tfile, "Bi", player[j].waypoint);
402 player[j].numwaypoints=0;
403 player[j].waypoint=0;
404 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
407 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
408 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
409 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
410 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
412 float headprop, bodyprop, armprop, legprop;
413 if(player[j].creature==wolftype){
414 headprop=player[j].proportionhead.x/1.1;
415 bodyprop=player[j].proportionbody.x/1.1;
416 armprop=player[j].proportionarms.x/1.1;
417 legprop=player[j].proportionlegs.x/1.1;
418 }else if(player[j].creature==rabbittype){
419 headprop=player[j].proportionhead.x/1.2;
420 bodyprop=player[j].proportionbody.x/1.05;
421 armprop=player[j].proportionarms.x/1.00;
422 legprop=player[j].proportionlegs.x/1.1;
425 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
427 fpackf(tfile, "Bi", player[j].numclothes);
428 if(player[j].numclothes)
429 for(int k=0;k<player[j].numclothes;k++){
431 templength=strlen(player[j].clothes[k]);
432 fpackf(tfile, "Bi", templength);
433 for(int l=0;l<templength;l++)
434 fpackf(tfile, "Bb", player[j].clothes[k][l]);
435 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
439 fpackf(tfile, "Bi", game->numpathpoints);
440 for(int j=0;j<game->numpathpoints;j++){
441 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
442 for(int k=0;k<game->numpathpointconnect[j];k++)
443 fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
446 fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
451 static void ch_cellar(Game *game, const char *args)
453 game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
456 static void ch_tint(Game *game, const char *args)
458 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
461 static void ch_tintr(Game *game, const char *args)
466 static void ch_tintg(Game *game, const char *args)
471 static void ch_tintb(Game *game, const char *args)
476 static void ch_speed(Game *game, const char *args)
478 player[0].speedmult = atof(args);
481 static void ch_strength(Game *game, const char *args)
483 player[0].power = atof(args);
486 static void ch_power(Game *game, const char *args)
488 player[0].power = atof(args);
491 static void ch_size(Game *game, const char *args)
493 player[0].scale = atof(args) * .2;
496 static int find_closest()
499 float closestdist = std::numeric_limits<float>::max();
501 for (int i = 1; i < numplayers; i++) {
503 distance = findDistancefast(&player[i].coords,&player[0].coords);
504 if (distance < closestdist) {
505 closestdist = distance;
512 static void ch_sizenear(Game *game, const char *args)
514 int closest = find_closest();
517 player[closest].scale = atof(args) * .2;
520 static void set_proportion(int pnum, const char *args)
522 float headprop,bodyprop,armprop,legprop;
524 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
526 if(player[pnum].creature==wolftype){
527 player[pnum].proportionhead=1.1*headprop;
528 player[pnum].proportionbody=1.1*bodyprop;
529 player[pnum].proportionarms=1.1*armprop;
530 player[pnum].proportionlegs=1.1*legprop;
531 } else if(player[pnum].creature==rabbittype){
532 player[pnum].proportionhead=1.2*headprop;
533 player[pnum].proportionbody=1.05*bodyprop;
534 player[pnum].proportionarms=1.00*armprop;
535 player[pnum].proportionlegs=1.1*legprop;
536 player[pnum].proportionlegs.y=1.05*legprop;
540 static void ch_proportion(Game *game, const char *args)
542 set_proportion(0, args);
545 static void ch_proportionnear(Game *game, const char *args)
547 int closest = find_closest();
549 set_proportion(closest, args);
552 static void set_protection(int pnum, const char *args)
554 float head, high, low;
555 sscanf(args, "%f%f%f", &head, &high, &low);
557 player[pnum].protectionhead = head;
558 player[pnum].protectionhigh = high;
559 player[pnum].protectionlow = low;
562 static void ch_protection(Game *game, const char *args)
564 set_protection(0, args);
567 static void ch_protectionnear(Game *game, const char *args)
569 int closest = find_closest();
571 set_protection(closest, args);
574 static void set_armor(int pnum, const char *args)
576 float head, high, low;
577 sscanf(args, "%f%f%f", &head, &high, &low);
579 player[pnum].armorhead = head;
580 player[pnum].armorhigh = high;
581 player[pnum].armorlow = low;
584 static void ch_armor(Game *game, const char *args)
589 static void ch_armornear(Game *game, const char *args)
591 int closest = find_closest();
593 set_armor(closest, args);
596 static void ch_protectionreset(Game *game, const char *args)
598 set_protection(0, "1 1 1");
599 set_armor(0, "1 1 1");
602 static void set_metal(int pnum, const char *args)
604 float head, high, low;
605 sscanf(args, "%f%f%f", &head, &high, &low);
607 player[pnum].metalhead = head;
608 player[pnum].metalhigh = high;
609 player[pnum].metallow = low;
612 static void ch_metal(Game *game, const char *args)
617 static void set_noclothes(int pnum, Game *game, const char *args)
619 player[pnum].numclothes = 0;
620 game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
621 &player[pnum].skeleton.drawmodel.textureptr,1,
622 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
625 static void ch_noclothes(Game *game, const char *args)
627 set_noclothes(0, game, args);
630 static void ch_noclothesnear(Game *game, const char *args)
632 int closest = find_closest();
634 set_noclothes(closest, game, args);
638 static void set_clothes(int pnum, Game *game, const char *args)
641 snprintf(buf, 63, ":Data:Textures:%s.png", args);
643 if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
646 player[pnum].DoMipmaps();
647 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
648 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
649 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
650 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
651 player[pnum].numclothes++;
654 static void ch_clothes(Game *game, const char *args)
656 set_clothes(0, game, args);
659 static void ch_clothesnear(Game *game, const char *args)
661 int closest = find_closest();
663 set_clothes(closest, game, args);
666 static void ch_belt(Game *game, const char *args)
668 player[0].skeleton.clothes = !player[0].skeleton.clothes;
672 static void ch_cellophane(Game *game, const char *args)
674 cellophane = !cellophane;
675 float mul = cellophane ? 0 : 1;
677 for (int i = 0; i < numplayers; i++) {
678 player[i].proportionhead.z = player[i].proportionhead.x * mul;
679 player[i].proportionbody.z = player[i].proportionbody.x * mul;
680 player[i].proportionarms.z = player[i].proportionarms.x * mul;
681 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
685 static void ch_funnybunny(Game *game, const char *args)
687 player[0].skeleton.id=0;
688 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
689 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
690 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
691 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
692 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
693 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
694 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
695 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
696 player[0].creature=rabbittype;
698 player[0].headless=0;
699 player[0].damagetolerance=200;
700 set_proportion(0, "1 1 1 1");
703 static void ch_wolfie(Game *game, const char *args)
705 player[0].skeleton.id=0;
706 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
707 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
708 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
709 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
710 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
711 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
712 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
713 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
714 player[0].creature=wolftype;
715 player[0].damagetolerance=300;
716 set_proportion(0, "1 1 1 1");
719 static void ch_wolfieisgod(Game *game, const char *args)
721 ch_wolfie(game, args);
724 static void ch_wolf(Game *game, const char *args)
726 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
727 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
730 static void ch_snowwolf(Game *game, const char *args)
732 game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
733 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
736 static void ch_darkwolf(Game *game, const char *args)
738 game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
739 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
742 static void ch_lizardwolf(Game *game, const char *args)
744 game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
745 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
748 static void ch_white(Game *game, const char *args)
750 game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
751 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
754 static void ch_brown(Game *game, const char *args)
756 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
757 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
760 static void ch_black(Game *game, const char *args)
762 game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
763 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
766 static void ch_sizemin(Game *game, const char *args)
768 for (int i = 1; i < numplayers; i++)
769 if (player[i].scale < 0.8 * 0.2)
770 player[i].scale = 0.8 * 0.2;
773 static void ch_tutorial(Game *game, const char *args)
775 tutoriallevel = atoi(args);
778 static void ch_hostile(Game *game, const char *args)
780 hostile = atoi(args);
783 static void ch_indemo(Game *game, const char *args)
786 hotspot[numhotspots]=player[0].coords;
787 hotspotsize[numhotspots]=0;
788 hotspottype[numhotspots]=-111;
789 strcpy(hotspottext[numhotspots],"mapname");
793 static void ch_notindemo(Game *game, const char *args)
799 static void ch_type(Game *game, const char *args)
801 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
802 for (int i = 0; i < n; i++)
803 if (stripfx(args, editortypenames[i])) {
809 static void ch_path(Game *game, const char *args)
811 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
812 for (int i = 0; i < n; i++)
813 if (stripfx(args, pathtypenames[i])) {
819 static void ch_hs(Game *game, const char *args)
821 hotspot[numhotspots]=player[0].coords;
825 sscanf(args, "%f%d %n", &size, &type, &shift);
827 hotspotsize[numhotspots] = size;
828 hotspottype[numhotspots] = type;
830 strcpy(hotspottext[numhotspots], args + shift);
831 strcat(hotspottext[numhotspots], "\n");
836 static void ch_dialogue(Game *game, const char *args)
839 char buf1[32], buf2[64];
841 sscanf(args, "%d %31s", &dlg, buf1);
842 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
844 dialoguetype[numdialogues] = dlg;
846 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
847 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
849 ifstream ipstream(ConvertFileName(buf2));
850 ipstream.ignore(256,':');
851 ipstream >> numdialogueboxes[numdialogues];
852 for(int i=0;i<numdialogueboxes[numdialogues];i++){
853 ipstream.ignore(256,':');
854 ipstream.ignore(256,':');
855 ipstream.ignore(256,' ');
856 ipstream >> dialogueboxlocation[numdialogues][i];
857 ipstream.ignore(256,':');
858 ipstream >> dialogueboxcolor[numdialogues][i][0];
859 ipstream >> dialogueboxcolor[numdialogues][i][1];
860 ipstream >> dialogueboxcolor[numdialogues][i][2];
861 ipstream.ignore(256,':');
862 ipstream.getline(dialoguename[numdialogues][i],64);
863 ipstream.ignore(256,':');
864 ipstream.ignore(256,' ');
865 ipstream.getline(dialoguetext[numdialogues][i],128);
866 for(int j=0;j<128;j++){
867 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
869 ipstream.ignore(256,':');
870 ipstream >> dialogueboxsound[numdialogues][i];
873 for(int i=0;i<numdialogueboxes[numdialogues];i++){
874 for(int j=0;j<numplayers;j++){
875 participantfacing[numdialogues][i][j]=player[j].facing;
882 whichdialogue=numdialogues;
887 static void ch_fixdialogue(Game *game, const char *args)
889 char buf1[32], buf2[64];
892 sscanf(args, "%d %31s", &whichdi, buf1);
893 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
895 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
896 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
898 ifstream ipstream(ConvertFileName(buf2));
899 ipstream.ignore(256,':');
900 ipstream >> numdialogueboxes[whichdi];
901 for(int i=0;i<numdialogueboxes[whichdi];i++){
902 ipstream.ignore(256,':');
903 ipstream.ignore(256,':');
904 ipstream.ignore(256,' ');
905 ipstream >> dialogueboxlocation[whichdi][i];
906 ipstream.ignore(256,':');
907 ipstream >> dialogueboxcolor[whichdi][i][0];
908 ipstream >> dialogueboxcolor[whichdi][i][1];
909 ipstream >> dialogueboxcolor[whichdi][i][2];
910 ipstream.ignore(256,':');
911 ipstream.getline(dialoguename[whichdi][i],64);
912 ipstream.ignore(256,':');
913 ipstream.ignore(256,' ');
914 ipstream.getline(dialoguetext[whichdi][i],128);
915 for(int j=0;j<128;j++){
916 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
918 ipstream.ignore(256,':');
919 ipstream >> dialogueboxsound[whichdi][i];
925 static void ch_fixtype(Game *game, const char *args)
928 sscanf(args, "%d", &dlg);
929 dialoguetype[0] = dlg;
932 static void ch_fixrotation(Game *game, const char *args)
934 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
937 static void ch_ddialogue(Game *game, const char *args)
943 static void ch_dhs(Game *game, const char *args)
949 static void ch_immobile(Game *game, const char *args)
951 player[0].immobile = 1;
954 static void ch_allimmobile(Game *game, const char *args)
956 for (int i = 1; i < numplayers; i++)
957 player[i].immobile = 1;
960 static void ch_mobile(Game *game, const char *args)
962 player[0].immobile = 0;
965 static void ch_default(Game *game, const char *args)
967 player[0].armorhead=1;
968 player[0].armorhigh=1;
969 player[0].armorlow=1;
970 player[0].protectionhead=1;
971 player[0].protectionhigh=1;
972 player[0].protectionlow=1;
973 player[0].metalhead=1;
974 player[0].metalhigh=1;
975 player[0].metallow=1;
977 player[0].speedmult=1;
980 if(player[0].creature==wolftype){
981 player[0].proportionhead=1.1;
982 player[0].proportionbody=1.1;
983 player[0].proportionarms=1.1;
984 player[0].proportionlegs=1.1;
985 } else if(player[0].creature==rabbittype){
986 player[0].proportionhead=1.2;
987 player[0].proportionbody=1.05;
988 player[0].proportionarms=1.00;
989 player[0].proportionlegs=1.1;
990 player[0].proportionlegs.y=1.05;
993 player[0].numclothes=0;
994 game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
995 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
996 &player[0].skeleton.skinsize);
998 editoractive=typeactive;
999 player[0].immobile=0;
1002 static void ch_play(Game *game, const char *args)
1005 sscanf(args, "%d", &dlg);
1006 whichdialogue = dlg;
1008 if (whichdialogue >= numdialogues)
1011 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1012 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1013 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1014 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1015 player[participantfocus[whichdialogue][i]].velocity=0;
1016 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1017 player[participantfocus[whichdialogue][i]].targetframe=0;
1023 playdialogueboxsound();
1026 static void ch_mapkilleveryone(Game *game, const char *args)
1028 maptype = mapkilleveryone;
1031 static void ch_mapkillmost(Game *game, const char *args)
1033 maptype = mapkillmost;
1036 static void ch_mapkillsomeone(Game *game, const char *args)
1038 maptype = mapkillsomeone;
1041 static void ch_mapgosomewhere(Game *game, const char *args)
1043 maptype = mapgosomewhere;
1046 static void ch_viewdistance(Game *game, const char *args)
1048 viewdistance = atof(args)*100;
1051 static void ch_fadestart(Game *game, const char *args)
1053 fadestart = atof(args);
1056 static void ch_slomo(Game *game, const char *args)
1058 slomospeed = atof(args);
1063 static void ch_slofreq(Game *game, const char *args)
1065 slomofreq = atof(args);
1068 static void ch_skytint(Game *game, const char *args)
1070 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1072 skyboxlightr=skyboxr;
1073 skyboxlightg=skyboxg;
1074 skyboxlightb=skyboxb;
1076 game->SetUpLighting();
1078 terrain.DoShadows();
1079 objects.DoShadows();
1082 static void ch_skylight(Game *game, const char *args)
1084 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1086 game->SetUpLighting();
1088 terrain.DoShadows();
1089 objects.DoShadows();
1092 static void ch_skybox(Game *game, const char *args)
1094 skyboxtexture = !skyboxtexture;
1096 game->SetUpLighting();
1098 terrain.DoShadows();
1099 objects.DoShadows();
1102 static void cmd_dispatch(Game *game, const char *cmd)
1104 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1106 for (i = 0; i < n_cmds; i++)
1107 if (stripfx(cmd, cmd_names[i]))
1109 cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
1112 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1115 /********************> Tick() <*****/
1116 extern bool save_image(const char * fname);
1117 void Screenshot (void)
1120 time_t t = time(NULL);
1121 struct tm *tme = localtime(&t);
1122 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);
1125 mkdir("Screenshots");
1127 mkdir("Screenshots", S_IRWXU);
1133 void Game::SetUpLighting(){
1134 if(environment==snowyenvironment)
1135 light.setColors(.65,.65,.7,.4,.4,.44);
1136 if(environment==desertenvironment)
1137 light.setColors(.95,.95,.95,.4,.35,.3);
1138 if(environment==grassyenvironment)
1139 light.setColors(.95,.95,1,.4,.4,.44);
1141 light.setColors(1,1,1,.4,.4,.4);
1143 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1144 light.color[0]*=(skyboxlightr+average)/2;
1145 light.color[1]*=(skyboxlightg+average)/2;
1146 light.color[2]*=(skyboxlightb+average)/2;
1147 light.ambient[0]*=(skyboxlightr+average)/2;
1148 light.ambient[1]*=(skyboxlightg+average)/2;
1149 light.ambient[2]*=(skyboxlightb+average)/2;
1152 int Game::findPathDist(int start,int end){
1153 int smallestcount,count,connected;
1154 int last,last2,last3,last4;
1158 for(int i=0;i<50;i++){
1164 while(last!=end&&count<30){
1166 for(int j=0;j<numpathpoints;j++){
1167 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1170 if(numpathpointconnect[j])
1171 for(int k=0;k<numpathpointconnect[j];k++){
1172 if(pathpointconnect[j][k]==last)connected=1;
1175 if(numpathpointconnect[last])
1176 for(int k=0;k<numpathpointconnect[last];k++){
1177 if(pathpointconnect[last][k]==j)connected=1;
1180 if(closest==-1||Random()%2==0){
1191 if(count<smallestcount)smallestcount=count;
1193 return smallestcount;
1196 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1197 static XYZ colpoint,colviewer,coltarget;
1198 static float minx,minz,maxx,maxz,miny,maxy;
1200 minx=min(startpoint.x,endpoint.x)-1;
1201 miny=min(startpoint.y,endpoint.y)-1;
1202 minz=min(startpoint.z,endpoint.z)-1;
1203 maxx=max(startpoint.x,endpoint.x)+1;
1204 maxy=max(startpoint.y,endpoint.y)+1;
1205 maxz=max(startpoint.z,endpoint.z)+1;
1207 for(int i=0;i<objects.numobjects;i++){
1208 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1209 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1210 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1211 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1212 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1213 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1214 if( objects.type[i]!=treeleavestype&&
1215 objects.type[i]!=bushtype&&
1216 objects.type[i]!=firetype){
1217 colviewer=startpoint;
1219 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1224 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1229 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1230 static XYZ colpoint,colviewer,coltarget;
1231 static float minx,minz,maxx,maxz,miny,maxy;
1232 static int i; //FIXME: see below
1234 minx=min(startpoint.x,endpoint.x)-1;
1235 miny=min(startpoint.y,endpoint.y)-1;
1236 minz=min(startpoint.z,endpoint.z)-1;
1237 maxx=max(startpoint.x,endpoint.x)+1;
1238 maxy=max(startpoint.y,endpoint.y)+1;
1239 maxz=max(startpoint.z,endpoint.z)+1;
1242 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1243 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1244 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1245 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1246 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1247 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1248 if( objects.type[what]!=treeleavestype&&
1249 objects.type[what]!=bushtype&&
1250 objects.type[what]!=firetype){
1251 colviewer=startpoint;
1254 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1259 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1264 void Game::Setenvironment(int which)
1268 LOG(" Setting environment...");
1270 float temptexdetail;
1273 pause_sound(stream_snowtheme);
1274 pause_sound(stream_grasstheme);
1275 pause_sound(stream_deserttheme);
1276 pause_sound(stream_wind);
1277 pause_sound(stream_desertambient);
1280 if(environment==snowyenvironment){
1284 emit_stream_np(stream_wind);
1286 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1287 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1288 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1289 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1291 footstepsound = footstepsn1;
1292 footstepsound2 = footstepsn2;
1293 footstepsound3 = footstepst1;
1294 footstepsound4 = footstepst2;
1296 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1298 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1300 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1305 temptexdetail=texdetail;
1306 if(texdetail>1)texdetail=4;
1307 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1308 ":Data:Textures:Skybox(snow):Left.jpg",
1309 ":Data:Textures:Skybox(snow):Back.jpg",
1310 ":Data:Textures:Skybox(snow):Right.jpg",
1311 ":Data:Textures:Skybox(snow):Up.jpg",
1312 ":Data:Textures:Skybox(snow):Down.jpg");
1317 texdetail=temptexdetail;
1318 } else if(environment==desertenvironment){
1321 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1322 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1323 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1324 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1328 emit_stream_np(stream_desertambient);
1330 footstepsound = footstepsn1;
1331 footstepsound2 = footstepsn2;
1332 footstepsound3 = footstepsn1;
1333 footstepsound4 = footstepsn2;
1335 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1337 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1339 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1343 temptexdetail=texdetail;
1344 if(texdetail>1)texdetail=4;
1345 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1346 ":Data:Textures:Skybox(sand):Left.jpg",
1347 ":Data:Textures:Skybox(sand):Back.jpg",
1348 ":Data:Textures:Skybox(sand):Right.jpg",
1349 ":Data:Textures:Skybox(sand):Up.jpg",
1350 ":Data:Textures:Skybox(sand):Down.jpg");
1355 texdetail=temptexdetail;
1356 } else if(environment==grassyenvironment){
1359 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1360 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1361 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1362 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1365 emit_stream_np(stream_wind, 100.);
1367 footstepsound = footstepgr1;
1368 footstepsound2 = footstepgr2;
1369 footstepsound3 = footstepst1;
1370 footstepsound4 = footstepst2;
1372 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1374 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1376 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1380 temptexdetail=texdetail;
1381 if(texdetail>1)texdetail=4;
1382 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1383 ":Data:Textures:Skybox(grass):Left.jpg",
1384 ":Data:Textures:Skybox(grass):Back.jpg",
1385 ":Data:Textures:Skybox(grass):Right.jpg",
1386 ":Data:Textures:Skybox(grass):Up.jpg",
1387 ":Data:Textures:Skybox(grass):Down.jpg");
1391 texdetail=temptexdetail;
1393 temptexdetail=texdetail;
1395 terrain.load(":Data:Textures:heightmap.png");
1397 texdetail=temptexdetail;
1400 void Game::Loadlevel(int which){
1406 Loadlevel("tutorial");
1407 }else if(which >= 0 && which <= 15){
1409 snprintf(buf, 32, "map%d", which + 1);
1412 Loadlevel("mapsave");
1415 void Game::Loadlevel(const char *name){
1418 static const char *pfx = ":Data:Maps:";
1421 float headprop,legprop,armprop,bodyprop;
1425 LOG(std::string("Loading level...") + name);
1437 if(tutoriallevel!=-1)
1442 if(tutoriallevel==1)
1444 if(tutorialstage==0){
1445 tutorialstagetime=0;
1449 pause_sound(whooshsound);
1450 pause_sound(stream_firesound);
1452 // Change the map filename into something that is os specific
1453 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1454 sprintf(buf, "%s%s", pfx, name);
1455 const char *FixedFN = ConvertFileName(buf);
1459 tfile=fopen( FixedFN, "rb" );
1461 pause_sound(stream_firesound);
1467 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1471 for(int i=0;i<20;i++)
1472 dialoguegonethrough[i]=0;
1481 difficulty=accountactive->getDifficulty();
1500 for(int i=0;i<100;i++)
1520 bonustotal=startbonustotal;
1525 emit_sound_np(consolesuccesssound);
1530 if(!stealthloading){
1531 terrain.numdecals=0;
1532 Sprite::deleteSprites();
1533 for(int i=0;i<objects.numobjects;i++)
1534 objects.model[i].numdecals=0;
1536 int j=objects.numobjects;
1537 for(int i=0;i<j;i++){
1538 objects.DeleteObject(0);
1543 for(int i=0;i<subdivision;i++)
1544 for(int j=0;j<subdivision;j++)
1545 terrain.patchobjectnum[i][j]=0;
1550 weapons.numweapons=0;
1552 funpackf(tfile, "Bi", &mapvers);
1554 funpackf(tfile, "Bi", &indemo);
1558 funpackf(tfile, "Bi", &maptype);
1560 maptype=mapkilleveryone;
1562 funpackf(tfile, "Bi", &hostile);
1566 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1572 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1580 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1582 skyboxlightr=skyboxr;
1583 skyboxlightg=skyboxg;
1584 skyboxlightb=skyboxb;
1587 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);
1589 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1590 player[0].originalcoords=player[0].coords;
1591 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1592 for(int j=0;j<player[0].num_weapons;j++){
1593 player[0].weaponids[j]=weapons.numweapons;
1594 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1595 weapons.owner[weapons.numweapons]=0;
1596 weapons.numweapons++;
1602 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1603 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1604 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1605 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1607 funpackf(tfile, "Bi", &player[0].numclothes);
1610 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1612 player[0].whichskin=0;
1613 player[0].creature=rabbittype;
1616 player[0].lastattack=-1;
1617 player[0].lastattack2=-1;
1618 player[0].lastattack3=-1;
1622 funpackf(tfile, "Bi", &numdialogues);
1623 for(int k=0;k<numdialogues;k++){
1624 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1625 funpackf(tfile, "Bi", &dialoguetype[k]);
1626 for(int l=0;l<10;l++){
1627 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1628 funpackf(tfile, "Bf", &participantrotation[k][l]);
1630 for(int l=0;l<numdialogueboxes[k];l++){
1631 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1632 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1633 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1634 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1635 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1637 funpackf(tfile, "Bi",&templength);
1638 if(templength>128||templength<=0)
1641 for(m=0;m<templength;m++){
1642 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1643 if(dialoguetext[k][l][m]=='\0')
1646 dialoguetext[k][l][m] = 0;
1648 funpackf(tfile, "Bi",&templength);
1649 if(templength>64||templength<=0)templength=64;
1650 for(m=0;m<templength;m++){
1651 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1652 if(dialoguename[k][l][m]=='\0')
1655 dialoguename[k][l][m] = 0;
1656 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1657 funpackf(tfile, "Bi", &participantfocus[k][l]);
1658 funpackf(tfile, "Bi", &participantaction[k][l]);
1661 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1663 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1669 for(int k=0;k<player[0].numclothes;k++){
1670 funpackf(tfile, "Bi", &templength);
1671 for(int l=0;l<templength;l++)
1672 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1673 player[0].clothes[k][templength]='\0';
1674 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1677 funpackf(tfile, "Bi", &environment);
1679 funpackf(tfile, "Bi", &objects.numobjects);
1680 for(int i=0;i<objects.numobjects;i++){
1681 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]);
1682 if(objects.type[i]==treeleavestype)
1683 objects.scale[i]=objects.scale[i-1];
1687 funpackf(tfile, "Bi", &numhotspots);
1688 for(int i=0;i<numhotspots;i++){
1689 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1690 funpackf(tfile, "Bi", &templength);
1692 for(int l=0;l<templength;l++)
1693 funpackf(tfile, "Bb", &hotspottext[i][l]);
1694 hotspottext[i][templength]='\0';
1695 if(hotspottype[i]==-111)
1704 if(!stealthloading){
1706 for(int i=0;i<objects.numobjects;i++)
1707 objects.center+=objects.position[i];
1708 objects.center/=objects.numobjects;
1714 float maxdistance=0;
1716 //~ int whichclosest;
1717 for(int i=0;i<objects.numobjects;i++){
1718 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1719 if(tempdist>maxdistance){
1721 maxdistance=tempdist;
1724 objects.radius=fast_sqrt(maxdistance);
1729 //mapcenter=objects.center;
1730 //mapradius=objects.radius;
1732 funpackf(tfile, "Bi", &numplayers);
1733 int howmanyremoved=0;
1734 bool removeanother=0;
1735 if(numplayers>1&&numplayers<maxplayers){
1736 for(int i=1;i<numplayers;i++){
1741 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);
1743 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1745 player[i-howmanyremoved].howactive=typeactive;
1747 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1749 player[i-howmanyremoved].scale=-1;
1751 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1753 player[i-howmanyremoved].immobile=0;
1755 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1757 player[i-howmanyremoved].rotation=0;
1758 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1759 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1764 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1765 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1766 player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1767 funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1768 weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1769 weapons.numweapons++;
1772 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1773 //player[i-howmanyremoved].numwaypoints=10;
1774 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1775 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1776 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1777 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1779 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1781 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1784 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1785 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1786 player[i-howmanyremoved].waypoint=0;
1788 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1789 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1790 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1791 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1794 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1801 if(player[i-howmanyremoved].creature==wolftype){
1802 player[i-howmanyremoved].proportionhead=1.1*headprop;
1803 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1804 player[i-howmanyremoved].proportionarms=1.1*armprop;
1805 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1808 if(player[i-howmanyremoved].creature==rabbittype){
1809 player[i-howmanyremoved].proportionhead=1.2*headprop;
1810 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1811 player[i-howmanyremoved].proportionarms=1.00*armprop;
1812 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1813 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1816 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1817 if(player[i-howmanyremoved].numclothes){
1818 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1820 funpackf(tfile, "Bi", &templength);
1821 for(int l=0;l<templength;l++)
1822 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1823 player[i-howmanyremoved].clothes[k][templength]='\0';
1824 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1833 numplayers-=howmanyremoved;
1834 funpackf(tfile, "Bi", &numpathpoints);
1835 if(numpathpoints>30||numpathpoints<0)
1837 for(int j=0;j<numpathpoints;j++){
1838 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1839 for(int k=0;k<numpathpointconnect[j];k++){
1840 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1846 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1849 if(environment!=oldenvironment)
1850 Setenvironment(environment);
1851 oldenvironment=environment;
1853 if(!stealthloading){
1854 int j=objects.numobjects;
1855 objects.numobjects=0;
1856 for(int i=0;i<j;i++){
1857 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1862 terrain.DoShadows();
1865 objects.DoShadows();
1872 if(numplayers>maxplayers-1)
1873 numplayers=maxplayers-1;
1874 for(int i=0;i<numplayers;i++){
1880 if(i==0||player[i].scale<0)
1882 player[i].skeleton.free=0;
1883 player[i].skeleton.id=i;
1885 player[i].creature=rabbittype;
1886 if(player[i].creature!=wolftype){
1887 player[i].skeleton.Load(
1888 (char *)":Data:Skeleton:Basic Figure",
1889 (char *)":Data:Skeleton:Basic Figurelow",
1890 (char *)":Data:Skeleton:Rabbitbelt",
1891 (char *)":Data:Models:Body.solid",
1892 (char *)":Data:Models:Body2.solid",
1893 (char *)":Data:Models:Body3.solid",
1894 (char *)":Data:Models:Body4.solid",
1895 (char *)":Data:Models:Body5.solid",
1896 (char *)":Data:Models:Body6.solid",
1897 (char *)":Data:Models:Body7.solid",
1898 (char *)":Data:Models:Bodylow.solid",
1899 (char *)":Data:Models:Belt.solid",0);
1901 if(player[i].creature!=wolftype){
1902 player[i].skeleton.Load(
1903 (char *)":Data:Skeleton:Basic Figure",
1904 (char *)":Data:Skeleton:Basic Figurelow",
1905 (char *)":Data:Skeleton:Rabbitbelt",
1906 (char *)":Data:Models:Body.solid",
1907 (char *)":Data:Models:Body2.solid",
1908 (char *)":Data:Models:Body3.solid",
1909 (char *)":Data:Models:Body4.solid",
1910 (char *)":Data:Models:Body5.solid",
1911 (char *)":Data:Models:Body6.solid",
1912 (char *)":Data:Models:Body7.solid",
1913 (char *)":Data:Models:Bodylow.solid",
1914 (char *)":Data:Models:Belt.solid",1);
1915 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1917 if(player[i].creature==wolftype){
1918 player[i].skeleton.Load(
1919 (char *)":Data:Skeleton:Basic Figure Wolf",
1920 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1921 (char *)":Data:Skeleton:Rabbitbelt",
1922 (char *)":Data:Models:Wolf.solid",
1923 (char *)":Data:Models:Wolf2.solid",
1924 (char *)":Data:Models:Wolf3.solid",
1925 (char *)":Data:Models:Wolf4.solid",
1926 (char *)":Data:Models:Wolf5.solid",
1927 (char *)":Data:Models:Wolf6.solid",
1928 (char *)":Data:Models:Wolf7.solid",
1929 (char *)":Data:Models:Wolflow.solid",
1930 (char *)":Data:Models:Belt.solid",0);
1936 //~ texsize=512*512*3/texdetail/texdetail;
1938 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1940 if(player[i].numclothes){
1941 for(int j=0;j<player[i].numclothes;j++){
1942 tintr=player[i].clothestintr[j];
1943 tintg=player[i].clothestintg[j];
1944 tintb=player[i].clothestintb[j];
1945 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1947 player[i].DoMipmaps();
1950 player[i].currentanimation=bounceidleanim;
1951 player[i].targetanimation=bounceidleanim;
1952 player[i].currentframe=0;
1953 player[i].targetframe=1;
1955 player[i].speed=1+(float)(Random()%100)/1000;
1957 player[i].speed-=.2;
1959 player[i].speed-=.1;
1961 player[i].velocity=0;
1962 player[i].oldcoords=player[i].coords;
1963 player[i].realoldcoords=player[i].coords;
1966 player[i].skeleton.id=i;
1967 player[i].updatedelay=0;
1968 player[i].normalsupdatedelay=0;
1970 player[i].aitype=passivetype;
1971 player[i].madskills=0;
1974 player[i].proportionhead=1.2;
1975 player[i].proportionbody=1.05;
1976 player[i].proportionarms=1.00;
1977 player[i].proportionlegs=1.1;
1978 player[i].proportionlegs.y=1.05;
1980 player[i].headless=0;
1981 player[i].currentoffset=0;
1982 player[i].targetoffset=0;
1984 player[i].damagetolerance=200;
1986 if(player[i].creature==wolftype){
1987 if(i==0||player[i].scale<0)
1988 player[i].scale=.23;
1989 player[i].damagetolerance=300;
1995 player[i].proportionhead.z=0;
1996 player[i].proportionbody.z=0;
1997 player[i].proportionarms.z=0;
1998 player[i].proportionlegs.z=0;
2001 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2003 player[i].headmorphness=0;
2004 player[i].targetheadmorphness=1;
2005 player[i].headmorphstart=0;
2006 player[i].headmorphend=0;
2008 player[i].pausetime=0;
2011 player[i].jumppower=5;
2013 player[i].permanentdamage=0;
2014 player[i].superpermanentdamage=0;
2016 player[i].forwardkeydown=0;
2017 player[i].leftkeydown=0;
2018 player[i].backkeydown=0;
2019 player[i].rightkeydown=0;
2020 player[i].jumpkeydown=0;
2021 player[i].crouchkeydown=0;
2022 player[i].throwkeydown=0;
2024 player[i].collided=-10;
2026 player[i].bloodloss=0;
2027 player[i].weaponactive=-1;
2028 player[i].weaponstuck=-1;
2029 player[i].bleeding=0;
2030 player[i].deathbleeding=0;
2031 player[i].stunned=0;
2032 player[i].hasvictim=0;
2033 player[i].wentforweapon=0;
2036 player[0].aitype=playercontrolled;
2037 player[0].weaponactive=-1;
2040 player[0].power=1/.9;
2043 player[0].power=1/.8;
2046 player[0].damagetolerance=250;
2048 player[0].damagetolerance=300;
2050 player[0].armorhead*=1.5;
2052 player[0].armorhigh*=1.5;
2054 player[0].armorlow*=1.5;
2055 cameraloc=player[0].coords;
2057 rotation=player[0].rotation;
2059 hawkcoords=player[0].coords;
2064 for(int i=0;i<weapons.numweapons;i++){
2065 weapons.bloody[i]=0;
2066 weapons.blooddrip[i]=0;
2067 weapons.blooddripdelay[i]=0;
2068 weapons.onfire[i]=0;
2069 weapons.flamedelay[i]=0;
2070 weapons.damage[i]=0;
2071 if(weapons.type[i]==sword){
2072 weapons.mass[i]=1.5;
2073 weapons.tipmass[i]=1;
2074 weapons.length[i]=.8;
2076 if(weapons.type[i]==staff){
2078 weapons.tipmass[i]=1;
2079 weapons.length[i]=1.5;
2081 if(weapons.type[i]==knife){
2083 weapons.tipmass[i]=1.2;
2084 weapons.length[i]=.25;
2086 weapons.position[i]=-1000;
2087 weapons.tippoint[i]=-1000;
2090 LOG("Starting background music...");
2092 OPENAL_StopSound(OPENAL_ALL);
2093 if(environment==snowyenvironment){
2095 emit_stream_np(stream_wind);
2096 }else if(environment==desertenvironment){
2098 emit_stream_np(stream_desertambient);
2099 }else if(environment==grassyenvironment){
2101 emit_stream_np(stream_wind, 100.);
2103 oldmusicvolume[0]=0;
2104 oldmusicvolume[1]=0;
2105 oldmusicvolume[2]=0;
2106 oldmusicvolume[3]=0;
2117 Values of mainmenu :
2119 2 Menu pause (resume/end game)
2121 4 Controls configuration menu
2122 5 Main game menu (choose level or challenge)
2123 6 Deleting user menu
2124 7 User managment menu (select/add)
2125 8 Choose difficulty menu
2126 9 Challenge level selection menu
2127 10 End of the campaign congratulation (is that really a menu?)
2128 11 Same that 9 ??? => unused
2129 18 stereo configuration
2132 void Game::MenuTick(){
2135 // some specific case where we do something even if the left mouse button is not pressed.
2136 if((mainmenu==5) && (endgame==2)) {
2137 accountactive->endGame();
2142 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
2143 stereoseparation-=0.001;
2145 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
2151 if(gameon) { //resume
2153 pause_sound(stream_menutheme);
2154 resume_stream(leveltheme);
2156 fireSound(firestartsound);
2158 mainmenu=(accountactive?5:7);
2166 if(newdetail>2) newdetail=detail;
2167 if(newdetail<0) newdetail=detail;
2168 if(newscreenwidth>3000) newscreenwidth=screenwidth;
2169 if(newscreenwidth<0) newscreenwidth=screenwidth;
2170 if(newscreenheight>3000) newscreenheight=screenheight;
2171 if(newscreenheight<0) newscreenheight=screenheight;
2176 if(gameon){ //end game
2181 pause_sound(stream_menutheme);
2188 bool isCustomResolution,found;
2191 extern SDL_Rect **resolutions;
2192 isCustomResolution = true;
2194 for(int i = 0; (!found) && (resolutions[i]); i++) {
2195 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2196 isCustomResolution = false;
2198 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
2200 if(resolutions[i] != NULL) {
2201 newscreenwidth = (int) resolutions[i]->w;
2202 newscreenheight = (int) resolutions[i]->h;
2203 } else if(isCustomResolution){
2204 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
2205 newscreenwidth = (int) resolutions[0]->w;
2206 newscreenheight = (int) resolutions[0]->h;
2208 newscreenwidth = screenwidth;
2209 newscreenheight = screenheight;
2212 newscreenwidth = (int) resolutions[0]->w;
2213 newscreenheight = (int) resolutions[0]->h;
2220 newscreenwidth = (int) resolutions[0]->w;
2221 newscreenheight = (int) resolutions[0]->h;
2226 if(newdetail>2) newdetail=0;
2230 if(bloodtoggle>2) bloodtoggle=0;
2234 if(difficulty>2) difficulty=0;
2237 ismotionblur = !ismotionblur;
2243 musictoggle = !musictoggle;
2246 emit_stream_np(stream_menutheme);
2248 pause_sound(leveltheme);
2249 pause_sound(stream_fighttheme);
2250 pause_sound(stream_menutheme);
2252 for(int i=0;i<4;i++){
2253 oldmusicvolume[i]=0;
2268 SaveSettings(*this);
2269 mainmenu=gameon?2:1;
2272 invertmouse = !invertmouse;
2275 usermousesensitivity+=.2;
2276 if(usermousesensitivity>2) usermousesensitivity=.2;
2280 if(volume>1.0001f) volume=0;
2281 OPENAL_SetSFXMasterVolume((int)(volume*255));
2286 newstereomode = stereomode;
2291 showdamagebar = !showdamagebar;
2298 if(selected<9 && keyselect==-1)
2312 if((selected-7 >= accountactive->getCampaignChoicesMade())) {
2322 whichchoice=selected-7-accountactive->getCampaignChoicesMade();
2325 Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
2329 pause_sound(stream_menutheme);
2346 pause_sound(stream_menutheme);
2355 mainmenu=(gameon?2:1);
2366 accountactive = Account::destroy(accountactive);
2368 } else if(selected==2) {
2375 if(selected==0 && Account::getNbAccounts()<8){
2377 } else if (selected < Account::getNbAccounts()+1) {
2380 accountactive=Account::get(selected-1);
2381 } else if (selected == Account::getNbAccounts()+1) {
2384 for(int j=0;j<255;j++){
2385 displaytext[0][j]=0;
2396 accountactive->setDifficulty(selected);
2400 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
2408 targetlevel=selected;
2409 if(firstload)TickOnceAfter();
2410 if(!firstload)LoadStuff();
2411 else Loadlevel(selected);
2416 pause_sound(stream_menutheme);
2418 if(selected==numchallengelevels){
2433 stereoseparation+=0.001;
2437 newstereomode = (StereoMode)(newstereomode + 1);
2438 while(!CanInitStereo(newstereomode)){
2439 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
2440 newstereomode = (StereoMode)(newstereomode + 1);
2441 if(newstereomode >= stereoCount)
2442 newstereomode = stereoNone;
2444 } else if(selected==2) {
2445 stereoreverse = !stereoreverse;
2446 } else if(selected==3) {
2450 stereomode = newstereomode;
2451 InitStereo(stereomode);
2458 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
2461 SaveSettings(*this);
2465 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
2468 inputText(displaytext[0],&displayselected,&displaychars[0]);
2469 if(!waiting) { // the input as finished
2470 if(displaychars[0]){ // with enter
2471 accountactive = Account::add(string(displaytext[0]));
2477 fireSound(firestartsound);
2479 for(int i=0;i<255;i++){
2480 displaytext[0][i]=0;
2489 displayblinkdelay-=multiplier;
2490 if(displayblinkdelay<=0){
2491 displayblinkdelay=.3;
2492 displayblink=1-displayblink;
2497 void Game::doTutorial(){
2498 if(tutorialstagetime>tutorialmaxtime){
2501 if(tutorialstage<=1){
2506 switch(tutorialstage){
2512 tutorialmaxtime=600;
2514 tutorialmaxtime=1000;
2516 tutorialmaxtime=600;
2518 tutorialmaxtime=600;
2520 tutorialmaxtime=600;
2522 tutorialmaxtime=600;
2524 tutorialmaxtime=600;
2528 tutorialmaxtime=1000;
2530 tutorialmaxtime=1000;
2545 player[1].coords=(temp+temp2)/2;
2547 emit_sound_at(fireendsound, player[1].coords);
2549 for(int i=0;i<player[1].skeleton.num_joints;i++){
2551 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2552 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2553 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;
2554 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2555 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2560 tutorialmaxtime=500;
2562 tutorialmaxtime=500;
2564 tutorialmaxtime=500;
2566 tutorialmaxtime=500;
2569 //tutorialmaxtime=500;
2571 tutorialmaxtime=500;
2573 tutorialmaxtime=500;
2580 tutorialmaxtime=500;
2582 tutorialmaxtime=500;
2584 tutorialmaxtime=500;
2586 tutorialmaxtime=500;
2593 player[1].aitype=attacktypecutoff;
2595 tutorialmaxtime=400;
2597 tutorialmaxtime=400;
2598 player[0].escapednum=0;
2603 player[1].aitype=passivetype;
2609 tutorialmaxtime=400;
2612 player[1].aitype=attacktypecutoff;
2614 tutorialmaxtime=400;
2616 tutorialmaxtime=400;
2621 player[1].aitype=passivetype;
2628 player[1].aitype=attacktypecutoff;
2633 player[1].aitype=passivetype;
2645 weapons.owner[weapons.numweapons]=-1;
2646 weapons.type[weapons.numweapons]=knife;
2647 weapons.damage[weapons.numweapons]=0;
2648 weapons.mass[weapons.numweapons]=1;
2649 weapons.tipmass[weapons.numweapons]=1.2;
2650 weapons.length[weapons.numweapons]=.25;
2651 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2652 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2654 weapons.velocity[weapons.numweapons]=0.1;
2655 weapons.tipvelocity[weapons.numweapons]=0.1;
2656 weapons.missed[weapons.numweapons]=1;
2657 weapons.hitsomething[weapons.numweapons]=0;
2658 weapons.freetime[weapons.numweapons]=0;
2659 weapons.firstfree[weapons.numweapons]=1;
2660 weapons.physics[weapons.numweapons]=1;
2662 weapons.numweapons++;
2665 tutorialmaxtime=300;
2667 tutorialmaxtime=300;
2671 tutorialmaxtime=300;
2674 player[0].weaponactive=-1;
2675 player[0].num_weapons=0;
2676 player[1].weaponactive=0;
2677 player[1].num_weapons=1;
2678 player[1].weaponids[0]=0;
2682 player[1].aitype=attacktypecutoff;
2684 tutorialmaxtime=300;
2687 player[0].weaponactive=-1;
2688 player[0].num_weapons=0;
2689 player[1].weaponactive=0;
2690 player[1].num_weapons=1;
2691 player[1].weaponids[0]=0;
2693 tutorialmaxtime=300;
2696 player[0].weaponactive=-1;
2697 player[0].num_weapons=0;
2698 player[1].weaponactive=0;
2699 player[1].num_weapons=1;
2700 player[1].weaponids[0]=0;
2702 weapons.type[0]=sword;
2704 tutorialmaxtime=300;
2717 weapons.owner[weapons.numweapons]=-1;
2718 weapons.type[weapons.numweapons]=sword;
2719 weapons.damage[weapons.numweapons]=0;
2720 weapons.mass[weapons.numweapons]=1;
2721 weapons.tipmass[weapons.numweapons]=1.2;
2722 weapons.length[weapons.numweapons]=.25;
2723 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2724 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2726 weapons.velocity[weapons.numweapons]=0.1;
2727 weapons.tipvelocity[weapons.numweapons]=0.1;
2728 weapons.missed[weapons.numweapons]=1;
2729 weapons.hitsomething[weapons.numweapons]=0;
2730 weapons.freetime[weapons.numweapons]=0;
2731 weapons.firstfree[weapons.numweapons]=1;
2732 weapons.physics[weapons.numweapons]=1;
2736 player[0].weaponactive=0;
2737 player[0].num_weapons=1;
2738 player[0].weaponids[0]=1;
2739 player[1].weaponactive=0;
2740 player[1].num_weapons=1;
2741 player[1].weaponids[0]=0;
2743 weapons.numweapons++;
2748 player[1].aitype=passivetype;
2754 player[0].weaponactive=0;
2755 player[0].num_weapons=1;
2756 player[0].weaponids[0]=1;
2757 player[1].weaponactive=0;
2758 player[1].num_weapons=1;
2759 player[1].weaponids[0]=0;
2761 if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
2762 else weapons.type[0]=staff;
2764 weapons.numweapons++;
2768 player[1].aitype=passivetype;
2770 tutorialmaxtime=200;
2772 weapons.position[1]=1000;
2773 weapons.tippoint[1]=1000;
2775 weapons.numweapons=1;
2777 player[1].weaponactive=-1;
2778 player[1].num_weapons=0;
2779 player[0].weaponactive=0;
2780 player[0].num_weapons=1;
2781 player[0].weaponids[0]=0;
2783 weapons.type[0]=knife;
2785 weapons.numweapons++;
2790 emit_sound_at(fireendsound, player[1].coords);
2792 for(int i=0;i<player[1].skeleton.num_joints;i++){
2794 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2795 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2796 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;
2797 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2798 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2802 player[1].num_weapons=0;
2803 player[1].weaponstuck=-1;
2804 player[1].weaponactive=-1;
2806 weapons.numweapons=0;
2808 weapons.owner[0]=-1;
2809 weapons.velocity[0]=0.1;
2810 weapons.tipvelocity[0]=-0.1;
2811 weapons.missed[0]=1;
2812 weapons.hitsomething[0]=0;
2813 weapons.freetime[0]=0;
2814 weapons.firstfree[0]=1;
2815 weapons.physics[0]=1;
2818 tutorialmaxtime=80000;
2819 break; default: break;
2821 if(tutorialstage<=51)tutorialstagetime=0;
2825 if(tutorialstagetime<tutorialmaxtime-3){
2826 switch(tutorialstage){
2827 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2828 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2829 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2830 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2831 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2832 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2833 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2834 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2835 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2836 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2837 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2838 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2839 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2840 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2841 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2842 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2843 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2844 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2845 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2846 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2847 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2849 if(player[0].escapednum==2){
2853 player[1].aitype=passivetype;
2855 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2856 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2858 if(animation[player[0].targetanimation].attack==reversal){
2862 player[1].aitype=passivetype;
2864 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2865 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2866 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2867 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2868 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2869 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2870 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2871 break; default: break;
2873 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2876 if(tutorialstagetime==tutorialmaxtime-3){
2877 emit_sound_np(consolesuccesssound);
2880 if(tutorialsuccess>=1){
2881 if(tutorialstage==34||tutorialstage==35)
2882 tutorialstagetime=tutorialmaxtime-1;
2886 if(tutorialstage<14||tutorialstage>=50){
2887 player[1].coords.y=300;
2888 player[1].velocity=0;
2892 void Game::doDebugKeys(){
2893 float headprop,bodyprop,armprop,legprop;
2895 if(Input::isKeyPressed(SDLK_h)){
2896 player[0].damagetolerance=200000;
2899 player[0].permanentdamage=0;
2900 player[0].superpermanentdamage=0;
2903 if(Input::isKeyPressed(SDLK_j)){
2907 Setenvironment(environment);
2910 if(Input::isKeyPressed(SDLK_c)){
2911 cameramode=1-cameramode;
2914 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2915 if(player[0].num_weapons>0){
2916 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
2917 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
2918 else weapons.type[player[0].weaponids[0]]=sword;
2919 if(weapons.type[player[0].weaponids[0]]==sword){
2920 weapons.mass[player[0].weaponids[0]]=1.5;
2921 weapons.tipmass[player[0].weaponids[0]]=1;
2922 weapons.length[player[0].weaponids[0]]=.8;
2924 if(weapons.type[player[0].weaponids[0]]==staff){
2925 weapons.mass[player[0].weaponids[0]]=2;
2926 weapons.tipmass[player[0].weaponids[0]]=1;
2927 weapons.length[player[0].weaponids[0]]=1.5;
2930 if(weapons.type[player[0].weaponids[0]]==knife){
2931 weapons.mass[player[0].weaponids[0]]=1;
2932 weapons.tipmass[player[0].weaponids[0]]=1.2;
2933 weapons.length[player[0].weaponids[0]]=.25;
2938 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2940 float closestdist=-1;
2943 for(int i=1;i<numplayers;i++){
2944 distance=findDistancefast(&player[i].coords,&player[0].coords);
2945 if(closestdist==-1||distance<closestdist){
2946 closestdist=distance;
2951 if(player[closest].num_weapons){
2952 if(weapons.type[player[closest].weaponids[0]]==sword)
2953 weapons.type[player[closest].weaponids[0]]=staff;
2954 else if(weapons.type[player[closest].weaponids[0]]==staff)
2955 weapons.type[player[closest].weaponids[0]]=knife;
2956 else weapons.type[player[closest].weaponids[0]]=sword;
2957 if(weapons.type[player[closest].weaponids[0]]==sword){
2958 weapons.mass[player[closest].weaponids[0]]=1.5;
2959 weapons.tipmass[player[closest].weaponids[0]]=1;
2960 weapons.length[player[closest].weaponids[0]]=.8;
2962 if(weapons.type[player[0].weaponids[0]]==staff){
2963 weapons.mass[player[0].weaponids[0]]=2;
2964 weapons.tipmass[player[0].weaponids[0]]=1;
2965 weapons.length[player[0].weaponids[0]]=1.5;
2967 if(weapons.type[player[closest].weaponids[0]]==knife){
2968 weapons.mass[player[closest].weaponids[0]]=1;
2969 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2970 weapons.length[player[closest].weaponids[0]]=.25;
2973 if(!player[closest].num_weapons){
2974 player[closest].weaponids[0]=weapons.numweapons;
2975 weapons.owner[weapons.numweapons]=closest;
2976 weapons.type[weapons.numweapons]=knife;
2977 weapons.damage[weapons.numweapons]=0;
2978 weapons.numweapons++;
2979 player[closest].num_weapons=1;
2980 if(weapons.type[player[closest].weaponids[0]]==sword){
2981 weapons.mass[player[closest].weaponids[0]]=1.5;
2982 weapons.tipmass[player[closest].weaponids[0]]=1;
2983 weapons.length[player[closest].weaponids[0]]=.8;
2985 if(weapons.type[player[closest].weaponids[0]]==knife){
2986 weapons.mass[player[closest].weaponids[0]]=1;
2987 weapons.tipmass[player[closest].weaponids[0]]=1.2;
2988 weapons.length[player[closest].weaponids[0]]=.25;
2994 if(Input::isKeyDown(SDLK_u)){
2996 float closestdist=-1;
2999 for(int i=1;i<numplayers;i++){
3000 distance=findDistancefast(&player[i].coords,&player[0].coords);
3001 if(closestdist==-1||distance<closestdist){
3002 closestdist=distance;
3006 player[closest].rotation+=multiplier*50;
3007 player[closest].targetrotation=player[closest].rotation;
3011 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
3013 float closestdist=-1;
3016 for(int i=1;i<numplayers;i++){
3017 distance=findDistancefast(&player[i].coords,&player[0].coords);
3018 if(closestdist==-1||distance<closestdist){
3019 closestdist=distance;
3023 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
3026 player[closest].whichskin++;
3027 if(player[closest].whichskin>9)
3028 player[closest].whichskin=0;
3029 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
3030 player[closest].whichskin=0;
3032 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
3033 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
3036 if(player[closest].numclothes){
3037 for(int i=0;i<player[closest].numclothes;i++){
3038 tintr=player[closest].clothestintr[i];
3039 tintg=player[closest].clothestintg[i];
3040 tintb=player[closest].clothestintb[i];
3041 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
3043 player[closest].DoMipmaps();
3047 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
3049 float closestdist=-1;
3052 for(int i=1;i<numplayers;i++){
3053 distance=findDistancefast(&player[i].coords,&player[0].coords);
3054 if(closestdist==-1||distance<closestdist){
3055 closestdist=distance;
3060 if(player[closest].creature==wolftype){
3061 headprop=player[closest].proportionhead.x/1.1;
3062 bodyprop=player[closest].proportionbody.x/1.1;
3063 armprop=player[closest].proportionarms.x/1.1;
3064 legprop=player[closest].proportionlegs.x/1.1;
3067 if(player[closest].creature==rabbittype){
3068 headprop=player[closest].proportionhead.x/1.2;
3069 bodyprop=player[closest].proportionbody.x/1.05;
3070 armprop=player[closest].proportionarms.x/1.00;
3071 legprop=player[closest].proportionlegs.x/1.1;
3075 if(player[closest].creature==rabbittype){
3076 player[closest].skeleton.id=closest;
3077 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);
3078 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
3079 player[closest].whichskin=0;
3080 player[closest].creature=wolftype;
3082 player[closest].proportionhead=1.1;
3083 player[closest].proportionbody=1.1;
3084 player[closest].proportionarms=1.1;
3085 player[closest].proportionlegs=1.1;
3086 player[closest].proportionlegs.y=1.1;
3087 player[closest].scale=.23*5*player[0].scale;
3089 player[closest].damagetolerance=300;
3093 player[closest].skeleton.id=closest;
3094 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);
3095 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
3096 player[closest].whichskin=0;
3097 player[closest].creature=rabbittype;
3099 player[closest].proportionhead=1.2;
3100 player[closest].proportionbody=1.05;
3101 player[closest].proportionarms=1.00;
3102 player[closest].proportionlegs=1.1;
3103 player[closest].proportionlegs.y=1.05;
3104 player[closest].scale=.2*5*player[0].scale;
3106 player[closest].damagetolerance=200;
3109 if(player[closest].creature==wolftype){
3110 player[closest].proportionhead=1.1*headprop;
3111 player[closest].proportionbody=1.1*bodyprop;
3112 player[closest].proportionarms=1.1*armprop;
3113 player[closest].proportionlegs=1.1*legprop;
3116 if(player[closest].creature==rabbittype){
3117 player[closest].proportionhead=1.2*headprop;
3118 player[closest].proportionbody=1.05*bodyprop;
3119 player[closest].proportionarms=1.00*armprop;
3120 player[closest].proportionlegs=1.1*legprop;
3121 player[closest].proportionlegs.y=1.05*legprop;
3127 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
3133 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
3135 float closestdist=-1;
3137 XYZ flatfacing2,flatvelocity2;
3140 for(int i=1;i<numplayers;i++){
3141 distance=findDistancefast(&player[i].coords,&player[0].coords);
3142 if(distance<144&&!player[i].headless)
3143 if(closestdist==-1||distance<closestdist){
3144 closestdist=distance;
3146 blah = player[i].coords;
3151 XYZ headspurtdirection;
3152 //int i = player[closest].skeleton.jointlabels[head];
3153 Joint& headjoint=playerJoint(closest,head);
3154 for(int k=0;k<player[closest].skeleton.num_joints; k++){
3155 if(!player[closest].skeleton.free)
3156 flatvelocity2=player[closest].velocity;
3157 if(player[closest].skeleton.free)
3158 flatvelocity2=headjoint.velocity;
3159 if(!player[closest].skeleton.free)
3160 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;
3161 if(player[closest].skeleton.free)
3162 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
3163 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3164 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3165 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3166 headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
3167 Normalise(&headspurtdirection);
3168 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
3169 flatvelocity2+=headspurtdirection*8;
3170 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
3172 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
3174 emit_sound_at(splattersound, blah);
3175 emit_sound_at(breaksound2, blah, 100.);
3177 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
3178 player[closest].RagDoll(0);
3179 player[closest].dead=2;
3180 player[closest].headless=1;
3181 player[closest].DoBloodBig(3,165);
3187 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
3189 float closestdist=-1;
3191 XYZ flatfacing2,flatvelocity2;
3194 for(int i=1;i<numplayers;i++){
3195 distance=findDistancefast(&player[i].coords,&player[0].coords);
3197 if(closestdist==-1||distance<closestdist){
3198 closestdist=distance;
3200 blah=player[i].coords;
3205 emit_sound_at(splattersound, blah);
3207 emit_sound_at(breaksound2, blah);
3209 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3210 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3211 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3212 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;
3213 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3214 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3215 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3216 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3217 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
3218 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
3219 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
3222 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3223 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3224 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3225 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;
3226 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3227 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3228 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3229 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3230 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
3231 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
3234 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3235 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3236 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3237 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;
3238 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3239 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3240 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3241 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3242 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
3243 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
3246 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3247 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3248 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3249 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;
3250 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3251 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3252 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3253 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3254 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
3255 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
3259 for(int j=0;j<numplayers; j++){
3261 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
3262 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
3263 if(player[j].skeleton.free==2)
3264 player[j].skeleton.free=1;
3265 player[j].skeleton.longdead=0;
3266 player[j].RagDoll(0);
3267 for(int i=0;i<player[j].skeleton.num_joints; i++){
3268 temppos=player[j].skeleton.joints[i].position+player[j].coords;
3269 if(findDistancefast(&temppos,&player[closest].coords)<25){
3270 flatvelocity2=temppos-player[closest].coords;
3271 Normalise(&flatvelocity2);
3272 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
3279 player[closest].DoDamage(10000);
3280 player[closest].RagDoll(0);
3281 player[closest].dead=2;
3282 player[closest].coords=20;
3283 player[closest].skeleton.free=2;
3290 if(Input::isKeyPressed(SDLK_f)){
3291 player[0].onfire=1-player[0].onfire;
3292 if(player[0].onfire){
3293 player[0].CatchFire();
3295 if(!player[0].onfire){
3296 emit_sound_at(fireendsound, player[0].coords);
3297 pause_sound(stream_firesound);
3301 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
3302 //if(!player[0].skeleton.free)player[0].damage+=500;
3303 player[0].RagDoll(0);
3304 //player[0].spurt=1;
3305 //player[0].DoDamage(1000);
3307 emit_sound_at(whooshsound, player[0].coords, 128.);
3310 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
3311 for(int i=0;i<objects.numobjects;i++){
3312 if(objects.type[i]==treeleavestype){
3313 objects.scale[i]*=.9;
3318 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3319 editorenabled=1-editorenabled;
3321 player[0].damagetolerance=100000;
3323 player[0].damagetolerance=200;
3325 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
3326 player[0].permanentdamage=0;
3327 player[0].superpermanentdamage=0;
3328 player[0].bloodloss=0;
3329 player[0].deathbleeding=0;
3333 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
3335 if(targetlevel>numchallengelevels-1)
3342 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
3344 float closestdist=-1;
3347 for(int i=1;i<numplayers;i++){
3348 distance=findDistancefast(&player[i].coords,&player[0].coords);
3349 if(closestdist==-1||distance<closestdist){
3350 closestdist=distance;
3354 if(closestdist>0&&closest>=0){
3355 //player[closest]=player[numplayers-1];
3356 //player[closest].skeleton=player[numplayers-1].skeleton;
3361 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
3363 float closestdist=-1;
3366 for(int i=1;i<max_objects;i++){
3367 distance=findDistancefast(&objects.position[i],&player[0].coords);
3368 if(closestdist==-1||distance<closestdist){
3369 closestdist=distance;
3373 if(closestdist>0&&closest>=0){
3374 objects.position[closest].y-=500;
3378 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3380 //if(drawmode>2)drawmode=0;
3381 if(objects.numobjects<max_objects-1){
3383 boxcoords.x=player[0].coords.x;
3384 boxcoords.z=player[0].coords.z;
3385 boxcoords.y=player[0].coords.y-3;
3386 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3387 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3388 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3389 float temprotat,temprotat2;
3390 temprotat=editorrotation;
3391 temprotat2=editorrotation2;
3392 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3393 if(temprotat2<0)temprotat2=Random()%360;
3395 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3396 if(editortype==treetrunktype)
3397 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
3401 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3402 if(numplayers<maxplayers-1){
3403 player[numplayers].scale=.2*5*player[0].scale;
3404 player[numplayers].creature=rabbittype;
3405 player[numplayers].howactive=editoractive;
3406 player[numplayers].skeleton.id=numplayers;
3407 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);
3409 //texsize=512*512*3/texdetail/texdetail;
3410 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3411 //player[numplayers].skeleton.skinText.resize(texsize);
3413 int k=abs(Random()%2)+1;
3415 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3416 player[numplayers].whichskin=0;
3419 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3420 player[numplayers].whichskin=1;
3423 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3424 player[numplayers].whichskin=2;
3427 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
3428 player[numplayers].power=1;
3429 player[numplayers].speedmult=1;
3430 player[numplayers].currentanimation=bounceidleanim;
3431 player[numplayers].targetanimation=bounceidleanim;
3432 player[numplayers].currentframe=0;
3433 player[numplayers].targetframe=1;
3434 player[numplayers].target=0;
3435 player[numplayers].bled=0;
3436 player[numplayers].speed=1+(float)(Random()%100)/1000;
3438 player[numplayers].targetrotation=player[0].targetrotation;
3439 player[numplayers].rotation=player[0].rotation;
3441 player[numplayers].velocity=0;
3442 player[numplayers].coords=player[0].coords;
3443 player[numplayers].oldcoords=player[numplayers].coords;
3444 player[numplayers].realoldcoords=player[numplayers].coords;
3446 player[numplayers].id=numplayers;
3447 player[numplayers].skeleton.id=numplayers;
3448 player[numplayers].updatedelay=0;
3449 player[numplayers].normalsupdatedelay=0;
3451 player[numplayers].aitype=passivetype;
3453 if(player[0].creature==wolftype){
3454 headprop=player[0].proportionhead.x/1.1;
3455 bodyprop=player[0].proportionbody.x/1.1;
3456 armprop=player[0].proportionarms.x/1.1;
3457 legprop=player[0].proportionlegs.x/1.1;
3460 if(player[0].creature==rabbittype){
3461 headprop=player[0].proportionhead.x/1.2;
3462 bodyprop=player[0].proportionbody.x/1.05;
3463 armprop=player[0].proportionarms.x/1.00;
3464 legprop=player[0].proportionlegs.x/1.1;
3467 if(player[numplayers].creature==wolftype){
3468 player[numplayers].proportionhead=1.1*headprop;
3469 player[numplayers].proportionbody=1.1*bodyprop;
3470 player[numplayers].proportionarms=1.1*armprop;
3471 player[numplayers].proportionlegs=1.1*legprop;
3474 if(player[numplayers].creature==rabbittype){
3475 player[numplayers].proportionhead=1.2*headprop;
3476 player[numplayers].proportionbody=1.05*bodyprop;
3477 player[numplayers].proportionarms=1.00*armprop;
3478 player[numplayers].proportionlegs=1.1*legprop;
3479 player[numplayers].proportionlegs.y=1.05*legprop;
3482 player[numplayers].headless=0;
3483 player[numplayers].onfire=0;
3486 player[numplayers].proportionhead.z=0;
3487 player[numplayers].proportionbody.z=0;
3488 player[numplayers].proportionarms.z=0;
3489 player[numplayers].proportionlegs.z=0;
3492 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3494 player[numplayers].damagetolerance=200;
3496 player[numplayers].protectionhead=player[0].protectionhead;
3497 player[numplayers].protectionhigh=player[0].protectionhigh;
3498 player[numplayers].protectionlow=player[0].protectionlow;
3499 player[numplayers].armorhead=player[0].armorhead;
3500 player[numplayers].armorhigh=player[0].armorhigh;
3501 player[numplayers].armorlow=player[0].armorlow;
3502 player[numplayers].metalhead=player[0].metalhead;
3503 player[numplayers].metalhigh=player[0].metalhigh;
3504 player[numplayers].metallow=player[0].metallow;
3506 player[numplayers].immobile=player[0].immobile;
3508 player[numplayers].numclothes=player[0].numclothes;
3509 if(player[numplayers].numclothes)
3510 for(int i=0;i<player[numplayers].numclothes;i++){
3511 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3512 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3513 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3514 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3515 tintr=player[numplayers].clothestintr[i];
3516 tintg=player[numplayers].clothestintg[i];
3517 tintb=player[numplayers].clothestintb[i];
3518 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3520 if(player[numplayers].numclothes){
3521 player[numplayers].DoMipmaps();
3524 player[numplayers].power=player[0].power;
3525 player[numplayers].speedmult=player[0].speedmult;
3527 player[numplayers].damage=0;
3528 player[numplayers].permanentdamage=0;
3529 player[numplayers].superpermanentdamage=0;
3530 player[numplayers].deathbleeding=0;
3531 player[numplayers].bleeding=0;
3532 player[numplayers].numwaypoints=0;
3533 player[numplayers].waypoint=0;
3534 player[numplayers].jumppath=0;
3535 player[numplayers].weaponstuck=-1;
3536 player[numplayers].weaponactive=-1;
3537 player[numplayers].num_weapons=0;
3538 player[numplayers].bloodloss=0;
3539 player[numplayers].dead=0;
3541 player[numplayers].loaded=1;
3547 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3548 if(player[numplayers-1].numwaypoints<90){
3549 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3550 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3551 player[numplayers-1].numwaypoints++;
3555 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3556 if(numpathpoints<30){
3557 bool connected,alreadyconnected;
3560 for(int i=0;i<numpathpoints;i++){
3561 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3563 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3564 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3566 if(!alreadyconnected){
3567 numpathpointconnect[pathpointselected]++;
3569 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3575 pathpoint[numpathpoints-1]=player[0].coords;
3576 numpathpointconnect[numpathpoints-1]=0;
3577 if(numpathpoints>1&&pathpointselected!=-1){
3578 numpathpointconnect[pathpointselected]++;
3579 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3581 pathpointselected=numpathpoints-1;
3586 if(Input::isKeyPressed(SDLK_PERIOD)){
3587 pathpointselected++;
3588 if(pathpointselected>=numpathpoints)
3589 pathpointselected=-1;
3591 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3592 pathpointselected--;
3593 if(pathpointselected<=-2)
3594 pathpointselected=numpathpoints-1;
3596 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3597 if(pathpointselected!=-1){
3599 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3600 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3601 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3602 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3604 for(int i=0;i<numpathpoints;i++){
3605 for(int j=0;j<numpathpointconnect[i];j++){
3606 if(pathpointconnect[i][j]==pathpointselected){
3607 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3608 numpathpointconnect[i]--;
3610 if(pathpointconnect[i][j]==numpathpoints){
3611 pathpointconnect[i][j]=pathpointselected;
3615 pathpointselected=numpathpoints-1;
3619 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3621 if(editortype==treeleavestype||editortype==10)editortype--;
3622 if(editortype<0)editortype=firetype;
3625 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3627 if(editortype==treeleavestype||editortype==10)editortype++;
3628 if(editortype>firetype)editortype=0;
3631 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3632 editorrotation-=multiplier*100;
3633 if(editorrotation<-.01)editorrotation=-.01;
3636 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3637 editorrotation+=multiplier*100;
3640 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3641 editorsize+=multiplier;
3644 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3645 editorsize-=multiplier;
3646 if(editorsize<.1)editorsize=.1;
3650 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3651 mapradius-=multiplier*10;
3654 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3655 mapradius+=multiplier*10;
3657 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3658 editorrotation2+=multiplier*100;
3661 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3662 editorrotation2-=multiplier*100;
3663 if(editorrotation2<-.01)editorrotation2=-.01;
3665 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3667 float closestdist=-1;
3669 for(int i=0;i<objects.numobjects;i++){
3670 distance=findDistancefast(&objects.position[i],&player[0].coords);
3671 if(closestdist==-1||distance<closestdist){
3672 closestdist=distance;
3676 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3682 void Game::doJumpReversals(){
3683 for(int k=0;k<numplayers;k++)
3684 for(int i=k;i<numplayers;i++){
3686 if( player[k].skeleton.free==0&&
3687 player[i].skeleton.oldfree==0&&
3688 (player[i].targetanimation==jumpupanim||
3689 player[k].targetanimation==jumpupanim)&&
3690 (player[i].aitype==playercontrolled||
3691 player[k].aitype==playercontrolled)&&
3692 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3693 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3694 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3695 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3696 //TODO: refactor two huge similar ifs
3697 if(player[i].targetanimation==jumpupanim&&
3698 player[k].targetanimation!=getupfrombackanim&&
3699 player[k].targetanimation!=getupfromfrontanim&&
3700 animation[player[k].targetanimation].height==middleheight&&
3701 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3702 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3703 player[k].aitype!=playercontrolled)){
3704 player[i].victim=&player[k];
3705 player[i].velocity=0;
3706 player[i].currentanimation=jumpreversedanim;
3707 player[i].targetanimation=jumpreversedanim;
3708 player[i].currentframe=0;
3709 player[i].targetframe=1;
3710 player[i].targettilt2=0;
3711 player[k].victim=&player[i];
3712 player[k].velocity=0;
3713 player[k].currentanimation=jumpreversalanim;
3714 player[k].targetanimation=jumpreversalanim;
3715 player[k].currentframe=0;
3716 player[k].targetframe=1;
3717 player[k].targettilt2=0;
3718 if(player[i].coords.y<player[k].coords.y+1){
3719 player[i].currentanimation=rabbitkickreversedanim;
3720 player[i].targetanimation=rabbitkickreversedanim;
3721 player[i].currentframe=1;
3722 player[i].targetframe=2;
3723 player[k].currentanimation=rabbitkickreversalanim;
3724 player[k].targetanimation=rabbitkickreversalanim;
3725 player[k].currentframe=1;
3726 player[k].targetframe=2;
3729 player[k].oldcoords=player[k].coords;
3730 player[i].coords=player[k].coords;
3731 player[k].targetrotation=player[i].targetrotation;
3732 player[k].rotation=player[i].targetrotation;
3733 if(player[k].aitype==attacktypecutoff)
3734 player[k].stunned=.5;
3736 if(player[k].targetanimation==jumpupanim&&
3737 player[i].targetanimation!=getupfrombackanim&&
3738 player[i].targetanimation!=getupfromfrontanim&&
3739 animation[player[i].targetanimation].height==middleheight&&
3740 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3741 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3742 player[i].aitype!=playercontrolled)){
3743 player[k].victim=&player[i];
3744 player[k].velocity=0;
3745 player[k].currentanimation=jumpreversedanim;
3746 player[k].targetanimation=jumpreversedanim;
3747 player[k].currentframe=0;
3748 player[k].targetframe=1;
3749 player[k].targettilt2=0;
3750 player[i].victim=&player[k];
3751 player[i].velocity=0;
3752 player[i].currentanimation=jumpreversalanim;
3753 player[i].targetanimation=jumpreversalanim;
3754 player[i].currentframe=0;
3755 player[i].targetframe=1;
3756 player[i].targettilt2=0;
3757 if(player[k].coords.y<player[i].coords.y+1){
3758 player[k].targetanimation=rabbitkickreversedanim;
3759 player[k].currentanimation=rabbitkickreversedanim;
3760 player[i].currentanimation=rabbitkickreversalanim;
3761 player[i].targetanimation=rabbitkickreversalanim;
3762 player[k].currentframe=1;
3763 player[k].targetframe=2;
3764 player[i].currentframe=1;
3765 player[i].targetframe=2;
3768 player[i].oldcoords=player[i].coords;
3769 player[k].coords=player[i].coords;
3770 player[i].targetrotation=player[k].targetrotation;
3771 player[i].rotation=player[k].targetrotation;
3772 if(player[i].aitype==attacktypecutoff)
3773 player[i].stunned=.5;
3780 void Game::doAerialAcrobatics(){
3781 static XYZ facing,flatfacing;
3782 for(int k=0;k<numplayers;k++){
3783 player[k].turnspeed=500;
3785 if((player[k].isRun()&&
3786 ((player[k].targetrotation!=rabbitrunninganim&&
3787 player[k].targetrotation!=wolfrunninganim)||
3788 player[k].targetframe==4))||
3789 player[k].targetanimation==removeknifeanim||
3790 player[k].targetanimation==crouchremoveknifeanim||
3791 player[k].targetanimation==flipanim||
3792 player[k].targetanimation==fightsidestep||
3793 player[k].targetanimation==walkanim){
3794 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3798 if(player[k].isStop()||
3799 player[k].isLanding()||
3800 player[k].targetanimation==staggerbackhighanim||
3801 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3802 player[k].targetanimation==staggerbackhardanim||
3803 player[k].targetanimation==backhandspringanim||
3804 player[k].targetanimation==dodgebackanim||
3805 player[k].targetanimation==rollanim||
3806 (animation[player[k].targetanimation].attack&&
3807 player[k].targetanimation!=rabbitkickanim&&
3808 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3809 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3810 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3813 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3814 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3817 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3818 player[k].DoStuff();
3819 if(player[k].immobile&&k!=0)
3820 player[k].coords=player[k].realoldcoords;
3822 //if player's position has changed (?)
3823 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3824 !player[k].skeleton.free&&
3825 player[k].targetanimation!=climbanim&&
3826 player[k].targetanimation!=hanganim){
3827 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3831 if(player[k].collide<-.3)
3832 player[k].collide=-.3;
3833 if(player[k].collide>1)
3834 player[k].collide=1;
3835 player[k].collide-=multiplier*30;
3838 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3840 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3841 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3842 if(objects.type[i]!=rocktype||
3843 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3844 objects.position[i].y>player[k].coords.y){
3845 lowpoint=player[k].coords;
3846 if(player[k].targetanimation!=jumpupanim&&
3847 player[k].targetanimation!=jumpdownanim&&
3848 !player[k].isFlip())
3852 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3853 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3854 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3855 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3856 flatfacing=lowpoint-player[k].coords;
3857 player[k].coords=lowpoint;
3858 player[k].coords.y-=1.3;
3859 player[k].collide=1;
3862 //TODO: refactor four similar blocks
3863 if(player[k].aitype==playercontrolled&&
3864 (player[k].targetanimation==jumpupanim||
3865 player[k].targetanimation==jumpdownanim||
3866 player[k].isFlip())&&
3867 !player[k].jumptogglekeydown&&
3868 player[k].jumpkeydown){
3869 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3870 XYZ tempcoords1=lowpoint;
3871 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3872 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3873 setAnimation(k,walljumpleftanim);
3874 emit_sound_at(movewhooshsound, player[k].coords);
3876 pause_sound(whooshsound);
3878 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3879 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3880 if(lowpointtarget.z<0)
3881 player[k].rotation=180-player[k].rotation;
3882 player[k].targetrotation=player[k].rotation;
3883 player[k].lowrotation=player[k].rotation;
3889 lowpoint=tempcoords1;
3890 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3891 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3892 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3893 setAnimation(k,walljumprightanim);
3894 emit_sound_at(movewhooshsound, player[k].coords);
3895 if(k==0)pause_sound(whooshsound);
3897 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3898 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3899 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3900 player[k].targetrotation=player[k].rotation;
3901 player[k].lowrotation=player[k].rotation;
3902 if(k==0)numwallflipped++;
3906 lowpoint=tempcoords1;
3907 lowpointtarget=lowpoint+player[k].facing*2;
3908 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3909 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3910 setAnimation(k,walljumpbackanim);
3911 emit_sound_at(movewhooshsound, player[k].coords);
3912 if(k==0)pause_sound(whooshsound);
3914 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3915 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3916 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3917 player[k].targetrotation=player[k].rotation;
3918 player[k].lowrotation=player[k].rotation;
3919 if(k==0)numwallflipped++;
3923 lowpoint=tempcoords1;
3924 lowpointtarget=lowpoint-player[k].facing*2;
3925 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3926 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3927 setAnimation(k,walljumpfrontanim);
3928 emit_sound_at(movewhooshsound, player[k].coords);
3929 if(k==0)pause_sound(whooshsound);
3931 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3932 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3933 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3934 player[k].rotation+=180;
3935 player[k].targetrotation=player[k].rotation;
3936 player[k].lowrotation=player[k].rotation;
3937 if(k==0)numwallflipped++;
3945 else if(objects.type[i]==rocktype){
3946 lowpoint2=player[k].coords;
3947 lowpoint=player[k].coords;
3949 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3950 player[k].coords=colpoint;
3951 player[k].collide=1;
3954 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3955 //flipped into a rock
3956 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3957 player[k].RagDoll(0);
3959 if(player[k].targetanimation==jumpupanim){
3960 player[k].jumppower=-4;
3961 player[k].targetanimation=player[k].getIdle();
3964 player[k].targetframe=0;
3965 player[k].onterrain=1;
3967 if(player[k].id==0){
3968 pause_sound(whooshsound);
3969 OPENAL_SetVolume(channels[whooshsound], 0);
3973 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3974 if(player[k].isFlip())
3975 player[k].jumppower=-4;
3976 player[k].targetanimation=player[k].getLanding();
3977 emit_sound_at(landsound, player[k].coords, 128.);
3979 envsound[numenvsounds]=player[k].coords;
3980 envsoundvol[numenvsounds]=16;
3981 envsoundlife[numenvsounds]=.4;
3991 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3992 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3993 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3994 lowpoint=player[k].coords;
3996 if(objects.type[i]!=rocktype)
3997 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3998 if(player[k].targetanimation!=jumpupanim&&
3999 player[k].targetanimation!=jumpdownanim&&
4000 player[k].onterrain)
4001 player[k].avoidcollided=1;
4002 player[k].coords=lowpoint;
4003 player[k].coords.y-=1.35;
4004 player[k].collide=1;
4006 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
4007 (player[k].currentanimation!=climbanim&&
4008 player[k].currentanimation!=hanganim&&
4009 !player[k].isWallJump()||
4010 player[k].targetanimation==jumpupanim||
4011 player[k].targetanimation==jumpdownanim)){
4012 lowpoint=player[k].coords;
4013 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
4014 lowpoint=player[k].coords;
4018 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
4019 lowpointtarget=lowpoint+facing*1.4;
4020 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4022 lowpoint=player[k].coords;
4024 lowpointtarget=lowpoint+facing*1.4;
4026 lowpointtarget2=lowpointtarget;
4028 lowpointtarget3=lowpointtarget;
4030 lowpointtarget4=lowpointtarget;
4032 lowpointtarget5=lowpointtarget;
4034 lowpointtarget6=lowpointtarget;
4036 lowpointtarget7=lowpoint;
4038 lowpointtarget2.x+=.1;
4040 lowpointtarget3.z+=.1;
4042 lowpointtarget4.x-=.1;
4044 lowpointtarget5.z-=.1;
4046 lowpointtarget6.y+=45/13;
4047 lowpointtarget6+=facing*.6;
4048 lowpointtarget7.y+=90/13;
4049 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4050 if(objects.friction[i]>.5)
4052 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
4053 player[k].collided=1;
4054 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
4055 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
4056 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
4057 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4058 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
4059 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4060 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
4061 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4062 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
4063 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
4064 for(int j=0;j<45;j++){
4065 lowpoint=player[k].coords;
4066 lowpoint.y+=(float)j/13;
4067 lowpointtarget=lowpoint+facing*1.4;
4068 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
4069 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
4070 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
4072 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
4073 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
4074 lowpoint=player[k].coords;
4075 lowpoint.y+=(float)j/13;
4076 lowpointtarget=lowpoint+facing*1.3;
4077 flatfacing=player[k].coords;
4078 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
4079 player[k].coords.y=lowpointtarget.y-.07;
4080 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
4082 if(j>10||!player[k].isRun()){
4083 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
4085 pause_sound(whooshsound);
4087 emit_sound_at(jumpsound, player[k].coords, 128.);
4089 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4090 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
4091 if(lowpointtarget.z<0)
4092 player[k].rotation=180-player[k].rotation;
4093 player[k].targetrotation=player[k].rotation;
4094 player[k].lowrotation=player[k].rotation;
4096 //player[k].velocity=lowpointtarget*.03;
4097 player[k].velocity=0;
4100 if(player[k].targetanimation==jumpupanim){
4101 player[k].targetanimation=climbanim;
4102 player[k].jumppower=0;
4103 player[k].jumpclimb=1;
4105 player[k].transspeed=6;
4107 player[k].targetframe=1;
4110 setAnimation(k,hanganim);
4111 player[k].jumppower=0;
4123 if(player[k].collide<=0){
4125 if(!player[k].onterrain&&
4126 player[k].targetanimation!=jumpupanim&&
4127 player[k].targetanimation!=jumpdownanim&&
4128 player[k].targetanimation!=climbanim&&
4129 player[k].targetanimation!=hanganim&&
4130 !player[k].isWallJump()&&
4131 !player[k].isFlip()){
4132 if(player[k].currentanimation!=climbanim&&
4133 player[k].currentanimation!=tempanim&&
4134 player[k].targetanimation!=backhandspringanim&&
4135 (player[k].targetanimation!=rollanim||
4136 player[k].targetframe<2||
4137 player[k].targetframe>6)){
4138 //stagger off ledge (?)
4139 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
4140 player[k].RagDoll(0);
4141 setAnimation(k,jumpdownanim);
4144 emit_sound_at(whooshsound, player[k].coords, 128.);
4147 player[k].velocity.y+=gravity;
4151 player[k].realoldcoords=player[k].coords;
4155 void Game::doAttacks(){
4156 static XYZ relative;
4157 static int randattack;
4158 static bool playerrealattackkeydown=0;
4160 if(!Input::isKeyDown(attackkey))
4163 player[0].attackkeydown=0;
4165 playerrealattackkeydown=0;
4167 playerrealattackkeydown=Input::isKeyDown(attackkey);
4168 if((player[0].parriedrecently<=0||
4169 player[0].weaponactive==-1)&&
4172 player[0].lastattack!=swordslashanim&&
4173 player[0].lastattack!=knifeslashstartanim&&
4174 player[0].lastattack!=staffhitanim&&
4175 player[0].lastattack!=staffspinhitanim)))
4176 player[0].attackkeydown=Input::isKeyDown(attackkey);
4177 if(Input::isKeyDown(attackkey)&&
4179 !player[0].backkeydown){
4180 for(int k=0;k<numplayers;k++){
4181 if((player[k].targetanimation==swordslashanim||
4182 player[k].targetanimation==staffhitanim||
4183 player[k].targetanimation==staffspinhitanim)&&
4184 player[0].currentanimation!=dodgebackanim&&
4185 !player[k].skeleton.free)
4186 player[k].Reverse();
4190 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
4192 for(int k=0;k<numplayers;k++){
4193 if(indialogue!=-1)player[k].attackkeydown=0;
4194 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
4195 if(player[k].aitype!=playercontrolled)
4196 player[k].victim=&player[0];
4197 //attack key pressed
4198 if(player[k].attackkeydown){
4200 if(player[k].backkeydown&&
4201 player[k].targetanimation!=backhandspringanim&&
4202 (player[k].isIdle()||
4203 player[k].isStop()||
4205 player[k].targetanimation==walkanim)){
4206 if(player[k].jumppower<=1){
4207 player[k].jumppower-=2;
4209 for(int i=0;i<numplayers;i++){
4211 if(player[i].targetanimation==swordslashanim||
4212 player[i].targetanimation==knifeslashstartanim||
4213 player[i].targetanimation==staffhitanim||
4214 player[i].targetanimation==staffspinhitanim)
4215 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
4216 setAnimation(k,dodgebackanim);
4217 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4218 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4221 if(player[k].targetanimation!=dodgebackanim){
4222 if(k==0)numflipped++;
4223 setAnimation(k,backhandspringanim);
4224 player[k].targetrotation=-rotation+180;
4225 if(player[k].leftkeydown)
4226 player[k].targetrotation-=45;
4227 if(player[k].rightkeydown)
4228 player[k].targetrotation+=45;
4229 player[k].rotation=player[k].targetrotation;
4230 player[k].jumppower-=2;
4235 if(!animation[player[k].targetanimation].attack&&
4236 !player[k].backkeydown&&
4237 (player[k].isIdle()||
4239 player[k].targetanimation==walkanim||
4240 player[k].targetanimation==sneakanim||
4241 player[k].isCrouch())){
4242 const int attackweapon=player[k].weaponactive==-1?0:weapons.type[player[k].weaponids[player[k].weaponactive]];
4243 //normal attacks (?)
4244 player[k].hasvictim=0;
4246 for(int i=0;i<numplayers;i++){
4247 if(i==k||!(k==0||i==0))continue;
4248 if(!player[k].hasvictim)
4249 if(animation[player[k].targetanimation].attack!=reversal){
4251 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4253 !player[i].skeleton.free&&
4254 player[i].howactive<typedead1&&
4255 player[i].targetanimation!=jumpreversedanim&&
4256 player[i].targetanimation!=rabbitkickreversedanim&&
4257 player[i].targetanimation!=rabbitkickanim&&
4258 player[k].targetanimation!=rabbitkickanim&&
4259 player[i].targetanimation!=getupfrombackanim&&
4260 (player[i].targetanimation!=staggerbackhighanim&&
4261 (player[i].targetanimation!=staggerbackhardanim||
4262 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
4263 player[i].targetanimation!=jumpdownanim&&
4264 player[i].targetanimation!=jumpupanim&&
4265 player[i].targetanimation!=getupfromfrontanim){
4266 player[k].victim=&player[i];
4267 player[k].hasvictim=1;
4268 if(player[k].aitype==playercontrolled){ //human player
4270 if(distance<2.5*sq(player[k].scale*5)&&
4271 player[k].crouchkeydown&&
4272 animation[player[i].targetanimation].height!=lowheight)
4273 player[k].targetanimation=sweepanim;
4275 else if(distance<1.5*sq(player[k].scale*5)&&
4276 animation[player[i].targetanimation].height!=lowheight&&
4277 !player[k].forwardkeydown&&
4278 !player[k].leftkeydown&&
4279 !player[k].rightkeydown&&
4280 !player[k].crouchkeydown&&
4283 player[k].targetanimation=winduppunchanim;
4285 else if(distance<2.5*sq(player[k].scale*5)&&
4286 animation[player[i].targetanimation].height!=lowheight&&
4287 !player[k].forwardkeydown&&
4288 !player[k].leftkeydown&&
4289 !player[k].rightkeydown&&
4290 !player[k].crouchkeydown&&
4292 player[k].targetanimation=upunchanim;
4294 else if(distance<2.5*sq(player[k].scale*5)&&
4295 player[i].staggerdelay>0&&
4296 attackweapon==knife&&
4297 player[i].bloodloss>player[i].damagetolerance/2)
4298 player[k].targetanimation=knifefollowanim;
4300 else if(distance<2.5*sq(player[k].scale*5)&&
4301 animation[player[i].targetanimation].height!=lowheight&&
4302 !player[k].forwardkeydown&&
4303 !player[k].leftkeydown&&
4304 !player[k].rightkeydown&&
4305 !player[k].crouchkeydown&&
4306 attackweapon==knife&&
4307 player[k].weaponmissdelay<=0)
4308 player[k].targetanimation=knifeslashstartanim;
4310 else if(distance<4.5*sq(player[k].scale*5)&&
4311 animation[player[i].targetanimation].height!=lowheight&&
4312 !player[k].crouchkeydown&&
4313 attackweapon==sword&&
4314 player[k].weaponmissdelay<=0)
4315 player[k].targetanimation=swordslashanim;
4317 else if(distance<4.5*sq(player[k].scale*5)&&
4318 animation[player[i].targetanimation].height!=lowheight&&
4319 !player[k].crouchkeydown&&
4320 attackweapon==staff&&
4321 player[k].weaponmissdelay<=0&&
4322 !player[k].leftkeydown&&
4323 !player[k].rightkeydown&&
4324 !player[k].forwardkeydown)
4325 player[k].targetanimation=staffhitanim;
4327 else if(distance<4.5*sq(player[k].scale*5)&&
4328 animation[player[i].targetanimation].height!=lowheight&&
4329 !player[k].crouchkeydown&&
4330 attackweapon==staff&&
4331 player[k].weaponmissdelay<=0)
4332 player[k].targetanimation=staffspinhitanim;
4334 else if(distance<2.5*sq(player[k].scale*5)&&
4335 animation[player[i].targetanimation].height!=lowheight)
4336 player[k].targetanimation=spinkickanim;
4338 else if(distance<2.5*sq(player[k].scale*5)&&
4339 animation[player[i].targetanimation].height==lowheight&&
4340 animation[player[k].targetanimation].attack!=normalattack)
4341 player[k].targetanimation=lowkickanim;
4342 } else { //AI player
4343 if(distance<4.5*sq(player[k].scale*5)){
4344 randattack=abs(Random()%5);
4345 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
4347 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
4348 player[k].targetanimation=sweepanim;
4350 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
4352 player[k].targetanimation=upunchanim;
4354 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
4355 player[k].targetanimation=spinkickanim;
4357 else if(animation[player[i].targetanimation].height==lowheight)
4358 player[k].targetanimation=lowkickanim;
4362 if((tutoriallevel!=1||!attackweapon)&&
4363 distance<2.5*sq(player[k].scale*5)&&
4365 animation[player[i].targetanimation].height!=lowheight)
4366 player[k].targetanimation=sweepanim;
4368 else if(distance<2.5*sq(player[k].scale*5)&&
4369 attackweapon==knife&&
4370 player[k].weaponmissdelay<=0)
4371 player[k].targetanimation=knifeslashstartanim;
4373 else if(!(player[0].victim==&player[i]&&
4374 player[0].hasvictim&&
4375 player[0].targetanimation==swordslashanim)&&
4376 attackweapon==sword&&
4377 player[k].weaponmissdelay<=0)
4378 player[k].targetanimation=swordslashanim;
4380 else if(!(player[0].victim==&player[i]&&
4381 player[0].hasvictim&&
4382 player[0].targetanimation==swordslashanim)&&
4383 attackweapon==staff&&
4384 player[k].weaponmissdelay<=0&&
4386 player[k].targetanimation=staffhitanim;
4388 else if(!(player[0].victim==&player[i]&&
4389 player[0].hasvictim&&
4390 player[0].targetanimation==swordslashanim)&&
4391 attackweapon==staff&&
4392 player[k].weaponmissdelay<=0&&
4394 player[k].targetanimation=staffspinhitanim;
4396 else if((tutoriallevel!=1||!attackweapon)&&
4397 distance<2.5*sq(player[k].scale*5)&&
4399 animation[player[i].targetanimation].height!=lowheight)
4400 player[k].targetanimation=spinkickanim;
4402 else if(distance<2.5*sq(player[k].scale*5)&&
4403 animation[player[i].targetanimation].height==lowheight&&
4404 animation[player[k].targetanimation].attack!=normalattack)
4405 player[k].targetanimation=lowkickanim;
4409 //upunch becomes wolfslap
4410 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
4411 player[k].targetanimation=wolfslapanim;
4414 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4415 player[i].howactive<typedead1&&
4416 distance<1.5*sq(player[k].scale*5)&&
4417 !player[i].skeleton.free&&
4418 player[i].targetanimation!=getupfrombackanim&&
4419 player[i].targetanimation!=getupfromfrontanim&&
4420 (player[i].stunned>0&&player[k].madskills||
4421 player[i].surprised>0||
4422 player[i].aitype==passivetype||
4423 attackweapon&&player[i].stunned>0)&&
4424 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4427 player[k].currentanimation=sneakattackanim;
4428 player[k].targetanimation=sneakattackanim;
4429 player[i].currentanimation=sneakattackedanim;
4430 player[i].targetanimation=sneakattackedanim;
4431 player[k].oldcoords=player[k].coords;
4432 player[k].coords=player[i].coords;
4435 if(attackweapon==knife){
4436 player[k].currentanimation=knifesneakattackanim;
4437 player[k].targetanimation=knifesneakattackanim;
4438 player[i].currentanimation=knifesneakattackedanim;
4439 player[i].targetanimation=knifesneakattackedanim;
4440 player[i].oldcoords=player[i].coords;
4441 player[i].coords=player[k].coords;
4444 if(attackweapon==sword){
4445 player[k].currentanimation=swordsneakattackanim;
4446 player[k].targetanimation=swordsneakattackanim;
4447 player[i].currentanimation=swordsneakattackedanim;
4448 player[i].targetanimation=swordsneakattackedanim;
4449 player[i].oldcoords=player[i].coords;
4450 player[i].coords=player[k].coords;
4452 if(attackweapon!=staff){
4453 player[k].victim=&player[i];
4454 player[k].hasvictim=1;
4455 player[i].targettilt2=0;
4456 player[i].targetframe=1;
4457 player[i].currentframe=0;
4459 player[i].velocity=0;
4460 player[k].targettilt2=player[i].targettilt2;
4461 player[k].currentframe=player[i].currentframe;
4462 player[k].targetframe=player[i].targetframe;
4463 player[k].target=player[i].target;
4464 player[k].velocity=0;
4465 player[k].targetrotation=player[i].rotation;
4466 player[k].rotation=player[i].rotation;
4467 player[i].targetrotation=player[i].rotation;
4470 if(animation[player[k].targetanimation].attack==normalattack&&
4471 player[k].victim==&player[i]&&
4472 (!player[i].skeleton.free)){
4474 player[k].targetframe=0;
4477 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4478 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4479 player[k].lastattack3=player[k].lastattack2;
4480 player[k].lastattack2=player[k].lastattack;
4481 player[k].lastattack=player[k].targetanimation;
4483 if(player[k].targetanimation==knifefollowanim&&
4484 player[k].victim==&player[i]){
4486 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4487 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4488 player[k].victim=&player[i];
4489 player[k].hasvictim=1;
4490 player[i].targetanimation=knifefollowedanim;
4491 player[i].currentanimation=knifefollowedanim;
4492 player[i].targettilt2=0;
4493 player[i].targettilt2=player[k].targettilt2;
4494 player[i].targetframe=1;
4495 player[i].currentframe=0;
4497 player[i].velocity=0;
4498 player[k].currentanimation=knifefollowanim;
4499 player[k].targetanimation=knifefollowanim;
4500 player[k].targettilt2=player[i].targettilt2;
4501 player[k].currentframe=player[i].currentframe;
4502 player[k].targetframe=player[i].targetframe;
4503 player[k].target=player[i].target;
4504 player[k].velocity=0;
4505 player[k].oldcoords=player[k].coords;
4506 player[i].coords=player[k].coords;
4507 player[i].targetrotation=player[k].targetrotation;
4508 player[i].rotation=player[k].targetrotation;
4509 player[k].rotation=player[k].targetrotation;
4510 player[i].rotation=player[k].targetrotation;
4514 const bool hasstaff=attackweapon==staff;
4515 if(k==0&&numplayers>1)
4516 for(int i=0;i<numplayers;i++){
4518 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4519 animation[player[k].targetanimation].attack==neutral){
4520 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4521 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4522 if(player[i].skeleton.free)
4523 if(distance<3.5*sq(player[k].scale*5)&&
4525 player[i].skeleton.longdead>1000||
4529 (player[i].skeleton.longdead>2000||
4530 player[i].damage>player[i].damagetolerance/8||
4531 player[i].bloodloss>player[i].damagetolerance/2)&&
4532 distance<1.5*sq(player[k].scale*5)))){
4533 player[k].victim=&player[i];
4534 player[k].hasvictim=1;
4535 if(attackweapon&&tutoriallevel!=1){
4537 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4538 player[k].targetanimation=crouchstabanim;
4540 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4541 player[k].targetanimation=swordgroundstabanim;
4543 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4544 player[k].targetanimation=staffgroundsmashanim;
4547 player[k].crouchkeydown&&
4548 player[k].targetanimation!=crouchstabanim&&
4551 player[i].skeleton.free&&
4552 player[i].skeleton.longdead>1000){
4553 player[k].targetanimation=killanim;
4554 //TODO: refactor this out, what does it do?
4555 for(int j=0;j<terrain.numdecals;j++){
4556 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4557 terrain.decalalivetime[j]<2)
4558 terrain.DeleteDecal(j);
4560 for(int l=0;l<objects.numobjects;l++){
4561 if(objects.model[l].type==decalstype)
4562 for(int j=0;j<objects.model[l].numdecals;j++){
4563 if((objects.model[l].decaltype[j]==blooddecal||
4564 objects.model[l].decaltype[j]==blooddecalslow)&&
4565 objects.model[l].decalalivetime[j]<2)
4566 objects.model[l].DeleteDecal(j);
4570 if(!player[i].dead||musictype!=2)
4572 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4573 player[k].staggerdelay<=0&&
4575 player[i].skeleton.longdead<300&&
4576 player[k].lastattack!=spinkickanim&&
4577 player[i].skeleton.free)&&
4578 (!player[i].dead||musictype!=stream_fighttheme)){
4579 player[k].targetanimation=dropkickanim;
4580 for(int j=0;j<terrain.numdecals;j++){
4581 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4582 terrain.decalalivetime[j]<2){
4583 terrain.DeleteDecal(j);
4586 for(int l=0;l<objects.numobjects;l++){
4587 if(objects.model[l].type==decalstype)
4588 for(int j=0;j<objects.model[l].numdecals;j++){
4589 if((objects.model[l].decaltype[j]==blooddecal||
4590 objects.model[l].decaltype[j]==blooddecalslow)&&
4591 objects.model[l].decalalivetime[j]<2){
4592 objects.model[l].DeleteDecal(j);
4598 if(animation[player[k].targetanimation].attack==normalattack&&
4599 player[k].victim==&player[i]&&
4600 (!player[i].skeleton.free||
4601 player[k].targetanimation==killanim||
4602 player[k].targetanimation==crouchstabanim||
4603 player[k].targetanimation==swordgroundstabanim||
4604 player[k].targetanimation==staffgroundsmashanim||
4605 player[k].targetanimation==dropkickanim)){
4607 player[k].targetframe=0;
4610 XYZ targetpoint=player[i].coords;
4611 if(player[k].targetanimation==crouchstabanim||
4612 player[k].targetanimation==swordgroundstabanim||
4613 player[k].targetanimation==staffgroundsmashanim){
4614 targetpoint+=(playerJoint(i,abdomen).position+
4615 playerJoint(i,neck).position)/2*
4618 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4619 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4621 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4622 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4625 if(player[k].targetanimation==staffgroundsmashanim)
4626 player[k].targettilt2+=10;
4628 player[k].lastattack3=player[k].lastattack2;
4629 player[k].lastattack2=player[k].lastattack;
4630 player[k].lastattack=player[k].targetanimation;
4632 if(player[k].targetanimation==swordgroundstabanim){
4633 player[k].targetrotation+=30;
4638 if(!player[k].hasvictim){
4640 for(int i=0;i<numplayers;i++){
4641 if(i==k||!(i==0||k==0))continue;
4642 if(!player[i].skeleton.free){
4643 if(player[k].hasvictim){
4644 if(findDistancefast(&player[k].coords,&player[i].coords)<
4645 findDistancefast(&player[k].coords,&player[k].victim->coords))
4646 player[k].victim=&player[i];
4648 player[k].victim=&player[i];
4649 player[k].hasvictim=1;
4654 if(player[k].aitype==playercontrolled)
4656 if(player[k].attackkeydown&&
4658 player[k].wasRun()&&
4659 ((player[k].hasvictim&&
4660 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4661 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4662 !player[k].victim->skeleton.free&&
4663 player[k].victim->targetanimation!=getupfrombackanim&&
4664 player[k].victim->targetanimation!=getupfromfrontanim&&
4665 animation[player[k].victim->targetanimation].height!=lowheight&&
4666 player[k].aitype!=playercontrolled&& //wat???
4667 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4668 player[k].rabbitkickenabled)||
4669 player[k].jumpkeydown)){
4671 setAnimation(k,rabbitkickanim);
4674 if(animation[player[k].targetanimation].attack&&k==0){
4676 switch(attackweapon){
4677 case 0: numunarmedattack++; break;
4678 case knife: numknifeattack++; break;
4679 case sword: numswordattack++; break;
4680 case staff: numstaffattack++; break;
4689 void Game::doPlayerCollisions(){
4690 static XYZ rotatetarget;
4691 static float collisionradius;
4693 for(int k=0;k<numplayers;k++)
4694 for(int i=k+1;i<numplayers;i++){
4695 //neither player is part of a reversal
4696 if((animation[player[i].targetanimation].attack!=reversed&&
4697 animation[player[i].targetanimation].attack!=reversal&&
4698 animation[player[k].targetanimation].attack!=reversed&&
4699 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4700 if((animation[player[i].currentanimation].attack!=reversed&&
4701 animation[player[i].currentanimation].attack!=reversal&&
4702 animation[player[k].currentanimation].attack!=reversed&&
4703 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4704 //neither is sleeping
4705 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4706 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4707 //in same patch, neither is climbing
4708 if(player[i].whichpatchx==player[k].whichpatchx&&
4709 player[i].whichpatchz==player[k].whichpatchz&&
4710 player[k].skeleton.oldfree==player[k].skeleton.free&&
4711 player[i].skeleton.oldfree==player[i].skeleton.free&&
4712 player[i].targetanimation!=climbanim&&
4713 player[i].targetanimation!=hanganim&&
4714 player[k].targetanimation!=climbanim&&
4715 player[k].targetanimation!=hanganim)
4716 //players are close (bounding box test)
4717 if(player[i].coords.y>player[k].coords.y-3)
4718 if(player[i].coords.y<player[k].coords.y+3)
4719 if(player[i].coords.x>player[k].coords.x-3)
4720 if(player[i].coords.x<player[k].coords.x+3)
4721 if(player[i].coords.z>player[k].coords.z-3)
4722 if(player[i].coords.z<player[k].coords.z+3){
4723 //spread fire from player to player
4724 if(findDistancefast(&player[i].coords,&player[k].coords)
4725 <3*sq((player[i].scale+player[k].scale)*2.5)){
4726 if(player[i].onfire||player[k].onfire){
4727 if(!player[i].onfire)player[i].CatchFire();
4728 if(!player[k].onfire)player[k].CatchFire();
4732 XYZ tempcoords1=player[i].coords;
4733 XYZ tempcoords2=player[k].coords;
4734 if(!player[i].skeleton.oldfree)
4735 tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
4736 if(!player[k].skeleton.oldfree)
4737 tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
4738 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4739 if(player[0].hasvictim)
4740 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4742 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4743 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4744 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4745 //jump down on a dead body
4748 if(player[0].targetanimation==jumpdownanim&&
4749 !player[0].skeleton.oldfree&&
4750 !player[0].skeleton.free&&
4751 player[l].skeleton.oldfree&&
4752 player[l].skeleton.free&&
4754 player[0].lastcollide<=0&&
4755 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4756 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4757 player[0].coords.y=player[l].coords.y;
4758 player[l].velocity=player[0].velocity;
4759 player[l].skeleton.free=0;
4760 player[l].rotation=0;
4761 player[l].RagDoll(0);
4762 player[l].DoDamage(20);
4764 player[l].skeleton.longdead=0;
4765 player[0].lastcollide=1;
4769 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4770 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4771 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4772 rotatetarget=player[k].velocity-player[i].velocity;
4773 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4774 player[i].skeleton.free)&&
4775 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4776 player[k].skeleton.free))
4777 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4778 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4779 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4781 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4782 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4783 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4784 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4785 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4787 if( (i!=0||player[i].skeleton.free)&&
4788 (k!=0||player[k].skeleton.free)||
4789 (animation[player[i].targetanimation].height==highheight&&
4790 animation[player[k].targetanimation].height==highheight)){
4791 if(tutoriallevel!=1){
4792 emit_sound_at(heavyimpactsound, player[i].coords);
4795 player[i].RagDoll(0);
4796 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4797 award_bonus(0, aimbonus);
4799 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4800 player[k].RagDoll(0);
4801 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4802 award_bonus(0, aimbonus); // Huh, again?
4804 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4806 for(int j=0;j<player[i].skeleton.num_joints;j++){
4807 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4809 for(int j=0;j<player[k].skeleton.num_joints;j++){
4810 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4815 if( (animation[player[i].targetanimation].attack==neutral||
4816 animation[player[i].targetanimation].attack==normalattack)&&
4817 (animation[player[k].targetanimation].attack==neutral||
4818 animation[player[k].targetanimation].attack==normalattack)){
4820 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4821 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4822 rotatetarget=player[k].coords-player[i].coords;
4823 Normalise(&rotatetarget);
4824 player[k].coords=(player[k].coords+player[i].coords)/2;
4825 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4826 *sq((player[i].scale+player[k].scale)*2.5);
4827 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4828 if(player[k].howactive==typeactive||hostile)
4829 if(player[k].isIdle()){
4830 if(player[k].howactive<typesleeping)
4831 setAnimation(k,player[k].getStop());
4832 else if(player[k].howactive==typesleeping)
4833 setAnimation(k,getupfromfrontanim);
4835 player[k].howactive=typeactive;
4837 if(player[i].howactive==typeactive||hostile)
4838 if(player[i].isIdle()){
4839 if(player[i].howactive<typesleeping)
4840 setAnimation(i,player[k].getStop());
4842 setAnimation(i,getupfromfrontanim);
4844 player[i].howactive=typeactive;
4847 //jump down on player
4849 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4850 !player[i].isCrouch()&&
4851 player[i].targetanimation!=rollanim&&
4852 !player[k].skeleton.oldfree&&!
4853 player[k].skeleton.free&&
4854 player[k].lastcollide<=0&&
4855 player[k].velocity.y<-10){
4856 player[i].velocity=player[k].velocity;
4857 player[k].velocity=player[k].velocity*-.5;
4858 player[k].velocity.y=player[i].velocity.y;
4859 player[i].DoDamage(20);
4860 player[i].RagDoll(0);
4861 player[k].lastcollide=1;
4862 award_bonus(k, AboveBonus);
4864 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4865 !player[k].isCrouch()&&
4866 player[k].targetanimation!=rollanim&&
4867 !player[i].skeleton.oldfree&&
4868 !player[i].skeleton.free&&
4869 player[i].lastcollide<=0&&
4870 player[i].velocity.y<-10){
4871 player[k].velocity=player[i].velocity;
4872 player[i].velocity=player[i].velocity*-.3;
4873 player[i].velocity.y=player[k].velocity.y;
4874 player[k].DoDamage(20);
4875 player[k].RagDoll(0);
4876 player[i].lastcollide=1;
4877 award_bonus(i, AboveBonus);
4883 player[i].CheckKick();
4884 player[k].CheckKick();
4890 void Game::doAI(int i){
4891 static bool connected;
4892 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4893 player[i].jumpclimb=0;
4894 //disable movement in editor
4896 player[i].stunned=1;
4899 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4900 player[0].coords.y>player[i].coords.y+2&&
4901 !player[0].onterrain)
4905 if(player[i].aitype==pathfindtype){
4906 if(player[i].finalpathfindpoint==-1){
4907 float closestdistance;
4913 for(int j=0;j<numpathpoints;j++)
4914 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4915 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4917 player[i].finaltarget=pathpoint[j];
4919 player[i].finalpathfindpoint=closest;
4920 for(int j=0;j<numpathpoints;j++)
4921 for(int k=0;k<numpathpointconnect[j];k++){
4922 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4923 if(sq(tempdist)<closestdistance)
4924 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4925 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4926 closestdistance=sq(tempdist);
4928 player[i].finaltarget=colpoint;
4931 player[i].finalpathfindpoint=closest;
4934 if(player[i].targetpathfindpoint==-1){
4935 float closestdistance;
4941 if(player[i].lastpathfindpoint==-1){
4942 for(int j=0;j<numpathpoints;j++){
4943 if(j!=player[i].lastpathfindpoint)
4944 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4945 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4949 player[i].targetpathfindpoint=closest;
4950 for(int j=0;j<numpathpoints;j++)
4951 if(j!=player[i].lastpathfindpoint)
4952 for(int k=0;k<numpathpointconnect[j];k++){
4953 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4954 if(sq(tempdist)<closestdistance){
4955 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4956 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4957 closestdistance=sq(tempdist);
4962 player[i].targetpathfindpoint=closest;
4966 for(int j=0;j<numpathpoints;j++)
4967 if(j!=player[i].lastpathfindpoint&&
4968 j!=player[i].lastpathfindpoint2&&
4969 j!=player[i].lastpathfindpoint3&&
4970 j!=player[i].lastpathfindpoint4){
4972 if(numpathpointconnect[j])
4973 for(int k=0;k<numpathpointconnect[j];k++)
4974 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4977 if(numpathpointconnect[player[i].lastpathfindpoint])
4978 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4979 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4982 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4983 if(closest==-1||tempdist<closestdistance){
4984 closestdistance=tempdist;
4989 player[i].targetpathfindpoint=closest;
4992 player[i].losupdatedelay-=multiplier;
4994 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4995 player[i].lookrotation=player[i].targetrotation;
4997 //reached target point
4998 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4999 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
5000 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
5001 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
5002 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
5003 if(player[i].lastpathfindpoint2==-1)
5004 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
5005 if(player[i].lastpathfindpoint3==-1)
5006 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
5007 if(player[i].lastpathfindpoint4==-1)
5008 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
5009 player[i].targetpathfindpoint=-1;
5011 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
5012 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
5013 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
5014 player[i].lastpathfindpoint==player[i].finalpathfindpoint){
5015 player[i].aitype=passivetype;
5018 player[i].forwardkeydown=1;
5019 player[i].leftkeydown=0;
5020 player[i].backkeydown=0;
5021 player[i].rightkeydown=0;
5022 player[i].crouchkeydown=0;
5023 player[i].attackkeydown=0;
5024 player[i].throwkeydown=0;
5026 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5027 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5029 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5030 player[i].jumpkeydown=0;
5031 if((player[i].collided>.8&&player[i].jumppower>=5))
5032 player[i].jumpkeydown=1;
5034 if((tutoriallevel!=1||cananger)&&
5037 findDistancefast(&player[i].coords,&player[0].coords)<400&&
5038 player[i].occluded<25){
5039 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
5040 animation[player[0].targetanimation].height!=lowheight&&
5042 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
5043 player[i].aitype=attacktypecutoff;
5044 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
5045 animation[player[0].targetanimation].height==highheight&&
5047 player[i].aitype=attacktypecutoff;
5049 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
5050 player[i].losupdatedelay=.2;
5051 for(int j=0;j<numplayers;j++)
5052 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
5053 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
5054 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
5055 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
5056 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
5057 if(!player[j].isWallJump()&&-1==checkcollide(
5058 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
5059 *player[i].scale+player[i].coords,
5060 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
5061 *player[j].scale+player[j].coords)||
5062 (player[j].targetanimation==hanganim&&
5063 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
5064 player[i].aitype=searchtype;
5065 player[i].lastchecktime=12;
5066 player[i].lastseen=player[j].coords;
5067 player[i].lastseentime=12;
5071 if(player[i].aitype==attacktypecutoff&&musictype!=2)
5072 if(player[i].creature!=wolftype){
5073 player[i].stunned=.6;
5074 player[i].surprised=.6;
5078 if(player[i].aitype!=passivetype&&leveltime>.5)
5079 player[i].howactive=typeactive;
5081 if(player[i].aitype==passivetype){
5082 player[i].aiupdatedelay-=multiplier;
5083 player[i].losupdatedelay-=multiplier;
5084 player[i].lastseentime+=multiplier;
5085 player[i].pausetime-=multiplier;
5086 if(player[i].lastseentime>1)
5087 player[i].lastseentime=1;
5089 if(player[i].aiupdatedelay<0){
5090 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
5091 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
5092 player[i].lookrotation=player[i].targetrotation;
5093 player[i].aiupdatedelay=.05;
5095 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
5096 if(player[i].waypointtype[player[i].waypoint]==wppause)
5097 player[i].pausetime=4;
5098 player[i].waypoint++;
5099 if(player[i].waypoint>player[i].numwaypoints-1)
5100 player[i].waypoint=0;
5105 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
5106 player[i].forwardkeydown=1;
5108 player[i].forwardkeydown=0;
5109 player[i].leftkeydown=0;
5110 player[i].backkeydown=0;
5111 player[i].rightkeydown=0;
5112 player[i].crouchkeydown=0;
5113 player[i].attackkeydown=0;
5114 player[i].throwkeydown=0;
5116 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5117 if(!player[i].avoidsomething)
5118 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5120 XYZ leftpos,rightpos;
5121 float leftdist,rightdist;
5122 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5123 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5124 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5125 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5126 if(leftdist<rightdist)
5127 player[i].targetrotation+=90;
5129 player[i].targetrotation-=90;
5133 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5134 player[i].jumpkeydown=0;
5135 if((player[i].collided>.8&&player[i].jumppower>=5))
5136 player[i].jumpkeydown=1;
5141 if(player[i].howactive<=typesleeping)
5142 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
5143 for(int j=0;j<numenvsounds;j++){
5144 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
5145 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
5146 2*(vol+vol*(player[i].creature==rabbittype)*3))
5147 player[i].aitype=attacktypecutoff;
5150 if(player[i].aitype!=passivetype){
5151 if(player[i].howactive==typesleeping)
5152 setAnimation(i,getupfromfrontanim);
5153 player[i].howactive=typeactive;
5157 if(player[i].howactive<typesleeping&&
5158 ((tutoriallevel!=1||cananger)&&hostile)&&
5160 findDistancefast(&player[i].coords,&player[0].coords)<400&&
5161 player[i].occluded<25){
5162 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
5163 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
5164 player[i].aitype=attacktypecutoff;
5165 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
5166 animation[player[0].targetanimation].height==highheight&&!editorenabled)
5167 player[i].aitype=attacktypecutoff;
5170 if(player[i].creature==wolftype){
5172 for(int j=0;j<numplayers;j++){
5173 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
5174 float smelldistance=50;
5175 if(j==0&&player[j].num_weapons>0){
5176 if(weapons.bloody[player[j].weaponids[0]])
5178 if(player[j].num_weapons==2)
5179 if(weapons.bloody[player[j].weaponids[1]])
5184 windsmell=windvector;
5185 Normalise(&windsmell);
5186 windsmell=windsmell*2+player[j].coords;
5187 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
5188 player[i].aitype=attacktypecutoff;
5193 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
5194 player[i].losupdatedelay=.2;
5195 for(int j=0;j<numplayers;j++){
5196 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
5197 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
5198 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
5199 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
5200 if((-1==checkcollide(
5201 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
5202 player[i].scale+player[i].coords,
5203 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
5204 player[j].scale+player[j].coords)&&
5205 !player[j].isWallJump())||
5206 (player[j].targetanimation==hanganim&&
5207 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
5208 player[i].lastseentime-=.2;
5209 if(j==0&&animation[player[j].targetanimation].height==lowheight)
5210 player[i].lastseentime-=.4;
5212 player[i].lastseentime-=.6;
5214 if(player[i].lastseentime<=0){
5215 player[i].aitype=searchtype;
5216 player[i].lastchecktime=12;
5217 player[i].lastseen=player[j].coords;
5218 player[i].lastseentime=12;
5225 if(player[i].aitype==attacktypecutoff&&musictype!=2){
5226 if(player[i].creature!=wolftype){
5227 player[i].stunned=.6;
5228 player[i].surprised=.6;
5230 if(player[i].creature==wolftype){
5231 player[i].stunned=.47;
5232 player[i].surprised=.47;
5240 if(player[i].aitype==searchtype){
5241 player[i].aiupdatedelay-=multiplier;
5242 player[i].losupdatedelay-=multiplier;
5243 if(!player[i].pause)
5244 player[i].lastseentime-=multiplier;
5245 player[i].lastchecktime-=multiplier;
5247 if(player[i].isRun()&&!player[i].onground){
5248 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5249 XYZ test2=player[i].coords+player[i].facing;
5251 XYZ test=player[i].coords+player[i].facing;
5253 j=checkcollide(test2,test,player[i].laststanding);
5255 j=checkcollide(test2,test);
5257 player[i].velocity=0;
5258 setAnimation(i,player[i].getStop());
5259 player[i].targetrotation+=180;
5260 player[i].stunned=.5;
5261 //player[i].aitype=passivetype;
5262 player[i].aitype=pathfindtype;
5263 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5264 player[i].finalpathfindpoint=-1;
5265 player[i].targetpathfindpoint=-1;
5266 player[i].lastpathfindpoint=-1;
5267 player[i].lastpathfindpoint2=-1;
5268 player[i].lastpathfindpoint3=-1;
5269 player[i].lastpathfindpoint4=-1;
5271 else player[i].laststanding=j;
5274 //check out last seen location
5275 if(player[i].aiupdatedelay<0){
5276 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
5277 player[i].lookrotation=player[i].targetrotation;
5278 player[i].aiupdatedelay=.05;
5279 player[i].forwardkeydown=1;
5281 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
5282 player[i].forwardkeydown=0;
5283 player[i].aiupdatedelay=1;
5284 player[i].lastseen.x+=(float(Random()%100)-50)/25;
5285 player[i].lastseen.z+=(float(Random()%100)-50)/25;
5286 player[i].lastchecktime=3;
5289 player[i].leftkeydown=0;
5290 player[i].backkeydown=0;
5291 player[i].rightkeydown=0;
5292 player[i].crouchkeydown=0;
5293 player[i].attackkeydown=0;
5294 player[i].throwkeydown=0;
5296 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5297 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5299 XYZ leftpos,rightpos;
5300 float leftdist,rightdist;
5301 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5302 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5303 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5304 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5305 if(leftdist<rightdist)player[i].targetrotation+=90;
5306 else player[i].targetrotation-=90;
5310 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5311 player[i].jumpkeydown=0;
5312 if((player[i].collided>.8&&player[i].jumppower>=5))
5313 player[i].jumpkeydown=1;
5315 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
5316 for(int k=0;k<numenvsounds;k++){
5317 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
5318 player[i].aitype=attacktypecutoff;
5322 if(!player[0].dead&&
5323 player[i].losupdatedelay<0&&
5325 player[i].occluded<2&&
5326 ((tutoriallevel!=1||cananger)&&hostile)){
5327 player[i].losupdatedelay=.2;
5328 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
5329 player[i].aitype=attacktypecutoff;
5330 player[i].lastseentime=1;
5332 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
5333 //TODO: factor out canSeePlayer()
5334 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
5335 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5337 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
5338 player[i].scale+player[i].coords,
5339 DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
5340 player[0].scale+player[0].coords)==-1)||
5341 (player[0].targetanimation==hanganim&&normaldotproduct(
5342 player[0].facing,player[i].coords-player[0].coords)<0)){
5343 /* //TODO: changed j to 0 on a whim, make sure this is correct
5344 (player[j].targetanimation==hanganim&&normaldotproduct(
5345 player[j].facing,player[i].coords-player[j].coords)<0)
5347 player[i].aitype=attacktypecutoff;
5348 player[i].lastseentime=1;
5352 if(player[i].lastseentime<0){
5353 //player[i].aitype=passivetype;
5355 player[i].aitype=pathfindtype;
5356 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5357 player[i].finalpathfindpoint=-1;
5358 player[i].targetpathfindpoint=-1;
5359 player[i].lastpathfindpoint=-1;
5360 player[i].lastpathfindpoint2=-1;
5361 player[i].lastpathfindpoint3=-1;
5362 player[i].lastpathfindpoint4=-1;
5366 if(player[i].aitype!=gethelptype)
5367 player[i].runninghowlong=0;
5369 //get help from buddies
5370 if(player[i].aitype==gethelptype){
5371 player[i].runninghowlong+=multiplier;
5372 player[i].aiupdatedelay-=multiplier;
5374 if(player[i].aiupdatedelay<0||player[i].ally==0){
5375 player[i].aiupdatedelay=.2;
5378 //TODO: factor out closest search somehow
5379 if(!player[i].ally){
5381 float closestdist=-1;
5382 for(int k=0;k<numplayers;k++){
5383 if(k!=i&&k!=0&&!player[k].dead&&
5384 player[k].howactive<typedead1&&
5385 !player[k].skeleton.free&&
5386 player[k].aitype==passivetype){
5387 float distance=findDistancefast(&player[i].coords,&player[k].coords);
5388 if(closestdist==-1||distance<closestdist){
5389 closestdist=distance;
5396 player[i].ally=closest;
5399 player[i].lastseen=player[0].coords;
5400 player[i].lastseentime=12;
5404 player[i].lastchecktime=12;
5406 XYZ facing=player[i].coords;
5407 XYZ flatfacing=player[player[i].ally].coords;
5408 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5409 flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
5410 if(-1!=checkcollide(facing,flatfacing))
5411 player[i].lastseentime-=.1;
5413 //no available ally, run back to player
5414 if(player[i].ally<=0||
5415 player[player[i].ally].skeleton.free||
5416 player[player[i].ally].aitype!=passivetype||
5417 player[i].lastseentime<=0){
5418 player[i].aitype=searchtype;
5419 player[i].lastseentime=12;
5423 if(player[i].ally>0){
5424 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5425 player[i].lookrotation=player[i].targetrotation;
5426 player[i].aiupdatedelay=.05;
5427 player[i].forwardkeydown=1;
5429 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
5430 player[i].aitype=searchtype;
5431 player[i].lastseentime=12;
5432 player[player[i].ally].aitype=searchtype;
5433 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5434 player[player[i].ally].lastseen=player[i].lastseen;
5435 player[player[i].ally].lastseentime=player[i].lastseentime;
5436 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5440 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5441 if(!player[i].avoidsomething)
5442 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5444 XYZ leftpos,rightpos;
5445 float leftdist,rightdist;
5446 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5447 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5448 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5449 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5450 if(leftdist<rightdist)
5451 player[i].targetrotation+=90;
5453 player[i].targetrotation-=90;
5458 player[i].leftkeydown=0;
5459 player[i].backkeydown=0;
5460 player[i].rightkeydown=0;
5461 player[i].crouchkeydown=0;
5462 player[i].attackkeydown=0;
5464 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5465 player[i].jumpkeydown=0;
5466 if(player[i].collided>.8&&player[i].jumppower>=5)
5467 player[i].jumpkeydown=1;
5470 //retreiving a weapon on the ground
5471 if(player[i].aitype==getweapontype){
5472 player[i].aiupdatedelay-=multiplier;
5473 player[i].lastchecktime-=multiplier;
5475 if(player[i].aiupdatedelay<0){
5476 player[i].aiupdatedelay=.2;
5479 if(player[i].ally<0){
5481 float closestdist=-1;
5482 for(int k=0;k<weapons.numweapons;k++)
5483 if(weapons.owner[k]==-1){
5484 float distance=findDistancefast(&player[i].coords,&weapons.position[k]);
5485 if(closestdist==-1||distance<closestdist){
5486 closestdist=distance;
5492 player[i].ally=closest;
5497 player[i].lastseentime=12;
5499 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5500 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5501 player[i].aitype=attacktypecutoff;
5502 player[i].lastseentime=1;
5505 if(player[i].ally>=0){
5506 if(weapons.owner[player[i].ally]!=-1||
5507 findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
5508 player[i].aitype=attacktypecutoff;
5509 player[i].lastseentime=1;
5511 //TODO: factor these out as moveToward()
5512 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[player[i].ally]);
5513 player[i].lookrotation=player[i].targetrotation;
5514 player[i].aiupdatedelay=.05;
5515 player[i].forwardkeydown=1;
5518 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5519 if(!player[i].avoidsomething)
5520 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5522 XYZ leftpos,rightpos;
5523 float leftdist,rightdist;
5524 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5525 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5526 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5527 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5528 if(leftdist<rightdist)
5529 player[i].targetrotation+=90;
5531 player[i].targetrotation-=90;
5536 player[i].leftkeydown=0;
5537 player[i].backkeydown=0;
5538 player[i].rightkeydown=0;
5539 player[i].attackkeydown=0;
5540 player[i].throwkeydown=1;
5541 player[i].crouchkeydown=0;
5542 if(player[i].targetanimation!=crouchremoveknifeanim&&
5543 player[i].targetanimation!=removeknifeanim)
5544 player[i].throwtogglekeydown=0;
5545 player[i].drawkeydown=0;
5547 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5548 player[i].jumpkeydown=0;
5549 if((player[i].collided>.8&&player[i].jumppower>=5))
5550 player[i].jumpkeydown=1;
5553 if(player[i].aitype==attacktypecutoff){
5554 player[i].aiupdatedelay-=multiplier;
5555 //dodge or reverse rabbit kicks, knife throws, flips
5556 if(player[i].damage<player[i].damagetolerance*2/3)
5557 if((player[0].targetanimation==rabbitkickanim||
5558 player[0].targetanimation==knifethrowanim||
5559 (player[0].isFlip()&&
5560 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5561 !player[0].skeleton.free&&
5562 (player[i].aiupdatedelay<.1)){
5563 player[i].attackkeydown=0;
5564 if(player[i].isIdle())
5565 player[i].crouchkeydown=1;
5566 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5567 if(weapons.type[player[0].weaponids[0]]==knife){
5568 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5569 if(abs(Random()%2==0))
5570 setAnimation(i,backhandspringanim);
5572 setAnimation(i,rollanim);
5573 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5574 player[i].wentforweapon=0;
5576 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5577 setAnimation(i,flipanim);
5580 player[i].forwardkeydown=0;
5581 player[i].aiupdatedelay=.02;
5583 //get confused by flips
5584 if(player[0].isFlip()&&
5585 !player[0].skeleton.free&&
5586 player[0].targetanimation!=walljumprightkickanim&&
5587 player[0].targetanimation!=walljumpleftkickanim){
5588 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5589 if((1-player[i].damage/player[i].damagetolerance)>.5)
5590 player[i].stunned=1;
5592 //go for weapon on the ground
5593 if(player[i].wentforweapon<3)
5594 for(int k=0;k<weapons.numweapons;k++)
5595 if(player[i].creature!=wolftype)
5596 if(player[i].num_weapons==0&&
5597 weapons.owner[k]==-1&&
5598 weapons.velocity[i].x==0&&
5599 weapons.velocity[i].z==0&&
5600 weapons.velocity[i].y==0){
5601 if(findDistancefast(&player[i].coords,&weapons.position[k])<16){
5602 player[i].wentforweapon++;
5603 player[i].lastchecktime=6;
5604 player[i].aitype=getweapontype;
5608 //dodge/reverse walljump kicks
5609 if(player[i].damage<player[i].damagetolerance/2)
5610 if(animation[player[i].targetanimation].height!=highheight)
5611 if(player[i].damage<player[i].damagetolerance*.5&&
5612 ((player[0].targetanimation==walljumprightkickanim||
5613 player[0].targetanimation==walljumpleftkickanim)&&
5614 ((player[i].aiupdatedelay<.15&&
5616 (player[i].aiupdatedelay<.08&&
5618 player[i].crouchkeydown=1;
5620 //walked off a ledge (?)
5621 if(player[i].isRun()&&!player[i].onground)
5622 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5623 XYZ test2=player[i].coords+player[i].facing;
5625 XYZ test=player[i].coords+player[i].facing;
5627 j=checkcollide(test2,test,player[i].laststanding);
5629 j=checkcollide(test2,test);
5631 player[i].velocity=0;
5632 setAnimation(i,player[i].getStop());
5633 player[i].targetrotation+=180;
5634 player[i].stunned=.5;
5635 player[i].aitype=pathfindtype;
5636 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5637 player[i].finalpathfindpoint=-1;
5638 player[i].targetpathfindpoint=-1;
5639 player[i].lastpathfindpoint=-1;
5640 player[i].lastpathfindpoint2=-1;
5641 player[i].lastpathfindpoint3=-1;
5642 player[i].lastpathfindpoint4=-1;
5644 player[i].laststanding=j;
5646 //lose sight of player in the air (?)
5647 if(player[0].coords.y>player[i].coords.y+5&&
5648 animation[player[0].targetanimation].height!=highheight&&
5649 !player[0].onterrain){
5650 player[i].aitype=pathfindtype;
5651 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5652 player[i].finalpathfindpoint=-1;
5653 player[i].targetpathfindpoint=-1;
5654 player[i].lastpathfindpoint=-1;
5655 player[i].lastpathfindpoint2=-1;
5656 player[i].lastpathfindpoint3=-1;
5657 player[i].lastpathfindpoint4=-1;
5659 //it's time to think (?)
5660 if(player[i].aiupdatedelay<0&&
5661 !animation[player[i].targetanimation].attack&&
5662 player[i].targetanimation!=staggerbackhighanim&&
5663 player[i].targetanimation!=staggerbackhardanim&&
5664 player[i].targetanimation!=backhandspringanim&&
5665 player[i].targetanimation!=dodgebackanim){
5667 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5668 player[i].drawkeydown=Random()%2;
5670 player[i].drawkeydown=0;
5671 player[i].rabbitkickenabled=Random()%2;
5673 XYZ rotatetarget=player[0].coords+player[0].velocity;
5674 XYZ targetpoint=player[0].coords;
5675 if(findDistancefast(&player[0].coords,&player[i].coords)<
5676 findDistancefast(&rotatetarget,&player[i].coords))
5677 targetpoint+=player[0].velocity*
5678 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5679 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5680 player[i].lookrotation=player[i].targetrotation;
5681 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5683 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5684 player[i].forwardkeydown=1;
5685 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5686 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5687 player[0].weaponactive!=-1)
5688 player[i].forwardkeydown=1;
5689 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5690 player[i].forwardkeydown=1;
5692 player[i].forwardkeydown=0;
5693 //chill out around the corpse
5695 player[i].forwardkeydown=0;
5697 player[i].forwardkeydown=1;
5698 if(Random()%100==0){
5699 player[i].aitype=pathfindtype;
5700 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5701 player[i].finalpathfindpoint=-1;
5702 player[i].targetpathfindpoint=-1;
5703 player[i].lastpathfindpoint=-1;
5704 player[i].lastpathfindpoint2=-1;
5705 player[i].lastpathfindpoint3=-1;
5706 player[i].lastpathfindpoint4=-1;
5709 player[i].leftkeydown=0;
5710 player[i].backkeydown=0;
5711 player[i].rightkeydown=0;
5712 player[i].crouchkeydown=0;
5713 player[i].throwkeydown=0;
5715 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5716 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5718 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5719 player[i].attackkeydown=1;
5721 player[i].attackkeydown=0;
5722 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5723 player[i].attackkeydown=0;
5726 if(player[i].aitype!=playercontrolled&&
5727 (player[i].isIdle()||
5728 player[i].isCrouch()||
5729 player[i].isRun())){
5731 for(int j=0;j<numplayers;j++)
5732 if(j!=i&&!player[j].skeleton.free&&
5733 player[j].hasvictim&&
5734 (tutoriallevel==1&&reversaltrain||
5735 Random()%2==0&&difficulty==2||
5736 Random()%4==0&&difficulty==1||
5737 Random()%8==0&&difficulty==0||
5738 player[j].lastattack2==player[j].targetanimation&&
5739 player[j].lastattack3==player[j].targetanimation&&
5740 (Random()%2==0||difficulty==2)||
5741 (player[i].isIdle()||player[i].isRun())&&
5742 player[j].weaponactive!=-1||
5743 player[j].targetanimation==swordslashanim&&
5744 player[i].weaponactive!=-1||
5745 player[j].targetanimation==staffhitanim||
5746 player[j].targetanimation==staffspinhitanim))
5747 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5748 player[j].victim==&player[i]&&
5749 (player[j].targetanimation==sweepanim||
5750 player[j].targetanimation==spinkickanim||
5751 player[j].targetanimation==staffhitanim||
5752 player[j].targetanimation==staffspinhitanim||
5753 player[j].targetanimation==winduppunchanim||
5754 player[j].targetanimation==upunchanim||
5755 player[j].targetanimation==wolfslapanim||
5756 player[j].targetanimation==knifeslashstartanim||
5757 player[j].targetanimation==swordslashanim&&
5758 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5759 player[i].weaponactive!=-1))){
5766 player[target].Reverse();
5769 if(player[i].collided<1)
5770 player[i].jumpkeydown=0;
5771 if(player[i].collided>.8&&player[i].jumppower>=5||
5772 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5773 player[i].onterrain&&
5774 player[i].creature==rabbittype)
5775 player[i].jumpkeydown=1;
5776 //TODO: why are we controlling the human?
5777 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5778 player[0].jumpkeydown=0;
5779 if(player[0].targetanimation==jumpdownanim&&
5780 findDistancefast(&player[0].coords,&player[i].coords)<40)
5781 player[i].crouchkeydown=1;
5782 if(player[i].jumpkeydown)
5783 player[i].attackkeydown=0;
5785 if(tutoriallevel==1)
5787 player[i].attackkeydown=0;
5790 XYZ facing=player[i].coords;
5791 XYZ flatfacing=player[0].coords;
5792 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5793 flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
5794 if(player[i].occluded>=2)
5795 if(-1!=checkcollide(facing,flatfacing)){
5796 if(!player[i].pause)
5797 player[i].lastseentime-=.2;
5798 if(player[i].lastseentime<=0&&
5799 (player[i].creature!=wolftype||
5800 player[i].weaponstuck==-1)){
5801 player[i].aitype=searchtype;
5802 player[i].lastchecktime=12;
5803 player[i].lastseen=player[0].coords;
5804 player[i].lastseentime=12;
5807 player[i].lastseentime=1;
5810 if(animation[player[0].targetanimation].height==highheight&&
5811 (player[i].aitype==attacktypecutoff||
5812 player[i].aitype==searchtype))
5813 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5814 XYZ test=player[0].coords;
5816 if(-1==checkcollide(player[0].coords,test))
5817 player[i].stunned=1;
5820 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5821 player[i].stunned>0||
5822 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5824 player[i].lastseentime=1;
5825 player[i].targetrotation=player[i].rotation;
5826 player[i].forwardkeydown=0;
5827 player[i].leftkeydown=0;
5828 player[i].backkeydown=0;
5829 player[i].rightkeydown=0;
5830 player[i].jumpkeydown=0;
5831 player[i].attackkeydown=0;
5832 player[i].crouchkeydown=0;
5833 player[i].throwkeydown=0;
5841 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5844 if(player[i].aitype==attacktypecutoff){
5845 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5846 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5847 }else if(player[i].howactive>=typesleeping){
5848 player[i].targetheadrotation=player[i].targetrotation;
5849 player[i].targetheadrotation2=0;
5851 if(player[i].interestdelay<=0){
5852 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5853 player[i].headtarget=player[i].coords;
5854 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5855 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5856 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5857 player[i].headtarget+=player[i].facing*1.5;
5859 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5860 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5866 static XYZ facing,flatfacing;
5869 for(int i=0;i<15;i++){
5870 displaytime[i]+=multiplier;
5876 if(Input::isKeyPressed(SDLK_F6)){
5877 if(Input::isKeyDown(SDLK_LSHIFT))
5880 stereoreverse=false;
5883 printf("Stereo reversed\n");
5885 printf("Stereo unreversed\n");
5888 if(Input::isKeyDown(SDLK_F7)){
5889 if(Input::isKeyDown(SDLK_LSHIFT))
5890 stereoseparation -= 0.001;
5892 stereoseparation -= 0.010;
5893 printf("Stereo decreased increased to %f\n", stereoseparation);
5896 if(Input::isKeyDown(SDLK_F8)){
5897 if(Input::isKeyDown(SDLK_LSHIFT))
5898 stereoseparation += 0.001;
5900 stereoseparation += 0.010;
5901 printf("Stereo separation increased to %f\n", stereoseparation);
5905 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5906 if(tutorialstage!=51)
5907 tutorialstagetime=tutorialmaxtime;
5908 emit_sound_np(consolefailsound, 128.);
5912 Values of mainmenu :
5914 2 Menu pause (resume/end game)
5916 4 Controls configuration menu
5917 5 Main game menu (choose level or challenge)
5918 6 Deleting user menu
5919 7 User managment menu (select/add)
5920 8 Choose difficulty menu
5921 9 Challenge level selection menu
5922 10 End of the campaign congratulation (is that really a menu?)
5923 11 Same that 9 ??? => unused
5924 18 stereo configuration
5929 if(mainmenu&&endgame==1)
5931 //escape key pressed
5932 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5933 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5934 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))){
5936 if(mainmenu==0&&!winfreeze)
5938 else if(mainmenu==0&&winfreeze&&campaignchoosenext[campaignchoicewhich[whichchoice]]==1){
5942 }else if(mainmenu==1||mainmenu==2)
5943 mainmenu=0; //unpause
5945 if(musictoggle&&(mainmenu==1||mainmenu==2||mainmenu==100)){
5946 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5947 emit_stream_np(stream_menutheme);
5948 pause_sound(leveltheme);
5950 //on resume, play level music
5952 pause_sound(stream_menutheme);
5953 resume_stream(leveltheme);
5955 //finished with settings menu
5957 SaveSettings(*this);
5960 if(mainmenu>=3&&mainmenu!=8){
5967 mainmenu=gameon?2:1; break;
5970 case 6: case 7: case 9: case 10: case 100:
5981 if(hostile==1)hostiletime+=multiplier;
5983 if(!winfreeze)leveltime+=multiplier;
5986 if(Input::isKeyPressed(SDLK_v)&&debugmode){
5989 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5993 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
5997 inputText(displaytext[0],&displayselected,&displaychars[0]);
5999 if(displaychars[0]){
6000 for(int j=0;j<255;j++)
6001 displaytext[0][j]=0;
6008 displayblinkdelay-=multiplier;
6009 if(displayblinkdelay<=0){
6010 displayblinkdelay=.3;
6011 displayblink=1-displayblink;
6017 if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){
6020 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6029 if(console&&!Input::isKeyDown(SDLK_LMETA)){
6030 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6033 if(consolechars[0]>0){
6034 consoletext[0][consolechars[0]]=' ';
6035 cmd_dispatch(this, consoletext[0]);
6036 for(int k=14;k>=1;k--){
6037 for(int j=0;j<255;j++)
6038 consoletext[k][j]=consoletext[k-1][j];
6039 consolechars[k]=consolechars[k-1];
6041 for(int j=0;j<255;j++)
6042 consoletext[0][j]=0;
6048 consoleblinkdelay-=multiplier;
6049 if(consoleblinkdelay<=0){
6050 consoleblinkdelay=.3;
6051 consoleblink=1-consoleblink;
6057 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6060 SaveSettings(*this);
6064 static int oldwinfreeze;
6065 if(winfreeze&&!oldwinfreeze){
6066 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6067 emit_sound_np(consolesuccesssound);
6070 oldwinfreeze=winfreeze;
6074 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6077 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6081 }else if(winfreeze){
6089 //TODO: what is this test?
6090 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6095 talkdelay-=multiplier;
6097 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6098 for(int i=0;i<numdialogues;i++){
6099 int realdialoguetype;
6101 if(dialoguetype[i]>49){
6102 realdialoguetype=dialoguetype[i]-50;
6105 else if(dialoguetype[i]>39){
6106 realdialoguetype=dialoguetype[i]-40;
6109 else if(dialoguetype[i]>29){
6110 realdialoguetype=dialoguetype[i]-30;
6113 else if(dialoguetype[i]>19){
6114 realdialoguetype=dialoguetype[i]-20;
6117 else if(dialoguetype[i]>9){
6118 realdialoguetype=dialoguetype[i]-10;
6122 realdialoguetype=dialoguetype[i];
6125 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6126 realdialoguetype<numplayers&&
6127 realdialoguetype>0&&
6128 (dialoguegonethrough[i]==0||!special)&&
6129 (special||Input::isKeyPressed(attackkey))){
6130 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6131 player[realdialoguetype].howactive>=typedead1||
6132 dialoguetype[i]>40&&dialoguetype[i]<50){
6134 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6135 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6136 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6137 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6138 player[participantfocus[whichdialogue][j]].velocity=0;
6139 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6140 player[participantfocus[whichdialogue][j]].targetframe=0;
6145 dialoguegonethrough[i]++;
6146 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6147 playdialogueboxsound();
6153 windvar+=multiplier;
6154 smoketex+=multiplier;
6155 tutorialstagetime+=multiplier;
6158 static float hotspotvisual[40];
6162 for(int i=0;i<numhotspots;i++)
6163 hotspotvisual[i]-=multiplier/320;
6165 for(int i=0;i<numhotspots;i++){
6166 //if(hotspottype[i]<=10)
6167 while(hotspotvisual[i]<0){
6169 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6170 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6171 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6172 hotspotsprite+=hotspot[i];
6173 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6174 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6178 for(int i=0;i<numhotspots;i++){
6179 if(hotspottype[i]<=10&&hotspottype[i]>0){
6180 hotspot[i]=player[hotspottype[i]].coords;
6191 if(tutoriallevel!=1){
6194 bonus!=spinecrusher&&
6195 bonus!=tracheotomy&&
6198 emit_sound_np(consolesuccesssound);
6200 } else if(bonustime==0){
6201 emit_sound_np(fireendsound);
6204 if(bonus!=solidhit&&
6206 bonus!=threexcombo&&
6211 bonusnum[bonus]+=0.15;
6214 bonusvalue/=bonusnum[bonus];
6215 bonustotal+=bonusvalue;
6217 bonustime+=multiplier;
6220 if(environment==snowyenvironment){
6221 precipdelay-=multiplier;
6222 while(precipdelay<0){
6226 XYZ footvel,footpoint;
6229 footpoint=viewer+viewerfacing*6;
6230 footpoint.y+=((float)abs(Random()%1200))/100-6;
6231 footpoint.x+=((float)abs(Random()%1200))/100-6;
6232 footpoint.z+=((float)abs(Random()%1200))/100-6;
6233 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6238 doAerialAcrobatics();
6241 static XYZ oldviewer;
6245 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6246 player[0].leftkeydown=Input::isKeyDown(leftkey);
6247 player[0].backkeydown=Input::isKeyDown(backkey);
6248 player[0].rightkeydown=Input::isKeyDown(rightkey);
6249 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6250 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6251 player[0].drawkeydown=Input::isKeyDown(drawkey);
6252 player[0].throwkeydown=Input::isKeyDown(throwkey);
6256 player[0].forwardkeydown=0;
6257 player[0].leftkeydown=0;
6258 player[0].backkeydown=0;
6259 player[0].rightkeydown=0;
6260 player[0].jumpkeydown=0;
6261 player[0].crouchkeydown=0;
6262 player[0].drawkeydown=0;
6263 player[0].throwkeydown=0;
6266 if(!player[0].jumpkeydown)
6267 player[0].jumpclimb=0;
6276 facing=DoRotation(facing,-rotation2,0,0);
6277 facing=DoRotation(facing,0,0-rotation,0);
6282 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6284 if(Input::isKeyDown(forwardkey))
6285 viewer+=facing*multiplier*4;
6286 if(Input::isKeyDown(backkey))
6287 viewer-=facing*multiplier*4;
6288 if(Input::isKeyDown(leftkey))
6289 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6290 if(Input::isKeyDown(rightkey))
6291 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6292 if(Input::isKeyDown(jumpkey))
6293 viewer.y+=multiplier*4;
6294 if(Input::isKeyDown(crouchkey))
6295 viewer.y-=multiplier*4;
6296 if( Input::isKeyPressed(SDLK_1)||
6297 Input::isKeyPressed(SDLK_2)||
6298 Input::isKeyPressed(SDLK_3)||
6299 Input::isKeyPressed(SDLK_4)||
6300 Input::isKeyPressed(SDLK_5)||
6301 Input::isKeyPressed(SDLK_6)||
6302 Input::isKeyPressed(SDLK_7)||
6303 Input::isKeyPressed(SDLK_8)||
6304 Input::isKeyPressed(SDLK_9)||
6305 Input::isKeyPressed(SDLK_0)||
6306 Input::isKeyPressed(SDLK_MINUS)){
6308 if(Input::isKeyPressed(SDLK_1))whichend=1;
6309 if(Input::isKeyPressed(SDLK_2))whichend=2;
6310 if(Input::isKeyPressed(SDLK_3))whichend=3;
6311 if(Input::isKeyPressed(SDLK_4))whichend=4;
6312 if(Input::isKeyPressed(SDLK_5))whichend=5;
6313 if(Input::isKeyPressed(SDLK_6))whichend=6;
6314 if(Input::isKeyPressed(SDLK_7))whichend=7;
6315 if(Input::isKeyPressed(SDLK_8))whichend=8;
6316 if(Input::isKeyPressed(SDLK_9))whichend=9;
6317 if(Input::isKeyPressed(SDLK_0))whichend=0;
6318 if(Input::isKeyPressed(SDLK_MINUS))
6321 participantfocus[whichdialogue][indialogue]=whichend;
6322 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6323 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6326 participantfocus[whichdialogue][indialogue]=-1;
6328 if(player[participantfocus[whichdialogue][indialogue]].dead){
6333 dialoguecamera[whichdialogue][indialogue]=viewer;
6334 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6335 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6337 if(indialogue<numdialogueboxes[whichdialogue]){
6338 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6339 playdialogueboxsound();
6343 for(int j=0;j<numplayers;j++){
6344 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6347 //TODO: should these be KeyDown or KeyPressed?
6348 if( Input::isKeyDown(SDLK_KP1)||
6349 Input::isKeyDown(SDLK_KP2)||
6350 Input::isKeyDown(SDLK_KP3)||
6351 Input::isKeyDown(SDLK_KP4)||
6352 Input::isKeyDown(SDLK_KP5)||
6353 Input::isKeyDown(SDLK_KP6)||
6354 Input::isKeyDown(SDLK_KP7)||
6355 Input::isKeyDown(SDLK_KP8)||
6356 Input::isKeyDown(SDLK_KP9)||
6357 Input::isKeyDown(SDLK_KP0)){
6359 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6360 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6361 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6362 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6363 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6364 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6365 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6366 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6367 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6368 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6369 participantfacing[whichdialogue][indialogue][whichend]=facing;
6371 if(indialogue>=numdialogueboxes[whichdialogue]){
6378 pause_sound(whooshsound);
6379 viewer=dialoguecamera[whichdialogue][indialogue];
6380 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6381 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6382 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6383 if(dialoguetime>0.5)
6384 if( Input::isKeyPressed(SDLK_1)||
6385 Input::isKeyPressed(SDLK_2)||
6386 Input::isKeyPressed(SDLK_3)||
6387 Input::isKeyPressed(SDLK_4)||
6388 Input::isKeyPressed(SDLK_5)||
6389 Input::isKeyPressed(SDLK_6)||
6390 Input::isKeyPressed(SDLK_7)||
6391 Input::isKeyPressed(SDLK_8)||
6392 Input::isKeyPressed(SDLK_9)||
6393 Input::isKeyPressed(SDLK_0)||
6394 Input::isKeyPressed(SDLK_MINUS)||
6395 Input::isKeyPressed(attackkey)){
6397 if(indialogue<numdialogueboxes[whichdialogue]){
6398 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6399 playdialogueboxsound();
6400 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6401 hotspot[numhotspots]=player[0].coords;
6402 hotspotsize[numhotspots]=10;
6403 hotspottype[numhotspots]=-1;
6407 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6411 if(player[participantfocus[whichdialogue][indialogue]].dead){
6419 if(indialogue>=numdialogueboxes[whichdialogue]){
6423 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6426 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6429 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6431 for(int i=1;i<numplayers;i++){
6432 player[i].aitype = attacktypecutoff;
6439 if(!player[0].jumpkeydown){
6440 player[0].jumptogglekeydown=0;
6442 if(player[0].jumpkeydown&&
6443 player[0].targetanimation!=jumpupanim&&
6444 player[0].targetanimation!=jumpdownanim&&
6445 !player[0].isFlip())
6446 player[0].jumptogglekeydown=1;
6449 dialoguetime+=multiplier;
6450 hawkrotation+=multiplier*25;
6452 realhawkcoords.x=25;
6453 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6454 hawkcalldelay-=multiplier/2;
6456 if(hawkcalldelay<=0){
6457 emit_sound_at(hawksound, realhawkcoords);
6459 hawkcalldelay=16+abs(Random()%8);
6466 doPlayerCollisions();
6470 for(int k=0;k<numplayers;k++)
6471 if(k!=0&&player[k].immobile)
6472 player[k].coords=player[k].realoldcoords;
6474 for(int k=0;k<numplayers;k++){
6475 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6476 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6477 player[k].DoDamage(1000);
6483 static bool respawnkeydown;
6486 (Input::isKeyDown(SDLK_z)&&
6487 Input::isKeyDown(SDLK_LMETA)&&
6489 (Input::isKeyDown(jumpkey)&&
6493 targetlevel=whichlevel;
6497 if(!Input::isKeyDown(jumpkey))
6499 if(Input::isKeyDown(jumpkey))
6505 static bool movekey;
6508 for(int i=0;i<numplayers;i++){
6509 static float oldtargetrotation;
6510 if(!player[i].skeleton.free){
6511 oldtargetrotation=player[i].targetrotation;
6512 if(i==0&&indialogue==-1){
6513 //TODO: refactor repetitive code
6514 if(!animation[player[0].targetanimation].attack&&
6515 player[0].targetanimation!=staggerbackhighanim&&
6516 player[0].targetanimation!=staggerbackhardanim&&
6517 player[0].targetanimation!=crouchremoveknifeanim&&
6518 player[0].targetanimation!=removeknifeanim&&
6519 player[0].targetanimation!=backhandspringanim&&
6520 player[0].targetanimation!=dodgebackanim&&
6521 player[0].targetanimation!=walljumprightkickanim&&
6522 player[0].targetanimation!=walljumpleftkickanim){
6524 player[0].targetrotation=0;
6526 player[0].targetrotation=-rotation+180;
6532 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6536 facing=DoRotation(facing,-rotation2,0,0);
6537 facing=DoRotation(facing,0,0-rotation,0);
6540 player[0].lookrotation=-rotation;
6542 player[i].targetheadrotation=rotation;
6543 player[i].targetheadrotation2=rotation2;
6545 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6546 if(!animation[player[i].targetanimation].attack&&
6547 player[i].targetanimation!=staggerbackhighanim&&
6548 player[i].targetanimation!=staggerbackhardanim&&
6549 player[i].targetanimation!=crouchremoveknifeanim&&
6550 player[i].targetanimation!=removeknifeanim&&
6551 player[i].targetanimation!=backhandspringanim&&
6552 player[i].targetanimation!=dodgebackanim&&
6553 player[i].targetanimation!=walljumprightkickanim&&
6554 player[i].targetanimation!=walljumpleftkickanim){
6555 player[i].targetrotation=-player[i].lookrotation+180;
6561 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6563 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6564 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6566 player[i].targetheadrotation=player[i].lookrotation;
6567 player[i].targetheadrotation2=player[i].lookrotation2;
6570 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6571 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6577 player[i].avoidsomething=0;
6579 //avoid flaming things
6580 for(int j=0;j<objects.numobjects;j++)
6581 if(objects.onfire[j])
6582 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6583 if( findDistancefast(&player[i].coords,&objects.position[j])<
6584 findDistancefast(&player[i].coords,&player[0].coords)){
6585 player[i].collided=0;
6586 player[i].avoidcollided=1;
6587 if(player[i].avoidsomething==0||
6588 findDistancefast(&player[i].coords,&objects.position[j])<
6589 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6590 player[i].avoidwhere=objects.position[j];
6591 player[i].avoidsomething=1;
6595 //avoid flaming players
6596 for(int j=0;j<numplayers;j++)
6597 if(player[j].onfire)
6598 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6599 if( findDistancefast(&player[i].coords,&player[j].coords)<
6600 findDistancefast(&player[i].coords,&player[0].coords)){
6601 player[i].collided=0;
6602 player[i].avoidcollided=1;
6603 if(player[i].avoidsomething==0||
6604 findDistancefast(&player[i].coords,&player[j].coords)<
6605 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6606 player[i].avoidwhere=player[j].coords;
6607 player[i].avoidsomething=1;
6611 if(player[i].collided>.8)
6612 player[i].avoidcollided=0;
6616 if(animation[player[i].targetanimation].attack==reversed){
6617 //player[i].targetrotation=player[i].rotation;
6618 player[i].forwardkeydown=0;
6619 player[i].leftkeydown=0;
6620 player[i].backkeydown=0;
6621 player[i].rightkeydown=0;
6622 player[i].jumpkeydown=0;
6623 player[i].attackkeydown=0;
6624 //player[i].crouchkeydown=0;
6625 player[i].throwkeydown=0;
6629 player[i].forwardkeydown=0;
6630 player[i].leftkeydown=0;
6631 player[i].backkeydown=0;
6632 player[i].rightkeydown=0;
6633 player[i].jumpkeydown=0;
6634 player[i].crouchkeydown=0;
6635 player[i].drawkeydown=0;
6636 player[i].throwkeydown=0;
6639 if(player[i].collided<-.3)
6640 player[i].collided=-.3;
6641 if(player[i].collided>1)
6642 player[i].collided=1;
6643 player[i].collided-=multiplier*4;
6644 player[i].whichdirectiondelay-=multiplier;
6645 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6646 player[i].avoidcollided=-.3;
6647 player[i].whichdirection=abs(Random()%2);
6648 player[i].whichdirectiondelay=.4;
6650 if(player[i].avoidcollided>1)
6651 player[i].avoidcollided=1;
6652 player[i].avoidcollided-=multiplier/4;
6653 if(!player[i].skeleton.free){
6654 player[i].stunned-=multiplier;
6655 player[i].surprised-=multiplier;
6657 if(i!=0&&player[i].surprised<=0&&
6658 player[i].aitype==attacktypecutoff&&
6660 !player[i].skeleton.free&&
6661 animation[player[i].targetanimation].attack==neutral)
6664 if(!player[i].throwkeydown)
6665 player[i].throwtogglekeydown=0;
6668 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6669 if(player[i].weaponactive==-1&&
6670 player[i].num_weapons<2&&
6671 (player[i].isIdle()||
6672 player[i].isCrouch()||
6673 player[i].targetanimation==sneakanim||
6674 player[i].targetanimation==rollanim||
6675 player[i].targetanimation==backhandspringanim||
6676 player[i].isFlip()||
6677 player[i].isFlip()||
6678 player[i].aitype!=playercontrolled)){
6679 for(int j=0;j<weapons.numweapons;j++){
6680 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6681 player[i].aitype==playercontrolled)&&
6682 weapons.owner[j]==-1&&
6683 player[i].weaponactive==-1)
6684 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
6685 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
6686 if(player[i].isCrouch()||
6687 player[i].targetanimation==sneakanim||
6689 player[i].isIdle()||
6690 player[i].aitype!=playercontrolled){
6691 player[i].throwtogglekeydown=1;
6692 setAnimation(i,crouchremoveknifeanim);
6693 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6694 player[i].hasvictim=0;
6696 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6697 player[i].throwtogglekeydown=1;
6698 player[i].hasvictim=0;
6700 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6701 player[i].aitype==playercontrolled)&&
6702 weapons.owner[j]==-1||
6704 weapons.owner[j]==player[i].victim->id)
6705 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1)
6706 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
6707 if(weapons.type[j]!=staff)
6708 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6710 player[i].weaponactive=0;
6711 weapons.owner[j]=player[i].id;
6712 if(player[i].num_weapons>0)
6713 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6714 player[i].num_weapons++;
6715 player[i].weaponids[0]=j;
6718 }else if((player[i].isIdle()||
6719 player[i].isFlip()||
6720 player[i].aitype!=playercontrolled)&&
6721 findDistancefast(&player[i].coords,&weapons.position[j])<5&&
6722 player[i].coords.y<weapons.position[j].y){
6723 if(!player[i].isFlip()){
6724 player[i].throwtogglekeydown=1;
6725 setAnimation(i,removeknifeanim);
6726 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6728 if(player[i].isFlip()){
6729 player[i].throwtogglekeydown=1;
6730 player[i].hasvictim=0;
6732 for(int k=0;k<weapons.numweapons;k++){
6733 if(player[i].weaponactive==-1)
6734 if((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0||
6735 player[i].aitype==playercontrolled)&&
6736 weapons.owner[k]==-1||
6738 weapons.owner[k]==player[i].victim->id)
6739 if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&
6740 player[i].weaponactive==-1){
6741 if(weapons.type[k]!=staff)
6742 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6744 player[i].weaponactive=0;
6745 weapons.owner[k]=player[i].id;
6746 if(player[i].num_weapons>0)
6747 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6748 player[i].num_weapons++;
6749 player[i].weaponids[0]=k;
6756 if(player[i].isCrouch()||
6757 player[i].targetanimation==sneakanim||
6759 player[i].isIdle()||player[i].targetanimation==rollanim||
6760 player[i].targetanimation==backhandspringanim){
6762 for(int j=0;j<numplayers;j++){
6763 if(player[i].weaponactive==-1)
6765 if(player[j].num_weapons&&
6766 player[j].skeleton.free&&
6767 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6768 (((player[j].skeleton.forward.y<0&&
6769 player[j].weaponstuckwhere==0)||
6770 (player[j].skeleton.forward.y>0&&
6771 player[j].weaponstuckwhere==1))||
6772 player[j].weaponstuck==-1||
6773 player[j].num_weapons>1)){
6774 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6775 player[i].throwtogglekeydown=1;
6776 player[i].victim=&player[j];
6777 player[i].hasvictim=1;
6778 setAnimation(i,crouchremoveknifeanim);
6779 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6781 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6782 player[i].throwtogglekeydown=1;
6783 player[i].victim=&player[j];
6784 player[i].hasvictim=1;
6785 int k = player[j].weaponids[0];
6786 if(player[i].hasvictim){
6789 if(player[i].victim->weaponstuck!=-1){
6790 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6795 if(weapons.type[k]!=staff)
6796 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6799 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6801 player[i].weaponactive=0;
6802 if(weapons.owner[k]!=-1){
6803 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6804 else player[i].victim->num_weapons=1;
6806 player[i].victim->skeleton.longdead=0;
6807 player[i].victim->skeleton.free=1;
6808 player[i].victim->skeleton.broken=0;
6810 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6811 player[i].victim->skeleton.joints[l].velchange=0;
6812 player[i].victim->skeleton.joints[l].locked=0;
6818 Normalise(&relative);
6819 XYZ footvel,footpoint;
6821 footpoint=weapons.position[k];
6822 if(player[i].victim->weaponstuck!=-1){
6823 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6824 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6825 weapons.bloody[k]=2;
6826 weapons.blooddrip[k]=5;
6827 player[i].victim->weaponstuck=-1;
6828 player[i].victim->bloodloss+=2000;
6829 player[i].victim->DoDamage(2000);
6832 if(player[i].victim->num_weapons>0){
6833 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6834 if(player[i].victim->weaponids[0]==k)
6835 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6838 player[i].victim->weaponactive=-1;
6840 playerJoint(player[i].victim,abdomen).velocity+=relative*6;
6841 playerJoint(player[i].victim,neck).velocity+=relative*6;
6842 playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
6843 playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
6846 if(player[i].num_weapons>0){
6847 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6849 player[i].num_weapons++;
6850 player[i].weaponids[0]=k;
6857 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6858 if(weapons.type[player[i].weaponids[0]]==knife){
6859 if(player[i].isIdle()||
6861 player[i].isCrouch()||
6862 player[i].targetanimation==sneakanim||
6865 for(int j=0;j<numplayers;j++){
6867 if(tutoriallevel!=1||tutorialstage==49)
6869 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6870 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6871 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6872 !player[j].skeleton.free&&
6873 -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)){
6874 if(!player[i].isFlip()){
6875 player[i].throwtogglekeydown=1;
6876 player[i].victim=&player[j];
6877 setAnimation(i,knifethrowanim);
6878 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6879 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6881 if(player[i].isFlip()){
6882 if(player[i].weaponactive!=-1){
6883 player[i].throwtogglekeydown=1;
6884 player[i].victim=&player[j];
6886 weapons.owner[player[i].weaponids[0]]=-1;
6887 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);
6890 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6892 weapons.velocity[player[i].weaponids[0]]=aim*50;
6893 weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
6894 weapons.missed[player[i].weaponids[0]]=0;
6895 weapons.freetime[player[i].weaponids[0]]=0;
6896 weapons.firstfree[player[i].weaponids[0]]=1;
6897 weapons.physics[player[i].weaponids[0]]=0;
6898 player[i].num_weapons--;
6899 if(player[i].num_weapons){
6900 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6902 player[i].weaponactive=-1;
6909 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6910 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6911 player[i].throwtogglekeydown=1;
6912 weapons.owner[player[i].weaponids[0]]=-1;
6913 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
6914 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
6915 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
6916 weapons.missed[player[i].weaponids[0]]=1;
6917 weapons.freetime[player[i].weaponids[0]]=0;
6918 weapons.firstfree[player[i].weaponids[0]]=1;
6919 weapons.physics[player[i].weaponids[0]]=1;
6920 player[i].num_weapons--;
6921 if(player[i].num_weapons){
6922 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6923 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6926 player[i].weaponactive=-1;
6927 for(int j=0;j<numplayers;j++){
6928 player[j].wentforweapon=0;
6936 if(i==0||!player[0].dead||player[i].weaponactive!=-1)
6937 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6938 player[i].num_weapons==2&&
6939 player[i].weaponactive==-1&&
6940 player[i].isIdle()||
6942 player[i].weaponactive!=-1&&
6945 if(player[i].weaponactive!=-1)
6946 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)
6948 if(isgood&&player[i].creature!=wolftype){
6949 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6950 setAnimation(i,drawrightanim);
6951 player[i].drawtogglekeydown=1;
6953 if((player[i].isIdle()||
6954 (player[i].aitype!=playercontrolled&&
6955 player[0].weaponactive!=-1&&
6956 player[i].isRun()))&&
6957 player[i].num_weapons&&
6958 weapons.type[player[i].weaponids[0]]==sword){
6959 setAnimation(i,drawleftanim);
6960 player[i].drawtogglekeydown=1;
6962 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
6963 setAnimation(i,crouchdrawrightanim);
6964 player[i].drawtogglekeydown=1;
6969 if(player[i].isCrouch()&&
6970 weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
6972 player[i].onterrain&&
6973 player[i].num_weapons&&
6974 player[i].weaponactive!=-1&&
6975 player[i].attackkeydown){
6976 if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
6977 player[i].onterrain&&
6978 bloodtoggle&&musictype!=stream_fighttheme){
6979 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)
6980 setAnimation(i,crouchstabanim);
6981 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)
6982 setAnimation(i,swordgroundstabanim);
6983 player[i].hasvictim=0;
6984 //player[i].attacktogglekeydown=1;
6988 if(!player[i].drawkeydown)
6989 player[i].drawtogglekeydown=0;
6996 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
6998 else absflatfacing=flatfacing;
7001 player[i].forwardkeydown=0;
7002 player[i].leftkeydown=0;
7003 player[i].backkeydown=0;
7004 player[i].rightkeydown=0;
7005 player[i].jumpkeydown=0;
7006 player[i].crouchkeydown=0;
7007 player[i].drawkeydown=0;
7008 player[i].throwkeydown=0;
7012 if(!animation[player[i].targetanimation].attack&&
7013 player[i].targetanimation!=staggerbackhighanim&&
7014 player[i].targetanimation!=staggerbackhardanim&&
7015 player[i].targetanimation!=backhandspringanim&&
7016 player[i].targetanimation!=dodgebackanim){
7017 if(!player[i].forwardkeydown)
7018 player[i].forwardstogglekeydown=0;
7019 if(player[i].crouchkeydown){
7023 player[i].superruntoggle=1;
7025 for(int j=0;j<numplayers;j++)
7026 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7027 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7028 player[i].superruntoggle=0;
7032 for(int j=0;j<numplayers;j++){
7033 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7034 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7035 player[j].victim==&player[i]&&
7036 (player[j].targetanimation==sweepanim||
7037 player[j].targetanimation==upunchanim||
7038 player[j].targetanimation==wolfslapanim||
7039 ((player[j].targetanimation==swordslashanim||
7040 player[j].targetanimation==knifeslashstartanim||
7041 player[j].targetanimation==staffhitanim||
7042 player[j].targetanimation==staffspinhitanim)&&
7043 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7052 player[target].Reverse();
7053 player[i].lowreversaldelay=.5;
7055 if(player[i].isIdle()){
7056 setAnimation(i,player[i].getCrouch());
7057 player[i].transspeed=10;
7059 if(player[i].isRun()||
7060 (player[i].isStop()&&
7061 (player[i].leftkeydown||
7062 player[i].rightkeydown||
7063 player[i].forwardkeydown||
7064 player[i].backkeydown))){
7065 setAnimation(i,rollanim);
7066 player[i].transspeed=20;
7069 if(!player[i].crouchkeydown){
7071 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7073 if(player[i].isCrouch()){
7075 for(int j=0;j<numplayers;j++){
7077 !player[j].skeleton.free&&
7079 player[i].highreversaldelay<=0){
7080 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7081 player[j].victim==&player[i]&&
7082 (player[j].targetanimation==spinkickanim)&&
7083 player[i].isCrouch()){
7092 player[target].Reverse();
7093 player[i].highreversaldelay=.5;
7095 if(player[i].isCrouch()){
7096 if(!player[i].wasCrouch()){
7097 player[i].currentanimation=player[i].getCrouch();
7098 player[i].currentframe=0;
7100 setAnimation(i,player[i].getIdle());
7101 player[i].transspeed=10;
7104 if(player[i].targetanimation==sneakanim){
7105 setAnimation(i,player[i].getIdle());
7106 player[i].transspeed=10;
7109 if(player[i].forwardkeydown){
7110 if(player[i].isIdle()||
7111 (player[i].isStop()&&
7112 player[i].targetrotation==player[i].rotation)||
7113 (player[i].isLanding()&&
7114 player[i].targetframe>0&&
7115 !player[i].jumpkeydown)||
7116 (player[i].isLandhard()&&
7117 player[i].targetframe>0&&
7118 !player[i].jumpkeydown&&
7119 player[i].crouchkeydown)){
7120 if(player[i].aitype==passivetype)
7121 setAnimation(i,walkanim);
7123 setAnimation(i,player[i].getRun());
7125 if(player[i].isCrouch()){
7126 player[i].targetanimation=sneakanim;
7127 if(player[i].wasCrouch())
7129 player[i].targetframe=0;
7131 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7132 setAnimation(i,climbanim);
7133 player[i].targetframe=1;
7134 player[i].jumpclimb=1;
7136 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7137 player[i].velocity+=absflatfacing*5*multiplier;
7139 player[i].forwardstogglekeydown=1;
7142 if (player[i].rightkeydown){
7143 if(player[i].isIdle()||
7144 (player[i].isStop()&&
7145 player[i].targetrotation==player[i].rotation)||
7146 (player[i].isLanding()&&
7147 player[i].targetframe>0&&
7148 !player[i].jumpkeydown)||
7149 (player[i].isLandhard()&&
7150 player[i].targetframe>0&&
7151 !player[i].jumpkeydown&&
7152 player[i].crouchkeydown)){
7153 setAnimation(i,player[i].getRun());
7155 if(player[i].isCrouch()){
7156 player[i].targetanimation=sneakanim;
7157 if(player[i].wasCrouch())
7159 player[i].targetframe=0;
7161 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7162 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7164 player[i].targetrotation-=90;
7165 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7166 if(player[i].backkeydown)player[i].targetrotation-=45;
7169 if ( player[i].leftkeydown){
7170 if(player[i].isIdle()||
7171 (player[i].isStop()&&
7172 player[i].targetrotation==player[i].rotation)||
7173 (player[i].isLanding()&&
7174 player[i].targetframe>0&&
7175 !player[i].jumpkeydown)||
7176 (player[i].isLandhard()&&
7177 player[i].targetframe>0&&
7178 !player[i].jumpkeydown&&
7179 player[i].crouchkeydown)){
7180 setAnimation(i,player[i].getRun());
7182 if(player[i].isCrouch()){
7183 player[i].targetanimation=sneakanim;
7184 if(player[i].wasCrouch())
7186 player[i].targetframe=0;
7188 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7189 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7191 player[i].targetrotation+=90;
7192 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7193 if(player[i].backkeydown)player[i].targetrotation+=45;
7196 if(player[i].backkeydown){
7197 if(player[i].isIdle()||
7198 (player[i].isStop()&&
7199 player[i].targetrotation==player[i].rotation)||
7200 (player[i].isLanding()&&
7201 player[i].targetframe>0&&
7202 !player[i].jumpkeydown)||
7203 (player[i].isLandhard()&&
7204 player[i].targetframe>0&&
7205 !player[i].jumpkeydown&&
7206 player[i].crouchkeydown)){
7207 setAnimation(i,player[i].getRun());
7209 if(player[i].isCrouch()){
7210 player[i].targetanimation=sneakanim;
7211 if(player[i].wasCrouch())
7213 player[i].targetframe=0;
7215 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7216 player[i].velocity-=absflatfacing*5*multiplier;
7218 if(player[i].targetanimation==hanganim){
7219 player[i].currentanimation=jumpdownanim;
7220 player[i].targetanimation=jumpdownanim;
7222 player[i].currentframe=0;
7223 player[i].targetframe=1;
7224 player[i].velocity=0;
7225 player[i].velocity.y+=gravity;
7226 player[i].coords.y-=1.4;
7227 player[i].grabdelay=1;
7229 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7230 player[i].targetrotation+=180;
7233 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7234 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7236 player[i].targetanimation==walkanim||
7237 player[i].isCrouch()||
7238 player[i].targetanimation==sneakanim)&&
7239 player[i].jumppower>1)&&
7240 ((player[i].targetanimation!=rabbitrunninganim&&
7241 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7242 player[i].jumpstart=0;
7243 setAnimation(i,jumpupanim);
7244 player[i].rotation=player[i].targetrotation;
7245 player[i].transspeed=20;
7246 player[i].FootLand(0,1);
7247 player[i].FootLand(1,1);
7251 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7253 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7254 if(!movekey)player[i].velocity=0;
7259 for(int j=0;j<numplayers;j++){
7260 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7261 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7262 player[j].victim==&player[i]&&
7263 (player[j].targetanimation==sweepanim)){
7264 if(target>=0)target=-1;
7269 if(target>=0)player[i].velocity.y=1;
7270 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7271 player[i].velocity.y=7;
7272 player[i].crouchtogglekeydown=1;
7274 else player[i].velocity.y=5;
7276 if(mousejump&&i==0&&debugmode){
7277 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7278 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7281 player[i].coords.y+=.2;
7282 player[i].jumppower-=1;
7285 emit_sound_at(whooshsound, player[i].coords, 128.);
7287 emit_sound_at(jumpsound, player[i].coords, 128.);
7289 if((player[i].isIdle())&&player[i].jumppower>1){
7290 setAnimation(i,player[i].getLanding());
7291 player[i].targetframe=2;
7292 player[i].landhard=0;
7293 player[i].jumpstart=1;
7294 player[i].tempdeltav=deltav;
7296 if(player[i].targetanimation==jumpupanim&&
7300 player[i].aitype!=playercontrolled)){
7301 if(player[i].jumppower>multiplier*6){
7302 player[i].velocity.y+=multiplier*6;
7303 player[i].jumppower-=multiplier*6;
7305 if(player[i].jumppower<=multiplier*6){
7306 player[i].velocity.y+=player[i].jumppower;
7307 player[i].jumppower=0;
7310 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7314 if(player[i].isRun()||player[i].targetanimation==walkanim)
7315 setAnimation(i,player[i].getStop());
7316 if(player[i].targetanimation==sneakanim){
7317 player[i].targetanimation=player[i].getCrouch();
7318 if(player[i].currentanimation==sneakanim)
7320 player[i].targetframe=0;
7323 if(player[i].targetanimation==walkanim&&
7324 (player[i].aitype==attacktypecutoff||
7325 player[i].aitype==searchtype||
7326 (player[i].aitype==passivetype&&
7327 player[i].numwaypoints<=1)))
7328 setAnimation(i,player[i].getStop());
7329 if(player[i].isRun()&&(player[i].aitype==passivetype))
7330 setAnimation(i,player[i].getStop());
7333 if(player[i].targetanimation==rollanim)
7334 player[i].targetrotation=oldtargetrotation;
7338 for(int k=0;k<numplayers;k++){
7339 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7340 if(player[k].rotation>player[k].targetrotation)
7341 player[k].rotation-=360;
7343 player[k].rotation+=360;
7346 //stop to turn in right direction
7347 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7348 setAnimation(k,player[k].getStop());
7350 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7351 player[k].targettilt=0;
7353 if(player[k].targetanimation!=jumpupanim&&
7354 player[k].targetanimation!=backhandspringanim&&
7355 player[k].targetanimation!=jumpdownanim&&
7356 !player[k].isFlip()){
7357 player[k].targettilt=0;
7358 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7359 player[k].jumppower=0;
7360 player[k].jumppower+=multiplier*7;
7361 if(player[k].isCrouch())
7362 player[k].jumppower+=multiplier*7;
7363 if(player[k].jumppower>5)
7364 player[k].jumppower=5;
7367 if(player[k].isRun())
7368 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7370 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7371 player[k].grabdelay-=multiplier;
7375 for(int k=0;k<numplayers;k++){
7376 player[k].DoAnimations();
7377 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7378 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7384 for(int j=numenvsounds-1;j>=0;j--){
7385 envsoundlife[j]-=multiplier;
7386 if(envsoundlife[j]<0){
7388 envsoundlife[j]=envsoundlife[numenvsounds];
7389 envsound[j]=envsound[numenvsounds];
7393 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7395 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7397 if(tutoriallevel==1){
7414 if(tutorialstage>=51)
7415 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7416 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7417 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7419 emit_stream_np(stream_menutheme);
7428 if(tutorialstage<51)
7429 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7430 emit_sound_at(fireendsound, player[0].coords);
7432 player[0].coords=(oldtemp+oldtemp2)/2;
7436 if(tutorialstage>=14&&tutorialstage<50)
7437 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7438 emit_sound_at(fireendsound, player[1].coords);
7440 for(int i=0;i<player[1].skeleton.num_joints;i++){
7442 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7443 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7444 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;
7445 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7446 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7450 player[1].coords=(oldtemp+oldtemp2)/2;
7451 for(int i=0;i<player[1].skeleton.num_joints;i++){
7452 player[1].skeleton.joints[i].velocity=0;
7454 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7455 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7456 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;
7457 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7458 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7466 static float gLoc[3];
7470 static float vel[3];
7471 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7472 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7473 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7475 //Set orientation with forward and up vectors
7476 static XYZ upvector;
7480 upvector=DoRotation(upvector,-rotation2+90,0,0);
7481 upvector=DoRotation(upvector,0,0-rotation,0);
7486 facing=DoRotation(facing,-rotation2,0,0);
7487 facing=DoRotation(facing,0,0-rotation,0);
7490 static float ori[6];
7494 ori[3] = -upvector.x;
7495 ori[4] = upvector.y;
7496 ori[5] = -upvector.z;
7498 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7505 if(Input::isKeyPressed(SDLK_F1))
7509 void Game::TickOnce(){
7511 rotation+=multiplier*5;
7513 if(directing||indialogue==-1) {
7514 rotation+=deltah*.7;
7516 rotation2+=deltav*.7;
7518 rotation2-=deltav*.7;
7526 void Game::TickOnceAfter(){
7527 static XYZ colviewer;
7528 static XYZ coltarget;
7532 static float changedelay;
7533 static bool alldead;
7534 static float unseendelay;
7535 static float cameraspeed;
7539 if(environment==snowyenvironment)
7540 leveltheme=stream_snowtheme;
7541 if(environment==grassyenvironment)
7542 leveltheme=stream_grasstheme;
7543 if(environment==desertenvironment)
7544 leveltheme=stream_deserttheme;
7548 musictype=leveltheme;
7549 for(int i=0;i<numplayers;i++){
7550 if((player[i].aitype==attacktypecutoff||
7551 player[i].aitype==getweapontype||
7552 player[i].aitype==gethelptype||
7553 player[i].aitype==searchtype)&&
7554 !player[i].dead/*&&player[i].surprised<=0*/&&
7555 (player[i].targetanimation!=sneakattackedanim&&
7556 player[i].targetanimation!=knifesneakattackedanim&&
7557 player[i].targetanimation!=swordsneakattackedanim)){
7558 musictype=stream_fighttheme;
7563 musictype=stream_menutheme;
7566 if(musictype==stream_fighttheme)
7569 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7570 unseendelay-=multiplier;
7572 musictype=stream_fighttheme;
7577 musictype=stream_menutheme;
7585 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7586 emit_sound_np(alarmsound);
7587 musicselected=musictype;
7589 if(musicselected==leveltheme)
7590 musicvolume[0]+=multiplier*450;
7592 musicvolume[0]-=multiplier*450;
7593 if(musicselected==stream_fighttheme)
7594 musicvolume[1]+=multiplier*450;
7596 musicvolume[1]-=multiplier*450;
7597 if(musicselected==stream_menutheme)
7598 musicvolume[2]+=multiplier*450;
7600 musicvolume[2]-=multiplier*450;
7602 for(int i=0;i<3;i++){
7603 if(musicvolume[i]<0)
7605 if(musicvolume[i]>512)
7609 if(musicvolume[2]>128&&!loading&&!mainmenu)
7613 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7614 emit_stream_np(leveltheme, musicvolume[0]);
7615 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7616 emit_stream_np(stream_fighttheme, musicvolume[1]);
7617 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7618 emit_stream_np(stream_menutheme, musicvolume[2]);
7619 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7620 pause_sound(leveltheme);
7621 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7622 pause_sound(stream_fighttheme);
7623 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7624 pause_sound(stream_menutheme);
7626 if(musicvolume[0]!=oldmusicvolume[0])
7627 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7628 if(musicvolume[1]!=oldmusicvolume[1])
7629 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7630 if(musicvolume[2]!=oldmusicvolume[2])
7631 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7633 for(int i=0;i<3;i++)
7634 oldmusicvolume[i]=musicvolume[i];
7636 pause_sound(leveltheme);
7637 pause_sound(stream_fighttheme);
7638 pause_sound(stream_menutheme);
7640 for(int i=0;i<4;i++){
7641 oldmusicvolume[i]=0;
7647 for(int i=0;i<numhotspots;i++){
7648 if(hotspottype[i]>10&&hotspottype[i]<20){
7649 if(player[hotspottype[i]-10].dead==0)
7651 else if(killhotspot==2)
7660 for(int i=0;i<numhotspots;i++)
7661 if(hotspottype[i]==-1)
7662 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7666 for(int i=1;i<numplayers;i++)
7667 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7669 if(numalarmed>maxalarmed)
7670 maxalarmed=numalarmed;
7672 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7673 if(player[0].dead&&changedelay<=0){
7675 targetlevel=whichlevel;
7678 for(int i=1;i<numplayers;i++)
7679 if(!player[i].dead&&player[i].howactive<typedead1)
7683 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7685 targetlevel=whichlevel+1;
7686 if(targetlevel>numchallengelevels-1)targetlevel=0;
7688 if(winhotspot||windialogue){
7690 targetlevel=whichlevel+1;
7691 if(targetlevel>numchallengelevels-1)targetlevel=0;
7697 targetlevel=whichlevel+1;
7698 if(targetlevel>numchallengelevels-1)targetlevel=0;
7701 if(changedelay>0&&!player[0].dead&&!won) {
7702 //high scores, awards, win
7704 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7707 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7723 if(!editorenabled&&gameon&&!mainmenu){
7724 if(changedelay!=-999)
7725 changedelay-=multiplier/7;
7727 targetlevel=whichlevel;
7728 if(loading==2&&!campaign){
7731 fireSound(firestartsound);
7733 if(!player[0].dead&&targetlevel!=whichlevel)
7734 startbonustotal=bonustotal;
7736 Loadlevel(whichlevel);
7738 Loadlevel(targetlevel);
7744 if(loading==2&&targetlevel==whichlevel){
7748 fireSound(firestartsound);
7750 Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);
7756 if(changedelay<=-999&&
7760 (alldead&&maptype==mapkilleveryone)||
7765 if((player[0].dead||
7766 (alldead&&maptype==mapkilleveryone)||
7771 if(whichlevel!=-2&&!loading&&!player[0].dead){
7781 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)
7782 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0)
7784 else if(mainmenu==0&&winfreeze){
7785 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
7790 if(!stealthloading){
7791 fireSound(firestartsound);
7808 Loadlevel(campaignmapname[campaignchoicewhich[0]]);
7812 pause_sound(stream_menutheme);
7822 oldmusictype=musictype;
7828 facing=DoRotation(facing,-rotation2,0,0);
7829 facing=DoRotation(facing,0,0-rotation,0);
7830 viewerfacing=facing;
7833 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;
7834 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;
7836 if(player[0].skeleton.free){
7837 for(int i=0;i<player[0].skeleton.num_joints;i++){
7838 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7839 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7843 if(player[0].skeleton.free!=2&&!autocam){
7845 if(findLengthfast(&player[0].velocity)>400){
7846 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7848 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7849 coltarget=target-cameraloc;
7850 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7852 Normalise(&coltarget);
7853 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7854 else cameraloc=cameraloc+coltarget*multiplier*8;
7856 if(editorenabled)cameraloc=target;
7857 cameradist+=multiplier*5;
7858 if(cameradist>2.3)cameradist=2.3;
7859 viewer=cameraloc-facing*cameradist;
7861 coltarget=cameraloc;
7862 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7863 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7864 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7865 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7867 coltarget=cameraloc;
7868 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7870 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7871 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7872 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7874 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7878 cameradist=findDistance(&viewer,&target);
7879 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7880 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7881 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7884 if(player[0].skeleton.free!=2&&autocam){
7886 if(findLengthfast(&player[0].velocity)>400){
7887 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7889 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7890 cameradist+=multiplier*5;
7891 if(cameradist>3.3)cameradist=3.3;
7892 coltarget=target-cameraloc;
7893 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7894 else if(findLengthfast(&coltarget)>1)
7896 Normalise(&coltarget);
7897 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7898 else cameraloc=cameraloc+coltarget*multiplier*8;
7900 if(editorenabled)cameraloc=target;
7903 coltarget=cameraloc;
7904 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7905 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7906 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7907 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7909 coltarget=cameraloc;
7910 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7912 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7913 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7914 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7916 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7920 cameradist=findDistance(&viewer,&target);
7921 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7922 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7923 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7926 if(camerashake>.8)camerashake=.8;
7927 //if(woozy>10)woozy=10;
7928 //woozy+=multiplier;
7930 if(player[0].dead)camerashake=0;
7931 if(player[0].dead)woozy=0;
7932 camerashake-=multiplier*2;
7933 blackout-=multiplier*2;
7934 //if(player[0].isCrouch())woozy-=multiplier*8;
7935 if(camerashake<0)camerashake=0;
7936 if(blackout<0)blackout=0;
7937 //if(woozy<0)woozy=0;
7939 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7940 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7941 viewer.z+=(float)(Random()%100)*.0005*camerashake;