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>
32 #include "openal_wrapper.h"
35 #include "Animation.h"
40 // Added more evilness needed for MSVC
42 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
43 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
47 extern float multiplier;
49 extern int environment;
50 extern Terrain terrain;
51 extern float screenwidth,screenheight;
54 extern float texdetail;
55 extern Objects objects;
57 extern float slomodelay;
58 extern bool floatjump;
61 extern float camerashake;
63 extern float blackout;
64 extern bool cellophane;
65 extern bool musictoggle;
66 extern int difficulty;
67 extern int bloodtoggle;
68 extern bool invertmouse;
70 extern float precipdelay;
71 extern XYZ viewerfacing;
72 extern bool ambientsound;
73 extern bool mousejump;
74 extern float viewdistance;
76 extern bool keyboardfrozen;
77 extern bool loadingstuff;
78 extern XYZ windvector;
79 extern bool debugmode;
82 extern bool visibleloading;
83 extern XYZ envsound[30];
84 extern float envsoundvol[30];
85 extern int numenvsounds;
86 extern float envsoundlife[30];
87 extern float usermousesensitivity;
88 extern bool ismotionblur;
89 extern bool showdamagebar; // (des)activate the damage bar
91 extern float tintr,tintg,tintb;
92 extern bool skyboxtexture;
96 extern float skyboxlightr;
97 extern float skyboxlightg;
98 extern float skyboxlightb;
99 extern float fadestart;
100 extern float slomospeed;
101 extern float slomofreq;
102 extern int tutoriallevel;
103 extern float smoketex;
104 extern float tutorialstagetime;
105 extern int tutorialstage;
106 extern float tutorialmaxtime;
107 extern float tutorialsuccess;
108 extern bool againbonus;
109 extern bool reversaltrain;
110 extern bool canattack;
111 extern bool cananger;
112 extern float damagedealt;
114 extern int editoractive;
115 extern int editorpathtype;
117 extern float hostiletime;
119 extern bool gamestarted;
121 extern int numhotspots;
122 extern int winhotspot;
123 extern int windialogue;
124 extern int killhotspot;
125 extern XYZ hotspot[40];
126 extern int hotspottype[40];
127 extern float hotspotsize[40];
128 extern char hotspottext[40][256];
129 extern int currenthotspot;
133 extern bool stillloading;
134 extern bool winfreeze;
136 extern bool campaign;
138 static const char *rabbitskin[] = {
139 ":Data:Textures:Fur3.jpg",
140 ":Data:Textures:Fur.jpg",
141 ":Data:Textures:Fur2.jpg",
142 ":Data:Textures:Lynx.jpg",
143 ":Data:Textures:Otter.jpg",
144 ":Data:Textures:Opal.jpg",
145 ":Data:Textures:Sable.jpg",
146 ":Data:Textures:Chocolate.jpg",
147 ":Data:Textures:BW2.jpg",
148 ":Data:Textures:WB2.jpg"
151 static const char *wolfskin[] = {
152 ":Data:Textures:Wolf.jpg",
153 ":Data:Textures:Darkwolf.jpg",
154 ":Data:Textures:Snowwolf.jpg"
157 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
158 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
160 static const char **creatureskin[] = {rabbitskin, wolfskin};
162 /* Return true if PFX is a prefix of STR (case-insensitive). */
163 static bool stripfx(const char *str, const char *pfx)
165 return !strncasecmp(str, pfx, strlen(pfx));
168 static const char *cmd_names[] = {
169 #define DECLARE_COMMAND(cmd) #cmd " ",
170 #include "ConsoleCmds.h"
171 #undef DECLARE_COMMAND
174 typedef void (*console_handler)(Game *game, const char *args);
176 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
177 #include "ConsoleCmds.h"
178 #undef DECLARE_COMMAND
180 static console_handler cmd_handlers[] = {
181 #define DECLARE_COMMAND(cmd) ch_##cmd,
182 #include "ConsoleCmds.h"
183 #undef DECLARE_COMMAND
188 // added utility functions -sf17k =============================================================
190 //TODO: try to hide these variables completely with a better interface
191 inline void setAnimation(int playerid,int animation){
192 player[playerid].targetanimation=animation;
193 player[playerid].targetframe=0;
194 player[playerid].target=0;
197 //TODO: this is incorrect but I'm afraid to change it and break something,
198 //probably causes quirky behavior that I might want to preserve
199 inline float roughDirection(XYZ vec){
201 float angle=-asin(-vec.x)*180/M_PI;
206 inline float roughDirectionTo(XYZ start, XYZ end){
207 return roughDirection(end-start);
210 //TODO: gotta be a better way
211 inline float pitch(XYZ vec){
213 return -asin(vec.y)*180/M_PI;
215 inline float pitchTo(XYZ start, XYZ end){
216 return pitch(end-start);
219 //change these to a Person method
220 inline Joint& playerJoint(int playerid, int bodypart){
221 return player[playerid].skeleton.joints[player[playerid].skeleton.jointlabels[bodypart]]; }
222 inline Joint& playerJoint(Person* pplayer, int bodypart){
223 return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; }
225 inline float sq(float n){ return n*n; }
227 inline float stepTowardf(float from, float to, float by){
228 if(fabs(from-to)<by) return to;
229 else if(from>to) return from-by;
233 void playdialogueboxsound(){
235 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
236 temppos=temppos-viewer;
241 switch(dialogueboxsound[whichdialogue][indialogue]){
242 case -6: sound=alarmsound; break;
243 case -4: sound=consolefailsound; break;
244 case -3: sound=consolesuccesssound; break;
245 case -2: sound=firestartsound; break;
246 case -1: sound=fireendsound; break;
247 case 1: sound=rabbitchitter; break;
248 case 2: sound=rabbitchitter2; break;
249 case 3: sound=rabbitpainsound; break;
250 case 4: sound=rabbitpain1sound; break;
251 case 5: sound=rabbitattacksound; break;
252 case 6: sound=rabbitattack2sound; break;
253 case 7: sound=rabbitattack3sound; break;
254 case 8: sound=rabbitattack4sound; break;
255 case 9: sound=growlsound; break;
256 case 10: sound=growl2sound; break;
257 case 11: sound=snarlsound; break;
258 case 12: sound=snarl2sound; break;
259 case 13: sound=barksound; break;
260 case 14: sound=bark2sound; break;
261 case 15: sound=bark3sound; break;
262 case 16: sound=barkgrowlsound; break;
266 emit_sound_at(sound, temppos);
269 // end added utility functions ================================================================
273 static void ch_quit(Game *game, const char *args)
278 static void ch_map(Game *game, const char *args)
280 game->Loadlevel(args);
281 game->whichlevel = -2;
285 static void ch_save(Game *game, const char *args){
287 snprintf(buf, 63, ":Data:Maps:%s", args);
292 tfile=fopen( ConvertFileName(buf), "wb" );
293 fpackf(tfile, "Bi", mapvers);
294 fpackf(tfile, "Bi", maptype);
295 fpackf(tfile, "Bi", hostile);
296 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
297 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
298 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
299 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
300 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
301 if(player[0].num_weapons>0&&player[0].num_weapons<5)
302 for(int j=0;j<player[0].num_weapons;j++)
303 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
305 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
306 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
307 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
308 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
310 fpackf(tfile, "Bi", player[0].numclothes);
312 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
314 fpackf(tfile, "Bi", numdialogues);
316 for(int k=0;k<numdialogues;k++){
317 fpackf(tfile, "Bi", numdialogueboxes[k]);
318 fpackf(tfile, "Bi", dialoguetype[k]);
319 for(int l=0;l<10;l++){
320 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
321 fpackf(tfile, "Bf", participantrotation[k][l]);
323 for(int l=0;l<numdialogueboxes[k];l++){
324 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
325 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
326 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
327 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
328 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
330 int templength=strlen(dialoguetext[k][l]);
331 fpackf(tfile, "Bi",(templength));
332 for(int m=0;m<templength;m++){
333 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
334 if(dialoguetext[k][l][m]=='\0')
338 templength=strlen(dialoguename[k][l]);
339 fpackf(tfile, "Bi",templength);
340 for(int m=0;m<templength;m++){
341 fpackf(tfile, "Bb", dialoguename[k][l][m]);
342 if(dialoguename[k][l][m]=='\0')
346 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
347 fpackf(tfile, "Bi", participantfocus[k][l]);
348 fpackf(tfile, "Bi", participantaction[k][l]);
350 for(int m=0;m<10;m++)
351 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
353 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
357 for(int k=0;k<player[0].numclothes;k++){
358 int templength=strlen(player[0].clothes[k]);
359 fpackf(tfile, "Bi", templength);
360 for(int l=0;l<templength;l++)
361 fpackf(tfile, "Bb", player[0].clothes[k][l]);
362 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
365 fpackf(tfile, "Bi", environment);
367 fpackf(tfile, "Bi", objects.numobjects);
369 for(int k=0;k<objects.numobjects;k++)
370 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
371 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
373 fpackf(tfile, "Bi", numhotspots);
374 for(int i=0;i<numhotspots;i++){
375 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
376 int templength=strlen(hotspottext[i]);
377 fpackf(tfile, "Bi",templength);
378 for(int l=0;l<templength;l++)
379 fpackf(tfile, "Bb", hotspottext[i][l]);
382 fpackf(tfile, "Bi", numplayers);
383 if(numplayers<maxplayers)
384 for(int j=1;j<numplayers;j++){
385 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
386 player[j].coords.x, player[j].coords.y, player[j].coords.z,
387 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
388 if(player[j].num_weapons<5)
389 for(int k=0;k<player[j].num_weapons;k++)
390 fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
391 if(player[j].numwaypoints<30){
392 fpackf(tfile, "Bi", player[j].numwaypoints);
393 for(int k=0;k<player[j].numwaypoints;k++){
394 fpackf(tfile, "Bf", player[j].waypoints[k].x);
395 fpackf(tfile, "Bf", player[j].waypoints[k].y);
396 fpackf(tfile, "Bf", player[j].waypoints[k].z);
397 fpackf(tfile, "Bi", player[j].waypointtype[k]);
399 fpackf(tfile, "Bi", player[j].waypoint);
401 player[j].numwaypoints=0;
402 player[j].waypoint=0;
403 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
406 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
407 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
408 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
409 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
411 float headprop, bodyprop, armprop, legprop;
412 if(player[j].creature==wolftype){
413 headprop=player[j].proportionhead.x/1.1;
414 bodyprop=player[j].proportionbody.x/1.1;
415 armprop=player[j].proportionarms.x/1.1;
416 legprop=player[j].proportionlegs.x/1.1;
417 }else if(player[j].creature==rabbittype){
418 headprop=player[j].proportionhead.x/1.2;
419 bodyprop=player[j].proportionbody.x/1.05;
420 armprop=player[j].proportionarms.x/1.00;
421 legprop=player[j].proportionlegs.x/1.1;
424 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
426 fpackf(tfile, "Bi", player[j].numclothes);
427 if(player[j].numclothes)
428 for(int k=0;k<player[j].numclothes;k++){
430 templength=strlen(player[j].clothes[k]);
431 fpackf(tfile, "Bi", templength);
432 for(int l=0;l<templength;l++)
433 fpackf(tfile, "Bb", player[j].clothes[k][l]);
434 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
438 fpackf(tfile, "Bi", game->numpathpoints);
439 for(int j=0;j<game->numpathpoints;j++){
440 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
441 for(int k=0;k<game->numpathpointconnect[j];k++)
442 fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
445 fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
450 static void ch_cellar(Game *game, const char *args)
452 game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
455 static void ch_tint(Game *game, const char *args)
457 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
460 static void ch_tintr(Game *game, const char *args)
465 static void ch_tintg(Game *game, const char *args)
470 static void ch_tintb(Game *game, const char *args)
475 static void ch_speed(Game *game, const char *args)
477 player[0].speedmult = atof(args);
480 static void ch_strength(Game *game, const char *args)
482 player[0].power = atof(args);
485 static void ch_power(Game *game, const char *args)
487 player[0].power = atof(args);
490 static void ch_size(Game *game, const char *args)
492 player[0].scale = atof(args) * .2;
495 static int find_closest()
498 float closestdist = 1.0/0.0;
500 for (int i = 1; i < numplayers; i++) {
502 distance = findDistancefast(&player[i].coords,&player[0].coords);
503 if (distance < closestdist) {
504 closestdist = distance;
511 static void ch_sizenear(Game *game, const char *args)
513 int closest = find_closest();
516 player[closest].scale = atof(args) * .2;
519 static void set_proportion(int pnum, const char *args)
521 float headprop,bodyprop,armprop,legprop;
523 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
525 if(player[pnum].creature==wolftype){
526 player[pnum].proportionhead=1.1*headprop;
527 player[pnum].proportionbody=1.1*bodyprop;
528 player[pnum].proportionarms=1.1*armprop;
529 player[pnum].proportionlegs=1.1*legprop;
530 } else if(player[pnum].creature==rabbittype){
531 player[pnum].proportionhead=1.2*headprop;
532 player[pnum].proportionbody=1.05*bodyprop;
533 player[pnum].proportionarms=1.00*armprop;
534 player[pnum].proportionlegs=1.1*legprop;
535 player[pnum].proportionlegs.y=1.05*legprop;
539 static void ch_proportion(Game *game, const char *args)
541 set_proportion(0, args);
544 static void ch_proportionnear(Game *game, const char *args)
546 int closest = find_closest();
548 set_proportion(closest, args);
551 static void set_protection(int pnum, const char *args)
553 float head, high, low;
554 sscanf(args, "%f%f%f", &head, &high, &low);
556 player[pnum].protectionhead = head;
557 player[pnum].protectionhigh = high;
558 player[pnum].protectionlow = low;
561 static void ch_protection(Game *game, const char *args)
563 set_protection(0, args);
566 static void ch_protectionnear(Game *game, const char *args)
568 int closest = find_closest();
570 set_protection(closest, args);
573 static void set_armor(int pnum, const char *args)
575 float head, high, low;
576 sscanf(args, "%f%f%f", &head, &high, &low);
578 player[pnum].armorhead = head;
579 player[pnum].armorhigh = high;
580 player[pnum].armorlow = low;
583 static void ch_armor(Game *game, const char *args)
588 static void ch_armornear(Game *game, const char *args)
590 int closest = find_closest();
592 set_armor(closest, args);
595 static void ch_protectionreset(Game *game, const char *args)
597 set_protection(0, "1 1 1");
598 set_armor(0, "1 1 1");
601 static void set_metal(int pnum, const char *args)
603 float head, high, low;
604 sscanf(args, "%f%f%f", &head, &high, &low);
606 player[pnum].metalhead = head;
607 player[pnum].metalhigh = high;
608 player[pnum].metallow = low;
611 static void ch_metal(Game *game, const char *args)
616 static void set_noclothes(int pnum, Game *game, const char *args)
618 player[pnum].numclothes = 0;
619 game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
620 &player[pnum].skeleton.drawmodel.textureptr,1,
621 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
624 static void ch_noclothes(Game *game, const char *args)
626 set_noclothes(0, game, args);
629 static void ch_noclothesnear(Game *game, const char *args)
631 int closest = find_closest();
633 set_noclothes(closest, game, args);
637 static void set_clothes(int pnum, Game *game, const char *args)
640 snprintf(buf, 63, ":Data:Textures:%s.png", args);
642 if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
645 player[pnum].DoMipmaps();
646 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
647 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
648 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
649 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
650 player[pnum].numclothes++;
653 static void ch_clothes(Game *game, const char *args)
655 set_clothes(0, game, args);
658 static void ch_clothesnear(Game *game, const char *args)
660 int closest = find_closest();
662 set_clothes(closest, game, args);
665 static void ch_belt(Game *game, const char *args)
667 player[0].skeleton.clothes = !player[0].skeleton.clothes;
671 static void ch_cellophane(Game *game, const char *args)
673 cellophane = !cellophane;
674 float mul = cellophane ? 0 : 1;
676 for (int i = 0; i < numplayers; i++) {
677 player[i].proportionhead.z = player[i].proportionhead.x * mul;
678 player[i].proportionbody.z = player[i].proportionbody.x * mul;
679 player[i].proportionarms.z = player[i].proportionarms.x * mul;
680 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
684 static void ch_funnybunny(Game *game, const char *args)
686 player[0].skeleton.id=0;
687 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
688 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
689 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
690 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
691 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
692 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
693 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
694 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
695 player[0].creature=rabbittype;
697 player[0].headless=0;
698 player[0].damagetolerance=200;
699 set_proportion(0, "1 1 1 1");
702 static void ch_wolfie(Game *game, const char *args)
704 player[0].skeleton.id=0;
705 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
706 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
707 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
708 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
709 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
710 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
711 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
712 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
713 player[0].creature=wolftype;
714 player[0].damagetolerance=300;
715 set_proportion(0, "1 1 1 1");
718 static void ch_wolfieisgod(Game *game, const char *args)
720 ch_wolfie(game, args);
723 static void ch_wolf(Game *game, const char *args)
725 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
726 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
729 static void ch_snowwolf(Game *game, const char *args)
731 game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
732 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
735 static void ch_darkwolf(Game *game, const char *args)
737 game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
738 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
741 static void ch_lizardwolf(Game *game, const char *args)
743 game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
744 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
747 static void ch_white(Game *game, const char *args)
749 game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
750 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
753 static void ch_brown(Game *game, const char *args)
755 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
756 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
759 static void ch_black(Game *game, const char *args)
761 game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
762 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
765 static void ch_sizemin(Game *game, const char *args)
767 for (int i = 1; i < numplayers; i++)
768 if (player[i].scale < 0.8 * 0.2)
769 player[i].scale = 0.8 * 0.2;
772 static void ch_tutorial(Game *game, const char *args)
774 tutoriallevel = atoi(args);
777 static void ch_hostile(Game *game, const char *args)
779 hostile = atoi(args);
782 static void ch_indemo(Game *game, const char *args)
785 hotspot[numhotspots]=player[0].coords;
786 hotspotsize[numhotspots]=0;
787 hotspottype[numhotspots]=-111;
788 strcpy(hotspottext[numhotspots],"mapname");
792 static void ch_notindemo(Game *game, const char *args)
798 static void ch_type(Game *game, const char *args)
800 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
801 for (int i = 0; i < n; i++)
802 if (stripfx(args, editortypenames[i])) {
808 static void ch_path(Game *game, const char *args)
810 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
811 for (int i = 0; i < n; i++)
812 if (stripfx(args, pathtypenames[i])) {
818 static void ch_hs(Game *game, const char *args)
820 hotspot[numhotspots]=player[0].coords;
824 sscanf(args, "%f%d %n", &size, &type, &shift);
826 hotspotsize[numhotspots] = size;
827 hotspottype[numhotspots] = type;
829 strcpy(hotspottext[numhotspots], args + shift);
830 strcat(hotspottext[numhotspots], "\n");
835 static void ch_dialogue(Game *game, const char *args)
838 char buf1[32], buf2[64];
840 sscanf(args, "%d %31s", &dlg, buf1);
841 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
843 dialoguetype[numdialogues] = dlg;
845 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
846 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
848 ifstream ipstream(ConvertFileName(buf2));
849 ipstream.ignore(256,':');
850 ipstream >> numdialogueboxes[numdialogues];
851 for(int i=0;i<numdialogueboxes[numdialogues];i++){
852 ipstream.ignore(256,':');
853 ipstream.ignore(256,':');
854 ipstream.ignore(256,' ');
855 ipstream >> dialogueboxlocation[numdialogues][i];
856 ipstream.ignore(256,':');
857 ipstream >> dialogueboxcolor[numdialogues][i][0];
858 ipstream >> dialogueboxcolor[numdialogues][i][1];
859 ipstream >> dialogueboxcolor[numdialogues][i][2];
860 ipstream.ignore(256,':');
861 ipstream.getline(dialoguename[numdialogues][i],64);
862 ipstream.ignore(256,':');
863 ipstream.ignore(256,' ');
864 ipstream.getline(dialoguetext[numdialogues][i],128);
865 for(int j=0;j<128;j++){
866 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
868 ipstream.ignore(256,':');
869 ipstream >> dialogueboxsound[numdialogues][i];
872 for(int i=0;i<numdialogueboxes[numdialogues];i++){
873 for(int j=0;j<numplayers;j++){
874 participantfacing[numdialogues][i][j]=player[j].facing;
881 whichdialogue=numdialogues;
886 static void ch_fixdialogue(Game *game, const char *args)
888 char buf1[32], buf2[64];
891 sscanf(args, "%d %31s", &whichdi, buf1);
892 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
894 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
895 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
897 ifstream ipstream(ConvertFileName(buf2));
898 ipstream.ignore(256,':');
899 ipstream >> numdialogueboxes[whichdi];
900 for(int i=0;i<numdialogueboxes[whichdi];i++){
901 ipstream.ignore(256,':');
902 ipstream.ignore(256,':');
903 ipstream.ignore(256,' ');
904 ipstream >> dialogueboxlocation[whichdi][i];
905 ipstream.ignore(256,':');
906 ipstream >> dialogueboxcolor[whichdi][i][0];
907 ipstream >> dialogueboxcolor[whichdi][i][1];
908 ipstream >> dialogueboxcolor[whichdi][i][2];
909 ipstream.ignore(256,':');
910 ipstream.getline(dialoguename[whichdi][i],64);
911 ipstream.ignore(256,':');
912 ipstream.ignore(256,' ');
913 ipstream.getline(dialoguetext[whichdi][i],128);
914 for(int j=0;j<128;j++){
915 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
917 ipstream.ignore(256,':');
918 ipstream >> dialogueboxsound[whichdi][i];
924 static void ch_fixtype(Game *game, const char *args)
927 sscanf(args, "%d", &dlg);
928 dialoguetype[0] = dlg;
931 static void ch_fixrotation(Game *game, const char *args)
933 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
936 static void ch_ddialogue(Game *game, const char *args)
942 static void ch_dhs(Game *game, const char *args)
948 static void ch_immobile(Game *game, const char *args)
950 player[0].immobile = 1;
953 static void ch_allimmobile(Game *game, const char *args)
955 for (int i = 1; i < numplayers; i++)
956 player[i].immobile = 1;
959 static void ch_mobile(Game *game, const char *args)
961 player[0].immobile = 0;
964 static void ch_default(Game *game, const char *args)
966 player[0].armorhead=1;
967 player[0].armorhigh=1;
968 player[0].armorlow=1;
969 player[0].protectionhead=1;
970 player[0].protectionhigh=1;
971 player[0].protectionlow=1;
972 player[0].metalhead=1;
973 player[0].metalhigh=1;
974 player[0].metallow=1;
976 player[0].speedmult=1;
979 if(player[0].creature==wolftype){
980 player[0].proportionhead=1.1;
981 player[0].proportionbody=1.1;
982 player[0].proportionarms=1.1;
983 player[0].proportionlegs=1.1;
984 } else if(player[0].creature==rabbittype){
985 player[0].proportionhead=1.2;
986 player[0].proportionbody=1.05;
987 player[0].proportionarms=1.00;
988 player[0].proportionlegs=1.1;
989 player[0].proportionlegs.y=1.05;
992 player[0].numclothes=0;
993 game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
994 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
995 &player[0].skeleton.skinsize);
997 editoractive=typeactive;
998 player[0].immobile=0;
1001 static void ch_play(Game *game, const char *args)
1004 sscanf(args, "%d", &dlg);
1005 whichdialogue = dlg;
1007 if (whichdialogue >= numdialogues)
1010 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1011 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1012 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1013 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1014 player[participantfocus[whichdialogue][i]].velocity=0;
1015 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1016 player[participantfocus[whichdialogue][i]].targetframe=0;
1022 playdialogueboxsound();
1025 static void ch_mapkilleveryone(Game *game, const char *args)
1027 maptype = mapkilleveryone;
1030 static void ch_mapkillmost(Game *game, const char *args)
1032 maptype = mapkillmost;
1035 static void ch_mapkillsomeone(Game *game, const char *args)
1037 maptype = mapkillsomeone;
1040 static void ch_mapgosomewhere(Game *game, const char *args)
1042 maptype = mapgosomewhere;
1045 static void ch_viewdistance(Game *game, const char *args)
1047 viewdistance = atof(args)*100;
1050 static void ch_fadestart(Game *game, const char *args)
1052 fadestart = atof(args);
1055 static void ch_slomo(Game *game, const char *args)
1057 slomospeed = atof(args);
1062 static void ch_slofreq(Game *game, const char *args)
1064 slomofreq = atof(args);
1067 static void ch_skytint(Game *game, const char *args)
1069 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1071 skyboxlightr=skyboxr;
1072 skyboxlightg=skyboxg;
1073 skyboxlightb=skyboxb;
1075 game->SetUpLighting();
1077 terrain.DoShadows();
1078 objects.DoShadows();
1081 static void ch_skylight(Game *game, const char *args)
1083 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1085 game->SetUpLighting();
1087 terrain.DoShadows();
1088 objects.DoShadows();
1091 static void ch_skybox(Game *game, const char *args)
1093 skyboxtexture = !skyboxtexture;
1095 game->SetUpLighting();
1097 terrain.DoShadows();
1098 objects.DoShadows();
1101 static void cmd_dispatch(Game *game, const char *cmd)
1103 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1105 for (i = 0; i < n_cmds; i++)
1106 if (stripfx(cmd, cmd_names[i]))
1108 cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
1111 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1114 /********************> Tick() <*****/
1115 extern bool save_image(const char * fname);
1116 void Screenshot (void)
1119 time_t t = time(NULL);
1120 struct tm *tme = localtime(&t);
1121 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);
1124 mkdir("Screenshots");
1126 mkdir("Screenshots", S_IRWXU);
1134 void Game::SetUpLighting(){
1135 if(environment==snowyenvironment)
1136 light.setColors(.65,.65,.7,.4,.4,.44);
1137 if(environment==desertenvironment)
1138 light.setColors(.95,.95,.95,.4,.35,.3);
1139 if(environment==grassyenvironment)
1140 light.setColors(.95,.95,1,.4,.4,.44);
1142 light.setColors(1,1,1,.4,.4,.4);
1144 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1145 light.color[0]*=(skyboxlightr+average)/2;
1146 light.color[1]*=(skyboxlightg+average)/2;
1147 light.color[2]*=(skyboxlightb+average)/2;
1148 light.ambient[0]*=(skyboxlightr+average)/2;
1149 light.ambient[1]*=(skyboxlightg+average)/2;
1150 light.ambient[2]*=(skyboxlightb+average)/2;
1153 int Game::findPathDist(int start,int end){
1154 int smallestcount,count,connected;
1155 int last,last2,last3,last4;
1159 for(int i=0;i<50;i++){
1165 while(last!=end&&count<30){
1167 for(int j=0;j<numpathpoints;j++){
1168 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1171 if(numpathpointconnect[j])
1172 for(int k=0;k<numpathpointconnect[j];k++){
1173 if(pathpointconnect[j][k]==last)connected=1;
1176 if(numpathpointconnect[last])
1177 for(int k=0;k<numpathpointconnect[last];k++){
1178 if(pathpointconnect[last][k]==j)connected=1;
1181 if(closest==-1||Random()%2==0){
1192 if(count<smallestcount)smallestcount=count;
1194 return smallestcount;
1197 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1198 static XYZ colpoint,colviewer,coltarget;
1199 static float minx,minz,maxx,maxz,miny,maxy;
1201 minx=min(startpoint.x,endpoint.x)-1;
1202 miny=min(startpoint.y,endpoint.y)-1;
1203 minz=min(startpoint.z,endpoint.z)-1;
1204 maxx=max(startpoint.x,endpoint.x)+1;
1205 maxy=max(startpoint.y,endpoint.y)+1;
1206 maxz=max(startpoint.z,endpoint.z)+1;
1208 for(int i=0;i<objects.numobjects;i++){
1209 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1210 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1211 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1212 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1213 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1214 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1215 if( objects.type[i]!=treeleavestype&&
1216 objects.type[i]!=bushtype&&
1217 objects.type[i]!=firetype){
1218 colviewer=startpoint;
1220 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1225 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1230 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1231 static XYZ colpoint,colviewer,coltarget;
1232 static float minx,minz,maxx,maxz,miny,maxy;
1233 static int i; //FIXME: see below
1235 minx=min(startpoint.x,endpoint.x)-1;
1236 miny=min(startpoint.y,endpoint.y)-1;
1237 minz=min(startpoint.z,endpoint.z)-1;
1238 maxx=max(startpoint.x,endpoint.x)+1;
1239 maxy=max(startpoint.y,endpoint.y)+1;
1240 maxz=max(startpoint.z,endpoint.z)+1;
1243 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1244 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1245 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1246 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1247 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1248 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1249 if( objects.type[what]!=treeleavestype&&
1250 objects.type[what]!=bushtype&&
1251 objects.type[what]!=firetype){
1252 colviewer=startpoint;
1255 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1260 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1265 void Game::Setenvironment(int which)
1269 LOG(" Setting environment...");
1271 float temptexdetail;
1274 pause_sound(stream_music1snow);
1275 pause_sound(stream_music1grass);
1276 pause_sound(stream_music1desert);
1277 pause_sound(stream_wind);
1278 pause_sound(stream_desertambient);
1281 if(environment==snowyenvironment){
1285 emit_stream_np(stream_wind);
1287 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1288 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1289 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1290 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1292 footstepsound = footstepsn1;
1293 footstepsound2 = footstepsn2;
1294 footstepsound3 = footstepst1;
1295 footstepsound4 = footstepst2;
1297 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1299 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1301 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1306 temptexdetail=texdetail;
1307 if(texdetail>1)texdetail=4;
1308 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1309 ":Data:Textures:Skybox(snow):Left.jpg",
1310 ":Data:Textures:Skybox(snow):Back.jpg",
1311 ":Data:Textures:Skybox(snow):Right.jpg",
1312 ":Data:Textures:Skybox(snow):Up.jpg",
1313 ":Data:Textures:Skybox(snow):Down.jpg");
1318 texdetail=temptexdetail;
1320 if(environment==desertenvironment){
1323 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1324 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1325 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1326 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1330 emit_stream_np(stream_desertambient);
1332 footstepsound = footstepsn1;
1333 footstepsound2 = footstepsn2;
1334 footstepsound3 = footstepsn1;
1335 footstepsound4 = footstepsn2;
1337 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1339 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1341 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1345 temptexdetail=texdetail;
1346 if(texdetail>1)texdetail=4;
1347 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1348 ":Data:Textures:Skybox(sand):Left.jpg",
1349 ":Data:Textures:Skybox(sand):Back.jpg",
1350 ":Data:Textures:Skybox(sand):Right.jpg",
1351 ":Data:Textures:Skybox(sand):Up.jpg",
1352 ":Data:Textures:Skybox(sand):Down.jpg");
1357 texdetail=temptexdetail;
1359 if(environment==grassyenvironment){
1362 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1363 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1364 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1365 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1368 emit_stream_np(stream_wind, 100.);
1370 footstepsound = footstepgr1;
1371 footstepsound2 = footstepgr2;
1372 footstepsound3 = footstepst1;
1373 footstepsound4 = footstepst2;
1375 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1377 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1379 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1383 temptexdetail=texdetail;
1384 if(texdetail>1)texdetail=4;
1385 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1386 ":Data:Textures:Skybox(grass):Left.jpg",
1387 ":Data:Textures:Skybox(grass):Back.jpg",
1388 ":Data:Textures:Skybox(grass):Right.jpg",
1389 ":Data:Textures:Skybox(grass):Up.jpg",
1390 ":Data:Textures:Skybox(grass):Down.jpg");
1394 texdetail=temptexdetail;
1396 temptexdetail=texdetail;
1398 terrain.load(":Data:Textures:heightmap.png");
1400 texdetail=temptexdetail;
1404 void Game::Loadlevel(int which){
1410 Loadlevel("tutorial");
1411 } else if (which >= 0 && which <= 15) {
1413 snprintf(buf, 32, "map%d", which + 1);
1416 Loadlevel("mapsave");
1419 void Game::Loadlevel(const char *name){
1420 static int oldlevel;
1424 static const char *pfx = ":Data:Maps:";
1427 float headprop,legprop,armprop,bodyprop;
1431 LOG(std::string("Loading level...") + name);
1443 if(tutoriallevel!=-1)
1448 if(tutoriallevel==1)
1450 if(tutorialstage==0){
1451 tutorialstagetime=0;
1457 pause_sound(whooshsound);
1458 pause_sound(stream_firesound);
1460 // Change the map filename into something that is os specific
1461 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1462 sprintf(buf, "%s%s", pfx, name);
1463 const char *FixedFN = ConvertFileName(buf);
1467 tfile=fopen( FixedFN, "rb" );
1469 pause_sound(stream_firesound);
1475 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1479 for(int i=0;i<20;i++)
1480 dialoguegonethrough[i]=0;
1489 difficulty=accountactive->getDifficulty();
1508 for(int i=0;i<100;i++)
1528 bonustotal=startbonustotal;
1533 emit_sound_np(consolesuccesssound);
1538 if(!stealthloading){
1539 terrain.numdecals=0;
1540 Sprite::deleteSprites();
1541 for(int i=0;i<objects.numobjects;i++)
1542 objects.model[i].numdecals=0;
1544 int j=objects.numobjects;
1545 for(int i=0;i<j;i++){
1546 objects.DeleteObject(0);
1551 for(int i=0;i<subdivision;i++)
1552 for(int j=0;j<subdivision;j++)
1553 terrain.patchobjectnum[i][j]=0;
1558 weapons.numweapons=0;
1560 funpackf(tfile, "Bi", &mapvers);
1562 funpackf(tfile, "Bi", &indemo);
1566 funpackf(tfile, "Bi", &maptype);
1568 maptype=mapkilleveryone;
1570 funpackf(tfile, "Bi", &hostile);
1574 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1580 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1588 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1590 skyboxlightr=skyboxr;
1591 skyboxlightg=skyboxg;
1592 skyboxlightb=skyboxb;
1595 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);
1597 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1598 player[0].originalcoords=player[0].coords;
1599 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1600 for(int j=0;j<player[0].num_weapons;j++){
1601 player[0].weaponids[j]=weapons.numweapons;
1602 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1603 weapons.owner[weapons.numweapons]=0;
1604 weapons.numweapons++;
1610 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1611 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1612 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1613 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1615 funpackf(tfile, "Bi", &player[0].numclothes);
1618 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1620 player[0].whichskin=0;
1621 player[0].creature=rabbittype;
1624 player[0].lastattack=-1;
1625 player[0].lastattack2=-1;
1626 player[0].lastattack3=-1;
1630 funpackf(tfile, "Bi", &numdialogues);
1631 for(int k=0;k<numdialogues;k++){
1632 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1633 funpackf(tfile, "Bi", &dialoguetype[k]);
1634 for(int l=0;l<10;l++){
1635 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1636 funpackf(tfile, "Bf", &participantrotation[k][l]);
1638 for(int l=0;l<numdialogueboxes[k];l++){
1639 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1640 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1641 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1642 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1643 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1647 funpackf(tfile, "Bi",&templength);
1648 if(templength>128||templength<=0)
1651 for(m=0;m<templength;m++){
1652 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1653 if(dialoguetext[k][l][m]=='\0')
1656 dialoguetext[k][l][m] = 0;
1658 funpackf(tfile, "Bi",&templength);
1659 if(templength>64||templength<=0)templength=64;
1660 for(m=0;m<templength;m++){
1661 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1662 if(dialoguename[k][l][m]=='\0')
1665 dialoguename[k][l][m] = 0;
1666 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1667 funpackf(tfile, "Bi", &participantfocus[k][l]);
1668 funpackf(tfile, "Bi", &participantaction[k][l]);
1671 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1673 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1679 for(int k=0;k<player[0].numclothes;k++){
1680 funpackf(tfile, "Bi", &templength);
1681 for(int l=0;l<templength;l++)
1682 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1683 player[0].clothes[k][templength]='\0';
1684 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1687 funpackf(tfile, "Bi", &environment);
1689 funpackf(tfile, "Bi", &objects.numobjects);
1690 for(int i=0;i<objects.numobjects;i++){
1691 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]);
1692 if(objects.type[i]==treeleavestype)
1693 objects.scale[i]=objects.scale[i-1];
1697 funpackf(tfile, "Bi", &numhotspots);
1698 for(int i=0;i<numhotspots;i++){
1699 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1700 funpackf(tfile, "Bi", &templength);
1702 for(int l=0;l<templength;l++)
1703 funpackf(tfile, "Bb", &hotspottext[i][l]);
1704 hotspottext[i][templength]='\0';
1705 if(hotspottype[i]==-111)
1714 if(!stealthloading){
1716 for(int i=0;i<objects.numobjects;i++)
1717 objects.center+=objects.position[i];
1718 objects.center/=objects.numobjects;
1724 float maxdistance=0;
1727 for(int i=0;i<objects.numobjects;i++){
1728 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1729 if(tempdist>maxdistance){
1731 maxdistance=tempdist;
1734 objects.radius=fast_sqrt(maxdistance);
1739 //mapcenter=objects.center;
1740 //mapradius=objects.radius;
1742 funpackf(tfile, "Bi", &numplayers);
1743 int howmanyremoved=0;
1744 bool removeanother=0;
1745 if(numplayers>1&&numplayers<maxplayers){
1746 for(int i=1;i<numplayers;i++){
1751 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);
1753 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1755 player[i-howmanyremoved].howactive=typeactive;
1757 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1759 player[i-howmanyremoved].scale=-1;
1761 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1763 player[i-howmanyremoved].immobile=0;
1765 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1767 player[i-howmanyremoved].rotation=0;
1768 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1769 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1774 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1775 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1776 player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1777 funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1778 weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1779 weapons.numweapons++;
1782 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1783 //player[i-howmanyremoved].numwaypoints=10;
1784 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1785 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1786 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1787 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1789 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1791 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1794 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1795 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1796 player[i-howmanyremoved].waypoint=0;
1798 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1799 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1800 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1801 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1804 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1811 if(player[i-howmanyremoved].creature==wolftype){
1812 player[i-howmanyremoved].proportionhead=1.1*headprop;
1813 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1814 player[i-howmanyremoved].proportionarms=1.1*armprop;
1815 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1818 if(player[i-howmanyremoved].creature==rabbittype){
1819 player[i-howmanyremoved].proportionhead=1.2*headprop;
1820 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1821 player[i-howmanyremoved].proportionarms=1.00*armprop;
1822 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1823 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1826 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1827 if(player[i-howmanyremoved].numclothes){
1828 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1830 funpackf(tfile, "Bi", &templength);
1831 for(int l=0;l<templength;l++)
1832 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1833 player[i-howmanyremoved].clothes[k][templength]='\0';
1834 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1843 numplayers-=howmanyremoved;
1844 funpackf(tfile, "Bi", &numpathpoints);
1845 if(numpathpoints>30||numpathpoints<0)
1847 for(int j=0;j<numpathpoints;j++){
1848 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1849 for(int k=0;k<numpathpointconnect[j];k++){
1850 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1856 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1859 if(environment!=oldenvironment)
1860 Setenvironment(environment);
1861 oldenvironment=environment;
1863 if(!stealthloading){
1864 int j=objects.numobjects;
1865 objects.numobjects=0;
1866 for(int i=0;i<j;i++){
1867 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1872 terrain.DoShadows();
1875 objects.DoShadows();
1882 oldlevel=whichlevel;
1885 if(numplayers>maxplayers-1)
1886 numplayers=maxplayers-1;
1887 for(int i=0;i<numplayers;i++){
1893 if(i==0||player[i].scale<0)
1895 player[i].skeleton.free=0;
1896 player[i].skeleton.id=i;
1898 player[i].creature=rabbittype;
1899 if(player[i].creature!=wolftype){
1900 player[i].skeleton.Load(
1901 (char *)":Data:Skeleton:Basic Figure",
1902 (char *)":Data:Skeleton:Basic Figurelow",
1903 (char *)":Data:Skeleton:Rabbitbelt",
1904 (char *)":Data:Models:Body.solid",
1905 (char *)":Data:Models:Body2.solid",
1906 (char *)":Data:Models:Body3.solid",
1907 (char *)":Data:Models:Body4.solid",
1908 (char *)":Data:Models:Body5.solid",
1909 (char *)":Data:Models:Body6.solid",
1910 (char *)":Data:Models:Body7.solid",
1911 (char *)":Data:Models:Bodylow.solid",
1912 (char *)":Data:Models:Belt.solid",0);
1914 if(player[i].creature!=wolftype){
1915 player[i].skeleton.Load(
1916 (char *)":Data:Skeleton:Basic Figure",
1917 (char *)":Data:Skeleton:Basic Figurelow",
1918 (char *)":Data:Skeleton:Rabbitbelt",
1919 (char *)":Data:Models:Body.solid",
1920 (char *)":Data:Models:Body2.solid",
1921 (char *)":Data:Models:Body3.solid",
1922 (char *)":Data:Models:Body4.solid",
1923 (char *)":Data:Models:Body5.solid",
1924 (char *)":Data:Models:Body6.solid",
1925 (char *)":Data:Models:Body7.solid",
1926 (char *)":Data:Models:Bodylow.solid",
1927 (char *)":Data:Models:Belt.solid",1);
1928 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1930 if(player[i].creature==wolftype){
1931 player[i].skeleton.Load(
1932 (char *)":Data:Skeleton:Basic Figure Wolf",
1933 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1934 (char *)":Data:Skeleton:Rabbitbelt",
1935 (char *)":Data:Models:Wolf.solid",
1936 (char *)":Data:Models:Wolf2.solid",
1937 (char *)":Data:Models:Wolf3.solid",
1938 (char *)":Data:Models:Wolf4.solid",
1939 (char *)":Data:Models:Wolf5.solid",
1940 (char *)":Data:Models:Wolf6.solid",
1941 (char *)":Data:Models:Wolf7.solid",
1942 (char *)":Data:Models:Wolflow.solid",
1943 (char *)":Data:Models:Belt.solid",0);
1949 texsize=512*512*3/texdetail/texdetail;
1951 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1953 if(player[i].numclothes){
1954 for(int j=0;j<player[i].numclothes;j++){
1955 tintr=player[i].clothestintr[j];
1956 tintg=player[i].clothestintg[j];
1957 tintb=player[i].clothestintb[j];
1958 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1960 player[i].DoMipmaps();
1963 player[i].currentanimation=bounceidleanim;
1964 player[i].targetanimation=bounceidleanim;
1965 player[i].currentframe=0;
1966 player[i].targetframe=1;
1968 player[i].speed=1+(float)(Random()%100)/1000;
1970 player[i].speed-=.2;
1972 player[i].speed-=.1;
1974 player[i].velocity=0;
1975 player[i].oldcoords=player[i].coords;
1976 player[i].realoldcoords=player[i].coords;
1979 player[i].skeleton.id=i;
1980 player[i].updatedelay=0;
1981 player[i].normalsupdatedelay=0;
1983 player[i].aitype=passivetype;
1984 player[i].madskills=0;
1987 player[i].proportionhead=1.2;
1988 player[i].proportionbody=1.05;
1989 player[i].proportionarms=1.00;
1990 player[i].proportionlegs=1.1;
1991 player[i].proportionlegs.y=1.05;
1993 player[i].headless=0;
1994 player[i].currentoffset=0;
1995 player[i].targetoffset=0;
1997 player[i].damagetolerance=200;
1999 if(player[i].creature==wolftype){
2000 if(i==0||player[i].scale<0)
2001 player[i].scale=.23;
2002 player[i].damagetolerance=300;
2008 player[i].proportionhead.z=0;
2009 player[i].proportionbody.z=0;
2010 player[i].proportionarms.z=0;
2011 player[i].proportionlegs.z=0;
2014 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2016 player[i].headmorphness=0;
2017 player[i].targetheadmorphness=1;
2018 player[i].headmorphstart=0;
2019 player[i].headmorphend=0;
2021 player[i].pausetime=0;
2024 player[i].jumppower=5;
2026 player[i].permanentdamage=0;
2027 player[i].superpermanentdamage=0;
2029 player[i].forwardkeydown=0;
2030 player[i].leftkeydown=0;
2031 player[i].backkeydown=0;
2032 player[i].rightkeydown=0;
2033 player[i].jumpkeydown=0;
2034 player[i].crouchkeydown=0;
2035 player[i].throwkeydown=0;
2037 player[i].collided=-10;
2039 player[i].bloodloss=0;
2040 player[i].weaponactive=-1;
2041 player[i].weaponstuck=-1;
2042 player[i].bleeding=0;
2043 player[i].deathbleeding=0;
2044 player[i].stunned=0;
2045 player[i].hasvictim=0;
2046 player[i].wentforweapon=0;
2049 player[0].aitype=playercontrolled;
2050 player[0].weaponactive=-1;
2053 player[0].power=1/.9;
2056 player[0].power=1/.8;
2059 player[0].damagetolerance=250;
2061 player[0].damagetolerance=300;
2063 player[0].armorhead*=1.5;
2065 player[0].armorhigh*=1.5;
2067 player[0].armorlow*=1.5;
2068 cameraloc=player[0].coords;
2070 rotation=player[0].rotation;
2072 hawkcoords=player[0].coords;
2077 for(int i=0;i<weapons.numweapons;i++){
2078 weapons.bloody[i]=0;
2079 weapons.blooddrip[i]=0;
2080 weapons.blooddripdelay[i]=0;
2081 weapons.onfire[i]=0;
2082 weapons.flamedelay[i]=0;
2083 weapons.damage[i]=0;
2084 if(weapons.type[i]==sword){
2085 weapons.mass[i]=1.5;
2086 weapons.tipmass[i]=1;
2087 weapons.length[i]=.8;
2089 if(weapons.type[i]==staff){
2091 weapons.tipmass[i]=1;
2092 weapons.length[i]=1.5;
2094 if(weapons.type[i]==knife){
2096 weapons.tipmass[i]=1.2;
2097 weapons.length[i]=.25;
2099 weapons.position[i]=-1000;
2100 weapons.tippoint[i]=-1000;
2103 LOG("Starting background music...");
2105 OPENAL_StopSound(OPENAL_ALL);
2106 if(environment==snowyenvironment){
2108 emit_stream_np(stream_wind);
2109 }else if(environment==desertenvironment){
2111 emit_stream_np(stream_desertambient);
2112 }else if(environment==grassyenvironment){
2114 emit_stream_np(stream_wind, 100.);
2116 oldmusicvolume[0]=0;
2117 oldmusicvolume[1]=0;
2118 oldmusicvolume[2]=0;
2119 oldmusicvolume[3]=0;
2131 void Game::MenuTick(){
2133 if(mainmenu==1||mainmenu==2){
2134 if(Input::MouseClicked()&&selected==1){
2136 fireSound(firestartsound);
2148 pause_sound(stream_music3);
2149 resume_stream(music1);
2153 if(Input::MouseClicked()&&selected==2){
2158 if(newdetail>2)newdetail=detail;
2159 if(newdetail<0)newdetail=detail;
2160 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2161 if(newscreenwidth<0)newscreenwidth=screenwidth;
2162 if(newscreenheight>3000)newscreenheight=screenheight;
2163 if(newscreenheight<0)newscreenheight=screenheight;
2166 if(Input::MouseClicked()&&selected==3){
2172 pause_sound(stream_music3);
2181 if(Input::MouseClicked()){
2188 extern SDL_Rect **resolutions;
2189 bool isCustomResolution = true;
2191 for(int i = 0; (!found) && (resolutions[i]); i++){
2192 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2193 isCustomResolution = false;
2195 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)){
2197 if(resolutions[i] != NULL){
2198 newscreenwidth = (int) resolutions[i]->w;
2199 newscreenheight = (int) resolutions[i]->h;
2200 }else if(isCustomResolution){
2201 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)){
2202 newscreenwidth = (int) resolutions[0]->w;
2203 newscreenheight = (int) resolutions[0]->h;
2205 newscreenwidth = screenwidth;
2206 newscreenheight = screenheight;
2209 newscreenwidth = (int) resolutions[0]->w;
2210 newscreenheight = (int) resolutions[0]->h;
2217 newscreenwidth = (int) resolutions[0]->w;
2218 newscreenheight = (int) resolutions[0]->h;
2223 if(newdetail>2)newdetail=0;
2227 if(bloodtoggle>2)bloodtoggle=0;
2231 if(difficulty>2)difficulty=0;
2234 ismotionblur=1-ismotionblur;
2240 musictoggle=1-musictoggle;
2243 pause_sound(music1);
2244 pause_sound(stream_music2);
2245 pause_sound(stream_music3);
2247 for(int i=0;i<4;i++){
2248 oldmusicvolume[i]=0;
2254 emit_stream_np(stream_music3);
2266 if(newdetail>2)newdetail=detail;
2267 if(newdetail<0)newdetail=detail;
2268 if(newscreenwidth<0)newscreenwidth=screenwidth;
2269 if(newscreenheight<0)newscreenheight=screenheight;
2271 SaveSettings(*this);
2272 if(mainmenu==3&&gameon)mainmenu=2;
2273 if(mainmenu==3&&!gameon)mainmenu=1;
2276 invertmouse=1-invertmouse;
2279 usermousesensitivity+=.2;
2280 if(usermousesensitivity>2)usermousesensitivity=.2;
2284 if(volume>1.0001f)volume=0;
2285 OPENAL_SetSFXMasterVolume((int)(volume*255));
2290 newstereomode = stereomode;
2295 showdamagebar=!showdamagebar;
2301 if(Input::MouseClicked()&&selected!=-1&&!waiting){
2303 if(selected<9&&keyselect==-1)
2312 if(newdetail>2)newdetail=detail;
2313 if(newdetail<0)newdetail=detail;
2314 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2315 if(newscreenwidth<0)newscreenwidth=screenwidth;
2316 if(newscreenheight>3000)newscreenheight=screenheight;
2317 if(newscreenheight<0)newscreenheight=screenheight;
2325 accountactive->endGame();
2329 if(Input::MouseClicked()){
2330 if((selected-7>=accountactive->getCampaignChoicesMade())){
2338 if(firstload) TickOnceAfter();
2340 whichchoice=selected-7-accountactive->getCampaignChoicesMade();
2343 Loadlevel(campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
2344 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2348 pause_sound(stream_music3);
2350 if(selected>=1 && selected<=5){
2361 if(firstload)TickOnceAfter();
2362 if(!firstload)LoadStuff();
2369 pause_sound(stream_music3);
2378 if(mainmenu==5&&gameon)mainmenu=2;
2379 if(mainmenu==5&&!gameon)mainmenu=1;
2387 else if(mainmenu==9){
2388 if(Input::MouseClicked()&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
2396 targetlevel=selected;
2397 if(firstload)TickOnceAfter();
2398 if(!firstload)LoadStuff();
2400 Loadlevel(selected);
2406 pause_sound(stream_music3);
2408 if(Input::MouseClicked()&&selected==numchallengelevels){
2416 if(Input::MouseClicked()&&selected==3){
2424 if(Input::MouseClicked()) {
2429 accountactive = Account::destroy(accountactive);
2431 } else if(selected==2) {
2439 if(Input::MouseClicked()) {
2442 if(selected==0&&Account::getNbAccounts()<8){
2444 } else if (selected<Account::getNbAccounts()+1) {
2445 accountactive=Account::get(selected-1);
2448 } else if (selected==Account::getNbAccounts()+1) {
2453 for(int j=0;j<255;j++){
2454 displaytext[0][j]=0;
2464 if(Input::MouseClicked()&&selected>-1){
2468 accountactive->setDifficulty(selected);
2473 if(Input::MouseClicked()&&selected==0) {
2474 newstereomode = (StereoMode)(newstereomode + 1);
2475 while(!CanInitStereo(newstereomode)) {
2476 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
2477 newstereomode = (StereoMode)(newstereomode + 1);
2478 if ( newstereomode >= stereoCount ) {
2479 newstereomode = stereoNone;
2484 if(Input::isKeyPressed(MOUSEBUTTON1)&&selected==1)
2485 stereoseparation+=0.001;
2486 if(Input::isKeyPressed(MOUSEBUTTON2)&&selected==1)
2487 stereoseparation-=0.001;
2489 if(Input::MouseClicked()&&selected==2) {
2490 stereoreverse =! stereoreverse;
2493 if(Input::MouseClicked()&&selected==3) {
2496 stereomode = newstereomode;
2497 InitStereo(stereomode);
2503 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
2506 if(newdetail>2)newdetail=detail;
2507 if(newdetail<0)newdetail=detail;
2508 if(newscreenwidth<0)newscreenwidth=screenwidth;
2509 if(newscreenheight<0)newscreenheight=screenheight;
2511 SaveSettings(*this);
2515 if(mainmenu==1||mainmenu==2){
2516 if(loaddistrib>4)transition+=multiplier/8;
2524 OPENAL_SetFrequency(channels[stream_music3], 22050);
2527 inputText(displaytext[0],&displayselected,&displaychars[0]);
2528 if(!waiting) { // the input as finished
2529 if(displaychars[0]){ // with enter
2530 accountactive = Account::add(string(displaytext[0]));
2536 fireSound(firestartsound);
2538 for(int i=0;i<255;i++){
2539 displaytext[0][i]=0;
2548 displayblinkdelay-=multiplier;
2549 if(displayblinkdelay<=0){
2550 displayblinkdelay=.3;
2551 displayblink=1-displayblink;
2556 void Game::doTutorial(){
2557 if(tutorialstagetime>tutorialmaxtime){
2560 if(tutorialstage<=1){
2565 switch(tutorialstage){
2571 tutorialmaxtime=600;
2573 tutorialmaxtime=1000;
2575 tutorialmaxtime=600;
2577 tutorialmaxtime=600;
2579 tutorialmaxtime=600;
2581 tutorialmaxtime=600;
2583 tutorialmaxtime=600;
2587 tutorialmaxtime=1000;
2589 tutorialmaxtime=1000;
2604 player[1].coords=(temp+temp2)/2;
2606 emit_sound_at(fireendsound, player[1].coords);
2608 for(int i=0;i<player[1].skeleton.num_joints;i++){
2610 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2611 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2612 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;
2613 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2614 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2619 tutorialmaxtime=500;
2621 tutorialmaxtime=500;
2623 tutorialmaxtime=500;
2625 tutorialmaxtime=500;
2628 //tutorialmaxtime=500;
2630 tutorialmaxtime=500;
2632 tutorialmaxtime=500;
2639 tutorialmaxtime=500;
2641 tutorialmaxtime=500;
2643 tutorialmaxtime=500;
2645 tutorialmaxtime=500;
2652 player[1].aitype=attacktypecutoff;
2654 tutorialmaxtime=400;
2656 tutorialmaxtime=400;
2657 player[0].escapednum=0;
2662 player[1].aitype=passivetype;
2668 tutorialmaxtime=400;
2671 player[1].aitype=attacktypecutoff;
2673 tutorialmaxtime=400;
2675 tutorialmaxtime=400;
2680 player[1].aitype=passivetype;
2687 player[1].aitype=attacktypecutoff;
2692 player[1].aitype=passivetype;
2704 weapons.owner[weapons.numweapons]=-1;
2705 weapons.type[weapons.numweapons]=knife;
2706 weapons.damage[weapons.numweapons]=0;
2707 weapons.mass[weapons.numweapons]=1;
2708 weapons.tipmass[weapons.numweapons]=1.2;
2709 weapons.length[weapons.numweapons]=.25;
2710 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2711 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2713 weapons.velocity[weapons.numweapons]=0.1;
2714 weapons.tipvelocity[weapons.numweapons]=0.1;
2715 weapons.missed[weapons.numweapons]=1;
2716 weapons.hitsomething[weapons.numweapons]=0;
2717 weapons.freetime[weapons.numweapons]=0;
2718 weapons.firstfree[weapons.numweapons]=1;
2719 weapons.physics[weapons.numweapons]=1;
2721 weapons.numweapons++;
2724 tutorialmaxtime=300;
2726 tutorialmaxtime=300;
2730 tutorialmaxtime=300;
2733 player[0].weaponactive=-1;
2734 player[0].num_weapons=0;
2735 player[1].weaponactive=0;
2736 player[1].num_weapons=1;
2737 player[1].weaponids[0]=0;
2741 player[1].aitype=attacktypecutoff;
2743 tutorialmaxtime=300;
2746 player[0].weaponactive=-1;
2747 player[0].num_weapons=0;
2748 player[1].weaponactive=0;
2749 player[1].num_weapons=1;
2750 player[1].weaponids[0]=0;
2752 tutorialmaxtime=300;
2755 player[0].weaponactive=-1;
2756 player[0].num_weapons=0;
2757 player[1].weaponactive=0;
2758 player[1].num_weapons=1;
2759 player[1].weaponids[0]=0;
2761 weapons.type[0]=sword;
2763 tutorialmaxtime=300;
2776 weapons.owner[weapons.numweapons]=-1;
2777 weapons.type[weapons.numweapons]=sword;
2778 weapons.damage[weapons.numweapons]=0;
2779 weapons.mass[weapons.numweapons]=1;
2780 weapons.tipmass[weapons.numweapons]=1.2;
2781 weapons.length[weapons.numweapons]=.25;
2782 weapons.position[weapons.numweapons]=(temp+temp2)/2;
2783 weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
2785 weapons.velocity[weapons.numweapons]=0.1;
2786 weapons.tipvelocity[weapons.numweapons]=0.1;
2787 weapons.missed[weapons.numweapons]=1;
2788 weapons.hitsomething[weapons.numweapons]=0;
2789 weapons.freetime[weapons.numweapons]=0;
2790 weapons.firstfree[weapons.numweapons]=1;
2791 weapons.physics[weapons.numweapons]=1;
2795 player[0].weaponactive=0;
2796 player[0].num_weapons=1;
2797 player[0].weaponids[0]=1;
2798 player[1].weaponactive=0;
2799 player[1].num_weapons=1;
2800 player[1].weaponids[0]=0;
2802 weapons.numweapons++;
2807 player[1].aitype=passivetype;
2813 player[0].weaponactive=0;
2814 player[0].num_weapons=1;
2815 player[0].weaponids[0]=1;
2816 player[1].weaponactive=0;
2817 player[1].num_weapons=1;
2818 player[1].weaponids[0]=0;
2820 if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
2821 else weapons.type[0]=staff;
2823 weapons.numweapons++;
2827 player[1].aitype=passivetype;
2829 tutorialmaxtime=200;
2831 weapons.position[1]=1000;
2832 weapons.tippoint[1]=1000;
2834 weapons.numweapons=1;
2836 player[1].weaponactive=-1;
2837 player[1].num_weapons=0;
2838 player[0].weaponactive=0;
2839 player[0].num_weapons=1;
2840 player[0].weaponids[0]=0;
2842 weapons.type[0]=knife;
2844 weapons.numweapons++;
2849 emit_sound_at(fireendsound, player[1].coords);
2851 for(int i=0;i<player[1].skeleton.num_joints;i++){
2853 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2854 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2855 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;
2856 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2857 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2861 player[1].num_weapons=0;
2862 player[1].weaponstuck=-1;
2863 player[1].weaponactive=-1;
2865 weapons.numweapons=0;
2867 weapons.owner[0]=-1;
2868 weapons.velocity[0]=0.1;
2869 weapons.tipvelocity[0]=-0.1;
2870 weapons.missed[0]=1;
2871 weapons.hitsomething[0]=0;
2872 weapons.freetime[0]=0;
2873 weapons.firstfree[0]=1;
2874 weapons.physics[0]=1;
2877 tutorialmaxtime=80000;
2878 break; default: break;
2880 if(tutorialstage<=51)tutorialstagetime=0;
2884 if(tutorialstagetime<tutorialmaxtime-3){
2885 switch(tutorialstage){
2886 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2887 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2888 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2889 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2890 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2891 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2892 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2893 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2894 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2895 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2896 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2897 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2898 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2899 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2900 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2901 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2902 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2903 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2904 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2905 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2906 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2908 if(player[0].escapednum==2){
2912 player[1].aitype=passivetype;
2914 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2915 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2917 if(animation[player[0].targetanimation].attack==reversal){
2921 player[1].aitype=passivetype;
2923 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2924 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2925 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2926 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2927 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2928 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2929 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2930 break; default: break;
2932 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2935 if(tutorialstagetime==tutorialmaxtime-3){
2936 emit_sound_np(consolesuccesssound);
2939 if(tutorialsuccess>=1){
2940 if(tutorialstage==34||tutorialstage==35)
2941 tutorialstagetime=tutorialmaxtime-1;
2945 if(tutorialstage<14||tutorialstage>=50){
2946 player[1].coords.y=300;
2947 player[1].velocity=0;
2953 void Game::doDebugKeys(){
2954 float headprop,bodyprop,armprop,legprop;
2956 if(Input::isKeyPressed(SDLK_h)){
2957 player[0].damagetolerance=200000;
2960 player[0].permanentdamage=0;
2961 player[0].superpermanentdamage=0;
2964 if(Input::isKeyPressed(SDLK_j)){
2968 Setenvironment(environment);
2971 if(Input::isKeyPressed(SDLK_c)){
2972 cameramode=1-cameramode;
2975 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2976 if(player[0].num_weapons>0){
2977 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
2978 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
2979 else weapons.type[player[0].weaponids[0]]=sword;
2980 if(weapons.type[player[0].weaponids[0]]==sword){
2981 weapons.mass[player[0].weaponids[0]]=1.5;
2982 weapons.tipmass[player[0].weaponids[0]]=1;
2983 weapons.length[player[0].weaponids[0]]=.8;
2985 if(weapons.type[player[0].weaponids[0]]==staff){
2986 weapons.mass[player[0].weaponids[0]]=2;
2987 weapons.tipmass[player[0].weaponids[0]]=1;
2988 weapons.length[player[0].weaponids[0]]=1.5;
2991 if(weapons.type[player[0].weaponids[0]]==knife){
2992 weapons.mass[player[0].weaponids[0]]=1;
2993 weapons.tipmass[player[0].weaponids[0]]=1.2;
2994 weapons.length[player[0].weaponids[0]]=.25;
2999 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
3001 float closestdist=-1;
3004 for(int i=1;i<numplayers;i++){
3005 distance=findDistancefast(&player[i].coords,&player[0].coords);
3006 if(closestdist==-1||distance<closestdist){
3007 closestdist=distance;
3012 if(player[closest].num_weapons){
3013 if(weapons.type[player[closest].weaponids[0]]==sword)
3014 weapons.type[player[closest].weaponids[0]]=staff;
3015 else if(weapons.type[player[closest].weaponids[0]]==staff)
3016 weapons.type[player[closest].weaponids[0]]=knife;
3017 else weapons.type[player[closest].weaponids[0]]=sword;
3018 if(weapons.type[player[closest].weaponids[0]]==sword){
3019 weapons.mass[player[closest].weaponids[0]]=1.5;
3020 weapons.tipmass[player[closest].weaponids[0]]=1;
3021 weapons.length[player[closest].weaponids[0]]=.8;
3023 if(weapons.type[player[0].weaponids[0]]==staff){
3024 weapons.mass[player[0].weaponids[0]]=2;
3025 weapons.tipmass[player[0].weaponids[0]]=1;
3026 weapons.length[player[0].weaponids[0]]=1.5;
3028 if(weapons.type[player[closest].weaponids[0]]==knife){
3029 weapons.mass[player[closest].weaponids[0]]=1;
3030 weapons.tipmass[player[closest].weaponids[0]]=1.2;
3031 weapons.length[player[closest].weaponids[0]]=.25;
3034 if(!player[closest].num_weapons){
3035 player[closest].weaponids[0]=weapons.numweapons;
3036 weapons.owner[weapons.numweapons]=closest;
3037 weapons.type[weapons.numweapons]=knife;
3038 weapons.damage[weapons.numweapons]=0;
3039 weapons.numweapons++;
3040 player[closest].num_weapons=1;
3041 if(weapons.type[player[closest].weaponids[0]]==sword){
3042 weapons.mass[player[closest].weaponids[0]]=1.5;
3043 weapons.tipmass[player[closest].weaponids[0]]=1;
3044 weapons.length[player[closest].weaponids[0]]=.8;
3046 if(weapons.type[player[closest].weaponids[0]]==knife){
3047 weapons.mass[player[closest].weaponids[0]]=1;
3048 weapons.tipmass[player[closest].weaponids[0]]=1.2;
3049 weapons.length[player[closest].weaponids[0]]=.25;
3055 if(Input::isKeyDown(SDLK_u)){
3057 float closestdist=-1;
3060 for(int i=1;i<numplayers;i++){
3061 distance=findDistancefast(&player[i].coords,&player[0].coords);
3062 if(closestdist==-1||distance<closestdist){
3063 closestdist=distance;
3067 player[closest].rotation+=multiplier*50;
3068 player[closest].targetrotation=player[closest].rotation;
3072 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
3074 float closestdist=-1;
3077 for(int i=1;i<numplayers;i++){
3078 distance=findDistancefast(&player[i].coords,&player[0].coords);
3079 if(closestdist==-1||distance<closestdist){
3080 closestdist=distance;
3084 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
3087 player[closest].whichskin++;
3088 if(player[closest].whichskin>9)
3089 player[closest].whichskin=0;
3090 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
3091 player[closest].whichskin=0;
3093 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
3094 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
3097 if(player[closest].numclothes){
3098 for(int i=0;i<player[closest].numclothes;i++){
3099 tintr=player[closest].clothestintr[i];
3100 tintg=player[closest].clothestintg[i];
3101 tintb=player[closest].clothestintb[i];
3102 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
3104 player[closest].DoMipmaps();
3108 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
3110 float closestdist=-1;
3113 for(int i=1;i<numplayers;i++){
3114 distance=findDistancefast(&player[i].coords,&player[0].coords);
3115 if(closestdist==-1||distance<closestdist){
3116 closestdist=distance;
3121 if(player[closest].creature==wolftype){
3122 headprop=player[closest].proportionhead.x/1.1;
3123 bodyprop=player[closest].proportionbody.x/1.1;
3124 armprop=player[closest].proportionarms.x/1.1;
3125 legprop=player[closest].proportionlegs.x/1.1;
3128 if(player[closest].creature==rabbittype){
3129 headprop=player[closest].proportionhead.x/1.2;
3130 bodyprop=player[closest].proportionbody.x/1.05;
3131 armprop=player[closest].proportionarms.x/1.00;
3132 legprop=player[closest].proportionlegs.x/1.1;
3136 if(player[closest].creature==rabbittype){
3137 player[closest].skeleton.id=closest;
3138 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);
3139 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
3140 player[closest].whichskin=0;
3141 player[closest].creature=wolftype;
3143 player[closest].proportionhead=1.1;
3144 player[closest].proportionbody=1.1;
3145 player[closest].proportionarms=1.1;
3146 player[closest].proportionlegs=1.1;
3147 player[closest].proportionlegs.y=1.1;
3148 player[closest].scale=.23*5*player[0].scale;
3150 player[closest].damagetolerance=300;
3154 player[closest].skeleton.id=closest;
3155 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);
3156 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
3157 player[closest].whichskin=0;
3158 player[closest].creature=rabbittype;
3160 player[closest].proportionhead=1.2;
3161 player[closest].proportionbody=1.05;
3162 player[closest].proportionarms=1.00;
3163 player[closest].proportionlegs=1.1;
3164 player[closest].proportionlegs.y=1.05;
3165 player[closest].scale=.2*5*player[0].scale;
3167 player[closest].damagetolerance=200;
3170 if(player[closest].creature==wolftype){
3171 player[closest].proportionhead=1.1*headprop;
3172 player[closest].proportionbody=1.1*bodyprop;
3173 player[closest].proportionarms=1.1*armprop;
3174 player[closest].proportionlegs=1.1*legprop;
3177 if(player[closest].creature==rabbittype){
3178 player[closest].proportionhead=1.2*headprop;
3179 player[closest].proportionbody=1.05*bodyprop;
3180 player[closest].proportionarms=1.00*armprop;
3181 player[closest].proportionlegs=1.1*legprop;
3182 player[closest].proportionlegs.y=1.05*legprop;
3188 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
3194 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
3196 float closestdist=-1;
3198 XYZ flatfacing2,flatvelocity2;
3201 for(int i=1;i<numplayers;i++){
3202 distance=findDistancefast(&player[i].coords,&player[0].coords);
3203 if(distance<144&&!player[i].headless)
3204 if(closestdist==-1||distance<closestdist){
3205 closestdist=distance;
3207 blah = player[i].coords;
3212 XYZ headspurtdirection;
3213 //int i = player[closest].skeleton.jointlabels[head];
3214 Joint& headjoint=playerJoint(closest,head);
3215 for(int k=0;k<player[closest].skeleton.num_joints; k++){
3216 if(!player[closest].skeleton.free)
3217 flatvelocity2=player[closest].velocity;
3218 if(player[closest].skeleton.free)
3219 flatvelocity2=headjoint.velocity;
3220 if(!player[closest].skeleton.free)
3221 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;
3222 if(player[closest].skeleton.free)
3223 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
3224 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3225 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3226 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3227 headspurtdirection=headjoint.position-playerJoint(closest,neck).position;
3228 Normalise(&headspurtdirection);
3229 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
3230 flatvelocity2+=headspurtdirection*8;
3231 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
3233 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
3235 emit_sound_at(splattersound, blah);
3236 emit_sound_at(breaksound2, blah, 100.);
3238 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
3239 player[closest].RagDoll(0);
3240 player[closest].dead=2;
3241 player[closest].headless=1;
3242 player[closest].DoBloodBig(3,165);
3248 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
3250 float closestdist=-1;
3252 XYZ flatfacing2,flatvelocity2;
3255 for(int i=1;i<numplayers;i++){
3256 distance=findDistancefast(&player[i].coords,&player[0].coords);
3258 if(closestdist==-1||distance<closestdist){
3259 closestdist=distance;
3261 blah=player[i].coords;
3266 emit_sound_at(splattersound, blah);
3268 emit_sound_at(breaksound2, blah);
3270 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3271 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3272 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3273 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;
3274 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3275 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3276 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3277 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3278 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
3279 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
3280 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
3283 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3284 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3285 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3286 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;
3287 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3288 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3289 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3290 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3291 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
3292 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
3295 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3296 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3297 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3298 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;
3299 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3300 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3301 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3302 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3303 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
3304 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
3307 for(int i=0;i<player[closest].skeleton.num_joints; i++){
3308 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
3309 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
3310 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;
3311 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
3312 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
3313 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
3314 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
3315 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
3316 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
3320 for(int j=0;j<numplayers; j++){
3322 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
3323 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
3324 if(player[j].skeleton.free==2)
3325 player[j].skeleton.free=1;
3326 player[j].skeleton.longdead=0;
3327 player[j].RagDoll(0);
3328 for(int i=0;i<player[j].skeleton.num_joints; i++){
3329 temppos=player[j].skeleton.joints[i].position+player[j].coords;
3330 if(findDistancefast(&temppos,&player[closest].coords)<25){
3331 flatvelocity2=temppos-player[closest].coords;
3332 Normalise(&flatvelocity2);
3333 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
3340 player[closest].DoDamage(10000);
3341 player[closest].RagDoll(0);
3342 player[closest].dead=2;
3343 player[closest].coords=20;
3344 player[closest].skeleton.free=2;
3351 if(Input::isKeyPressed(SDLK_f)){
3352 player[0].onfire=1-player[0].onfire;
3353 if(player[0].onfire){
3354 player[0].CatchFire();
3356 if(!player[0].onfire){
3357 emit_sound_at(fireendsound, player[0].coords);
3358 pause_sound(stream_firesound);
3362 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
3363 //if(!player[0].skeleton.free)player[0].damage+=500;
3364 player[0].RagDoll(0);
3365 //player[0].spurt=1;
3366 //player[0].DoDamage(1000);
3368 emit_sound_at(whooshsound, player[0].coords, 128.);
3371 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
3373 float closestdist=-1;
3375 for(int i=0;i<objects.numobjects;i++){
3376 if(objects.type[i]==treeleavestype){
3377 objects.scale[i]*=.9;
3382 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3383 editorenabled=1-editorenabled;
3385 player[0].damagetolerance=100000;
3387 player[0].damagetolerance=200;
3389 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
3390 player[0].permanentdamage=0;
3391 player[0].superpermanentdamage=0;
3392 player[0].bloodloss=0;
3393 player[0].deathbleeding=0;
3397 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
3399 if(targetlevel>numchallengelevels-1)
3406 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
3408 float closestdist=-1;
3411 for(int i=1;i<numplayers;i++){
3412 distance=findDistancefast(&player[i].coords,&player[0].coords);
3413 if(closestdist==-1||distance<closestdist){
3414 closestdist=distance;
3418 if(closestdist>0&&closest>=0){
3419 //player[closest]=player[numplayers-1];
3420 //player[closest].skeleton=player[numplayers-1].skeleton;
3425 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
3427 float closestdist=-1;
3430 for(int i=1;i<max_objects;i++){
3431 distance=findDistancefast(&objects.position[i],&player[0].coords);
3432 if(closestdist==-1||distance<closestdist){
3433 closestdist=distance;
3437 if(closestdist>0&&closest>=0){
3438 objects.position[closest].y-=500;
3442 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3444 //if(drawmode>2)drawmode=0;
3445 if(objects.numobjects<max_objects-1){
3447 boxcoords.x=player[0].coords.x;
3448 boxcoords.z=player[0].coords.z;
3449 boxcoords.y=player[0].coords.y-3;
3450 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3451 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3452 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3453 float temprotat,temprotat2;
3454 temprotat=editorrotation;
3455 temprotat2=editorrotation2;
3456 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3457 if(temprotat2<0)temprotat2=Random()%360;
3459 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3460 if(editortype==treetrunktype)
3461 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
3465 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3466 if(numplayers<maxplayers-1){
3467 player[numplayers].scale=.2*5*player[0].scale;
3468 player[numplayers].creature=rabbittype;
3469 player[numplayers].howactive=editoractive;
3470 player[numplayers].skeleton.id=numplayers;
3471 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);
3473 //texsize=512*512*3/texdetail/texdetail;
3474 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3475 //player[numplayers].skeleton.skinText.resize(texsize);
3477 int k=abs(Random()%2)+1;
3479 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3480 player[numplayers].whichskin=0;
3483 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3484 player[numplayers].whichskin=1;
3487 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3488 player[numplayers].whichskin=2;
3491 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
3492 player[numplayers].power=1;
3493 player[numplayers].speedmult=1;
3494 player[numplayers].currentanimation=bounceidleanim;
3495 player[numplayers].targetanimation=bounceidleanim;
3496 player[numplayers].currentframe=0;
3497 player[numplayers].targetframe=1;
3498 player[numplayers].target=0;
3499 player[numplayers].bled=0;
3500 player[numplayers].speed=1+(float)(Random()%100)/1000;
3502 player[numplayers].targetrotation=player[0].targetrotation;
3503 player[numplayers].rotation=player[0].rotation;
3505 player[numplayers].velocity=0;
3506 player[numplayers].coords=player[0].coords;
3507 player[numplayers].oldcoords=player[numplayers].coords;
3508 player[numplayers].realoldcoords=player[numplayers].coords;
3510 player[numplayers].id=numplayers;
3511 player[numplayers].skeleton.id=numplayers;
3512 player[numplayers].updatedelay=0;
3513 player[numplayers].normalsupdatedelay=0;
3515 player[numplayers].aitype=passivetype;
3517 if(player[0].creature==wolftype){
3518 headprop=player[0].proportionhead.x/1.1;
3519 bodyprop=player[0].proportionbody.x/1.1;
3520 armprop=player[0].proportionarms.x/1.1;
3521 legprop=player[0].proportionlegs.x/1.1;
3524 if(player[0].creature==rabbittype){
3525 headprop=player[0].proportionhead.x/1.2;
3526 bodyprop=player[0].proportionbody.x/1.05;
3527 armprop=player[0].proportionarms.x/1.00;
3528 legprop=player[0].proportionlegs.x/1.1;
3531 if(player[numplayers].creature==wolftype){
3532 player[numplayers].proportionhead=1.1*headprop;
3533 player[numplayers].proportionbody=1.1*bodyprop;
3534 player[numplayers].proportionarms=1.1*armprop;
3535 player[numplayers].proportionlegs=1.1*legprop;
3538 if(player[numplayers].creature==rabbittype){
3539 player[numplayers].proportionhead=1.2*headprop;
3540 player[numplayers].proportionbody=1.05*bodyprop;
3541 player[numplayers].proportionarms=1.00*armprop;
3542 player[numplayers].proportionlegs=1.1*legprop;
3543 player[numplayers].proportionlegs.y=1.05*legprop;
3546 player[numplayers].headless=0;
3547 player[numplayers].onfire=0;
3550 player[numplayers].proportionhead.z=0;
3551 player[numplayers].proportionbody.z=0;
3552 player[numplayers].proportionarms.z=0;
3553 player[numplayers].proportionlegs.z=0;
3556 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3558 player[numplayers].damagetolerance=200;
3560 player[numplayers].protectionhead=player[0].protectionhead;
3561 player[numplayers].protectionhigh=player[0].protectionhigh;
3562 player[numplayers].protectionlow=player[0].protectionlow;
3563 player[numplayers].armorhead=player[0].armorhead;
3564 player[numplayers].armorhigh=player[0].armorhigh;
3565 player[numplayers].armorlow=player[0].armorlow;
3566 player[numplayers].metalhead=player[0].metalhead;
3567 player[numplayers].metalhigh=player[0].metalhigh;
3568 player[numplayers].metallow=player[0].metallow;
3570 player[numplayers].immobile=player[0].immobile;
3572 player[numplayers].numclothes=player[0].numclothes;
3573 if(player[numplayers].numclothes)
3574 for(int i=0;i<player[numplayers].numclothes;i++){
3575 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3576 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3577 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3578 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3579 tintr=player[numplayers].clothestintr[i];
3580 tintg=player[numplayers].clothestintg[i];
3581 tintb=player[numplayers].clothestintb[i];
3582 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3584 if(player[numplayers].numclothes){
3585 player[numplayers].DoMipmaps();
3588 player[numplayers].power=player[0].power;
3589 player[numplayers].speedmult=player[0].speedmult;
3591 player[numplayers].damage=0;
3592 player[numplayers].permanentdamage=0;
3593 player[numplayers].superpermanentdamage=0;
3594 player[numplayers].deathbleeding=0;
3595 player[numplayers].bleeding=0;
3596 player[numplayers].numwaypoints=0;
3597 player[numplayers].waypoint=0;
3598 player[numplayers].jumppath=0;
3599 player[numplayers].weaponstuck=-1;
3600 player[numplayers].weaponactive=-1;
3601 player[numplayers].num_weapons=0;
3602 player[numplayers].bloodloss=0;
3603 player[numplayers].dead=0;
3605 player[numplayers].loaded=1;
3611 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3612 if(player[numplayers-1].numwaypoints<90){
3613 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3614 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3615 player[numplayers-1].numwaypoints++;
3619 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3620 if(numpathpoints<30){
3621 bool connected,alreadyconnected;
3624 for(int i=0;i<numpathpoints;i++){
3625 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3627 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3628 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3630 if(!alreadyconnected){
3631 numpathpointconnect[pathpointselected]++;
3633 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3639 pathpoint[numpathpoints-1]=player[0].coords;
3640 numpathpointconnect[numpathpoints-1]=0;
3641 if(numpathpoints>1&&pathpointselected!=-1){
3642 numpathpointconnect[pathpointselected]++;
3643 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3645 pathpointselected=numpathpoints-1;
3650 if(Input::isKeyPressed(SDLK_PERIOD)){
3651 pathpointselected++;
3652 if(pathpointselected>=numpathpoints)
3653 pathpointselected=-1;
3655 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3656 pathpointselected--;
3657 if(pathpointselected<=-2)
3658 pathpointselected=numpathpoints-1;
3660 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3661 if(pathpointselected!=-1){
3663 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3664 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3665 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3666 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3668 for(int i=0;i<numpathpoints;i++){
3669 for(int j=0;j<numpathpointconnect[i];j++){
3670 if(pathpointconnect[i][j]==pathpointselected){
3671 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3672 numpathpointconnect[i]--;
3674 if(pathpointconnect[i][j]==numpathpoints){
3675 pathpointconnect[i][j]=pathpointselected;
3679 pathpointselected=numpathpoints-1;
3683 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3685 if(editortype==treeleavestype||editortype==10)editortype--;
3686 if(editortype<0)editortype=firetype;
3689 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3691 if(editortype==treeleavestype||editortype==10)editortype++;
3692 if(editortype>firetype)editortype=0;
3695 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3696 editorrotation-=multiplier*100;
3697 if(editorrotation<-.01)editorrotation=-.01;
3700 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3701 editorrotation+=multiplier*100;
3704 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3705 editorsize+=multiplier;
3708 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3709 editorsize-=multiplier;
3710 if(editorsize<.1)editorsize=.1;
3714 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3715 mapradius-=multiplier*10;
3718 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3719 mapradius+=multiplier*10;
3721 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3722 editorrotation2+=multiplier*100;
3725 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3726 editorrotation2-=multiplier*100;
3727 if(editorrotation2<-.01)editorrotation2=-.01;
3729 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3731 float closestdist=-1;
3733 for(int i=0;i<objects.numobjects;i++){
3734 distance=findDistancefast(&objects.position[i],&player[0].coords);
3735 if(closestdist==-1||distance<closestdist){
3736 closestdist=distance;
3740 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3748 void Game::doJumpReversals(){
3749 for(int k=0;k<numplayers;k++)
3750 for(int i=k;i<numplayers;i++){
3752 if( player[k].skeleton.free==0&&
3753 player[i].skeleton.oldfree==0&&
3754 (player[i].targetanimation==jumpupanim||
3755 player[k].targetanimation==jumpupanim)&&
3756 (player[i].aitype==playercontrolled||
3757 player[k].aitype==playercontrolled)&&
3758 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3759 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3760 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3761 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3762 //TODO: refactor two huge similar ifs
3763 if(player[i].targetanimation==jumpupanim&&
3764 player[k].targetanimation!=getupfrombackanim&&
3765 player[k].targetanimation!=getupfromfrontanim&&
3766 animation[player[k].targetanimation].height==middleheight&&
3767 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3768 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3769 player[k].aitype!=playercontrolled)){
3770 player[i].victim=&player[k];
3771 player[i].velocity=0;
3772 player[i].currentanimation=jumpreversedanim;
3773 player[i].targetanimation=jumpreversedanim;
3774 player[i].currentframe=0;
3775 player[i].targetframe=1;
3776 player[i].targettilt2=0;
3777 player[k].victim=&player[i];
3778 player[k].velocity=0;
3779 player[k].currentanimation=jumpreversalanim;
3780 player[k].targetanimation=jumpreversalanim;
3781 player[k].currentframe=0;
3782 player[k].targetframe=1;
3783 player[k].targettilt2=0;
3784 if(player[i].coords.y<player[k].coords.y+1){
3785 player[i].currentanimation=rabbitkickreversedanim;
3786 player[i].targetanimation=rabbitkickreversedanim;
3787 player[i].currentframe=1;
3788 player[i].targetframe=2;
3789 player[k].currentanimation=rabbitkickreversalanim;
3790 player[k].targetanimation=rabbitkickreversalanim;
3791 player[k].currentframe=1;
3792 player[k].targetframe=2;
3795 player[k].oldcoords=player[k].coords;
3796 player[i].coords=player[k].coords;
3797 player[k].targetrotation=player[i].targetrotation;
3798 player[k].rotation=player[i].targetrotation;
3799 if(player[k].aitype==attacktypecutoff)
3800 player[k].stunned=.5;
3802 if(player[k].targetanimation==jumpupanim&&
3803 player[i].targetanimation!=getupfrombackanim&&
3804 player[i].targetanimation!=getupfromfrontanim&&
3805 animation[player[i].targetanimation].height==middleheight&&
3806 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3807 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3808 player[i].aitype!=playercontrolled)){
3809 player[k].victim=&player[i];
3810 player[k].velocity=0;
3811 player[k].currentanimation=jumpreversedanim;
3812 player[k].targetanimation=jumpreversedanim;
3813 player[k].currentframe=0;
3814 player[k].targetframe=1;
3815 player[k].targettilt2=0;
3816 player[i].victim=&player[k];
3817 player[i].velocity=0;
3818 player[i].currentanimation=jumpreversalanim;
3819 player[i].targetanimation=jumpreversalanim;
3820 player[i].currentframe=0;
3821 player[i].targetframe=1;
3822 player[i].targettilt2=0;
3823 if(player[k].coords.y<player[i].coords.y+1){
3824 player[k].targetanimation=rabbitkickreversedanim;
3825 player[k].currentanimation=rabbitkickreversedanim;
3826 player[i].currentanimation=rabbitkickreversalanim;
3827 player[i].targetanimation=rabbitkickreversalanim;
3828 player[k].currentframe=1;
3829 player[k].targetframe=2;
3830 player[i].currentframe=1;
3831 player[i].targetframe=2;
3834 player[i].oldcoords=player[i].coords;
3835 player[k].coords=player[i].coords;
3836 player[i].targetrotation=player[k].targetrotation;
3837 player[i].rotation=player[k].targetrotation;
3838 if(player[i].aitype==attacktypecutoff)
3839 player[i].stunned=.5;
3846 void Game::doAerialAcrobatics(){
3847 static XYZ facing,flatfacing;
3848 for(int k=0;k<numplayers;k++){
3849 player[k].turnspeed=500;
3851 if((player[k].isRun()&&
3852 ((player[k].targetrotation!=rabbitrunninganim&&
3853 player[k].targetrotation!=wolfrunninganim)||
3854 player[k].targetframe==4))||
3855 player[k].targetanimation==removeknifeanim||
3856 player[k].targetanimation==crouchremoveknifeanim||
3857 player[k].targetanimation==flipanim||
3858 player[k].targetanimation==fightsidestep||
3859 player[k].targetanimation==walkanim){
3860 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3864 if(player[k].isStop()||
3865 player[k].isLanding()||
3866 player[k].targetanimation==staggerbackhighanim||
3867 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3868 player[k].targetanimation==staggerbackhardanim||
3869 player[k].targetanimation==backhandspringanim||
3870 player[k].targetanimation==dodgebackanim||
3871 player[k].targetanimation==rollanim||
3872 (animation[player[k].targetanimation].attack&&
3873 player[k].targetanimation!=rabbitkickanim&&
3874 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3875 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3876 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3879 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3880 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3883 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3884 player[k].DoStuff();
3885 if(player[k].immobile&&k!=0)
3886 player[k].coords=player[k].realoldcoords;
3888 //if player's position has changed (?)
3889 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3890 !player[k].skeleton.free&&
3891 player[k].targetanimation!=climbanim&&
3892 player[k].targetanimation!=hanganim){
3893 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3897 if(player[k].collide<-.3)
3898 player[k].collide=-.3;
3899 if(player[k].collide>1)
3900 player[k].collide=1;
3901 player[k].collide-=multiplier*30;
3904 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3906 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3907 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3908 if(objects.type[i]!=rocktype||
3909 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3910 objects.position[i].y>player[k].coords.y){
3911 lowpoint=player[k].coords;
3912 if(player[k].targetanimation!=jumpupanim&&
3913 player[k].targetanimation!=jumpdownanim&&
3914 !player[k].isFlip())
3918 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3919 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3920 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3921 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3922 flatfacing=lowpoint-player[k].coords;
3923 player[k].coords=lowpoint;
3924 player[k].coords.y-=1.3;
3925 player[k].collide=1;
3928 //TODO: refactor four similar blocks
3929 if(player[k].aitype==playercontrolled&&
3930 (player[k].targetanimation==jumpupanim||
3931 player[k].targetanimation==jumpdownanim||
3932 player[k].isFlip())&&
3933 !player[k].jumptogglekeydown&&
3934 player[k].jumpkeydown){
3935 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3936 XYZ tempcoords1=lowpoint;
3937 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3938 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3939 setAnimation(k,walljumpleftanim);
3940 emit_sound_at(movewhooshsound, player[k].coords);
3942 pause_sound(whooshsound);
3944 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3945 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3946 if(lowpointtarget.z<0)
3947 player[k].rotation=180-player[k].rotation;
3948 player[k].targetrotation=player[k].rotation;
3949 player[k].lowrotation=player[k].rotation;
3955 lowpoint=tempcoords1;
3956 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3957 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3958 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3959 setAnimation(k,walljumprightanim);
3960 emit_sound_at(movewhooshsound, player[k].coords);
3961 if(k==0)pause_sound(whooshsound);
3963 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3964 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3965 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3966 player[k].targetrotation=player[k].rotation;
3967 player[k].lowrotation=player[k].rotation;
3968 if(k==0)numwallflipped++;
3972 lowpoint=tempcoords1;
3973 lowpointtarget=lowpoint+player[k].facing*2;
3974 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3975 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3976 setAnimation(k,walljumpbackanim);
3977 emit_sound_at(movewhooshsound, player[k].coords);
3978 if(k==0)pause_sound(whooshsound);
3980 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3981 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3982 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3983 player[k].targetrotation=player[k].rotation;
3984 player[k].lowrotation=player[k].rotation;
3985 if(k==0)numwallflipped++;
3989 lowpoint=tempcoords1;
3990 lowpointtarget=lowpoint-player[k].facing*2;
3991 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3992 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3993 setAnimation(k,walljumpfrontanim);
3994 emit_sound_at(movewhooshsound, player[k].coords);
3995 if(k==0)pause_sound(whooshsound);
3997 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3998 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3999 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
4000 player[k].rotation+=180;
4001 player[k].targetrotation=player[k].rotation;
4002 player[k].lowrotation=player[k].rotation;
4003 if(k==0)numwallflipped++;
4011 else if(objects.type[i]==rocktype){
4012 lowpoint2=player[k].coords;
4013 lowpoint=player[k].coords;
4015 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
4016 player[k].coords=colpoint;
4017 player[k].collide=1;
4020 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
4021 //flipped into a rock
4022 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
4023 player[k].RagDoll(0);
4025 if(player[k].targetanimation==jumpupanim){
4026 player[k].jumppower=-4;
4027 player[k].targetanimation=player[k].getIdle();
4030 player[k].targetframe=0;
4031 player[k].onterrain=1;
4033 if(player[k].id==0){
4034 pause_sound(whooshsound);
4035 OPENAL_SetVolume(channels[whooshsound], 0);
4039 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
4040 if(player[k].isFlip())
4041 player[k].jumppower=-4;
4042 player[k].targetanimation=player[k].getLanding();
4043 emit_sound_at(landsound, player[k].coords, 128.);
4045 envsound[numenvsounds]=player[k].coords;
4046 envsoundvol[numenvsounds]=16;
4047 envsoundlife[numenvsounds]=.4;
4057 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
4058 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
4059 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
4060 lowpoint=player[k].coords;
4062 if(objects.type[i]!=rocktype)
4063 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
4064 if(player[k].targetanimation!=jumpupanim&&
4065 player[k].targetanimation!=jumpdownanim&&
4066 player[k].onterrain)
4067 player[k].avoidcollided=1;
4068 player[k].coords=lowpoint;
4069 player[k].coords.y-=1.35;
4070 player[k].collide=1;
4072 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
4073 (player[k].currentanimation!=climbanim&&
4074 player[k].currentanimation!=hanganim&&
4075 !player[k].isWallJump()||
4076 player[k].targetanimation==jumpupanim||
4077 player[k].targetanimation==jumpdownanim)){
4078 lowpoint=player[k].coords;
4079 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
4080 lowpoint=player[k].coords;
4084 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
4085 lowpointtarget=lowpoint+facing*1.4;
4086 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4088 lowpoint=player[k].coords;
4090 lowpointtarget=lowpoint+facing*1.4;
4092 lowpointtarget2=lowpointtarget;
4094 lowpointtarget3=lowpointtarget;
4096 lowpointtarget4=lowpointtarget;
4098 lowpointtarget5=lowpointtarget;
4100 lowpointtarget6=lowpointtarget;
4102 lowpointtarget7=lowpoint;
4104 lowpointtarget2.x+=.1;
4106 lowpointtarget3.z+=.1;
4108 lowpointtarget4.x-=.1;
4110 lowpointtarget5.z-=.1;
4112 lowpointtarget6.y+=45/13;
4113 lowpointtarget6+=facing*.6;
4114 lowpointtarget7.y+=90/13;
4115 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
4116 if(objects.friction[i]>.5)
4118 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
4119 player[k].collided=1;
4120 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
4121 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
4122 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
4123 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4124 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
4125 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4126 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
4127 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
4128 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
4129 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
4130 for(int j=0;j<45;j++){
4131 lowpoint=player[k].coords;
4132 lowpoint.y+=(float)j/13;
4133 lowpointtarget=lowpoint+facing*1.4;
4134 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
4135 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
4136 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
4138 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
4139 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
4140 lowpoint=player[k].coords;
4141 lowpoint.y+=(float)j/13;
4142 lowpointtarget=lowpoint+facing*1.3;
4143 flatfacing=player[k].coords;
4144 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
4145 player[k].coords.y=lowpointtarget.y-.07;
4146 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
4148 if(j>10||!player[k].isRun()){
4149 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
4151 pause_sound(whooshsound);
4153 emit_sound_at(jumpsound, player[k].coords, 128.);
4155 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
4156 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
4157 if(lowpointtarget.z<0)
4158 player[k].rotation=180-player[k].rotation;
4159 player[k].targetrotation=player[k].rotation;
4160 player[k].lowrotation=player[k].rotation;
4162 //player[k].velocity=lowpointtarget*.03;
4163 player[k].velocity=0;
4166 if(player[k].targetanimation==jumpupanim){
4167 player[k].targetanimation=climbanim;
4168 player[k].jumppower=0;
4169 player[k].jumpclimb=1;
4171 player[k].transspeed=6;
4173 player[k].targetframe=1;
4176 setAnimation(k,hanganim);
4177 player[k].jumppower=0;
4189 if(player[k].collide<=0){
4191 if(!player[k].onterrain&&
4192 player[k].targetanimation!=jumpupanim&&
4193 player[k].targetanimation!=jumpdownanim&&
4194 player[k].targetanimation!=climbanim&&
4195 player[k].targetanimation!=hanganim&&
4196 !player[k].isWallJump()&&
4197 !player[k].isFlip()){
4198 if(player[k].currentanimation!=climbanim&&
4199 player[k].currentanimation!=tempanim&&
4200 player[k].targetanimation!=backhandspringanim&&
4201 (player[k].targetanimation!=rollanim||
4202 player[k].targetframe<2||
4203 player[k].targetframe>6)){
4204 //stagger off ledge (?)
4205 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
4206 player[k].RagDoll(0);
4207 setAnimation(k,jumpdownanim);
4210 emit_sound_at(whooshsound, player[k].coords, 128.);
4213 player[k].velocity.y+=gravity;
4217 player[k].realoldcoords=player[k].coords;
4221 void Game::doAttacks(){
4222 static XYZ relative;
4223 static int randattack;
4224 static bool playerrealattackkeydown=0;
4226 if(!Input::isKeyDown(attackkey))
4229 player[0].attackkeydown=0;
4231 playerrealattackkeydown=0;
4233 playerrealattackkeydown=Input::isKeyDown(attackkey);
4234 if((player[0].parriedrecently<=0||
4235 player[0].weaponactive==-1)&&
4238 player[0].lastattack!=swordslashanim&&
4239 player[0].lastattack!=knifeslashstartanim&&
4240 player[0].lastattack!=staffhitanim&&
4241 player[0].lastattack!=staffspinhitanim)))
4242 player[0].attackkeydown=Input::isKeyDown(attackkey);
4243 if(Input::isKeyDown(attackkey)&&
4245 !player[0].backkeydown){
4246 for(int k=0;k<numplayers;k++){
4247 if((player[k].targetanimation==swordslashanim||
4248 player[k].targetanimation==staffhitanim||
4249 player[k].targetanimation==staffspinhitanim)&&
4250 player[0].currentanimation!=dodgebackanim&&
4251 !player[k].skeleton.free)
4252 player[k].Reverse();
4256 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
4258 for(int k=0;k<numplayers;k++){
4259 if(indialogue!=-1)player[k].attackkeydown=0;
4260 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
4261 if(player[k].aitype!=playercontrolled)
4262 player[k].victim=&player[0];
4263 //attack key pressed
4264 if(player[k].attackkeydown){
4266 if(player[k].backkeydown&&
4267 player[k].targetanimation!=backhandspringanim&&
4268 (player[k].isIdle()||
4269 player[k].isStop()||
4271 player[k].targetanimation==walkanim)){
4272 if(player[k].jumppower<=1){
4273 player[k].jumppower-=2;
4275 for(int i=0;i<numplayers;i++){
4277 if(player[i].targetanimation==swordslashanim||
4278 player[i].targetanimation==knifeslashstartanim||
4279 player[i].targetanimation==staffhitanim||
4280 player[i].targetanimation==staffspinhitanim)
4281 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
4282 setAnimation(k,dodgebackanim);
4283 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4284 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4287 if(player[k].targetanimation!=dodgebackanim){
4288 if(k==0)numflipped++;
4289 setAnimation(k,backhandspringanim);
4290 player[k].targetrotation=-rotation+180;
4291 if(player[k].leftkeydown)
4292 player[k].targetrotation-=45;
4293 if(player[k].rightkeydown)
4294 player[k].targetrotation+=45;
4295 player[k].rotation=player[k].targetrotation;
4296 player[k].jumppower-=2;
4301 if(!animation[player[k].targetanimation].attack&&
4302 !player[k].backkeydown&&
4303 (player[k].isIdle()||
4305 player[k].targetanimation==walkanim||
4306 player[k].targetanimation==sneakanim||
4307 player[k].isCrouch())){
4308 const int attackweapon=player[k].weaponactive==-1?0:weapons.type[player[k].weaponids[player[k].weaponactive]];
4309 //normal attacks (?)
4310 player[k].hasvictim=0;
4312 for(int i=0;i<numplayers;i++){
4313 if(i==k||!(k==0||i==0))continue;
4314 if(!player[k].hasvictim)
4315 if(animation[player[k].targetanimation].attack!=reversal){
4317 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4319 !player[i].skeleton.free&&
4320 player[i].howactive<typedead1&&
4321 player[i].targetanimation!=jumpreversedanim&&
4322 player[i].targetanimation!=rabbitkickreversedanim&&
4323 player[i].targetanimation!=rabbitkickanim&&
4324 player[k].targetanimation!=rabbitkickanim&&
4325 player[i].targetanimation!=getupfrombackanim&&
4326 (player[i].targetanimation!=staggerbackhighanim&&
4327 (player[i].targetanimation!=staggerbackhardanim||
4328 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
4329 player[i].targetanimation!=jumpdownanim&&
4330 player[i].targetanimation!=jumpupanim&&
4331 player[i].targetanimation!=getupfromfrontanim){
4332 player[k].victim=&player[i];
4333 player[k].hasvictim=1;
4334 if(player[k].aitype==playercontrolled){ //human player
4336 if(distance<2.5*sq(player[k].scale*5)&&
4337 player[k].crouchkeydown&&
4338 animation[player[i].targetanimation].height!=lowheight)
4339 player[k].targetanimation=sweepanim;
4341 else if(distance<1.5*sq(player[k].scale*5)&&
4342 animation[player[i].targetanimation].height!=lowheight&&
4343 !player[k].forwardkeydown&&
4344 !player[k].leftkeydown&&
4345 !player[k].rightkeydown&&
4346 !player[k].crouchkeydown&&
4349 player[k].targetanimation=winduppunchanim;
4351 else if(distance<2.5*sq(player[k].scale*5)&&
4352 animation[player[i].targetanimation].height!=lowheight&&
4353 !player[k].forwardkeydown&&
4354 !player[k].leftkeydown&&
4355 !player[k].rightkeydown&&
4356 !player[k].crouchkeydown&&
4358 player[k].targetanimation=upunchanim;
4360 else if(distance<2.5*sq(player[k].scale*5)&&
4361 player[i].staggerdelay>0&&
4362 attackweapon==knife&&
4363 player[i].bloodloss>player[i].damagetolerance/2)
4364 player[k].targetanimation=knifefollowanim;
4366 else if(distance<2.5*sq(player[k].scale*5)&&
4367 animation[player[i].targetanimation].height!=lowheight&&
4368 !player[k].forwardkeydown&&
4369 !player[k].leftkeydown&&
4370 !player[k].rightkeydown&&
4371 !player[k].crouchkeydown&&
4372 attackweapon==knife&&
4373 player[k].weaponmissdelay<=0)
4374 player[k].targetanimation=knifeslashstartanim;
4376 else if(distance<4.5*sq(player[k].scale*5)&&
4377 animation[player[i].targetanimation].height!=lowheight&&
4378 !player[k].crouchkeydown&&
4379 attackweapon==sword&&
4380 player[k].weaponmissdelay<=0)
4381 player[k].targetanimation=swordslashanim;
4383 else if(distance<4.5*sq(player[k].scale*5)&&
4384 animation[player[i].targetanimation].height!=lowheight&&
4385 !player[k].crouchkeydown&&
4386 attackweapon==staff&&
4387 player[k].weaponmissdelay<=0&&
4388 !player[k].leftkeydown&&
4389 !player[k].rightkeydown&&
4390 !player[k].forwardkeydown)
4391 player[k].targetanimation=staffhitanim;
4393 else if(distance<4.5*sq(player[k].scale*5)&&
4394 animation[player[i].targetanimation].height!=lowheight&&
4395 !player[k].crouchkeydown&&
4396 attackweapon==staff&&
4397 player[k].weaponmissdelay<=0)
4398 player[k].targetanimation=staffspinhitanim;
4400 else if(distance<2.5*sq(player[k].scale*5)&&
4401 animation[player[i].targetanimation].height!=lowheight)
4402 player[k].targetanimation=spinkickanim;
4404 else if(distance<2.5*sq(player[k].scale*5)&&
4405 animation[player[i].targetanimation].height==lowheight&&
4406 animation[player[k].targetanimation].attack!=normalattack)
4407 player[k].targetanimation=lowkickanim;
4408 } else { //AI player
4409 if(distance<4.5*sq(player[k].scale*5)){
4410 randattack=abs(Random()%5);
4411 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
4413 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
4414 player[k].targetanimation=sweepanim;
4416 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
4418 player[k].targetanimation=upunchanim;
4420 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
4421 player[k].targetanimation=spinkickanim;
4423 else if(animation[player[i].targetanimation].height==lowheight)
4424 player[k].targetanimation=lowkickanim;
4428 if((tutoriallevel!=1||!attackweapon)&&
4429 distance<2.5*sq(player[k].scale*5)&&
4431 animation[player[i].targetanimation].height!=lowheight)
4432 player[k].targetanimation=sweepanim;
4434 else if(distance<2.5*sq(player[k].scale*5)&&
4435 attackweapon==knife&&
4436 player[k].weaponmissdelay<=0)
4437 player[k].targetanimation=knifeslashstartanim;
4439 else if(!(player[0].victim==&player[i]&&
4440 player[0].hasvictim&&
4441 player[0].targetanimation==swordslashanim)&&
4442 attackweapon==sword&&
4443 player[k].weaponmissdelay<=0)
4444 player[k].targetanimation=swordslashanim;
4446 else if(!(player[0].victim==&player[i]&&
4447 player[0].hasvictim&&
4448 player[0].targetanimation==swordslashanim)&&
4449 attackweapon==staff&&
4450 player[k].weaponmissdelay<=0&&
4452 player[k].targetanimation=staffhitanim;
4454 else if(!(player[0].victim==&player[i]&&
4455 player[0].hasvictim&&
4456 player[0].targetanimation==swordslashanim)&&
4457 attackweapon==staff&&
4458 player[k].weaponmissdelay<=0&&
4460 player[k].targetanimation=staffspinhitanim;
4462 else if((tutoriallevel!=1||!attackweapon)&&
4463 distance<2.5*sq(player[k].scale*5)&&
4465 animation[player[i].targetanimation].height!=lowheight)
4466 player[k].targetanimation=spinkickanim;
4468 else if(distance<2.5*sq(player[k].scale*5)&&
4469 animation[player[i].targetanimation].height==lowheight&&
4470 animation[player[k].targetanimation].attack!=normalattack)
4471 player[k].targetanimation=lowkickanim;
4475 //upunch becomes wolfslap
4476 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
4477 player[k].targetanimation=wolfslapanim;
4480 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4481 player[i].howactive<typedead1&&
4482 distance<1.5*sq(player[k].scale*5)&&
4483 !player[i].skeleton.free&&
4484 player[i].targetanimation!=getupfrombackanim&&
4485 player[i].targetanimation!=getupfromfrontanim&&
4486 (player[i].stunned>0&&player[k].madskills||
4487 player[i].surprised>0||
4488 player[i].aitype==passivetype||
4489 attackweapon&&player[i].stunned>0)&&
4490 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4493 player[k].currentanimation=sneakattackanim;
4494 player[k].targetanimation=sneakattackanim;
4495 player[i].currentanimation=sneakattackedanim;
4496 player[i].targetanimation=sneakattackedanim;
4497 player[k].oldcoords=player[k].coords;
4498 player[k].coords=player[i].coords;
4501 if(attackweapon==knife){
4502 player[k].currentanimation=knifesneakattackanim;
4503 player[k].targetanimation=knifesneakattackanim;
4504 player[i].currentanimation=knifesneakattackedanim;
4505 player[i].targetanimation=knifesneakattackedanim;
4506 player[i].oldcoords=player[i].coords;
4507 player[i].coords=player[k].coords;
4510 if(attackweapon==sword){
4511 player[k].currentanimation=swordsneakattackanim;
4512 player[k].targetanimation=swordsneakattackanim;
4513 player[i].currentanimation=swordsneakattackedanim;
4514 player[i].targetanimation=swordsneakattackedanim;
4515 player[i].oldcoords=player[i].coords;
4516 player[i].coords=player[k].coords;
4518 if(attackweapon!=staff){
4519 player[k].victim=&player[i];
4520 player[k].hasvictim=1;
4521 player[i].targettilt2=0;
4522 player[i].targetframe=1;
4523 player[i].currentframe=0;
4525 player[i].velocity=0;
4526 player[k].targettilt2=player[i].targettilt2;
4527 player[k].currentframe=player[i].currentframe;
4528 player[k].targetframe=player[i].targetframe;
4529 player[k].target=player[i].target;
4530 player[k].velocity=0;
4531 player[k].targetrotation=player[i].rotation;
4532 player[k].rotation=player[i].rotation;
4533 player[i].targetrotation=player[i].rotation;
4536 if(animation[player[k].targetanimation].attack==normalattack&&
4537 player[k].victim==&player[i]&&
4538 (!player[i].skeleton.free)){
4540 player[k].targetframe=0;
4543 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4544 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4545 player[k].lastattack3=player[k].lastattack2;
4546 player[k].lastattack2=player[k].lastattack;
4547 player[k].lastattack=player[k].targetanimation;
4549 if(player[k].targetanimation==knifefollowanim&&
4550 player[k].victim==&player[i]){
4552 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4553 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4554 player[k].victim=&player[i];
4555 player[k].hasvictim=1;
4556 player[i].targetanimation=knifefollowedanim;
4557 player[i].currentanimation=knifefollowedanim;
4558 player[i].targettilt2=0;
4559 player[i].targettilt2=player[k].targettilt2;
4560 player[i].targetframe=1;
4561 player[i].currentframe=0;
4563 player[i].velocity=0;
4564 player[k].currentanimation=knifefollowanim;
4565 player[k].targetanimation=knifefollowanim;
4566 player[k].targettilt2=player[i].targettilt2;
4567 player[k].currentframe=player[i].currentframe;
4568 player[k].targetframe=player[i].targetframe;
4569 player[k].target=player[i].target;
4570 player[k].velocity=0;
4571 player[k].oldcoords=player[k].coords;
4572 player[i].coords=player[k].coords;
4573 player[i].targetrotation=player[k].targetrotation;
4574 player[i].rotation=player[k].targetrotation;
4575 player[k].rotation=player[k].targetrotation;
4576 player[i].rotation=player[k].targetrotation;
4580 const bool hasstaff=attackweapon==staff;
4581 if(k==0&&numplayers>1)
4582 for(int i=0;i<numplayers;i++){
4584 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4585 animation[player[k].targetanimation].attack==neutral){
4586 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4587 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4588 if(player[i].skeleton.free)
4589 if(distance<3.5*sq(player[k].scale*5)&&
4591 player[i].skeleton.longdead>1000||
4595 (player[i].skeleton.longdead>2000||
4596 player[i].damage>player[i].damagetolerance/8||
4597 player[i].bloodloss>player[i].damagetolerance/2)&&
4598 distance<1.5*sq(player[k].scale*5)))){
4599 player[k].victim=&player[i];
4600 player[k].hasvictim=1;
4601 if(attackweapon&&tutoriallevel!=1){
4603 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4604 player[k].targetanimation=crouchstabanim;
4606 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4607 player[k].targetanimation=swordgroundstabanim;
4609 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4610 player[k].targetanimation=staffgroundsmashanim;
4613 player[k].crouchkeydown&&
4614 player[k].targetanimation!=crouchstabanim&&
4617 player[i].skeleton.free&&
4618 player[i].skeleton.longdead>1000){
4619 player[k].targetanimation=killanim;
4620 //TODO: refactor this out, what does it do?
4621 for(int j=0;j<terrain.numdecals;j++){
4622 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4623 terrain.decalalivetime[j]<2)
4624 terrain.DeleteDecal(j);
4626 for(int l=0;l<objects.numobjects;l++){
4627 if(objects.model[l].type==decalstype)
4628 for(int j=0;j<objects.model[l].numdecals;j++){
4629 if((objects.model[l].decaltype[j]==blooddecal||
4630 objects.model[l].decaltype[j]==blooddecalslow)&&
4631 objects.model[l].decalalivetime[j]<2)
4632 objects.model[l].DeleteDecal(j);
4636 if(!player[i].dead||musictype!=2)
4638 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4639 player[k].staggerdelay<=0&&
4641 player[i].skeleton.longdead<300&&
4642 player[k].lastattack!=spinkickanim&&
4643 player[i].skeleton.free)&&
4644 (!player[i].dead||musictype!=stream_music2)){
4645 player[k].targetanimation=dropkickanim;
4646 for(int j=0;j<terrain.numdecals;j++){
4647 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4648 terrain.decalalivetime[j]<2){
4649 terrain.DeleteDecal(j);
4652 for(int l=0;l<objects.numobjects;l++){
4653 if(objects.model[l].type==decalstype)
4654 for(int j=0;j<objects.model[l].numdecals;j++){
4655 if((objects.model[l].decaltype[j]==blooddecal||
4656 objects.model[l].decaltype[j]==blooddecalslow)&&
4657 objects.model[l].decalalivetime[j]<2){
4658 objects.model[l].DeleteDecal(j);
4664 if(animation[player[k].targetanimation].attack==normalattack&&
4665 player[k].victim==&player[i]&&
4666 (!player[i].skeleton.free||
4667 player[k].targetanimation==killanim||
4668 player[k].targetanimation==crouchstabanim||
4669 player[k].targetanimation==swordgroundstabanim||
4670 player[k].targetanimation==staffgroundsmashanim||
4671 player[k].targetanimation==dropkickanim)){
4673 player[k].targetframe=0;
4676 XYZ targetpoint=player[i].coords;
4677 if(player[k].targetanimation==crouchstabanim||
4678 player[k].targetanimation==swordgroundstabanim||
4679 player[k].targetanimation==staffgroundsmashanim){
4680 targetpoint+=(playerJoint(i,abdomen).position+
4681 playerJoint(i,neck).position)/2*
4684 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4685 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4687 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4688 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4691 if(player[k].targetanimation==staffgroundsmashanim)
4692 player[k].targettilt2+=10;
4694 player[k].lastattack3=player[k].lastattack2;
4695 player[k].lastattack2=player[k].lastattack;
4696 player[k].lastattack=player[k].targetanimation;
4698 if(player[k].targetanimation==swordgroundstabanim){
4699 player[k].targetrotation+=30;
4704 if(!player[k].hasvictim){
4706 for(int i=0;i<numplayers;i++){
4707 if(i==k||!(i==0||k==0))continue;
4708 if(!player[i].skeleton.free){
4709 if(player[k].hasvictim){
4710 if(findDistancefast(&player[k].coords,&player[i].coords)<
4711 findDistancefast(&player[k].coords,&player[k].victim->coords))
4712 player[k].victim=&player[i];
4714 player[k].victim=&player[i];
4715 player[k].hasvictim=1;
4720 if(player[k].aitype==playercontrolled)
4722 if(player[k].attackkeydown&&
4724 player[k].wasRun()&&
4725 ((player[k].hasvictim&&
4726 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4727 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4728 !player[k].victim->skeleton.free&&
4729 player[k].victim->targetanimation!=getupfrombackanim&&
4730 player[k].victim->targetanimation!=getupfromfrontanim&&
4731 animation[player[k].victim->targetanimation].height!=lowheight&&
4732 player[k].aitype!=playercontrolled&& //wat???
4733 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4734 player[k].rabbitkickenabled)||
4735 player[k].jumpkeydown)){
4737 setAnimation(k,rabbitkickanim);
4740 if(animation[player[k].targetanimation].attack&&k==0){
4742 switch(attackweapon){
4743 case 0: numunarmedattack++; break;
4744 case knife: numknifeattack++; break;
4745 case sword: numswordattack++; break;
4746 case staff: numstaffattack++; break;
4755 void Game::doPlayerCollisions(){
4756 static XYZ rotatetarget;
4757 static float collisionradius;
4759 for(int k=0;k<numplayers;k++)
4760 for(int i=k+1;i<numplayers;i++){
4761 //neither player is part of a reversal
4762 if((animation[player[i].targetanimation].attack!=reversed&&
4763 animation[player[i].targetanimation].attack!=reversal&&
4764 animation[player[k].targetanimation].attack!=reversed&&
4765 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4766 if((animation[player[i].currentanimation].attack!=reversed&&
4767 animation[player[i].currentanimation].attack!=reversal&&
4768 animation[player[k].currentanimation].attack!=reversed&&
4769 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4770 //neither is sleeping
4771 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4772 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4773 //in same patch, neither is climbing
4774 if(player[i].whichpatchx==player[k].whichpatchx&&
4775 player[i].whichpatchz==player[k].whichpatchz&&
4776 player[k].skeleton.oldfree==player[k].skeleton.free&&
4777 player[i].skeleton.oldfree==player[i].skeleton.free&&
4778 player[i].targetanimation!=climbanim&&
4779 player[i].targetanimation!=hanganim&&
4780 player[k].targetanimation!=climbanim&&
4781 player[k].targetanimation!=hanganim)
4782 //players are close (bounding box test)
4783 if(player[i].coords.y>player[k].coords.y-3)
4784 if(player[i].coords.y<player[k].coords.y+3)
4785 if(player[i].coords.x>player[k].coords.x-3)
4786 if(player[i].coords.x<player[k].coords.x+3)
4787 if(player[i].coords.z>player[k].coords.z-3)
4788 if(player[i].coords.z<player[k].coords.z+3){
4789 //spread fire from player to player
4790 if(findDistancefast(&player[i].coords,&player[k].coords)
4791 <3*sq((player[i].scale+player[k].scale)*2.5)){
4792 if(player[i].onfire||player[k].onfire){
4793 if(!player[i].onfire)player[i].CatchFire();
4794 if(!player[k].onfire)player[k].CatchFire();
4798 XYZ tempcoords1=player[i].coords;
4799 XYZ tempcoords2=player[k].coords;
4800 if(!player[i].skeleton.oldfree)
4801 tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
4802 if(!player[k].skeleton.oldfree)
4803 tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
4804 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4805 if(player[0].hasvictim)
4806 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4808 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4809 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4810 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4811 //jump down on a dead body
4814 if(player[0].targetanimation==jumpdownanim&&
4815 !player[0].skeleton.oldfree&&
4816 !player[0].skeleton.free&&
4817 player[l].skeleton.oldfree&&
4818 player[l].skeleton.free&&
4820 player[0].lastcollide<=0&&
4821 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4822 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4823 player[0].coords.y=player[l].coords.y;
4824 player[l].velocity=player[0].velocity;
4825 player[l].skeleton.free=0;
4826 player[l].rotation=0;
4827 player[l].RagDoll(0);
4828 player[l].DoDamage(20);
4830 player[l].skeleton.longdead=0;
4831 player[0].lastcollide=1;
4835 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4836 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4837 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4838 rotatetarget=player[k].velocity-player[i].velocity;
4839 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4840 player[i].skeleton.free)&&
4841 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4842 player[k].skeleton.free))
4843 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4844 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4845 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4847 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4848 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4849 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4850 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4851 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4853 if( (i!=0||player[i].skeleton.free)&&
4854 (k!=0||player[k].skeleton.free)||
4855 (animation[player[i].targetanimation].height==highheight&&
4856 animation[player[k].targetanimation].height==highheight)){
4857 if(tutoriallevel!=1){
4858 emit_sound_at(heavyimpactsound, player[i].coords);
4861 player[i].RagDoll(0);
4862 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4863 award_bonus(0, aimbonus);
4865 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4866 player[k].RagDoll(0);
4867 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4868 award_bonus(0, aimbonus); // Huh, again?
4870 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4872 for(int j=0;j<player[i].skeleton.num_joints;j++){
4873 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4875 for(int j=0;j<player[k].skeleton.num_joints;j++){
4876 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4881 if( (animation[player[i].targetanimation].attack==neutral||
4882 animation[player[i].targetanimation].attack==normalattack)&&
4883 (animation[player[k].targetanimation].attack==neutral||
4884 animation[player[k].targetanimation].attack==normalattack)){
4886 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4887 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4888 rotatetarget=player[k].coords-player[i].coords;
4889 Normalise(&rotatetarget);
4890 player[k].coords=(player[k].coords+player[i].coords)/2;
4891 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4892 *sq((player[i].scale+player[k].scale)*2.5);
4893 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4894 if(player[k].howactive==typeactive||hostile)
4895 if(player[k].isIdle()){
4896 if(player[k].howactive<typesleeping)
4897 setAnimation(k,player[k].getStop());
4898 else if(player[k].howactive==typesleeping)
4899 setAnimation(k,getupfromfrontanim);
4901 player[k].howactive=typeactive;
4903 if(player[i].howactive==typeactive||hostile)
4904 if(player[i].isIdle()){
4905 if(player[i].howactive<typesleeping)
4906 setAnimation(i,player[k].getStop());
4908 setAnimation(i,getupfromfrontanim);
4910 player[i].howactive=typeactive;
4913 //jump down on player
4915 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4916 !player[i].isCrouch()&&
4917 player[i].targetanimation!=rollanim&&
4918 !player[k].skeleton.oldfree&&!
4919 player[k].skeleton.free&&
4920 player[k].lastcollide<=0&&
4921 player[k].velocity.y<-10){
4922 player[i].velocity=player[k].velocity;
4923 player[k].velocity=player[k].velocity*-.5;
4924 player[k].velocity.y=player[i].velocity.y;
4925 player[i].DoDamage(20);
4926 player[i].RagDoll(0);
4927 player[k].lastcollide=1;
4928 award_bonus(k, AboveBonus);
4930 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4931 !player[k].isCrouch()&&
4932 player[k].targetanimation!=rollanim&&
4933 !player[i].skeleton.oldfree&&
4934 !player[i].skeleton.free&&
4935 player[i].lastcollide<=0&&
4936 player[i].velocity.y<-10){
4937 player[k].velocity=player[i].velocity;
4938 player[i].velocity=player[i].velocity*-.3;
4939 player[i].velocity.y=player[k].velocity.y;
4940 player[k].DoDamage(20);
4941 player[k].RagDoll(0);
4942 player[i].lastcollide=1;
4943 award_bonus(i, AboveBonus);
4949 player[i].CheckKick();
4950 player[k].CheckKick();
4958 void Game::doAI(int i){
4959 static bool connected;
4960 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4961 player[i].jumpclimb=0;
4962 //disable movement in editor
4964 player[i].stunned=1;
4967 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4968 player[0].coords.y>player[i].coords.y+2&&
4969 !player[0].onterrain)
4973 if(player[i].aitype==pathfindtype){
4974 if(player[i].finalpathfindpoint==-1){
4975 float closestdistance;
4981 for(int j=0;j<numpathpoints;j++)
4982 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4983 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4985 player[i].finaltarget=pathpoint[j];
4987 player[i].finalpathfindpoint=closest;
4988 for(int j=0;j<numpathpoints;j++)
4989 for(int k=0;k<numpathpointconnect[j];k++){
4990 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4991 if(sq(tempdist)<closestdistance)
4992 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4993 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4994 closestdistance=sq(tempdist);
4996 player[i].finaltarget=colpoint;
4999 player[i].finalpathfindpoint=closest;
5002 if(player[i].targetpathfindpoint==-1){
5003 float closestdistance;
5009 if(player[i].lastpathfindpoint==-1){
5010 for(int j=0;j<numpathpoints;j++){
5011 if(j!=player[i].lastpathfindpoint)
5012 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
5013 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
5017 player[i].targetpathfindpoint=closest;
5018 for(int j=0;j<numpathpoints;j++)
5019 if(j!=player[i].lastpathfindpoint)
5020 for(int k=0;k<numpathpointconnect[j];k++){
5021 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
5022 if(sq(tempdist)<closestdistance){
5023 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
5024 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
5025 closestdistance=sq(tempdist);
5030 player[i].targetpathfindpoint=closest;
5034 for(int j=0;j<numpathpoints;j++)
5035 if(j!=player[i].lastpathfindpoint&&
5036 j!=player[i].lastpathfindpoint2&&
5037 j!=player[i].lastpathfindpoint3&&
5038 j!=player[i].lastpathfindpoint4){
5040 if(numpathpointconnect[j])
5041 for(int k=0;k<numpathpointconnect[j];k++)
5042 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
5045 if(numpathpointconnect[player[i].lastpathfindpoint])
5046 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
5047 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
5050 tempdist=findPathDist(j,player[i].finalpathfindpoint);
5051 if(closest==-1||tempdist<closestdistance){
5052 closestdistance=tempdist;
5057 player[i].targetpathfindpoint=closest;
5060 player[i].losupdatedelay-=multiplier;
5062 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
5063 player[i].lookrotation=player[i].targetrotation;
5065 //reached target point
5066 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
5067 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
5068 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
5069 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
5070 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
5071 if(player[i].lastpathfindpoint2==-1)
5072 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
5073 if(player[i].lastpathfindpoint3==-1)
5074 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
5075 if(player[i].lastpathfindpoint4==-1)
5076 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
5077 player[i].targetpathfindpoint=-1;
5079 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
5080 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
5081 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
5082 player[i].lastpathfindpoint==player[i].finalpathfindpoint){
5083 player[i].aitype=passivetype;
5086 player[i].forwardkeydown=1;
5087 player[i].leftkeydown=0;
5088 player[i].backkeydown=0;
5089 player[i].rightkeydown=0;
5090 player[i].crouchkeydown=0;
5091 player[i].attackkeydown=0;
5092 player[i].throwkeydown=0;
5094 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5095 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5097 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5098 player[i].jumpkeydown=0;
5099 if((player[i].collided>.8&&player[i].jumppower>=5))
5100 player[i].jumpkeydown=1;
5102 if((tutoriallevel!=1||cananger)&&
5105 findDistancefast(&player[i].coords,&player[0].coords)<400&&
5106 player[i].occluded<25){
5107 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
5108 animation[player[0].targetanimation].height!=lowheight&&
5110 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
5111 player[i].aitype=attacktypecutoff;
5112 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
5113 animation[player[0].targetanimation].height==highheight&&
5115 player[i].aitype=attacktypecutoff;
5117 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
5118 player[i].losupdatedelay=.2;
5119 for(int j=0;j<numplayers;j++)
5120 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
5121 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
5122 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
5123 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
5124 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
5125 if(!player[j].isWallJump()&&-1==checkcollide(
5126 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)
5127 *player[i].scale+player[i].coords,
5128 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)
5129 *player[j].scale+player[j].coords)||
5130 (player[j].targetanimation==hanganim&&
5131 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
5132 player[i].aitype=searchtype;
5133 player[i].lastchecktime=12;
5134 player[i].lastseen=player[j].coords;
5135 player[i].lastseentime=12;
5139 if(player[i].aitype==attacktypecutoff&&musictype!=2)
5140 if(player[i].creature!=wolftype){
5141 player[i].stunned=.6;
5142 player[i].surprised=.6;
5146 if(player[i].aitype!=passivetype&&leveltime>.5)
5147 player[i].howactive=typeactive;
5149 if(player[i].aitype==passivetype){
5150 player[i].aiupdatedelay-=multiplier;
5151 player[i].losupdatedelay-=multiplier;
5152 player[i].lastseentime+=multiplier;
5153 player[i].pausetime-=multiplier;
5154 if(player[i].lastseentime>1)
5155 player[i].lastseentime=1;
5157 if(player[i].aiupdatedelay<0){
5158 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
5159 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
5160 player[i].lookrotation=player[i].targetrotation;
5161 player[i].aiupdatedelay=.05;
5163 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
5164 if(player[i].waypointtype[player[i].waypoint]==wppause)
5165 player[i].pausetime=4;
5166 player[i].waypoint++;
5167 if(player[i].waypoint>player[i].numwaypoints-1)
5168 player[i].waypoint=0;
5173 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
5174 player[i].forwardkeydown=1;
5176 player[i].forwardkeydown=0;
5177 player[i].leftkeydown=0;
5178 player[i].backkeydown=0;
5179 player[i].rightkeydown=0;
5180 player[i].crouchkeydown=0;
5181 player[i].attackkeydown=0;
5182 player[i].throwkeydown=0;
5184 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5185 if(!player[i].avoidsomething)
5186 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5188 XYZ leftpos,rightpos;
5189 float leftdist,rightdist;
5190 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5191 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5192 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5193 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5194 if(leftdist<rightdist)
5195 player[i].targetrotation+=90;
5197 player[i].targetrotation-=90;
5201 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5202 player[i].jumpkeydown=0;
5203 if((player[i].collided>.8&&player[i].jumppower>=5))
5204 player[i].jumpkeydown=1;
5209 if(player[i].howactive<=typesleeping)
5210 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
5211 for(int j=0;j<numenvsounds;j++){
5212 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
5213 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
5214 2*(vol+vol*(player[i].creature==rabbittype)*3))
5215 player[i].aitype=attacktypecutoff;
5218 if(player[i].aitype!=passivetype){
5219 if(player[i].howactive==typesleeping)
5220 setAnimation(i,getupfromfrontanim);
5221 player[i].howactive=typeactive;
5225 if(player[i].howactive<typesleeping&&
5226 ((tutoriallevel!=1||cananger)&&hostile)&&
5228 findDistancefast(&player[i].coords,&player[0].coords)<400&&
5229 player[i].occluded<25){
5230 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
5231 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
5232 player[i].aitype=attacktypecutoff;
5233 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
5234 animation[player[0].targetanimation].height==highheight&&!editorenabled)
5235 player[i].aitype=attacktypecutoff;
5238 if(player[i].creature==wolftype){
5240 for(int j=0;j<numplayers;j++){
5241 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
5242 float smelldistance=50;
5243 if(j==0&&player[j].num_weapons>0){
5244 if(weapons.bloody[player[j].weaponids[0]])
5246 if(player[j].num_weapons==2)
5247 if(weapons.bloody[player[j].weaponids[1]])
5252 windsmell=windvector;
5253 Normalise(&windsmell);
5254 windsmell=windsmell*2+player[j].coords;
5255 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
5256 player[i].aitype=attacktypecutoff;
5261 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
5262 player[i].losupdatedelay=.2;
5263 for(int j=0;j<numplayers;j++){
5264 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
5265 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
5266 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
5267 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
5268 if((-1==checkcollide(
5269 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
5270 player[i].scale+player[i].coords,
5271 DoRotation(playerJoint(j,head).position,0,player[j].rotation,0)*
5272 player[j].scale+player[j].coords)&&
5273 !player[j].isWallJump())||
5274 (player[j].targetanimation==hanganim&&
5275 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
5276 player[i].lastseentime-=.2;
5277 if(j==0&&animation[player[j].targetanimation].height==lowheight)
5278 player[i].lastseentime-=.4;
5280 player[i].lastseentime-=.6;
5282 if(player[i].lastseentime<=0){
5283 player[i].aitype=searchtype;
5284 player[i].lastchecktime=12;
5285 player[i].lastseen=player[j].coords;
5286 player[i].lastseentime=12;
5293 if(player[i].aitype==attacktypecutoff&&musictype!=2){
5294 if(player[i].creature!=wolftype){
5295 player[i].stunned=.6;
5296 player[i].surprised=.6;
5298 if(player[i].creature==wolftype){
5299 player[i].stunned=.47;
5300 player[i].surprised=.47;
5308 if(player[i].aitype==searchtype){
5309 player[i].aiupdatedelay-=multiplier;
5310 player[i].losupdatedelay-=multiplier;
5311 if(!player[i].pause)
5312 player[i].lastseentime-=multiplier;
5313 player[i].lastchecktime-=multiplier;
5315 if(player[i].isRun()&&!player[i].onground){
5316 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5317 XYZ test2=player[i].coords+player[i].facing;
5319 XYZ test=player[i].coords+player[i].facing;
5321 j=checkcollide(test2,test,player[i].laststanding);
5323 j=checkcollide(test2,test);
5325 player[i].velocity=0;
5326 setAnimation(i,player[i].getStop());
5327 player[i].targetrotation+=180;
5328 player[i].stunned=.5;
5329 //player[i].aitype=passivetype;
5330 player[i].aitype=pathfindtype;
5331 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5332 player[i].finalpathfindpoint=-1;
5333 player[i].targetpathfindpoint=-1;
5334 player[i].lastpathfindpoint=-1;
5335 player[i].lastpathfindpoint2=-1;
5336 player[i].lastpathfindpoint3=-1;
5337 player[i].lastpathfindpoint4=-1;
5339 else player[i].laststanding=j;
5342 //check out last seen location
5343 if(player[i].aiupdatedelay<0){
5344 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
5345 player[i].lookrotation=player[i].targetrotation;
5346 player[i].aiupdatedelay=.05;
5347 player[i].forwardkeydown=1;
5349 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
5350 player[i].forwardkeydown=0;
5351 player[i].aiupdatedelay=1;
5352 player[i].lastseen.x+=(float(Random()%100)-50)/25;
5353 player[i].lastseen.z+=(float(Random()%100)-50)/25;
5354 player[i].lastchecktime=3;
5357 player[i].leftkeydown=0;
5358 player[i].backkeydown=0;
5359 player[i].rightkeydown=0;
5360 player[i].crouchkeydown=0;
5361 player[i].attackkeydown=0;
5362 player[i].throwkeydown=0;
5364 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5365 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5367 XYZ leftpos,rightpos;
5368 float leftdist,rightdist;
5369 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5370 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5371 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5372 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5373 if(leftdist<rightdist)player[i].targetrotation+=90;
5374 else player[i].targetrotation-=90;
5378 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5379 player[i].jumpkeydown=0;
5380 if((player[i].collided>.8&&player[i].jumppower>=5))
5381 player[i].jumpkeydown=1;
5383 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
5384 for(int k=0;k<numenvsounds;k++){
5385 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
5386 player[i].aitype=attacktypecutoff;
5390 if(!player[0].dead&&
5391 player[i].losupdatedelay<0&&
5393 player[i].occluded<2&&
5394 ((tutoriallevel!=1||cananger)&&hostile)){
5395 player[i].losupdatedelay=.2;
5396 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
5397 player[i].aitype=attacktypecutoff;
5398 player[i].lastseentime=1;
5400 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
5401 //TODO: factor out canSeePlayer()
5402 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
5403 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5405 DoRotation(playerJoint(i,head).position,0,player[i].rotation,0)*
5406 player[i].scale+player[i].coords,
5407 DoRotation(playerJoint(0,head).position,0,player[0].rotation,0)*
5408 player[0].scale+player[0].coords)==-1)||
5409 (player[0].targetanimation==hanganim&&normaldotproduct(
5410 player[0].facing,player[i].coords-player[0].coords)<0)){
5411 /* //TODO: changed j to 0 on a whim, make sure this is correct
5412 (player[j].targetanimation==hanganim&&normaldotproduct(
5413 player[j].facing,player[i].coords-player[j].coords)<0)
5415 player[i].aitype=attacktypecutoff;
5416 player[i].lastseentime=1;
5420 if(player[i].lastseentime<0){
5421 //player[i].aitype=passivetype;
5423 player[i].aitype=pathfindtype;
5424 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5425 player[i].finalpathfindpoint=-1;
5426 player[i].targetpathfindpoint=-1;
5427 player[i].lastpathfindpoint=-1;
5428 player[i].lastpathfindpoint2=-1;
5429 player[i].lastpathfindpoint3=-1;
5430 player[i].lastpathfindpoint4=-1;
5434 if(player[i].aitype!=gethelptype)
5435 player[i].runninghowlong=0;
5437 //get help from buddies
5438 if(player[i].aitype==gethelptype){
5439 player[i].runninghowlong+=multiplier;
5440 player[i].aiupdatedelay-=multiplier;
5442 if(player[i].aiupdatedelay<0||player[i].ally==0){
5443 player[i].aiupdatedelay=.2;
5446 //TODO: factor out closest search somehow
5447 if(!player[i].ally){
5449 float closestdist=-1;
5450 for(int k=0;k<numplayers;k++){
5451 if(k!=i&&k!=0&&!player[k].dead&&
5452 player[k].howactive<typedead1&&
5453 !player[k].skeleton.free&&
5454 player[k].aitype==passivetype){
5455 float distance=findDistancefast(&player[i].coords,&player[k].coords);
5456 if(closestdist==-1||distance<closestdist){
5457 closestdist=distance;
5464 player[i].ally=closest;
5467 player[i].lastseen=player[0].coords;
5468 player[i].lastseentime=12;
5472 player[i].lastchecktime=12;
5474 XYZ facing=player[i].coords;
5475 XYZ flatfacing=player[player[i].ally].coords;
5476 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5477 flatfacing.y+=playerJoint(player[i].ally,head).position.y*player[player[i].ally].scale;
5478 if(-1!=checkcollide(facing,flatfacing))
5479 player[i].lastseentime-=.1;
5481 //no available ally, run back to player
5482 if(player[i].ally<=0||
5483 player[player[i].ally].skeleton.free||
5484 player[player[i].ally].aitype!=passivetype||
5485 player[i].lastseentime<=0){
5486 player[i].aitype=searchtype;
5487 player[i].lastseentime=12;
5491 if(player[i].ally>0){
5492 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5493 player[i].lookrotation=player[i].targetrotation;
5494 player[i].aiupdatedelay=.05;
5495 player[i].forwardkeydown=1;
5497 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
5498 player[i].aitype=searchtype;
5499 player[i].lastseentime=12;
5500 player[player[i].ally].aitype=searchtype;
5501 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5502 player[player[i].ally].lastseen=player[i].lastseen;
5503 player[player[i].ally].lastseentime=player[i].lastseentime;
5504 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5508 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5509 if(!player[i].avoidsomething)
5510 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5512 XYZ leftpos,rightpos;
5513 float leftdist,rightdist;
5514 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5515 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5516 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5517 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5518 if(leftdist<rightdist)
5519 player[i].targetrotation+=90;
5521 player[i].targetrotation-=90;
5526 player[i].leftkeydown=0;
5527 player[i].backkeydown=0;
5528 player[i].rightkeydown=0;
5529 player[i].crouchkeydown=0;
5530 player[i].attackkeydown=0;
5532 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5533 player[i].jumpkeydown=0;
5534 if(player[i].collided>.8&&player[i].jumppower>=5)
5535 player[i].jumpkeydown=1;
5538 //retreiving a weapon on the ground
5539 if(player[i].aitype==getweapontype){
5540 player[i].aiupdatedelay-=multiplier;
5541 player[i].lastchecktime-=multiplier;
5543 if(player[i].aiupdatedelay<0){
5544 player[i].aiupdatedelay=.2;
5547 if(player[i].ally<0){
5549 float closestdist=-1;
5550 for(int k=0;k<weapons.numweapons;k++)
5551 if(weapons.owner[k]==-1){
5552 float distance=findDistancefast(&player[i].coords,&weapons.position[k]);
5553 if(closestdist==-1||distance<closestdist){
5554 closestdist=distance;
5560 player[i].ally=closest;
5565 player[i].lastseentime=12;
5567 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5568 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5569 player[i].aitype=attacktypecutoff;
5570 player[i].lastseentime=1;
5573 if(player[i].ally>=0){
5574 if(weapons.owner[player[i].ally]!=-1||
5575 findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
5576 player[i].aitype=attacktypecutoff;
5577 player[i].lastseentime=1;
5579 //TODO: factor these out as moveToward()
5580 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[player[i].ally]);
5581 player[i].lookrotation=player[i].targetrotation;
5582 player[i].aiupdatedelay=.05;
5583 player[i].forwardkeydown=1;
5586 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5587 if(!player[i].avoidsomething)
5588 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5590 XYZ leftpos,rightpos;
5591 float leftdist,rightdist;
5592 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5593 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5594 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5595 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5596 if(leftdist<rightdist)
5597 player[i].targetrotation+=90;
5599 player[i].targetrotation-=90;
5604 player[i].leftkeydown=0;
5605 player[i].backkeydown=0;
5606 player[i].rightkeydown=0;
5607 player[i].attackkeydown=0;
5608 player[i].throwkeydown=1;
5609 player[i].crouchkeydown=0;
5610 if(player[i].targetanimation!=crouchremoveknifeanim&&
5611 player[i].targetanimation!=removeknifeanim)
5612 player[i].throwtogglekeydown=0;
5613 player[i].drawkeydown=0;
5615 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5616 player[i].jumpkeydown=0;
5617 if((player[i].collided>.8&&player[i].jumppower>=5))
5618 player[i].jumpkeydown=1;
5621 if(player[i].aitype==attacktypecutoff){
5622 player[i].aiupdatedelay-=multiplier;
5623 //dodge or reverse rabbit kicks, knife throws, flips
5624 if(player[i].damage<player[i].damagetolerance*2/3)
5625 if((player[0].targetanimation==rabbitkickanim||
5626 player[0].targetanimation==knifethrowanim||
5627 (player[0].isFlip()&&
5628 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5629 !player[0].skeleton.free&&
5630 (player[i].aiupdatedelay<.1)){
5631 player[i].attackkeydown=0;
5632 if(player[i].isIdle())
5633 player[i].crouchkeydown=1;
5634 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5635 if(weapons.type[player[0].weaponids[0]]==knife){
5636 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5637 if(abs(Random()%2==0))
5638 setAnimation(i,backhandspringanim);
5640 setAnimation(i,rollanim);
5641 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5642 player[i].wentforweapon=0;
5644 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5645 setAnimation(i,flipanim);
5648 player[i].forwardkeydown=0;
5649 player[i].aiupdatedelay=.02;
5651 //get confused by flips
5652 if(player[0].isFlip()&&
5653 !player[0].skeleton.free&&
5654 player[0].targetanimation!=walljumprightkickanim&&
5655 player[0].targetanimation!=walljumpleftkickanim){
5656 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5657 if((1-player[i].damage/player[i].damagetolerance)>.5)
5658 player[i].stunned=1;
5660 //go for weapon on the ground
5661 if(player[i].wentforweapon<3)
5662 for(int k=0;k<weapons.numweapons;k++)
5663 if(player[i].creature!=wolftype)
5664 if(player[i].num_weapons==0&&
5665 weapons.owner[k]==-1&&
5666 weapons.velocity[i].x==0&&
5667 weapons.velocity[i].z==0&&
5668 weapons.velocity[i].y==0){
5669 if(findDistancefast(&player[i].coords,&weapons.position[k])<16){
5670 player[i].wentforweapon++;
5671 player[i].lastchecktime=6;
5672 player[i].aitype=getweapontype;
5676 //dodge/reverse walljump kicks
5677 if(player[i].damage<player[i].damagetolerance/2)
5678 if(animation[player[i].targetanimation].height!=highheight)
5679 if(player[i].damage<player[i].damagetolerance*.5&&
5680 ((player[0].targetanimation==walljumprightkickanim||
5681 player[0].targetanimation==walljumpleftkickanim)&&
5682 ((player[i].aiupdatedelay<.15&&
5684 (player[i].aiupdatedelay<.08&&
5686 player[i].crouchkeydown=1;
5688 //walked off a ledge (?)
5689 if(player[i].isRun()&&!player[i].onground)
5690 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5691 XYZ test2=player[i].coords+player[i].facing;
5693 XYZ test=player[i].coords+player[i].facing;
5695 j=checkcollide(test2,test,player[i].laststanding);
5697 j=checkcollide(test2,test);
5699 player[i].velocity=0;
5700 setAnimation(i,player[i].getStop());
5701 player[i].targetrotation+=180;
5702 player[i].stunned=.5;
5703 player[i].aitype=pathfindtype;
5704 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5705 player[i].finalpathfindpoint=-1;
5706 player[i].targetpathfindpoint=-1;
5707 player[i].lastpathfindpoint=-1;
5708 player[i].lastpathfindpoint2=-1;
5709 player[i].lastpathfindpoint3=-1;
5710 player[i].lastpathfindpoint4=-1;
5712 player[i].laststanding=j;
5714 //lose sight of player in the air (?)
5715 if(player[0].coords.y>player[i].coords.y+5&&
5716 animation[player[0].targetanimation].height!=highheight&&
5717 !player[0].onterrain){
5718 player[i].aitype=pathfindtype;
5719 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5720 player[i].finalpathfindpoint=-1;
5721 player[i].targetpathfindpoint=-1;
5722 player[i].lastpathfindpoint=-1;
5723 player[i].lastpathfindpoint2=-1;
5724 player[i].lastpathfindpoint3=-1;
5725 player[i].lastpathfindpoint4=-1;
5727 //it's time to think (?)
5728 if(player[i].aiupdatedelay<0&&
5729 !animation[player[i].targetanimation].attack&&
5730 player[i].targetanimation!=staggerbackhighanim&&
5731 player[i].targetanimation!=staggerbackhardanim&&
5732 player[i].targetanimation!=backhandspringanim&&
5733 player[i].targetanimation!=dodgebackanim){
5735 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5736 player[i].drawkeydown=Random()%2;
5738 player[i].drawkeydown=0;
5739 player[i].rabbitkickenabled=Random()%2;
5741 XYZ rotatetarget=player[0].coords+player[0].velocity;
5742 XYZ targetpoint=player[0].coords;
5743 if(findDistancefast(&player[0].coords,&player[i].coords)<
5744 findDistancefast(&rotatetarget,&player[i].coords))
5745 targetpoint+=player[0].velocity*
5746 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5747 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5748 player[i].lookrotation=player[i].targetrotation;
5749 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5751 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5752 player[i].forwardkeydown=1;
5753 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5754 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5755 player[0].weaponactive!=-1)
5756 player[i].forwardkeydown=1;
5757 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5758 player[i].forwardkeydown=1;
5760 player[i].forwardkeydown=0;
5761 //chill out around the corpse
5763 player[i].forwardkeydown=0;
5765 player[i].forwardkeydown=1;
5766 if(Random()%100==0){
5767 player[i].aitype=pathfindtype;
5768 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5769 player[i].finalpathfindpoint=-1;
5770 player[i].targetpathfindpoint=-1;
5771 player[i].lastpathfindpoint=-1;
5772 player[i].lastpathfindpoint2=-1;
5773 player[i].lastpathfindpoint3=-1;
5774 player[i].lastpathfindpoint4=-1;
5777 player[i].leftkeydown=0;
5778 player[i].backkeydown=0;
5779 player[i].rightkeydown=0;
5780 player[i].crouchkeydown=0;
5781 player[i].throwkeydown=0;
5783 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5784 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5786 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5787 player[i].attackkeydown=1;
5789 player[i].attackkeydown=0;
5790 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5791 player[i].attackkeydown=0;
5794 if(player[i].aitype!=playercontrolled&&
5795 (player[i].isIdle()||
5796 player[i].isCrouch()||
5797 player[i].isRun())){
5799 for(int j=0;j<numplayers;j++)
5800 if(j!=i&&!player[j].skeleton.free&&
5801 player[j].hasvictim&&
5802 (tutoriallevel==1&&reversaltrain||
5803 Random()%2==0&&difficulty==2||
5804 Random()%4==0&&difficulty==1||
5805 Random()%8==0&&difficulty==0||
5806 player[j].lastattack2==player[j].targetanimation&&
5807 player[j].lastattack3==player[j].targetanimation&&
5808 (Random()%2==0||difficulty==2)||
5809 (player[i].isIdle()||player[i].isRun())&&
5810 player[j].weaponactive!=-1||
5811 player[j].targetanimation==swordslashanim&&
5812 player[i].weaponactive!=-1||
5813 player[j].targetanimation==staffhitanim||
5814 player[j].targetanimation==staffspinhitanim))
5815 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5816 player[j].victim==&player[i]&&
5817 (player[j].targetanimation==sweepanim||
5818 player[j].targetanimation==spinkickanim||
5819 player[j].targetanimation==staffhitanim||
5820 player[j].targetanimation==staffspinhitanim||
5821 player[j].targetanimation==winduppunchanim||
5822 player[j].targetanimation==upunchanim||
5823 player[j].targetanimation==wolfslapanim||
5824 player[j].targetanimation==knifeslashstartanim||
5825 player[j].targetanimation==swordslashanim&&
5826 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5827 player[i].weaponactive!=-1))){
5834 player[target].Reverse();
5837 if(player[i].collided<1)
5838 player[i].jumpkeydown=0;
5839 if(player[i].collided>.8&&player[i].jumppower>=5||
5840 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5841 player[i].onterrain&&
5842 player[i].creature==rabbittype)
5843 player[i].jumpkeydown=1;
5844 //TODO: why are we controlling the human?
5845 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5846 player[0].jumpkeydown=0;
5847 if(player[0].targetanimation==jumpdownanim&&
5848 findDistancefast(&player[0].coords,&player[i].coords)<40)
5849 player[i].crouchkeydown=1;
5850 if(player[i].jumpkeydown)
5851 player[i].attackkeydown=0;
5853 if(tutoriallevel==1)
5855 player[i].attackkeydown=0;
5858 XYZ facing=player[i].coords;
5859 XYZ flatfacing=player[0].coords;
5860 facing.y+=playerJoint(i,head).position.y*player[i].scale;
5861 flatfacing.y+=playerJoint(0,head).position.y*player[0].scale;
5862 if(player[i].occluded>=2)
5863 if(-1!=checkcollide(facing,flatfacing)){
5864 if(!player[i].pause)
5865 player[i].lastseentime-=.2;
5866 if(player[i].lastseentime<=0&&
5867 (player[i].creature!=wolftype||
5868 player[i].weaponstuck==-1)){
5869 player[i].aitype=searchtype;
5870 player[i].lastchecktime=12;
5871 player[i].lastseen=player[0].coords;
5872 player[i].lastseentime=12;
5875 player[i].lastseentime=1;
5878 if(animation[player[0].targetanimation].height==highheight&&
5879 (player[i].aitype==attacktypecutoff||
5880 player[i].aitype==searchtype))
5881 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5882 XYZ test=player[0].coords;
5884 if(-1==checkcollide(player[0].coords,test))
5885 player[i].stunned=1;
5888 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5889 player[i].stunned>0||
5890 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5892 player[i].lastseentime=1;
5893 player[i].targetrotation=player[i].rotation;
5894 player[i].forwardkeydown=0;
5895 player[i].leftkeydown=0;
5896 player[i].backkeydown=0;
5897 player[i].rightkeydown=0;
5898 player[i].jumpkeydown=0;
5899 player[i].attackkeydown=0;
5900 player[i].crouchkeydown=0;
5901 player[i].throwkeydown=0;
5909 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5912 if(player[i].aitype==attacktypecutoff){
5913 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5914 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5915 }else if(player[i].howactive>=typesleeping){
5916 player[i].targetheadrotation=player[i].targetrotation;
5917 player[i].targetheadrotation2=0;
5919 if(player[i].interestdelay<=0){
5920 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5921 player[i].headtarget=player[i].coords;
5922 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5923 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5924 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5925 player[i].headtarget+=player[i].facing*1.5;
5927 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5928 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5936 static XYZ facing,flatfacing;
5941 for(int i=0;i<15;i++){
5942 displaytime[i]+=multiplier;
5948 if(Input::isKeyPressed(SDLK_F6)){
5949 if(Input::isKeyDown(SDLK_LSHIFT))
5952 stereoreverse=false;
5955 printf("Stereo reversed\n");
5957 printf("Stereo unreversed\n");
5960 if(Input::isKeyDown(SDLK_F7)){
5961 if(Input::isKeyDown(SDLK_LSHIFT))
5962 stereoseparation -= 0.001;
5964 stereoseparation -= 0.010;
5965 printf("Stereo decreased increased to %f\n", stereoseparation);
5968 if(Input::isKeyDown(SDLK_F8)){
5969 if(Input::isKeyDown(SDLK_LSHIFT))
5970 stereoseparation += 0.001;
5972 stereoseparation += 0.010;
5973 printf("Stereo separation increased to %f\n", stereoseparation);
5977 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5978 if(tutorialstage!=51)
5979 tutorialstagetime=tutorialmaxtime;
5980 emit_sound_np(consolefailsound, 128.);
5984 if(mainmenu&&endgame==1)mainmenu=10;
5986 if( (Input::isKeyPressed(SDLK_ESCAPE)
5988 &&((Input::isKeyPressed(jumpkey)
5989 ||Input::isKeyPressed(SDLK_SPACE)
5993 && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)){
5995 if(mainmenu==1||mainmenu==2||mainmenu==0){
5996 if(mainmenu==0&&!winfreeze)mainmenu=2;
5997 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
5998 else if(mainmenu==0&&winfreeze){ }
5999 else if(mainmenu==1||mainmenu==2)mainmenu=0;
6000 if(mainmenu&&musictoggle){
6001 if(mainmenu==1||mainmenu==2||mainmenu==100){
6002 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6003 emit_stream_np(stream_music3);
6004 pause_sound(music1);
6008 pause_sound(stream_music3);
6009 resume_stream(music1);
6013 if(newdetail>2)newdetail=detail;
6014 if(newdetail<0)newdetail=detail;
6015 if(newscreenwidth<0)newscreenwidth=screenwidth;
6016 if(newscreenheight<0)newscreenheight=screenheight;
6017 SaveSettings(*this);
6019 if((mainmenu>=3 && mainmenu<=7)||mainmenu==9||mainmenu==10||mainmenu==100){
6023 if(mainmenu==3&&gameon)mainmenu=2;
6024 if(mainmenu==3&&!gameon)mainmenu=1;
6025 if(mainmenu==5&&gameon)mainmenu=2;
6026 if(mainmenu==5&&!gameon)mainmenu=1;
6027 if(mainmenu==4)mainmenu=3;
6028 if(mainmenu==6)mainmenu=5;
6029 if(mainmenu==7)mainmenu=1;
6030 if(mainmenu==9)mainmenu=5;
6031 if(mainmenu==10)mainmenu=5;
6045 if(hostile==1)hostiletime+=multiplier;
6047 if(!winfreeze)leveltime+=multiplier;
6050 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6053 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6057 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6061 inputText(displaytext[0],&displayselected,&displaychars[0]);
6063 if(displaychars[0]){
6064 for(int j=0;j<255;j++)
6065 displaytext[0][j]=0;
6072 displayblinkdelay-=multiplier;
6073 if(displayblinkdelay<=0){
6074 displayblinkdelay=.3;
6075 displayblink=1-displayblink;
6081 if(Input::isKeyPressed(SDLK_BACKQUOTE)&&debugmode){
6084 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6093 if(console&&!Input::isKeyDown(SDLK_LMETA)){
6094 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6097 if(consolechars[0]>0){
6098 consoletext[0][consolechars[0]]=' ';
6099 cmd_dispatch(this, consoletext[0]);
6100 for(int k=14;k>=1;k--){
6101 for(int j=0;j<255;j++)
6102 consoletext[k][j]=consoletext[k-1][j];
6103 consolechars[k]=consolechars[k-1];
6105 for(int j=0;j<255;j++)
6106 consoletext[0][j]=0;
6112 consoleblinkdelay-=multiplier;
6113 if(consoleblinkdelay<=0){
6114 consoleblinkdelay=.3;
6115 consoleblink=1-consoleblink;
6121 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6124 if(newdetail>2)newdetail=detail;
6125 if(newdetail<0)newdetail=detail;
6126 if(newscreenwidth<0)newscreenwidth=screenwidth;
6127 if(newscreenheight<0)newscreenheight=screenheight;
6129 SaveSettings(*this);
6133 static int oldwinfreeze;
6134 if(winfreeze&&!oldwinfreeze){
6135 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6136 emit_sound_np(consolesuccesssound);
6139 oldwinfreeze=winfreeze;
6143 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6146 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6150 }else if(winfreeze){
6158 //TODO: what is this test?
6159 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6164 talkdelay-=multiplier;
6166 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6167 for(int i=0;i<numdialogues;i++){
6168 int realdialoguetype;
6170 if(dialoguetype[i]>49){
6171 realdialoguetype=dialoguetype[i]-50;
6174 else if(dialoguetype[i]>39){
6175 realdialoguetype=dialoguetype[i]-40;
6178 else if(dialoguetype[i]>29){
6179 realdialoguetype=dialoguetype[i]-30;
6182 else if(dialoguetype[i]>19){
6183 realdialoguetype=dialoguetype[i]-20;
6186 else if(dialoguetype[i]>9){
6187 realdialoguetype=dialoguetype[i]-10;
6191 realdialoguetype=dialoguetype[i];
6194 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6195 realdialoguetype<numplayers&&
6196 realdialoguetype>0&&
6197 (dialoguegonethrough[i]==0||!special)&&
6198 (special||Input::isKeyPressed(attackkey))){
6199 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6200 player[realdialoguetype].howactive>=typedead1||
6201 dialoguetype[i]>40&&dialoguetype[i]<50){
6203 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6204 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6205 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6206 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6207 player[participantfocus[whichdialogue][j]].velocity=0;
6208 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6209 player[participantfocus[whichdialogue][j]].targetframe=0;
6214 dialoguegonethrough[i]++;
6215 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6216 playdialogueboxsound();
6222 windvar+=multiplier;
6223 smoketex+=multiplier;
6224 tutorialstagetime+=multiplier;
6227 static float hotspotvisual[40];
6231 for(int i=0;i<numhotspots;i++)
6232 hotspotvisual[i]-=multiplier/320;
6234 for(int i=0;i<numhotspots;i++){
6235 //if(hotspottype[i]<=10)
6236 while(hotspotvisual[i]<0){
6238 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6239 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6240 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6241 hotspotsprite+=hotspot[i];
6242 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6243 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6247 for(int i=0;i<numhotspots;i++){
6248 if(hotspottype[i]<=10&&hotspottype[i]>0){
6249 hotspot[i]=player[hotspottype[i]].coords;
6260 if(tutoriallevel!=1){
6263 bonus!=spinecrusher&&
6264 bonus!=tracheotomy&&
6267 emit_sound_np(consolesuccesssound);
6269 } else if(bonustime==0){
6270 emit_sound_np(fireendsound);
6273 if(bonus!=solidhit&&
6275 bonus!=threexcombo&&
6280 bonusnum[bonus]+=0.15;
6283 bonusvalue/=bonusnum[bonus];
6284 bonustotal+=bonusvalue;
6286 bonustime+=multiplier;
6289 if(environment==snowyenvironment){
6290 precipdelay-=multiplier;
6291 while(precipdelay<0){
6295 XYZ footvel,footpoint;
6298 footpoint=viewer+viewerfacing*6;
6299 footpoint.y+=((float)abs(Random()%1200))/100-6;
6300 footpoint.x+=((float)abs(Random()%1200))/100-6;
6301 footpoint.z+=((float)abs(Random()%1200))/100-6;
6302 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6307 doAerialAcrobatics();
6310 static XYZ oldviewer;
6314 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6315 player[0].leftkeydown=Input::isKeyDown(leftkey);
6316 player[0].backkeydown=Input::isKeyDown(backkey);
6317 player[0].rightkeydown=Input::isKeyDown(rightkey);
6318 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6319 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6320 player[0].drawkeydown=Input::isKeyDown(drawkey);
6321 player[0].throwkeydown=Input::isKeyDown(throwkey);
6325 player[0].forwardkeydown=0;
6326 player[0].leftkeydown=0;
6327 player[0].backkeydown=0;
6328 player[0].rightkeydown=0;
6329 player[0].jumpkeydown=0;
6330 player[0].crouchkeydown=0;
6331 player[0].drawkeydown=0;
6332 player[0].throwkeydown=0;
6335 if(!player[0].jumpkeydown)
6336 player[0].jumpclimb=0;
6345 facing=DoRotation(facing,-rotation2,0,0);
6346 facing=DoRotation(facing,0,0-rotation,0);
6351 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6353 if(Input::isKeyDown(forwardkey))
6354 viewer+=facing*multiplier*4;
6355 if(Input::isKeyDown(backkey))
6356 viewer-=facing*multiplier*4;
6357 if(Input::isKeyDown(leftkey))
6358 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6359 if(Input::isKeyDown(rightkey))
6360 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6361 if(Input::isKeyDown(jumpkey))
6362 viewer.y+=multiplier*4;
6363 if(Input::isKeyDown(crouchkey))
6364 viewer.y-=multiplier*4;
6365 if( Input::isKeyPressed(SDLK_1)||
6366 Input::isKeyPressed(SDLK_2)||
6367 Input::isKeyPressed(SDLK_3)||
6368 Input::isKeyPressed(SDLK_4)||
6369 Input::isKeyPressed(SDLK_5)||
6370 Input::isKeyPressed(SDLK_6)||
6371 Input::isKeyPressed(SDLK_7)||
6372 Input::isKeyPressed(SDLK_8)||
6373 Input::isKeyPressed(SDLK_9)||
6374 Input::isKeyPressed(SDLK_0)||
6375 Input::isKeyPressed(SDLK_MINUS)){
6377 if(Input::isKeyPressed(SDLK_1))whichend=1;
6378 if(Input::isKeyPressed(SDLK_2))whichend=2;
6379 if(Input::isKeyPressed(SDLK_3))whichend=3;
6380 if(Input::isKeyPressed(SDLK_4))whichend=4;
6381 if(Input::isKeyPressed(SDLK_5))whichend=5;
6382 if(Input::isKeyPressed(SDLK_6))whichend=6;
6383 if(Input::isKeyPressed(SDLK_7))whichend=7;
6384 if(Input::isKeyPressed(SDLK_8))whichend=8;
6385 if(Input::isKeyPressed(SDLK_9))whichend=9;
6386 if(Input::isKeyPressed(SDLK_0))whichend=0;
6387 if(Input::isKeyPressed(SDLK_MINUS))
6390 participantfocus[whichdialogue][indialogue]=whichend;
6391 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6392 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6395 participantfocus[whichdialogue][indialogue]=-1;
6397 if(player[participantfocus[whichdialogue][indialogue]].dead){
6402 dialoguecamera[whichdialogue][indialogue]=viewer;
6403 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6404 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6406 if(indialogue<numdialogueboxes[whichdialogue]){
6407 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6408 playdialogueboxsound();
6412 for(int j=0;j<numplayers;j++){
6413 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6416 //TODO: should these be KeyDown or KeyPressed?
6417 if( Input::isKeyDown(SDLK_KP1)||
6418 Input::isKeyDown(SDLK_KP2)||
6419 Input::isKeyDown(SDLK_KP3)||
6420 Input::isKeyDown(SDLK_KP4)||
6421 Input::isKeyDown(SDLK_KP5)||
6422 Input::isKeyDown(SDLK_KP6)||
6423 Input::isKeyDown(SDLK_KP7)||
6424 Input::isKeyDown(SDLK_KP8)||
6425 Input::isKeyDown(SDLK_KP9)||
6426 Input::isKeyDown(SDLK_KP0)){
6428 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6429 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6430 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6431 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6432 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6433 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6434 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6435 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6436 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6437 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6438 participantfacing[whichdialogue][indialogue][whichend]=facing;
6440 if(indialogue>=numdialogueboxes[whichdialogue]){
6447 pause_sound(whooshsound);
6448 viewer=dialoguecamera[whichdialogue][indialogue];
6449 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6450 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6451 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6452 if(dialoguetime>0.5)
6453 if( Input::isKeyPressed(SDLK_1)||
6454 Input::isKeyPressed(SDLK_2)||
6455 Input::isKeyPressed(SDLK_3)||
6456 Input::isKeyPressed(SDLK_4)||
6457 Input::isKeyPressed(SDLK_5)||
6458 Input::isKeyPressed(SDLK_6)||
6459 Input::isKeyPressed(SDLK_7)||
6460 Input::isKeyPressed(SDLK_8)||
6461 Input::isKeyPressed(SDLK_9)||
6462 Input::isKeyPressed(SDLK_0)||
6463 Input::isKeyPressed(SDLK_MINUS)||
6464 Input::isKeyPressed(attackkey)){
6466 if(indialogue<numdialogueboxes[whichdialogue]){
6467 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6468 playdialogueboxsound();
6469 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6470 hotspot[numhotspots]=player[0].coords;
6471 hotspotsize[numhotspots]=10;
6472 hotspottype[numhotspots]=-1;
6476 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6480 if(player[participantfocus[whichdialogue][indialogue]].dead){
6488 if(indialogue>=numdialogueboxes[whichdialogue]){
6492 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6495 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6498 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6500 for(int i=1;i<numplayers;i++){
6501 player[i].aitype = attacktypecutoff;
6508 static float keyrefreshdelay=0,bigrefreshdelay=0;
6510 if(!player[0].jumpkeydown){
6511 player[0].jumptogglekeydown=0;
6513 if(player[0].jumpkeydown&&
6514 player[0].targetanimation!=jumpupanim&&
6515 player[0].targetanimation!=jumpdownanim&&
6516 !player[0].isFlip())
6517 player[0].jumptogglekeydown=1;
6520 dialoguetime+=multiplier;
6521 hawkrotation+=multiplier*25;
6523 realhawkcoords.x=25;
6524 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6525 hawkcalldelay-=multiplier/2;
6527 if(hawkcalldelay<=0){
6528 emit_sound_at(hawksound, realhawkcoords);
6530 hawkcalldelay=16+abs(Random()%8);
6532 static float temptexdetail;
6539 doPlayerCollisions();
6543 for(int k=0;k<numplayers;k++)
6544 if(k!=0&&player[k].immobile)
6545 player[k].coords=player[k].realoldcoords;
6547 for(int k=0;k<numplayers;k++){
6548 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6549 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6550 player[k].DoDamage(1000);
6556 static bool respawnkeydown;
6559 (Input::isKeyDown(SDLK_z)&&
6560 Input::isKeyDown(SDLK_LMETA)&&
6562 (Input::isKeyDown(jumpkey)&&
6566 targetlevel=whichlevel;
6570 if(!Input::isKeyDown(jumpkey))
6572 if(Input::isKeyDown(jumpkey))
6578 static bool movekey;
6581 for(int i=0;i<numplayers;i++){
6582 static float oldtargetrotation;
6583 if(!player[i].skeleton.free){
6584 oldtargetrotation=player[i].targetrotation;
6585 if(i==0&&indialogue==-1){
6586 //TODO: refactor repetitive code
6587 if(!animation[player[0].targetanimation].attack&&
6588 player[0].targetanimation!=staggerbackhighanim&&
6589 player[0].targetanimation!=staggerbackhardanim&&
6590 player[0].targetanimation!=crouchremoveknifeanim&&
6591 player[0].targetanimation!=removeknifeanim&&
6592 player[0].targetanimation!=backhandspringanim&&
6593 player[0].targetanimation!=dodgebackanim&&
6594 player[0].targetanimation!=walljumprightkickanim&&
6595 player[0].targetanimation!=walljumpleftkickanim){
6597 player[0].targetrotation=0;
6599 player[0].targetrotation=-rotation+180;
6605 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6609 facing=DoRotation(facing,-rotation2,0,0);
6610 facing=DoRotation(facing,0,0-rotation,0);
6613 player[0].lookrotation=-rotation;
6615 player[i].targetheadrotation=rotation;
6616 player[i].targetheadrotation2=rotation2;
6618 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6619 if(!animation[player[i].targetanimation].attack&&
6620 player[i].targetanimation!=staggerbackhighanim&&
6621 player[i].targetanimation!=staggerbackhardanim&&
6622 player[i].targetanimation!=crouchremoveknifeanim&&
6623 player[i].targetanimation!=removeknifeanim&&
6624 player[i].targetanimation!=backhandspringanim&&
6625 player[i].targetanimation!=dodgebackanim&&
6626 player[i].targetanimation!=walljumprightkickanim&&
6627 player[i].targetanimation!=walljumpleftkickanim){
6628 player[i].targetrotation=-player[i].lookrotation+180;
6634 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6636 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6637 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6639 player[i].targetheadrotation=player[i].lookrotation;
6640 player[i].targetheadrotation2=player[i].lookrotation2;
6643 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6644 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6652 player[i].avoidsomething=0;
6654 //avoid flaming things
6655 for(int j=0;j<objects.numobjects;j++)
6656 if(objects.onfire[j])
6657 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6658 if( findDistancefast(&player[i].coords,&objects.position[j])<
6659 findDistancefast(&player[i].coords,&player[0].coords)){
6660 player[i].collided=0;
6661 player[i].avoidcollided=1;
6662 if(player[i].avoidsomething==0||
6663 findDistancefast(&player[i].coords,&objects.position[j])<
6664 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6665 player[i].avoidwhere=objects.position[j];
6666 player[i].avoidsomething=1;
6670 //avoid flaming players
6671 for(int j=0;j<numplayers;j++)
6672 if(player[j].onfire)
6673 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6674 if( findDistancefast(&player[i].coords,&player[j].coords)<
6675 findDistancefast(&player[i].coords,&player[0].coords)){
6676 player[i].collided=0;
6677 player[i].avoidcollided=1;
6678 if(player[i].avoidsomething==0||
6679 findDistancefast(&player[i].coords,&player[j].coords)<
6680 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6681 player[i].avoidwhere=player[j].coords;
6682 player[i].avoidsomething=1;
6686 if(player[i].collided>.8)
6687 player[i].avoidcollided=0;
6691 if(animation[player[i].targetanimation].attack==reversed){
6692 //player[i].targetrotation=player[i].rotation;
6693 player[i].forwardkeydown=0;
6694 player[i].leftkeydown=0;
6695 player[i].backkeydown=0;
6696 player[i].rightkeydown=0;
6697 player[i].jumpkeydown=0;
6698 player[i].attackkeydown=0;
6699 //player[i].crouchkeydown=0;
6700 player[i].throwkeydown=0;
6704 player[i].forwardkeydown=0;
6705 player[i].leftkeydown=0;
6706 player[i].backkeydown=0;
6707 player[i].rightkeydown=0;
6708 player[i].jumpkeydown=0;
6709 player[i].crouchkeydown=0;
6710 player[i].drawkeydown=0;
6711 player[i].throwkeydown=0;
6714 if(player[i].collided<-.3)
6715 player[i].collided=-.3;
6716 if(player[i].collided>1)
6717 player[i].collided=1;
6718 player[i].collided-=multiplier*4;
6719 player[i].whichdirectiondelay-=multiplier;
6720 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6721 player[i].avoidcollided=-.3;
6722 player[i].whichdirection=abs(Random()%2);
6723 player[i].whichdirectiondelay=.4;
6725 if(player[i].avoidcollided>1)
6726 player[i].avoidcollided=1;
6727 player[i].avoidcollided-=multiplier/4;
6728 if(!player[i].skeleton.free){
6729 player[i].stunned-=multiplier;
6730 player[i].surprised-=multiplier;
6732 if(i!=0&&player[i].surprised<=0&&
6733 player[i].aitype==attacktypecutoff&&
6735 !player[i].skeleton.free&&
6736 animation[player[i].targetanimation].attack==neutral)
6739 if(!player[i].throwkeydown)
6740 player[i].throwtogglekeydown=0;
6743 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6744 if(player[i].weaponactive==-1&&
6745 player[i].num_weapons<2&&
6746 (player[i].isIdle()||
6747 player[i].isCrouch()||
6748 player[i].targetanimation==sneakanim||
6749 player[i].targetanimation==rollanim||
6750 player[i].targetanimation==backhandspringanim||
6751 player[i].isFlip()||
6752 player[i].isFlip()||
6753 player[i].aitype!=playercontrolled)){
6754 for(int j=0;j<weapons.numweapons;j++){
6755 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6756 player[i].aitype==playercontrolled)&&
6757 weapons.owner[j]==-1&&
6758 player[i].weaponactive==-1)
6759 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
6760 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
6761 if(player[i].isCrouch()||
6762 player[i].targetanimation==sneakanim||
6764 player[i].isIdle()||
6765 player[i].aitype!=playercontrolled){
6766 player[i].throwtogglekeydown=1;
6767 setAnimation(i,crouchremoveknifeanim);
6768 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6769 player[i].hasvictim=0;
6771 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6772 player[i].throwtogglekeydown=1;
6773 player[i].hasvictim=0;
6775 if((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0||
6776 player[i].aitype==playercontrolled)&&
6777 weapons.owner[j]==-1||
6779 weapons.owner[j]==player[i].victim->id)
6780 if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1)
6781 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
6782 if(weapons.type[j]!=staff)
6783 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6785 player[i].weaponactive=0;
6786 weapons.owner[j]=player[i].id;
6787 if(player[i].num_weapons>0)
6788 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6789 player[i].num_weapons++;
6790 player[i].weaponids[0]=j;
6793 }else if((player[i].isIdle()||
6794 player[i].isFlip()||
6795 player[i].aitype!=playercontrolled)&&
6796 findDistancefast(&player[i].coords,&weapons.position[j])<5&&
6797 player[i].coords.y<weapons.position[j].y){
6798 if(!player[i].isFlip()){
6799 player[i].throwtogglekeydown=1;
6800 setAnimation(i,removeknifeanim);
6801 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons.position[j]);
6803 if(player[i].isFlip()){
6804 player[i].throwtogglekeydown=1;
6805 player[i].hasvictim=0;
6807 for(int k=0;k<weapons.numweapons;k++){
6808 if(player[i].weaponactive==-1)
6809 if((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0||
6810 player[i].aitype==playercontrolled)&&
6811 weapons.owner[k]==-1||
6813 weapons.owner[k]==player[i].victim->id)
6814 if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&
6815 player[i].weaponactive==-1){
6816 if(weapons.type[k]!=staff)
6817 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6819 player[i].weaponactive=0;
6820 weapons.owner[k]=player[i].id;
6821 if(player[i].num_weapons>0)
6822 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6823 player[i].num_weapons++;
6824 player[i].weaponids[0]=k;
6831 if(player[i].isCrouch()||
6832 player[i].targetanimation==sneakanim||
6834 player[i].isIdle()||player[i].targetanimation==rollanim||
6835 player[i].targetanimation==backhandspringanim){
6837 for(int j=0;j<numplayers;j++){
6838 if(player[i].weaponactive==-1)
6840 if(player[j].num_weapons&&
6841 player[j].skeleton.free&&
6842 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6843 (((player[j].skeleton.forward.y<0&&
6844 player[j].weaponstuckwhere==0)||
6845 (player[j].skeleton.forward.y>0&&
6846 player[j].weaponstuckwhere==1))||
6847 player[j].weaponstuck==-1||
6848 player[j].num_weapons>1)){
6849 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6850 player[i].throwtogglekeydown=1;
6851 player[i].victim=&player[j];
6852 player[i].hasvictim=1;
6853 setAnimation(i,crouchremoveknifeanim);
6854 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6856 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6857 player[i].throwtogglekeydown=1;
6858 player[i].victim=&player[j];
6859 player[i].hasvictim=1;
6860 int k = player[j].weaponids[0];
6861 if(player[i].hasvictim){
6864 if(player[i].victim->weaponstuck!=-1){
6865 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6870 if(weapons.type[k]!=staff)
6871 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6874 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6876 player[i].weaponactive=0;
6877 if(weapons.owner[k]!=-1){
6878 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6879 else player[i].victim->num_weapons=1;
6881 player[i].victim->skeleton.longdead=0;
6882 player[i].victim->skeleton.free=1;
6883 player[i].victim->skeleton.broken=0;
6885 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6886 player[i].victim->skeleton.joints[l].velchange=0;
6887 player[i].victim->skeleton.joints[l].locked=0;
6893 Normalise(&relative);
6894 XYZ footvel,footpoint;
6896 footpoint=weapons.position[k];
6897 if(player[i].victim->weaponstuck!=-1){
6898 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6899 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6900 weapons.bloody[k]=2;
6901 weapons.blooddrip[k]=5;
6902 player[i].victim->weaponstuck=-1;
6903 player[i].victim->bloodloss+=2000;
6904 player[i].victim->DoDamage(2000);
6907 if(player[i].victim->num_weapons>0){
6908 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6909 if(player[i].victim->weaponids[0]==k)
6910 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6913 player[i].victim->weaponactive=-1;
6915 playerJoint(player[i].victim,abdomen).velocity+=relative*6;
6916 playerJoint(player[i].victim,neck).velocity+=relative*6;
6917 playerJoint(player[i].victim,rightshoulder).velocity+=relative*6;
6918 playerJoint(player[i].victim,leftshoulder).velocity+=relative*6;
6921 if(player[i].num_weapons>0){
6922 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6924 player[i].num_weapons++;
6925 player[i].weaponids[0]=k;
6932 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6933 if(weapons.type[player[i].weaponids[0]]==knife){
6934 if(player[i].isIdle()||
6936 player[i].isCrouch()||
6937 player[i].targetanimation==sneakanim||
6940 for(int j=0;j<numplayers;j++){
6942 if(tutoriallevel!=1||tutorialstage==49)
6944 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6945 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6946 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6947 !player[j].skeleton.free&&
6948 -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)){
6949 if(!player[i].isFlip()){
6950 player[i].throwtogglekeydown=1;
6951 player[i].victim=&player[j];
6952 setAnimation(i,knifethrowanim);
6953 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6954 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6956 if(player[i].isFlip()){
6957 if(player[i].weaponactive!=-1){
6958 player[i].throwtogglekeydown=1;
6959 player[i].victim=&player[j];
6961 weapons.owner[player[i].weaponids[0]]=-1;
6962 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);
6965 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6967 weapons.velocity[player[i].weaponids[0]]=aim*50;
6968 weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
6969 weapons.missed[player[i].weaponids[0]]=0;
6970 weapons.freetime[player[i].weaponids[0]]=0;
6971 weapons.firstfree[player[i].weaponids[0]]=1;
6972 weapons.physics[player[i].weaponids[0]]=0;
6973 player[i].num_weapons--;
6974 if(player[i].num_weapons){
6975 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6977 player[i].weaponactive=-1;
6984 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6985 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6986 player[i].throwtogglekeydown=1;
6987 weapons.owner[player[i].weaponids[0]]=-1;
6988 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
6989 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
6990 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
6991 weapons.missed[player[i].weaponids[0]]=1;
6992 weapons.freetime[player[i].weaponids[0]]=0;
6993 weapons.firstfree[player[i].weaponids[0]]=1;
6994 weapons.physics[player[i].weaponids[0]]=1;
6995 player[i].num_weapons--;
6996 if(player[i].num_weapons){
6997 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6998 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7001 player[i].weaponactive=-1;
7002 for(int j=0;j<numplayers;j++){
7003 player[j].wentforweapon=0;
7011 if(i==0||!player[0].dead||player[i].weaponactive!=-1)
7012 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
7013 player[i].num_weapons==2&&
7014 player[i].weaponactive==-1&&
7015 player[i].isIdle()||
7017 player[i].weaponactive!=-1&&
7020 if(player[i].weaponactive!=-1)
7021 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)
7023 if(isgood&&player[i].creature!=wolftype){
7024 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7025 setAnimation(i,drawrightanim);
7026 player[i].drawtogglekeydown=1;
7028 if((player[i].isIdle()||
7029 (player[i].aitype!=playercontrolled&&
7030 player[0].weaponactive!=-1&&
7031 player[i].isRun()))&&
7032 player[i].num_weapons&&
7033 weapons.type[player[i].weaponids[0]]==sword){
7034 setAnimation(i,drawleftanim);
7035 player[i].drawtogglekeydown=1;
7037 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
7038 setAnimation(i,crouchdrawrightanim);
7039 player[i].drawtogglekeydown=1;
7044 if(player[i].isCrouch()&&
7045 weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7047 player[i].onterrain&&
7048 player[i].num_weapons&&
7049 player[i].weaponactive!=-1&&
7050 player[i].attackkeydown){
7051 if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&
7052 player[i].onterrain&&
7053 bloodtoggle&&musictype!=stream_music2){
7054 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)
7055 setAnimation(i,crouchstabanim);
7056 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)
7057 setAnimation(i,swordgroundstabanim);
7058 player[i].hasvictim=0;
7059 //player[i].attacktogglekeydown=1;
7063 if(!player[i].drawkeydown)
7064 player[i].drawtogglekeydown=0;
7071 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
7073 else absflatfacing=flatfacing;
7076 player[i].forwardkeydown=0;
7077 player[i].leftkeydown=0;
7078 player[i].backkeydown=0;
7079 player[i].rightkeydown=0;
7080 player[i].jumpkeydown=0;
7081 player[i].crouchkeydown=0;
7082 player[i].drawkeydown=0;
7083 player[i].throwkeydown=0;
7087 if(!animation[player[i].targetanimation].attack&&
7088 player[i].targetanimation!=staggerbackhighanim&&
7089 player[i].targetanimation!=staggerbackhardanim&&
7090 player[i].targetanimation!=backhandspringanim&&
7091 player[i].targetanimation!=dodgebackanim){
7092 if(!player[i].forwardkeydown)
7093 player[i].forwardstogglekeydown=0;
7094 if(player[i].crouchkeydown){
7098 player[i].superruntoggle=1;
7100 for(int j=0;j<numplayers;j++)
7101 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7102 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7103 player[i].superruntoggle=0;
7107 for(int j=0;j<numplayers;j++){
7108 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7109 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7110 player[j].victim==&player[i]&&
7111 (player[j].targetanimation==sweepanim||
7112 player[j].targetanimation==upunchanim||
7113 player[j].targetanimation==wolfslapanim||
7114 ((player[j].targetanimation==swordslashanim||
7115 player[j].targetanimation==knifeslashstartanim||
7116 player[j].targetanimation==staffhitanim||
7117 player[j].targetanimation==staffspinhitanim)&&
7118 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7127 player[target].Reverse();
7128 player[i].lowreversaldelay=.5;
7130 if(player[i].isIdle()){
7131 setAnimation(i,player[i].getCrouch());
7132 player[i].transspeed=10;
7134 if(player[i].isRun()||
7135 (player[i].isStop()&&
7136 (player[i].leftkeydown||
7137 player[i].rightkeydown||
7138 player[i].forwardkeydown||
7139 player[i].backkeydown))){
7140 setAnimation(i,rollanim);
7141 player[i].transspeed=20;
7144 if(!player[i].crouchkeydown){
7146 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7148 if(player[i].isCrouch()){
7150 for(int j=0;j<numplayers;j++){
7152 !player[j].skeleton.free&&
7154 player[i].highreversaldelay<=0){
7155 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7156 player[j].victim==&player[i]&&
7157 (player[j].targetanimation==spinkickanim)&&
7158 player[i].isCrouch()){
7167 player[target].Reverse();
7168 player[i].highreversaldelay=.5;
7170 if(player[i].isCrouch()){
7171 if(!player[i].wasCrouch()){
7172 player[i].currentanimation=player[i].getCrouch();
7173 player[i].currentframe=0;
7175 setAnimation(i,player[i].getIdle());
7176 player[i].transspeed=10;
7179 if(player[i].targetanimation==sneakanim){
7180 setAnimation(i,player[i].getIdle());
7181 player[i].transspeed=10;
7184 if(player[i].forwardkeydown){
7185 if(player[i].isIdle()||
7186 (player[i].isStop()&&
7187 player[i].targetrotation==player[i].rotation)||
7188 (player[i].isLanding()&&
7189 player[i].targetframe>0&&
7190 !player[i].jumpkeydown)||
7191 (player[i].isLandhard()&&
7192 player[i].targetframe>0&&
7193 !player[i].jumpkeydown&&
7194 player[i].crouchkeydown)){
7195 if(player[i].aitype==passivetype)
7196 setAnimation(i,walkanim);
7198 setAnimation(i,player[i].getRun());
7200 if(player[i].isCrouch()){
7201 player[i].targetanimation=sneakanim;
7202 if(player[i].wasCrouch())
7204 player[i].targetframe=0;
7206 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7207 setAnimation(i,climbanim);
7208 player[i].targetframe=1;
7209 player[i].jumpclimb=1;
7211 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7212 player[i].velocity+=absflatfacing*5*multiplier;
7214 player[i].forwardstogglekeydown=1;
7217 if (player[i].rightkeydown){
7218 if(player[i].isIdle()||
7219 (player[i].isStop()&&
7220 player[i].targetrotation==player[i].rotation)||
7221 (player[i].isLanding()&&
7222 player[i].targetframe>0&&
7223 !player[i].jumpkeydown)||
7224 (player[i].isLandhard()&&
7225 player[i].targetframe>0&&
7226 !player[i].jumpkeydown&&
7227 player[i].crouchkeydown)){
7228 setAnimation(i,player[i].getRun());
7230 if(player[i].isCrouch()){
7231 player[i].targetanimation=sneakanim;
7232 if(player[i].wasCrouch())
7234 player[i].targetframe=0;
7236 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7237 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7239 player[i].targetrotation-=90;
7240 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7241 if(player[i].backkeydown)player[i].targetrotation-=45;
7244 if ( player[i].leftkeydown){
7245 if(player[i].isIdle()||
7246 (player[i].isStop()&&
7247 player[i].targetrotation==player[i].rotation)||
7248 (player[i].isLanding()&&
7249 player[i].targetframe>0&&
7250 !player[i].jumpkeydown)||
7251 (player[i].isLandhard()&&
7252 player[i].targetframe>0&&
7253 !player[i].jumpkeydown&&
7254 player[i].crouchkeydown)){
7255 setAnimation(i,player[i].getRun());
7257 if(player[i].isCrouch()){
7258 player[i].targetanimation=sneakanim;
7259 if(player[i].wasCrouch())
7261 player[i].targetframe=0;
7263 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7264 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7266 player[i].targetrotation+=90;
7267 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7268 if(player[i].backkeydown)player[i].targetrotation+=45;
7271 if(player[i].backkeydown){
7272 if(player[i].isIdle()||
7273 (player[i].isStop()&&
7274 player[i].targetrotation==player[i].rotation)||
7275 (player[i].isLanding()&&
7276 player[i].targetframe>0&&
7277 !player[i].jumpkeydown)||
7278 (player[i].isLandhard()&&
7279 player[i].targetframe>0&&
7280 !player[i].jumpkeydown&&
7281 player[i].crouchkeydown)){
7282 setAnimation(i,player[i].getRun());
7284 if(player[i].isCrouch()){
7285 player[i].targetanimation=sneakanim;
7286 if(player[i].wasCrouch())
7288 player[i].targetframe=0;
7290 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7291 player[i].velocity-=absflatfacing*5*multiplier;
7293 if(player[i].targetanimation==hanganim){
7294 player[i].currentanimation=jumpdownanim;
7295 player[i].targetanimation=jumpdownanim;
7297 player[i].currentframe=0;
7298 player[i].targetframe=1;
7299 player[i].velocity=0;
7300 player[i].velocity.y+=gravity;
7301 player[i].coords.y-=1.4;
7302 player[i].grabdelay=1;
7304 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7305 player[i].targetrotation+=180;
7308 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7309 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7311 player[i].targetanimation==walkanim||
7312 player[i].isCrouch()||
7313 player[i].targetanimation==sneakanim)&&
7314 player[i].jumppower>1)&&
7315 ((player[i].targetanimation!=rabbitrunninganim&&
7316 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7317 player[i].jumpstart=0;
7318 setAnimation(i,jumpupanim);
7319 player[i].rotation=player[i].targetrotation;
7320 player[i].transspeed=20;
7321 player[i].FootLand(0,1);
7322 player[i].FootLand(1,1);
7326 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7328 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7329 if(!movekey)player[i].velocity=0;
7334 for(int j=0;j<numplayers;j++){
7335 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7336 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7337 player[j].victim==&player[i]&&
7338 (player[j].targetanimation==sweepanim)){
7339 if(target>=0)target=-1;
7344 if(target>=0)player[i].velocity.y=1;
7345 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7346 player[i].velocity.y=7;
7347 player[i].crouchtogglekeydown=1;
7349 else player[i].velocity.y=5;
7351 if(mousejump&&i==0&&debugmode){
7352 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7353 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7356 player[i].coords.y+=.2;
7357 player[i].jumppower-=1;
7360 emit_sound_at(whooshsound, player[i].coords, 128.);
7362 emit_sound_at(jumpsound, player[i].coords, 128.);
7364 if((player[i].isIdle())&&player[i].jumppower>1){
7365 setAnimation(i,player[i].getLanding());
7366 player[i].targetframe=2;
7367 player[i].landhard=0;
7368 player[i].jumpstart=1;
7369 player[i].tempdeltav=deltav;
7371 if(player[i].targetanimation==jumpupanim&&
7375 player[i].aitype!=playercontrolled)){
7376 if(player[i].jumppower>multiplier*6){
7377 player[i].velocity.y+=multiplier*6;
7378 player[i].jumppower-=multiplier*6;
7380 if(player[i].jumppower<=multiplier*6){
7381 player[i].velocity.y+=player[i].jumppower;
7382 player[i].jumppower=0;
7385 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7389 if(player[i].isRun()||player[i].targetanimation==walkanim)
7390 setAnimation(i,player[i].getStop());
7391 if(player[i].targetanimation==sneakanim){
7392 player[i].targetanimation=player[i].getCrouch();
7393 if(player[i].currentanimation==sneakanim)
7395 player[i].targetframe=0;
7398 if(player[i].targetanimation==walkanim&&
7399 (player[i].aitype==attacktypecutoff||
7400 player[i].aitype==searchtype||
7401 (player[i].aitype==passivetype&&
7402 player[i].numwaypoints<=1)))
7403 setAnimation(i,player[i].getStop());
7404 if(player[i].isRun()&&(player[i].aitype==passivetype))
7405 setAnimation(i,player[i].getStop());
7408 if(player[i].targetanimation==rollanim)
7409 player[i].targetrotation=oldtargetrotation;
7413 for(int k=0;k<numplayers;k++){
7414 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7415 if(player[k].rotation>player[k].targetrotation)
7416 player[k].rotation-=360;
7418 player[k].rotation+=360;
7421 //stop to turn in right direction
7422 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7423 setAnimation(k,player[k].getStop());
7425 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7426 player[k].targettilt=0;
7428 if(player[k].targetanimation!=jumpupanim&&
7429 player[k].targetanimation!=backhandspringanim&&
7430 player[k].targetanimation!=jumpdownanim&&
7431 !player[k].isFlip()){
7432 player[k].targettilt=0;
7433 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7434 player[k].jumppower=0;
7435 player[k].jumppower+=multiplier*7;
7436 if(player[k].isCrouch())
7437 player[k].jumppower+=multiplier*7;
7438 if(player[k].jumppower>5)
7439 player[k].jumppower=5;
7442 if(player[k].isRun())
7443 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7445 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7446 player[k].grabdelay-=multiplier;
7450 for(int k=0;k<numplayers;k++){
7451 player[k].DoAnimations();
7452 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7453 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7459 for(int j=numenvsounds-1;j>=0;j--){
7460 envsoundlife[j]-=multiplier;
7461 if(envsoundlife[j]<0){
7463 envsoundlife[j]=envsoundlife[numenvsounds];
7464 envsound[j]=envsound[numenvsounds];
7468 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7470 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7472 if(tutoriallevel==1){
7489 if(tutorialstage>=51)
7490 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7491 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7492 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7494 emit_stream_np(stream_music3);
7503 if(tutorialstage<51)
7504 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7505 emit_sound_at(fireendsound, player[0].coords);
7507 player[0].coords=(oldtemp+oldtemp2)/2;
7511 if(tutorialstage>=14&&tutorialstage<50)
7512 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7513 emit_sound_at(fireendsound, player[1].coords);
7515 for(int i=0;i<player[1].skeleton.num_joints;i++){
7517 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7518 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7519 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;
7520 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7521 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7525 player[1].coords=(oldtemp+oldtemp2)/2;
7526 for(int i=0;i<player[1].skeleton.num_joints;i++){
7527 player[1].skeleton.joints[i].velocity=0;
7529 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7530 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7531 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;
7532 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7533 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7541 static float gLoc[3];
7545 static float vel[3];
7546 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7547 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7548 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7550 //Set orientation with forward and up vectors
7551 static XYZ upvector;
7555 upvector=DoRotation(upvector,-rotation2+90,0,0);
7556 upvector=DoRotation(upvector,0,0-rotation,0);
7561 facing=DoRotation(facing,-rotation2,0,0);
7562 facing=DoRotation(facing,0,0-rotation,0);
7565 static float ori[6];
7569 ori[3] = -upvector.x;
7570 ori[4] = upvector.y;
7571 ori[5] = -upvector.z;
7573 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7580 if(Input::isKeyPressed(SDLK_F1))
7586 void Game::TickOnce(){
7588 rotation+=multiplier*5;
7590 if(directing||indialogue==-1) {
7591 rotation+=deltah*.7;
7593 rotation2+=deltav*.7;
7595 rotation2-=deltav*.7;
7603 void Game::TickOnceAfter(){
7604 static XYZ colviewer;
7605 static XYZ coltarget;
7608 static float brotate;
7610 static float changedelay;
7611 static bool alldead;
7612 static float unseendelay;
7613 static float cameraspeed;
7617 if(environment==snowyenvironment)
7618 music1=stream_music1snow;
7619 if(environment==grassyenvironment)
7620 music1=stream_music1grass;
7621 if(environment==desertenvironment)
7622 music1=stream_music1desert;
7627 for(int i=0;i<numplayers;i++){
7628 if((player[i].aitype==attacktypecutoff||
7629 player[i].aitype==getweapontype||
7630 player[i].aitype==gethelptype||
7631 player[i].aitype==searchtype)&&
7632 !player[i].dead/*&&player[i].surprised<=0*/&&
7633 (player[i].targetanimation!=sneakattackedanim&&
7634 player[i].targetanimation!=knifesneakattackedanim&&
7635 player[i].targetanimation!=swordsneakattackedanim)){
7636 musictype=stream_music2;
7641 musictype=stream_music3;
7644 if(musictype==stream_music2)
7647 if(oldmusictype==stream_music2&&musictype!=stream_music2){
7648 unseendelay-=multiplier;
7650 musictype=stream_music2;
7655 musictype=stream_music3;
7663 if(musictype!=oldmusictype&&musictype==stream_music2)
7664 emit_sound_np(alarmsound);
7665 musicselected=musictype;
7667 if(musicselected==music1)
7668 musicvolume[0]+=multiplier*450;
7670 musicvolume[0]-=multiplier*450;
7671 if(musicselected==stream_music2)
7672 musicvolume[1]+=multiplier*450;
7674 musicvolume[1]-=multiplier*450;
7675 if(musicselected==stream_music3)
7676 musicvolume[2]+=multiplier*450;
7678 musicvolume[2]-=multiplier*450;
7680 for(int i=0;i<3;i++){
7681 if(musicvolume[i]<0)
7683 if(musicvolume[i]>512)
7687 if(musicvolume[2]>128&&!loading&&!mainmenu)
7691 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7692 emit_stream_np(music1, musicvolume[0]);
7693 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7694 emit_stream_np(stream_music2, musicvolume[1]);
7695 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7696 emit_stream_np(stream_music3, musicvolume[2]);
7697 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7698 pause_sound(music1);
7699 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7700 pause_sound(stream_music2);
7701 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7702 pause_sound(stream_music3);
7704 if(musicvolume[0]!=oldmusicvolume[0])
7705 OPENAL_SetVolume(channels[music1], musicvolume[0]);
7706 if(musicvolume[1]!=oldmusicvolume[1])
7707 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
7708 if(musicvolume[2]!=oldmusicvolume[2])
7709 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
7711 for(int i=0;i<3;i++)
7712 oldmusicvolume[i]=musicvolume[i];
7714 pause_sound(music1);
7715 pause_sound(stream_music2);
7716 pause_sound(stream_music3);
7718 for(int i=0;i<4;i++){
7719 oldmusicvolume[i]=0;
7725 for(int i=0;i<numhotspots;i++){
7726 if(hotspottype[i]>10&&hotspottype[i]<20){
7727 if(player[hotspottype[i]-10].dead==0)
7729 else if(killhotspot==2)
7738 for(int i=0;i<numhotspots;i++)
7739 if(hotspottype[i]==-1)
7740 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7744 for(int i=1;i<numplayers;i++)
7745 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7747 if(numalarmed>maxalarmed)
7748 maxalarmed=numalarmed;
7750 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7751 if(player[0].dead&&changedelay<=0){
7753 targetlevel=whichlevel;
7756 for(int i=1;i<numplayers;i++)
7757 if(!player[i].dead&&player[i].howactive<typedead1)
7761 if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
7763 targetlevel=whichlevel+1;
7764 if(targetlevel>numchallengelevels-1)targetlevel=0;
7766 if(winhotspot||windialogue){
7768 targetlevel=whichlevel+1;
7769 if(targetlevel>numchallengelevels-1)targetlevel=0;
7775 targetlevel=whichlevel+1;
7776 if(targetlevel>numchallengelevels-1)targetlevel=0;
7779 if(changedelay>0&&!player[0].dead&&!won){
7780 //high scores, awards, win
7782 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7785 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7801 if(!editorenabled&&gameon&&!mainmenu){
7802 if(changedelay!=-999)
7803 changedelay-=multiplier/7;
7805 targetlevel=whichlevel;
7806 if(loading==2&&!campaign){
7809 fireSound(firestartsound);
7811 if(!player[0].dead&&targetlevel!=whichlevel)
7812 startbonustotal=bonustotal;
7814 Loadlevel(whichlevel);
7816 Loadlevel(targetlevel);
7822 if(loading==2&&targetlevel==whichlevel){
7826 fireSound(firestartsound);
7828 Loadlevel(campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);
7834 if(changedelay<=-999&&
7838 (alldead&&maptype==mapkilleveryone)||
7843 if((player[0].dead||
7844 (alldead&&maptype==mapkilleveryone)||
7849 if(whichlevel!=-2&&!loading&&!player[0].dead){
7859 if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)
7860 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0)
7862 else if(mainmenu==0&&winfreeze){
7863 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
7868 if(!stealthloading){
7869 float gLoc[3]={0,0,0};
7870 float vel[3]={0,0,0};
7871 fireSound(firestartsound);
7878 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
7879 ipstream.ignore(256,':');
7880 ipstream >> campaignnumlevels;
7881 for(int i=0;i<campaignnumlevels;i++){
7882 ipstream.ignore(256,':');
7883 ipstream.ignore(256,':');
7884 ipstream.ignore(256,' ');
7885 ipstream >> campaignmapname[i];
7886 ipstream.ignore(256,':');
7887 ipstream >> campaigndescription[i];
7888 for(int j=0;j<256;j++){
7889 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
7891 ipstream.ignore(256,':');
7892 ipstream >> campaignchoosenext[i];
7893 ipstream.ignore(256,':');
7894 ipstream >> campaignnumnext[i];
7895 for(int j=0;j<campaignnumnext[i];j++){
7896 ipstream.ignore(256,':');
7897 ipstream >> campaignnextlevel[i][j];
7898 campaignnextlevel[i][j]-=1;
7900 ipstream.ignore(256,':');
7901 ipstream >> campaignlocationx[i];
7902 ipstream.ignore(256,':');
7903 ipstream >> campaignlocationy[i];
7907 for(int i=0;i<campaignnumlevels;i++){
7909 levelhighlight[i]=0;
7913 for(int i=0;i<campaignnumlevels;i++){
7915 levelhighlight[i]=0;
7920 for(int i=0;i<accountactive->getCampaignChoicesMade();i++){
7921 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
7922 levelvisible[levelorder[i+1]]=1;
7924 int whichlevelstart;
7925 whichlevelstart=accountactive->getCampaignChoicesMade()-1;
7926 if(whichlevelstart<0){
7927 campaignchoicenum=1;
7928 campaignchoicewhich[0]=0;
7932 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
7933 for(int i=0;i<campaignchoicenum;i++){
7934 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
7935 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
7936 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
7943 if(!firstload)LoadStuff();
7947 Loadlevel(campaignmapname[campaignchoicewhich[0]]);
7951 pause_sound(stream_music3);
7961 oldmusictype=musictype;
7967 facing=DoRotation(facing,-rotation2,0,0);
7968 facing=DoRotation(facing,0,0-rotation,0);
7969 viewerfacing=facing;
7973 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;
7974 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;
7976 if(player[0].skeleton.free){
7977 for(int i=0;i<player[0].skeleton.num_joints;i++){
7978 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7979 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7983 if(player[0].skeleton.free!=2&&!autocam){
7985 if(findLengthfast(&player[0].velocity)>400){
7986 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7988 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7989 coltarget=target-cameraloc;
7990 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7992 Normalise(&coltarget);
7993 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7994 else cameraloc=cameraloc+coltarget*multiplier*8;
7996 if(editorenabled)cameraloc=target;
7997 cameradist+=multiplier*5;
7998 if(cameradist>2.3)cameradist=2.3;
7999 viewer=cameraloc-facing*cameradist;
8001 coltarget=cameraloc;
8002 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8003 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8004 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8005 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8007 coltarget=cameraloc;
8008 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8010 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8011 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8012 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8014 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8018 cameradist=findDistance(&viewer,&target);
8019 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8020 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8021 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8024 if(player[0].skeleton.free!=2&&autocam){
8026 if(findLengthfast(&player[0].velocity)>400){
8027 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8029 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8030 cameradist+=multiplier*5;
8031 if(cameradist>3.3)cameradist=3.3;
8032 coltarget=target-cameraloc;
8033 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8034 else if(findLengthfast(&coltarget)>1)
8036 Normalise(&coltarget);
8037 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8038 else cameraloc=cameraloc+coltarget*multiplier*8;
8040 if(editorenabled)cameraloc=target;
8043 coltarget=cameraloc;
8044 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8045 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8046 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8047 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8049 coltarget=cameraloc;
8050 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
8052 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8053 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8054 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8056 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
8060 cameradist=findDistance(&viewer,&target);
8061 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8062 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8063 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8066 if(camerashake>.8)camerashake=.8;
8067 //if(woozy>10)woozy=10;
8068 //woozy+=multiplier;
8070 if(player[0].dead)camerashake=0;
8071 if(player[0].dead)woozy=0;
8072 camerashake-=multiplier*2;
8073 blackout-=multiplier*2;
8074 //if(player[0].isCrouch())woozy-=multiplier*8;
8075 if(camerashake<0)camerashake=0;
8076 if(blackout<0)blackout=0;
8077 //if(woozy<0)woozy=0;
8079 viewer.x+=(float)(Random()%100)*.0005*camerashake;
8080 viewer.y+=(float)(Random()%100)*.0005*camerashake;
8081 viewer.z+=(float)(Random()%100)*.0005*camerashake;