2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
33 #include "openal_wrapper.h"
36 #include "Animation.h"
43 // Added more evilness needed for MSVC
45 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
46 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
50 extern float multiplier;
52 extern int environment;
53 extern Terrain terrain;
54 extern float screenwidth,screenheight;
57 extern float texdetail;
58 extern Objects objects;
60 extern float slomodelay;
61 extern bool floatjump;
64 extern float camerashake;
66 extern float blackout;
67 extern bool cellophane;
68 extern bool musictoggle;
69 extern int difficulty;
70 extern int bloodtoggle;
71 extern bool invertmouse;
73 extern float precipdelay;
74 extern XYZ viewerfacing;
75 extern bool ambientsound;
76 extern bool mousejump;
77 extern float viewdistance;
79 extern bool keyboardfrozen;
80 extern bool loadingstuff;
81 extern XYZ windvector;
82 extern bool debugmode;
83 static int leveltheme;
85 extern bool visibleloading;
86 extern XYZ envsound[30];
87 extern float envsoundvol[30];
88 extern int numenvsounds;
89 extern float envsoundlife[30];
90 extern float usermousesensitivity;
91 extern bool ismotionblur;
92 extern bool showdamagebar; // (des)activate the damage bar
94 extern float tintr,tintg,tintb;
95 extern bool skyboxtexture;
99 extern float skyboxlightr;
100 extern float skyboxlightg;
101 extern float skyboxlightb;
102 extern float fadestart;
103 extern float slomospeed;
104 extern float slomofreq;
105 extern int tutoriallevel;
106 extern float smoketex;
107 extern float tutorialstagetime;
108 extern int tutorialstage;
109 extern float tutorialmaxtime;
110 extern float tutorialsuccess;
111 extern bool againbonus;
112 extern bool reversaltrain;
113 extern bool canattack;
114 extern bool cananger;
115 extern float damagedealt;
117 extern int editoractive;
118 extern int editorpathtype;
120 extern float hostiletime;
122 extern bool gamestarted;
124 extern int numhotspots;
125 extern int killhotspot;
126 extern XYZ hotspot[40];
127 extern int hotspottype[40];
128 extern float hotspotsize[40];
129 extern char hotspottext[40][256];
130 extern int currenthotspot;
134 extern bool stillloading;
135 extern bool winfreeze;
137 extern bool campaign;
139 static const char *rabbitskin[] = {
140 ":Data:Textures:Fur3.jpg",
141 ":Data:Textures:Fur.jpg",
142 ":Data:Textures:Fur2.jpg",
143 ":Data:Textures:Lynx.jpg",
144 ":Data:Textures:Otter.jpg",
145 ":Data:Textures:Opal.jpg",
146 ":Data:Textures:Sable.jpg",
147 ":Data:Textures:Chocolate.jpg",
148 ":Data:Textures:BW2.jpg",
149 ":Data:Textures:WB2.jpg"
152 static const char *wolfskin[] = {
153 ":Data:Textures:Wolf.jpg",
154 ":Data:Textures:Darkwolf.jpg",
155 ":Data:Textures:Snowwolf.jpg"
158 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
159 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
161 static const char **creatureskin[] = {rabbitskin, wolfskin};
163 /* Return true if PFX is a prefix of STR (case-insensitive). */
164 static bool stripfx(const char *str, const char *pfx)
166 return !strncasecmp(str, pfx, strlen(pfx));
169 static const char *cmd_names[] = {
170 #define DECLARE_COMMAND(cmd) #cmd,
171 #include "ConsoleCmds.h"
172 #undef DECLARE_COMMAND
175 typedef void (*console_handler)(Game *game, const char *args);
177 #define DECLARE_COMMAND(cmd) static void ch_##cmd(Game *game, const char *args);
178 #include "ConsoleCmds.h"
179 #undef DECLARE_COMMAND
181 static console_handler cmd_handlers[] = {
182 #define DECLARE_COMMAND(cmd) ch_##cmd,
183 #include "ConsoleCmds.h"
184 #undef DECLARE_COMMAND
189 // added utility functions -sf17k =============================================================
191 //TODO: this is incorrect but I'm afraid to change it and break something,
192 //probably causes quirky behavior that I might want to preserve
193 inline float roughDirection(XYZ vec){
195 float angle=-asin(-vec.x)*180/M_PI;
200 inline float roughDirectionTo(XYZ start, XYZ end){
201 return roughDirection(end-start);
204 //TODO: gotta be a better way
205 inline float pitch(XYZ vec){
207 return -asin(vec.y)*180/M_PI;
209 inline float pitchTo(XYZ start, XYZ end){
210 return pitch(end-start);
213 inline float sq(float n) { return n*n; }
215 inline float stepTowardf(float from, float to, float by){
216 if(fabs(from-to)<by) return to;
217 else if(from>to) return from-by;
221 void playdialogueboxsound(){
223 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
224 temppos=temppos-viewer;
229 switch(dialogueboxsound[whichdialogue][indialogue]){
230 case -6: sound=alarmsound; break;
231 case -4: sound=consolefailsound; break;
232 case -3: sound=consolesuccesssound; break;
233 case -2: sound=firestartsound; break;
234 case -1: sound=fireendsound; break;
235 case 1: sound=rabbitchitter; break;
236 case 2: sound=rabbitchitter2; break;
237 case 3: sound=rabbitpainsound; break;
238 case 4: sound=rabbitpain1sound; break;
239 case 5: sound=rabbitattacksound; break;
240 case 6: sound=rabbitattack2sound; break;
241 case 7: sound=rabbitattack3sound; break;
242 case 8: sound=rabbitattack4sound; break;
243 case 9: sound=growlsound; break;
244 case 10: sound=growl2sound; break;
245 case 11: sound=snarlsound; break;
246 case 12: sound=snarl2sound; break;
247 case 13: sound=barksound; break;
248 case 14: sound=bark2sound; break;
249 case 15: sound=bark3sound; break;
250 case 16: sound=barkgrowlsound; break;
254 emit_sound_at(sound, temppos);
257 // end added utility functions ================================================================
261 static void ch_quit(Game *game, const char *args)
266 static void ch_map(Game *game, const char *args)
268 game->Loadlevel(args);
269 game->whichlevel = -2;
273 static void ch_save(Game *game, const char *args){
275 snprintf(buf, 63, ":Data:Maps:%s", args);
280 tfile=fopen( ConvertFileName(buf), "wb" );
281 fpackf(tfile, "Bi", mapvers);
282 fpackf(tfile, "Bi", maptype);
283 fpackf(tfile, "Bi", hostile);
284 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
285 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
286 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
287 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
288 player[0].rotation, player[0].targetrotation, player[0].num_weapons);
289 if(player[0].num_weapons>0&&player[0].num_weapons<5)
290 for(int j=0;j<player[0].num_weapons;j++)
291 fpackf(tfile, "Bi", weapons[player[0].weaponids[j]].getType());
293 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
294 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
295 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
296 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
298 fpackf(tfile, "Bi", player[0].numclothes);
300 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
302 fpackf(tfile, "Bi", numdialogues);
304 for(int k=0;k<numdialogues;k++){
305 fpackf(tfile, "Bi", numdialogueboxes[k]);
306 fpackf(tfile, "Bi", dialoguetype[k]);
307 for(int l=0;l<10;l++){
308 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
309 fpackf(tfile, "Bf", participantrotation[k][l]);
311 for(int l=0;l<numdialogueboxes[k];l++){
312 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
313 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
314 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
315 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
316 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
318 int templength=strlen(dialoguetext[k][l]);
319 fpackf(tfile, "Bi",(templength));
320 for(int m=0;m<templength;m++){
321 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
322 if(dialoguetext[k][l][m]=='\0')
326 templength=strlen(dialoguename[k][l]);
327 fpackf(tfile, "Bi",templength);
328 for(int m=0;m<templength;m++){
329 fpackf(tfile, "Bb", dialoguename[k][l][m]);
330 if(dialoguename[k][l][m]=='\0')
334 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
335 fpackf(tfile, "Bi", participantfocus[k][l]);
336 fpackf(tfile, "Bi", participantaction[k][l]);
338 for(int m=0;m<10;m++)
339 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
341 fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
345 for(int k=0;k<player[0].numclothes;k++){
346 int templength=strlen(player[0].clothes[k]);
347 fpackf(tfile, "Bi", templength);
348 for(int l=0;l<templength;l++)
349 fpackf(tfile, "Bb", player[0].clothes[k][l]);
350 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
353 fpackf(tfile, "Bi", environment);
355 fpackf(tfile, "Bi", objects.numobjects);
357 for(int k=0;k<objects.numobjects;k++)
358 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k],
359 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
361 fpackf(tfile, "Bi", numhotspots);
362 for(int i=0;i<numhotspots;i++){
363 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
364 int templength=strlen(hotspottext[i]);
365 fpackf(tfile, "Bi",templength);
366 for(int l=0;l<templength;l++)
367 fpackf(tfile, "Bb", hotspottext[i][l]);
370 fpackf(tfile, "Bi", numplayers);
371 if(numplayers<maxplayers)
372 for(int j=1;j<numplayers;j++){
373 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
374 player[j].coords.x, player[j].coords.y, player[j].coords.z,
375 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
376 if(player[j].num_weapons<5)
377 for(int k=0;k<player[j].num_weapons;k++)
378 fpackf(tfile, "Bi", weapons[player[j].weaponids[k]].getType());
379 if(player[j].numwaypoints<30){
380 fpackf(tfile, "Bi", player[j].numwaypoints);
381 for(int k=0;k<player[j].numwaypoints;k++){
382 fpackf(tfile, "Bf", player[j].waypoints[k].x);
383 fpackf(tfile, "Bf", player[j].waypoints[k].y);
384 fpackf(tfile, "Bf", player[j].waypoints[k].z);
385 fpackf(tfile, "Bi", player[j].waypointtype[k]);
387 fpackf(tfile, "Bi", player[j].waypoint);
389 player[j].numwaypoints=0;
390 player[j].waypoint=0;
391 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
394 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
395 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
396 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
397 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
399 float headprop, bodyprop, armprop, legprop;
400 if(player[j].creature==wolftype){
401 headprop=player[j].proportionhead.x/1.1;
402 bodyprop=player[j].proportionbody.x/1.1;
403 armprop=player[j].proportionarms.x/1.1;
404 legprop=player[j].proportionlegs.x/1.1;
405 }else if(player[j].creature==rabbittype){
406 headprop=player[j].proportionhead.x/1.2;
407 bodyprop=player[j].proportionbody.x/1.05;
408 armprop=player[j].proportionarms.x/1.00;
409 legprop=player[j].proportionlegs.x/1.1;
412 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
414 fpackf(tfile, "Bi", player[j].numclothes);
415 if(player[j].numclothes)
416 for(int k=0;k<player[j].numclothes;k++){
418 templength=strlen(player[j].clothes[k]);
419 fpackf(tfile, "Bi", templength);
420 for(int l=0;l<templength;l++)
421 fpackf(tfile, "Bb", player[j].clothes[k][l]);
422 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
426 fpackf(tfile, "Bi", game->numpathpoints);
427 for(int j=0;j<game->numpathpoints;j++){
428 fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
429 for(int k=0;k<game->numpathpointconnect[j];k++)
430 fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
433 fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
438 static void ch_cellar(Game *game, const char *args)
440 game->LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
443 static void ch_tint(Game *game, const char *args)
445 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
448 static void ch_tintr(Game *game, const char *args)
453 static void ch_tintg(Game *game, const char *args)
458 static void ch_tintb(Game *game, const char *args)
463 static void ch_speed(Game *game, const char *args)
465 player[0].speedmult = atof(args);
468 static void ch_strength(Game *game, const char *args)
470 player[0].power = atof(args);
473 static void ch_power(Game *game, const char *args)
475 player[0].power = atof(args);
478 static void ch_size(Game *game, const char *args)
480 player[0].scale = atof(args) * .2;
483 static int find_closest()
486 float closestdist = std::numeric_limits<float>::max();
488 for (int i = 1; i < numplayers; i++) {
490 distance = findDistancefast(&player[i].coords,&player[0].coords);
491 if (distance < closestdist) {
492 closestdist = distance;
499 static void ch_sizenear(Game *game, const char *args)
501 int closest = find_closest();
504 player[closest].scale = atof(args) * .2;
507 static void set_proportion(int pnum, const char *args)
509 float headprop,bodyprop,armprop,legprop;
511 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
513 if(player[pnum].creature==wolftype){
514 player[pnum].proportionhead=1.1*headprop;
515 player[pnum].proportionbody=1.1*bodyprop;
516 player[pnum].proportionarms=1.1*armprop;
517 player[pnum].proportionlegs=1.1*legprop;
518 } else if(player[pnum].creature==rabbittype){
519 player[pnum].proportionhead=1.2*headprop;
520 player[pnum].proportionbody=1.05*bodyprop;
521 player[pnum].proportionarms=1.00*armprop;
522 player[pnum].proportionlegs=1.1*legprop;
523 player[pnum].proportionlegs.y=1.05*legprop;
527 static void ch_proportion(Game *game, const char *args)
529 set_proportion(0, args);
532 static void ch_proportionnear(Game *game, const char *args)
534 int closest = find_closest();
536 set_proportion(closest, args);
539 static void set_protection(int pnum, const char *args)
541 float head, high, low;
542 sscanf(args, "%f%f%f", &head, &high, &low);
544 player[pnum].protectionhead = head;
545 player[pnum].protectionhigh = high;
546 player[pnum].protectionlow = low;
549 static void ch_protection(Game *game, const char *args)
551 set_protection(0, args);
554 static void ch_protectionnear(Game *game, const char *args)
556 int closest = find_closest();
558 set_protection(closest, args);
561 static void set_armor(int pnum, const char *args)
563 float head, high, low;
564 sscanf(args, "%f%f%f", &head, &high, &low);
566 player[pnum].armorhead = head;
567 player[pnum].armorhigh = high;
568 player[pnum].armorlow = low;
571 static void ch_armor(Game *game, const char *args)
576 static void ch_armornear(Game *game, const char *args)
578 int closest = find_closest();
580 set_armor(closest, args);
583 static void ch_protectionreset(Game *game, const char *args)
585 set_protection(0, "1 1 1");
586 set_armor(0, "1 1 1");
589 static void set_metal(int pnum, const char *args)
591 float head, high, low;
592 sscanf(args, "%f%f%f", &head, &high, &low);
594 player[pnum].metalhead = head;
595 player[pnum].metalhigh = high;
596 player[pnum].metallow = low;
599 static void ch_metal(Game *game, const char *args)
604 static void set_noclothes(int pnum, Game *game, const char *args)
606 player[pnum].numclothes = 0;
607 game->LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
608 &player[pnum].skeleton.drawmodel.textureptr,1,
609 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
612 static void ch_noclothes(Game *game, const char *args)
614 set_noclothes(0, game, args);
617 static void ch_noclothesnear(Game *game, const char *args)
619 int closest = find_closest();
621 set_noclothes(closest, game, args);
625 static void set_clothes(int pnum, Game *game, const char *args)
628 snprintf(buf, 63, ":Data:Textures:%s.png", args);
630 if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
633 player[pnum].DoMipmaps();
634 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
635 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
636 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
637 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
638 player[pnum].numclothes++;
641 static void ch_clothes(Game *game, const char *args)
643 set_clothes(0, game, args);
646 static void ch_clothesnear(Game *game, const char *args)
648 int closest = find_closest();
650 set_clothes(closest, game, args);
653 static void ch_belt(Game *game, const char *args)
655 player[0].skeleton.clothes = !player[0].skeleton.clothes;
659 static void ch_cellophane(Game *game, const char *args)
661 cellophane = !cellophane;
662 float mul = cellophane ? 0 : 1;
664 for (int i = 0; i < numplayers; i++) {
665 player[i].proportionhead.z = player[i].proportionhead.x * mul;
666 player[i].proportionbody.z = player[i].proportionbody.x * mul;
667 player[i].proportionarms.z = player[i].proportionarms.x * mul;
668 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
672 static void ch_funnybunny(Game *game, const char *args)
674 player[0].skeleton.id=0;
675 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
676 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
677 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
678 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
679 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
680 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
681 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
682 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
683 player[0].creature=rabbittype;
685 player[0].headless=0;
686 player[0].damagetolerance=200;
687 set_proportion(0, "1 1 1 1");
690 static void ch_wolfie(Game *game, const char *args)
692 player[0].skeleton.id=0;
693 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
694 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
695 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
696 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
697 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
698 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
699 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
700 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
701 player[0].creature=wolftype;
702 player[0].damagetolerance=300;
703 set_proportion(0, "1 1 1 1");
706 static void ch_wolfieisgod(Game *game, const char *args)
708 ch_wolfie(game, args);
711 static void ch_wolf(Game *game, const char *args)
713 game->LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
714 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
717 static void ch_snowwolf(Game *game, const char *args)
719 game->LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
720 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
723 static void ch_darkwolf(Game *game, const char *args)
725 game->LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
726 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
729 static void ch_lizardwolf(Game *game, const char *args)
731 game->LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
732 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
735 static void ch_white(Game *game, const char *args)
737 game->LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
738 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
741 static void ch_brown(Game *game, const char *args)
743 game->LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
744 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
747 static void ch_black(Game *game, const char *args)
749 game->LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
750 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
753 static void ch_sizemin(Game *game, const char *args)
755 for (int i = 1; i < numplayers; i++)
756 if (player[i].scale < 0.8 * 0.2)
757 player[i].scale = 0.8 * 0.2;
760 static void ch_tutorial(Game *game, const char *args)
762 tutoriallevel = atoi(args);
765 static void ch_hostile(Game *game, const char *args)
767 hostile = atoi(args);
770 static void ch_indemo(Game *game, const char *args)
773 hotspot[numhotspots]=player[0].coords;
774 hotspotsize[numhotspots]=0;
775 hotspottype[numhotspots]=-111;
776 strcpy(hotspottext[numhotspots],"mapname");
780 static void ch_notindemo(Game *game, const char *args)
786 static void ch_type(Game *game, const char *args)
788 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
789 for (int i = 0; i < n; i++)
790 if (stripfx(args, editortypenames[i])) {
796 static void ch_path(Game *game, const char *args)
798 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
799 for (int i = 0; i < n; i++)
800 if (stripfx(args, pathtypenames[i])) {
806 static void ch_hs(Game *game, const char *args)
808 hotspot[numhotspots]=player[0].coords;
812 sscanf(args, "%f%d %n", &size, &type, &shift);
814 hotspotsize[numhotspots] = size;
815 hotspottype[numhotspots] = type;
817 strcpy(hotspottext[numhotspots], args + shift);
818 strcat(hotspottext[numhotspots], "\n");
823 static void ch_dialogue(Game *game, const char *args)
826 char buf1[32], buf2[64];
828 sscanf(args, "%d %31s", &dlg, buf1);
829 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
831 dialoguetype[numdialogues] = dlg;
833 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
834 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
836 ifstream ipstream(ConvertFileName(buf2));
837 ipstream.ignore(256,':');
838 ipstream >> numdialogueboxes[numdialogues];
839 for(int i=0;i<numdialogueboxes[numdialogues];i++){
840 ipstream.ignore(256,':');
841 ipstream.ignore(256,':');
842 ipstream.ignore(256,' ');
843 ipstream >> dialogueboxlocation[numdialogues][i];
844 ipstream.ignore(256,':');
845 ipstream >> dialogueboxcolor[numdialogues][i][0];
846 ipstream >> dialogueboxcolor[numdialogues][i][1];
847 ipstream >> dialogueboxcolor[numdialogues][i][2];
848 ipstream.ignore(256,':');
849 ipstream.getline(dialoguename[numdialogues][i],64);
850 ipstream.ignore(256,':');
851 ipstream.ignore(256,' ');
852 ipstream.getline(dialoguetext[numdialogues][i],128);
853 for(int j=0;j<128;j++){
854 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
856 ipstream.ignore(256,':');
857 ipstream >> dialogueboxsound[numdialogues][i];
860 for(int i=0;i<numdialogueboxes[numdialogues];i++){
861 for(int j=0;j<numplayers;j++){
862 participantfacing[numdialogues][i][j]=player[j].facing;
869 whichdialogue=numdialogues;
874 static void ch_fixdialogue(Game *game, const char *args)
876 char buf1[32], buf2[64];
879 sscanf(args, "%d %31s", &whichdi, buf1);
880 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
882 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
883 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
885 ifstream ipstream(ConvertFileName(buf2));
886 ipstream.ignore(256,':');
887 ipstream >> numdialogueboxes[whichdi];
888 for(int i=0;i<numdialogueboxes[whichdi];i++){
889 ipstream.ignore(256,':');
890 ipstream.ignore(256,':');
891 ipstream.ignore(256,' ');
892 ipstream >> dialogueboxlocation[whichdi][i];
893 ipstream.ignore(256,':');
894 ipstream >> dialogueboxcolor[whichdi][i][0];
895 ipstream >> dialogueboxcolor[whichdi][i][1];
896 ipstream >> dialogueboxcolor[whichdi][i][2];
897 ipstream.ignore(256,':');
898 ipstream.getline(dialoguename[whichdi][i],64);
899 ipstream.ignore(256,':');
900 ipstream.ignore(256,' ');
901 ipstream.getline(dialoguetext[whichdi][i],128);
902 for(int j=0;j<128;j++){
903 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
905 ipstream.ignore(256,':');
906 ipstream >> dialogueboxsound[whichdi][i];
912 static void ch_fixtype(Game *game, const char *args)
915 sscanf(args, "%d", &dlg);
916 dialoguetype[0] = dlg;
919 static void ch_fixrotation(Game *game, const char *args)
921 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
924 static void ch_ddialogue(Game *game, const char *args)
930 static void ch_dhs(Game *game, const char *args)
936 static void ch_immobile(Game *game, const char *args)
938 player[0].immobile = 1;
941 static void ch_allimmobile(Game *game, const char *args)
943 for (int i = 1; i < numplayers; i++)
944 player[i].immobile = 1;
947 static void ch_mobile(Game *game, const char *args)
949 player[0].immobile = 0;
952 static void ch_default(Game *game, const char *args)
954 player[0].armorhead=1;
955 player[0].armorhigh=1;
956 player[0].armorlow=1;
957 player[0].protectionhead=1;
958 player[0].protectionhigh=1;
959 player[0].protectionlow=1;
960 player[0].metalhead=1;
961 player[0].metalhigh=1;
962 player[0].metallow=1;
964 player[0].speedmult=1;
967 if(player[0].creature==wolftype){
968 player[0].proportionhead=1.1;
969 player[0].proportionbody=1.1;
970 player[0].proportionarms=1.1;
971 player[0].proportionlegs=1.1;
972 } else if(player[0].creature==rabbittype){
973 player[0].proportionhead=1.2;
974 player[0].proportionbody=1.05;
975 player[0].proportionarms=1.00;
976 player[0].proportionlegs=1.1;
977 player[0].proportionlegs.y=1.05;
980 player[0].numclothes=0;
981 game->LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
982 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
983 &player[0].skeleton.skinsize);
985 editoractive=typeactive;
986 player[0].immobile=0;
989 static void ch_play(Game *game, const char *args)
992 sscanf(args, "%d", &dlg);
995 if (whichdialogue >= numdialogues)
998 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
999 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1000 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1001 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
1002 player[participantfocus[whichdialogue][i]].velocity=0;
1003 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1004 player[participantfocus[whichdialogue][i]].targetframe=0;
1010 playdialogueboxsound();
1013 static void ch_mapkilleveryone(Game *game, const char *args)
1015 maptype = mapkilleveryone;
1018 static void ch_mapkillmost(Game *game, const char *args)
1020 maptype = mapkillmost;
1023 static void ch_mapkillsomeone(Game *game, const char *args)
1025 maptype = mapkillsomeone;
1028 static void ch_mapgosomewhere(Game *game, const char *args)
1030 maptype = mapgosomewhere;
1033 static void ch_viewdistance(Game *game, const char *args)
1035 viewdistance = atof(args)*100;
1038 static void ch_fadestart(Game *game, const char *args)
1040 fadestart = atof(args);
1043 static void ch_slomo(Game *game, const char *args)
1045 slomospeed = atof(args);
1050 static void ch_slofreq(Game *game, const char *args)
1052 slomofreq = atof(args);
1055 static void ch_skytint(Game *game, const char *args)
1057 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1059 skyboxlightr=skyboxr;
1060 skyboxlightg=skyboxg;
1061 skyboxlightb=skyboxb;
1063 game->SetUpLighting();
1065 terrain.DoShadows();
1066 objects.DoShadows();
1069 static void ch_skylight(Game *game, const char *args)
1071 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1073 game->SetUpLighting();
1075 terrain.DoShadows();
1076 objects.DoShadows();
1079 static void ch_skybox(Game *game, const char *args)
1081 skyboxtexture = !skyboxtexture;
1083 game->SetUpLighting();
1085 terrain.DoShadows();
1086 objects.DoShadows();
1089 static void cmd_dispatch(Game *game, const string cmd)
1091 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1093 for (i = 0; i < n_cmds; i++)
1094 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1096 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1097 cmd_handlers[i](game, cmd.substr(cmd.find(' ')+1).c_str());
1100 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1103 /********************> Tick() <*****/
1104 extern bool save_image(const char * fname);
1105 void Screenshot (void)
1108 time_t t = time(NULL);
1109 struct tm *tme = localtime(&t);
1110 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);
1113 mkdir("Screenshots");
1115 mkdir("Screenshots", S_IRWXU);
1121 void Game::SetUpLighting(){
1122 if(environment==snowyenvironment)
1123 light.setColors(.65,.65,.7,.4,.4,.44);
1124 if(environment==desertenvironment)
1125 light.setColors(.95,.95,.95,.4,.35,.3);
1126 if(environment==grassyenvironment)
1127 light.setColors(.95,.95,1,.4,.4,.44);
1129 light.setColors(1,1,1,.4,.4,.4);
1131 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1132 light.color[0]*=(skyboxlightr+average)/2;
1133 light.color[1]*=(skyboxlightg+average)/2;
1134 light.color[2]*=(skyboxlightb+average)/2;
1135 light.ambient[0]*=(skyboxlightr+average)/2;
1136 light.ambient[1]*=(skyboxlightg+average)/2;
1137 light.ambient[2]*=(skyboxlightb+average)/2;
1140 int Game::findPathDist(int start,int end){
1141 int smallestcount,count,connected;
1142 int last,last2,last3,last4;
1146 for(int i=0;i<50;i++){
1152 while(last!=end&&count<30){
1154 for(int j=0;j<numpathpoints;j++){
1155 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1158 if(numpathpointconnect[j])
1159 for(int k=0;k<numpathpointconnect[j];k++){
1160 if(pathpointconnect[j][k]==last)connected=1;
1163 if(numpathpointconnect[last])
1164 for(int k=0;k<numpathpointconnect[last];k++){
1165 if(pathpointconnect[last][k]==j)connected=1;
1168 if(closest==-1||Random()%2==0){
1179 if(count<smallestcount)smallestcount=count;
1181 return smallestcount;
1184 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1185 static XYZ colpoint,colviewer,coltarget;
1186 static float minx,minz,maxx,maxz,miny,maxy;
1188 minx=min(startpoint.x,endpoint.x)-1;
1189 miny=min(startpoint.y,endpoint.y)-1;
1190 minz=min(startpoint.z,endpoint.z)-1;
1191 maxx=max(startpoint.x,endpoint.x)+1;
1192 maxy=max(startpoint.y,endpoint.y)+1;
1193 maxz=max(startpoint.z,endpoint.z)+1;
1195 for(int i=0;i<objects.numobjects;i++){
1196 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1197 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1198 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1199 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1200 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1201 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1202 if( objects.type[i]!=treeleavestype&&
1203 objects.type[i]!=bushtype&&
1204 objects.type[i]!=firetype){
1205 colviewer=startpoint;
1207 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
1212 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1217 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1218 static XYZ colpoint,colviewer,coltarget;
1219 static float minx,minz,maxx,maxz,miny,maxy;
1220 static int i; //FIXME: see below
1222 minx=min(startpoint.x,endpoint.x)-1;
1223 miny=min(startpoint.y,endpoint.y)-1;
1224 minz=min(startpoint.z,endpoint.z)-1;
1225 maxx=max(startpoint.x,endpoint.x)+1;
1226 maxy=max(startpoint.y,endpoint.y)+1;
1227 maxz=max(startpoint.z,endpoint.z)+1;
1230 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1231 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1232 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1233 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1234 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1235 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1236 if( objects.type[what]!=treeleavestype&&
1237 objects.type[what]!=bushtype&&
1238 objects.type[what]!=firetype){
1239 colviewer=startpoint;
1242 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
1247 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1252 void Game::Setenvironment(int which)
1256 LOG(" Setting environment...");
1258 float temptexdetail;
1261 pause_sound(stream_snowtheme);
1262 pause_sound(stream_grasstheme);
1263 pause_sound(stream_deserttheme);
1264 pause_sound(stream_wind);
1265 pause_sound(stream_desertambient);
1268 if(environment==snowyenvironment){
1272 emit_stream_np(stream_wind);
1274 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1275 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1276 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1277 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1279 footstepsound = footstepsn1;
1280 footstepsound2 = footstepsn2;
1281 footstepsound3 = footstepst1;
1282 footstepsound4 = footstepst2;
1284 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1286 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1288 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1293 temptexdetail=texdetail;
1294 if(texdetail>1)texdetail=4;
1295 skybox.load( ":Data:Textures:Skybox(snow):Front.jpg",
1296 ":Data:Textures:Skybox(snow):Left.jpg",
1297 ":Data:Textures:Skybox(snow):Back.jpg",
1298 ":Data:Textures:Skybox(snow):Right.jpg",
1299 ":Data:Textures:Skybox(snow):Up.jpg",
1300 ":Data:Textures:Skybox(snow):Down.jpg");
1305 texdetail=temptexdetail;
1306 } else if(environment==desertenvironment){
1309 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1310 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1311 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1312 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1316 emit_stream_np(stream_desertambient);
1318 footstepsound = footstepsn1;
1319 footstepsound2 = footstepsn2;
1320 footstepsound3 = footstepsn1;
1321 footstepsound4 = footstepsn2;
1323 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1325 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1327 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1331 temptexdetail=texdetail;
1332 if(texdetail>1)texdetail=4;
1333 skybox.load( ":Data:Textures:Skybox(sand):Front.jpg",
1334 ":Data:Textures:Skybox(sand):Left.jpg",
1335 ":Data:Textures:Skybox(sand):Back.jpg",
1336 ":Data:Textures:Skybox(sand):Right.jpg",
1337 ":Data:Textures:Skybox(sand):Up.jpg",
1338 ":Data:Textures:Skybox(sand):Down.jpg");
1343 texdetail=temptexdetail;
1344 } else if(environment==grassyenvironment){
1347 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1348 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1349 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1350 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1353 emit_stream_np(stream_wind, 100.);
1355 footstepsound = footstepgr1;
1356 footstepsound2 = footstepgr2;
1357 footstepsound3 = footstepst1;
1358 footstepsound4 = footstepst2;
1360 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1362 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1364 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1368 temptexdetail=texdetail;
1369 if(texdetail>1)texdetail=4;
1370 skybox.load( ":Data:Textures:Skybox(grass):Front.jpg",
1371 ":Data:Textures:Skybox(grass):Left.jpg",
1372 ":Data:Textures:Skybox(grass):Back.jpg",
1373 ":Data:Textures:Skybox(grass):Right.jpg",
1374 ":Data:Textures:Skybox(grass):Up.jpg",
1375 ":Data:Textures:Skybox(grass):Down.jpg");
1379 texdetail=temptexdetail;
1381 temptexdetail=texdetail;
1383 terrain.load(":Data:Textures:heightmap.png");
1385 texdetail=temptexdetail;
1388 void Game::Loadlevel(int which) {
1394 Loadlevel("tutorial");
1395 } else if(which >= 0 && which <= 15) {
1397 snprintf(buf, 32, "map%d", which + 1); // challenges
1400 Loadlevel("mapsave");
1403 void Game::Loadlevel(const char *name) {
1406 static const char *pfx = ":Data:Maps:";
1409 float headprop,legprop,armprop,bodyprop;
1413 LOG(std::string("Loading level...") + name);
1425 if(tutoriallevel!=-1)
1430 if(tutoriallevel==1)
1432 if(tutorialstage==0) {
1433 tutorialstagetime=0;
1437 pause_sound(whooshsound);
1438 pause_sound(stream_firesound);
1440 // Change the map filename into something that is os specific
1441 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1442 sprintf(buf, "%s%s", pfx, name);
1443 const char *FixedFN = ConvertFileName(buf);
1447 //~ char* buff=getcwd(NULL,0);
1448 //~ cout << buff << " " << FixedFN << endl;
1450 tfile=fopen( FixedFN, "rb" );
1452 pause_sound(stream_firesound);
1458 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1462 for(int i=0;i<20;i++)
1463 dialoguegonethrough[i]=0;
1472 difficulty=accountactive->getDifficulty();
1491 for(int i=0;i<100;i++)
1511 bonustotal=startbonustotal;
1516 emit_sound_np(consolesuccesssound);
1521 if(!stealthloading){
1522 terrain.numdecals=0;
1523 Sprite::deleteSprites();
1524 for(int i=0;i<objects.numobjects;i++)
1525 objects.model[i].numdecals=0;
1527 int j=objects.numobjects;
1528 for(int i=0;i<j;i++){
1529 objects.DeleteObject(0);
1534 for(int i=0;i<subdivision;i++)
1535 for(int j=0;j<subdivision;j++)
1536 terrain.patchobjectnum[i][j]=0;
1543 funpackf(tfile, "Bi", &mapvers);
1545 funpackf(tfile, "Bi", &indemo);
1549 funpackf(tfile, "Bi", &maptype);
1551 maptype=mapkilleveryone;
1553 funpackf(tfile, "Bi", &hostile);
1557 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1563 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1571 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1573 skyboxlightr=skyboxr;
1574 skyboxlightg=skyboxg;
1575 skyboxlightb=skyboxb;
1578 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);
1580 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1581 player[0].originalcoords=player[0].coords;
1582 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1583 for(int j=0;j<player[0].num_weapons;j++){
1584 player[0].weaponids[j]=weapons.size();
1586 funpackf(tfile, "Bi", &type);
1587 weapons.push_back(Weapon(type,0));
1593 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1594 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1595 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1596 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1598 funpackf(tfile, "Bi", &player[0].numclothes);
1601 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1603 player[0].whichskin=0;
1604 player[0].creature=rabbittype;
1607 player[0].lastattack=-1;
1608 player[0].lastattack2=-1;
1609 player[0].lastattack3=-1;
1613 funpackf(tfile, "Bi", &numdialogues);
1614 for(int k=0;k<numdialogues;k++){
1615 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1616 funpackf(tfile, "Bi", &dialoguetype[k]);
1617 for(int l=0;l<10;l++){
1618 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1619 funpackf(tfile, "Bf", &participantrotation[k][l]);
1621 for(int l=0;l<numdialogueboxes[k];l++){
1622 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1623 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1624 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1625 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1626 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1628 funpackf(tfile, "Bi",&templength);
1629 if(templength>128||templength<=0)
1632 for(m=0;m<templength;m++){
1633 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1634 if(dialoguetext[k][l][m]=='\0')
1637 dialoguetext[k][l][m] = 0;
1639 funpackf(tfile, "Bi",&templength);
1640 if(templength>64||templength<=0)templength=64;
1641 for(m=0;m<templength;m++){
1642 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1643 if(dialoguename[k][l][m]=='\0')
1646 dialoguename[k][l][m] = 0;
1647 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1648 funpackf(tfile, "Bi", &participantfocus[k][l]);
1649 funpackf(tfile, "Bi", &participantaction[k][l]);
1652 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1654 funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1660 for(int k=0;k<player[0].numclothes;k++){
1661 funpackf(tfile, "Bi", &templength);
1662 for(int l=0;l<templength;l++)
1663 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1664 player[0].clothes[k][templength]='\0';
1665 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1668 funpackf(tfile, "Bi", &environment);
1670 funpackf(tfile, "Bi", &objects.numobjects);
1671 for(int i=0;i<objects.numobjects;i++){
1672 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]);
1673 if(objects.type[i]==treeleavestype)
1674 objects.scale[i]=objects.scale[i-1];
1678 funpackf(tfile, "Bi", &numhotspots);
1679 for(int i=0;i<numhotspots;i++){
1680 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1681 funpackf(tfile, "Bi", &templength);
1683 for(int l=0;l<templength;l++)
1684 funpackf(tfile, "Bb", &hotspottext[i][l]);
1685 hotspottext[i][templength]='\0';
1686 if(hotspottype[i]==-111)
1695 if(!stealthloading){
1697 for(int i=0;i<objects.numobjects;i++)
1698 objects.center+=objects.position[i];
1699 objects.center/=objects.numobjects;
1705 float maxdistance=0;
1707 //~ int whichclosest;
1708 for(int i=0;i<objects.numobjects;i++){
1709 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1710 if(tempdist>maxdistance){
1712 maxdistance=tempdist;
1715 objects.radius=fast_sqrt(maxdistance);
1720 //mapcenter=objects.center;
1721 //mapradius=objects.radius;
1723 funpackf(tfile, "Bi", &numplayers);
1724 int howmanyremoved=0;
1725 bool removeanother=0;
1726 if(numplayers>1&&numplayers<maxplayers){
1727 for(int i=1;i<numplayers;i++){
1732 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);
1734 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1736 player[i-howmanyremoved].howactive=typeactive;
1738 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1740 player[i-howmanyremoved].scale=-1;
1742 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1744 player[i-howmanyremoved].immobile=0;
1746 funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1748 player[i-howmanyremoved].rotation=0;
1749 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1750 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1755 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1756 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1757 player[i-howmanyremoved].weaponids[j]=weapons.size();
1759 funpackf(tfile, "Bi", &type);
1760 weapons.push_back(Weapon(type,i));
1763 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1764 //player[i-howmanyremoved].numwaypoints=10;
1765 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1766 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1767 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1768 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1770 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1772 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1775 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1776 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1777 player[i-howmanyremoved].waypoint=0;
1779 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1780 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1781 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1782 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1785 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1792 if(player[i-howmanyremoved].creature==wolftype){
1793 player[i-howmanyremoved].proportionhead=1.1*headprop;
1794 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1795 player[i-howmanyremoved].proportionarms=1.1*armprop;
1796 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1799 if(player[i-howmanyremoved].creature==rabbittype){
1800 player[i-howmanyremoved].proportionhead=1.2*headprop;
1801 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1802 player[i-howmanyremoved].proportionarms=1.00*armprop;
1803 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1804 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1807 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1808 if(player[i-howmanyremoved].numclothes){
1809 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1811 funpackf(tfile, "Bi", &templength);
1812 for(int l=0;l<templength;l++)
1813 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1814 player[i-howmanyremoved].clothes[k][templength]='\0';
1815 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1824 numplayers-=howmanyremoved;
1825 funpackf(tfile, "Bi", &numpathpoints);
1826 if(numpathpoints>30||numpathpoints<0)
1828 for(int j=0;j<numpathpoints;j++){
1829 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1830 for(int k=0;k<numpathpointconnect[j];k++){
1831 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1837 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1840 if(environment!=oldenvironment)
1841 Setenvironment(environment);
1842 oldenvironment=environment;
1844 if(!stealthloading){
1845 int j=objects.numobjects;
1846 objects.numobjects=0;
1847 for(int i=0;i<j;i++){
1848 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1853 terrain.DoShadows();
1856 objects.DoShadows();
1863 if(numplayers>maxplayers-1)
1864 numplayers=maxplayers-1;
1865 for(int i=0;i<numplayers;i++){
1871 if(i==0||player[i].scale<0)
1873 player[i].skeleton.free=0;
1874 player[i].skeleton.id=i;
1876 player[i].creature=rabbittype;
1877 if(player[i].creature!=wolftype){
1878 player[i].skeleton.Load(
1879 (char *)":Data:Skeleton:Basic Figure",
1880 (char *)":Data:Skeleton:Basic Figurelow",
1881 (char *)":Data:Skeleton:Rabbitbelt",
1882 (char *)":Data:Models:Body.solid",
1883 (char *)":Data:Models:Body2.solid",
1884 (char *)":Data:Models:Body3.solid",
1885 (char *)":Data:Models:Body4.solid",
1886 (char *)":Data:Models:Body5.solid",
1887 (char *)":Data:Models:Body6.solid",
1888 (char *)":Data:Models:Body7.solid",
1889 (char *)":Data:Models:Bodylow.solid",
1890 (char *)":Data:Models:Belt.solid",0);
1892 if(player[i].creature!=wolftype){
1893 player[i].skeleton.Load(
1894 (char *)":Data:Skeleton:Basic Figure",
1895 (char *)":Data:Skeleton:Basic Figurelow",
1896 (char *)":Data:Skeleton:Rabbitbelt",
1897 (char *)":Data:Models:Body.solid",
1898 (char *)":Data:Models:Body2.solid",
1899 (char *)":Data:Models:Body3.solid",
1900 (char *)":Data:Models:Body4.solid",
1901 (char *)":Data:Models:Body5.solid",
1902 (char *)":Data:Models:Body6.solid",
1903 (char *)":Data:Models:Body7.solid",
1904 (char *)":Data:Models:Bodylow.solid",
1905 (char *)":Data:Models:Belt.solid",1);
1906 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1908 if(player[i].creature==wolftype){
1909 player[i].skeleton.Load(
1910 (char *)":Data:Skeleton:Basic Figure Wolf",
1911 (char *)":Data:Skeleton:Basic Figure Wolf Low",
1912 (char *)":Data:Skeleton:Rabbitbelt",
1913 (char *)":Data:Models:Wolf.solid",
1914 (char *)":Data:Models:Wolf2.solid",
1915 (char *)":Data:Models:Wolf3.solid",
1916 (char *)":Data:Models:Wolf4.solid",
1917 (char *)":Data:Models:Wolf5.solid",
1918 (char *)":Data:Models:Wolf6.solid",
1919 (char *)":Data:Models:Wolf7.solid",
1920 (char *)":Data:Models:Wolflow.solid",
1921 (char *)":Data:Models:Belt.solid",0);
1927 //~ texsize=512*512*3/texdetail/texdetail;
1929 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1931 if(player[i].numclothes){
1932 for(int j=0;j<player[i].numclothes;j++){
1933 tintr=player[i].clothestintr[j];
1934 tintg=player[i].clothestintg[j];
1935 tintb=player[i].clothestintb[j];
1936 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
1938 player[i].DoMipmaps();
1941 player[i].currentanimation=bounceidleanim;
1942 player[i].targetanimation=bounceidleanim;
1943 player[i].currentframe=0;
1944 player[i].targetframe=1;
1946 player[i].speed=1+(float)(Random()%100)/1000;
1948 player[i].speed-=.2;
1950 player[i].speed-=.1;
1952 player[i].velocity=0;
1953 player[i].oldcoords=player[i].coords;
1954 player[i].realoldcoords=player[i].coords;
1957 player[i].skeleton.id=i;
1958 player[i].updatedelay=0;
1959 player[i].normalsupdatedelay=0;
1961 player[i].aitype=passivetype;
1962 player[i].madskills=0;
1965 player[i].proportionhead=1.2;
1966 player[i].proportionbody=1.05;
1967 player[i].proportionarms=1.00;
1968 player[i].proportionlegs=1.1;
1969 player[i].proportionlegs.y=1.05;
1971 player[i].headless=0;
1972 player[i].currentoffset=0;
1973 player[i].targetoffset=0;
1975 player[i].damagetolerance=200;
1977 if(player[i].creature==wolftype){
1978 if(i==0||player[i].scale<0)
1979 player[i].scale=.23;
1980 player[i].damagetolerance=300;
1986 player[i].proportionhead.z=0;
1987 player[i].proportionbody.z=0;
1988 player[i].proportionarms.z=0;
1989 player[i].proportionlegs.z=0;
1992 player[i].tempanimation.Load((char *)"Tempanim",0,0);
1994 player[i].headmorphness=0;
1995 player[i].targetheadmorphness=1;
1996 player[i].headmorphstart=0;
1997 player[i].headmorphend=0;
1999 player[i].pausetime=0;
2002 player[i].jumppower=5;
2004 player[i].permanentdamage=0;
2005 player[i].superpermanentdamage=0;
2007 player[i].forwardkeydown=0;
2008 player[i].leftkeydown=0;
2009 player[i].backkeydown=0;
2010 player[i].rightkeydown=0;
2011 player[i].jumpkeydown=0;
2012 player[i].crouchkeydown=0;
2013 player[i].throwkeydown=0;
2015 player[i].collided=-10;
2017 player[i].bloodloss=0;
2018 player[i].weaponactive=-1;
2019 player[i].weaponstuck=-1;
2020 player[i].bleeding=0;
2021 player[i].deathbleeding=0;
2022 player[i].stunned=0;
2023 player[i].hasvictim=0;
2024 player[i].wentforweapon=0;
2027 player[0].aitype=playercontrolled;
2028 player[0].weaponactive=-1;
2031 player[0].power=1/.9;
2034 player[0].power=1/.8;
2037 player[0].damagetolerance=250;
2039 player[0].damagetolerance=300;
2041 player[0].armorhead*=1.5;
2043 player[0].armorhigh*=1.5;
2045 player[0].armorlow*=1.5;
2046 cameraloc=player[0].coords;
2048 rotation=player[0].rotation;
2050 hawkcoords=player[0].coords;
2055 //~ for(int i=0;i<weapons.size();i++){
2058 LOG("Starting background music...");
2060 OPENAL_StopSound(OPENAL_ALL);
2061 if(environment==snowyenvironment){
2063 emit_stream_np(stream_wind);
2064 }else if(environment==desertenvironment){
2066 emit_stream_np(stream_desertambient);
2067 }else if(environment==grassyenvironment){
2069 emit_stream_np(stream_wind, 100.);
2071 oldmusicvolume[0]=0;
2072 oldmusicvolume[1]=0;
2073 oldmusicvolume[2]=0;
2074 oldmusicvolume[3]=0;
2086 void Game::doTutorial(){
2087 if(tutorialstagetime>tutorialmaxtime){
2090 if(tutorialstage<=1){
2095 switch(tutorialstage){
2101 tutorialmaxtime=600;
2103 tutorialmaxtime=1000;
2105 tutorialmaxtime=600;
2107 tutorialmaxtime=600;
2109 tutorialmaxtime=600;
2111 tutorialmaxtime=600;
2113 tutorialmaxtime=600;
2117 tutorialmaxtime=1000;
2119 tutorialmaxtime=1000;
2134 player[1].coords=(temp+temp2)/2;
2136 emit_sound_at(fireendsound, player[1].coords);
2138 for(int i=0;i<player[1].skeleton.num_joints;i++){
2140 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2141 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2142 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;
2143 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2144 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2149 tutorialmaxtime=500;
2151 tutorialmaxtime=500;
2153 tutorialmaxtime=500;
2155 tutorialmaxtime=500;
2158 //tutorialmaxtime=500;
2160 tutorialmaxtime=500;
2162 tutorialmaxtime=500;
2169 tutorialmaxtime=500;
2171 tutorialmaxtime=500;
2173 tutorialmaxtime=500;
2175 tutorialmaxtime=500;
2182 player[1].aitype=attacktypecutoff;
2184 tutorialmaxtime=400;
2186 tutorialmaxtime=400;
2187 player[0].escapednum=0;
2192 player[1].aitype=passivetype;
2198 tutorialmaxtime=400;
2201 player[1].aitype=attacktypecutoff;
2203 tutorialmaxtime=400;
2205 tutorialmaxtime=400;
2210 player[1].aitype=passivetype;
2217 player[1].aitype=attacktypecutoff;
2222 player[1].aitype=passivetype;
2234 w.position=(temp+temp2)/2;
2235 w.tippoint=(temp+temp2)/2;
2245 weapons.push_back(w);
2248 tutorialmaxtime=300;
2250 tutorialmaxtime=300;
2254 tutorialmaxtime=300;
2257 player[0].weaponactive=-1;
2258 player[0].num_weapons=0;
2259 player[1].weaponactive=0;
2260 player[1].num_weapons=1;
2261 player[1].weaponids[0]=0;
2265 player[1].aitype=attacktypecutoff;
2267 tutorialmaxtime=300;
2270 player[0].weaponactive=-1;
2271 player[0].num_weapons=0;
2272 player[1].weaponactive=0;
2273 player[1].num_weapons=1;
2274 player[1].weaponids[0]=0;
2276 tutorialmaxtime=300;
2279 player[0].weaponactive=-1;
2280 player[0].num_weapons=0;
2281 player[1].weaponactive=0;
2282 player[1].num_weapons=1;
2283 player[1].weaponids[0]=0;
2285 weapons[0].setType(sword);
2287 tutorialmaxtime=300;
2301 w.position=(temp+temp2)/2;
2302 w.tippoint=(temp+temp2)/2;
2312 weapons.push_back(w);
2316 player[0].weaponactive=0;
2317 player[0].num_weapons=1;
2318 player[0].weaponids[0]=1;
2319 player[1].weaponactive=0;
2320 player[1].num_weapons=1;
2321 player[1].weaponids[0]=0;
2327 player[1].aitype=passivetype;
2333 player[0].weaponactive=0;
2334 player[0].num_weapons=1;
2335 player[0].weaponids[0]=1;
2336 player[1].weaponactive=0;
2337 player[1].num_weapons=1;
2338 player[1].weaponids[0]=0;
2340 if(player[0].weaponactive!=-1)
2341 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2343 weapons[0].setType(staff);
2347 player[1].aitype=passivetype;
2349 tutorialmaxtime=200;
2351 weapons[1].position=1000;
2352 weapons[1].tippoint=1000;
2354 weapons[0].setType(knife);
2357 player[1].weaponactive=-1;
2358 player[1].num_weapons=0;
2359 player[0].weaponactive=0;
2360 player[0].num_weapons=1;
2361 player[0].weaponids[0]=0;
2367 emit_sound_at(fireendsound, player[1].coords);
2369 for(int i=0;i<player[1].skeleton.num_joints;i++){
2371 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2372 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2373 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;
2374 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2375 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2379 player[1].num_weapons=0;
2380 player[1].weaponstuck=-1;
2381 player[1].weaponactive=-1;
2386 tutorialmaxtime=80000;
2387 break; default: break;
2389 if(tutorialstage<=51)tutorialstagetime=0;
2393 if(tutorialstagetime<tutorialmaxtime-3){
2394 switch(tutorialstage){
2395 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2396 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2397 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2398 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2399 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2400 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2401 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2402 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2403 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2404 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2405 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2406 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2407 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2408 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2409 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2410 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2411 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2412 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2413 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2414 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2415 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2417 if(player[0].escapednum==2) {
2421 player[1].aitype=passivetype;
2423 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2424 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2426 if(animation[player[0].targetanimation].attack==reversal){
2430 player[1].aitype=passivetype;
2432 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2433 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2434 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2435 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2436 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2437 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2438 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2439 break; default: break;
2441 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2444 if(tutorialstagetime==tutorialmaxtime-3){
2445 emit_sound_np(consolesuccesssound);
2448 if(tutorialsuccess>=1){
2449 if(tutorialstage==34||tutorialstage==35)
2450 tutorialstagetime=tutorialmaxtime-1;
2454 if(tutorialstage<14||tutorialstage>=50){
2455 player[1].coords.y=300;
2456 player[1].velocity=0;
2460 void Game::doDebugKeys(){
2461 float headprop,bodyprop,armprop,legprop;
2463 if(Input::isKeyPressed(SDLK_h)){
2464 player[0].damagetolerance=200000;
2467 player[0].permanentdamage=0;
2468 player[0].superpermanentdamage=0;
2471 if(Input::isKeyPressed(SDLK_j)){
2475 Setenvironment(environment);
2478 if(Input::isKeyPressed(SDLK_c)){
2479 cameramode=1-cameramode;
2482 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2483 if(player[0].num_weapons>0){
2484 if(weapons[player[0].weaponids[0]].getType()==sword)
2485 weapons[player[0].weaponids[0]].setType(staff);
2486 else if(weapons[player[0].weaponids[0]].getType()==staff)
2487 weapons[player[0].weaponids[0]].setType(knife);
2489 weapons[player[0].weaponids[0]].setType(sword);
2493 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2495 float closestdist=-1;
2498 for(int i=1;i<numplayers;i++){
2499 distance=findDistancefast(&player[i].coords,&player[0].coords);
2500 if(closestdist==-1||distance<closestdist){
2501 closestdist=distance;
2506 if(player[closest].num_weapons){
2507 if(weapons[player[closest].weaponids[0]].getType()==sword)
2508 weapons[player[closest].weaponids[0]].setType(staff);
2509 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2510 weapons[player[closest].weaponids[0]].setType(knife);
2512 weapons[player[closest].weaponids[0]].setType(sword);
2514 if(!player[closest].num_weapons){
2515 player[closest].weaponids[0]=weapons.size();
2517 weapons.push_back(Weapon(knife,closest));
2519 player[closest].num_weapons=1;
2524 if(Input::isKeyDown(SDLK_u)){
2526 float closestdist=-1;
2529 for(int i=1;i<numplayers;i++){
2530 distance=findDistancefast(&player[i].coords,&player[0].coords);
2531 if(closestdist==-1||distance<closestdist){
2532 closestdist=distance;
2536 player[closest].rotation+=multiplier*50;
2537 player[closest].targetrotation=player[closest].rotation;
2541 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2543 float closestdist=-1;
2546 for(int i=1;i<numplayers;i++){
2547 distance=findDistancefast(&player[i].coords,&player[0].coords);
2548 if(closestdist==-1||distance<closestdist){
2549 closestdist=distance;
2553 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2556 player[closest].whichskin++;
2557 if(player[closest].whichskin>9)
2558 player[closest].whichskin=0;
2559 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2560 player[closest].whichskin=0;
2562 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2563 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2566 if(player[closest].numclothes){
2567 for(int i=0;i<player[closest].numclothes;i++){
2568 tintr=player[closest].clothestintr[i];
2569 tintg=player[closest].clothestintg[i];
2570 tintb=player[closest].clothestintb[i];
2571 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2573 player[closest].DoMipmaps();
2577 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2579 float closestdist=-1;
2582 for(int i=1;i<numplayers;i++){
2583 distance=findDistancefast(&player[i].coords,&player[0].coords);
2584 if(closestdist==-1||distance<closestdist){
2585 closestdist=distance;
2590 if(player[closest].creature==wolftype){
2591 headprop=player[closest].proportionhead.x/1.1;
2592 bodyprop=player[closest].proportionbody.x/1.1;
2593 armprop=player[closest].proportionarms.x/1.1;
2594 legprop=player[closest].proportionlegs.x/1.1;
2597 if(player[closest].creature==rabbittype){
2598 headprop=player[closest].proportionhead.x/1.2;
2599 bodyprop=player[closest].proportionbody.x/1.05;
2600 armprop=player[closest].proportionarms.x/1.00;
2601 legprop=player[closest].proportionlegs.x/1.1;
2605 if(player[closest].creature==rabbittype){
2606 player[closest].skeleton.id=closest;
2607 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);
2608 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2609 player[closest].whichskin=0;
2610 player[closest].creature=wolftype;
2612 player[closest].proportionhead=1.1;
2613 player[closest].proportionbody=1.1;
2614 player[closest].proportionarms=1.1;
2615 player[closest].proportionlegs=1.1;
2616 player[closest].proportionlegs.y=1.1;
2617 player[closest].scale=.23*5*player[0].scale;
2619 player[closest].damagetolerance=300;
2623 player[closest].skeleton.id=closest;
2624 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);
2625 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2626 player[closest].whichskin=0;
2627 player[closest].creature=rabbittype;
2629 player[closest].proportionhead=1.2;
2630 player[closest].proportionbody=1.05;
2631 player[closest].proportionarms=1.00;
2632 player[closest].proportionlegs=1.1;
2633 player[closest].proportionlegs.y=1.05;
2634 player[closest].scale=.2*5*player[0].scale;
2636 player[closest].damagetolerance=200;
2639 if(player[closest].creature==wolftype){
2640 player[closest].proportionhead=1.1*headprop;
2641 player[closest].proportionbody=1.1*bodyprop;
2642 player[closest].proportionarms=1.1*armprop;
2643 player[closest].proportionlegs=1.1*legprop;
2646 if(player[closest].creature==rabbittype){
2647 player[closest].proportionhead=1.2*headprop;
2648 player[closest].proportionbody=1.05*bodyprop;
2649 player[closest].proportionarms=1.00*armprop;
2650 player[closest].proportionlegs=1.1*legprop;
2651 player[closest].proportionlegs.y=1.05*legprop;
2657 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2663 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2665 float closestdist=-1;
2667 XYZ flatfacing2,flatvelocity2;
2670 for(int i=1;i<numplayers;i++){
2671 distance=findDistancefast(&player[i].coords,&player[0].coords);
2672 if(distance<144&&!player[i].headless)
2673 if(closestdist==-1||distance<closestdist){
2674 closestdist=distance;
2676 blah = player[i].coords;
2681 XYZ headspurtdirection;
2682 //int i = player[closest].skeleton.jointlabels[head];
2683 Joint& headjoint= player[closest].getJointFor(head);
2684 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2685 if(!player[closest].skeleton.free)
2686 flatvelocity2=player[closest].velocity;
2687 if(player[closest].skeleton.free)
2688 flatvelocity2=headjoint.velocity;
2689 if(!player[closest].skeleton.free)
2690 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;
2691 if(player[closest].skeleton.free)
2692 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2693 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2694 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2695 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2696 headspurtdirection=headjoint.position-player[closest].getJointFor(neck).position;
2697 Normalise(&headspurtdirection);
2698 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2699 flatvelocity2+=headspurtdirection*8;
2700 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2702 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2704 emit_sound_at(splattersound, blah);
2705 emit_sound_at(breaksound2, blah, 100.);
2707 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2708 player[closest].RagDoll(0);
2709 player[closest].dead=2;
2710 player[closest].headless=1;
2711 player[closest].DoBloodBig(3,165);
2717 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2719 float closestdist=-1;
2721 XYZ flatfacing2,flatvelocity2;
2724 for(int i=1;i<numplayers;i++){
2725 distance=findDistancefast(&player[i].coords,&player[0].coords);
2727 if(closestdist==-1||distance<closestdist){
2728 closestdist=distance;
2730 blah=player[i].coords;
2735 emit_sound_at(splattersound, blah);
2737 emit_sound_at(breaksound2, blah);
2739 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2740 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2741 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2742 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;
2743 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2744 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2745 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2746 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2747 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2748 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2749 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2752 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2753 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2754 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2755 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;
2756 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2757 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2758 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2759 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2760 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2761 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2764 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2765 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2766 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2767 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;
2768 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2769 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2770 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2771 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2772 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2773 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2776 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2777 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2778 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2779 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;
2780 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2781 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2782 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2783 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2784 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2785 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2789 for(int j=0;j<numplayers; j++){
2791 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2792 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2793 if(player[j].skeleton.free==2)
2794 player[j].skeleton.free=1;
2795 player[j].skeleton.longdead=0;
2796 player[j].RagDoll(0);
2797 for(int i=0;i<player[j].skeleton.num_joints; i++){
2798 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2799 if(findDistancefast(&temppos,&player[closest].coords)<25){
2800 flatvelocity2=temppos-player[closest].coords;
2801 Normalise(&flatvelocity2);
2802 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2809 player[closest].DoDamage(10000);
2810 player[closest].RagDoll(0);
2811 player[closest].dead=2;
2812 player[closest].coords=20;
2813 player[closest].skeleton.free=2;
2820 if(Input::isKeyPressed(SDLK_f)){
2821 player[0].onfire=1-player[0].onfire;
2822 if(player[0].onfire){
2823 player[0].CatchFire();
2825 if(!player[0].onfire){
2826 emit_sound_at(fireendsound, player[0].coords);
2827 pause_sound(stream_firesound);
2831 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2832 //if(!player[0].skeleton.free)player[0].damage+=500;
2833 player[0].RagDoll(0);
2834 //player[0].spurt=1;
2835 //player[0].DoDamage(1000);
2837 emit_sound_at(whooshsound, player[0].coords, 128.);
2840 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2841 for(int i=0;i<objects.numobjects;i++){
2842 if(objects.type[i]==treeleavestype){
2843 objects.scale[i]*=.9;
2848 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2849 editorenabled=1-editorenabled;
2851 player[0].damagetolerance=100000;
2853 player[0].damagetolerance=200;
2855 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2856 player[0].permanentdamage=0;
2857 player[0].superpermanentdamage=0;
2858 player[0].bloodloss=0;
2859 player[0].deathbleeding=0;
2863 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2865 if(targetlevel>numchallengelevels-1)
2872 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2874 float closestdist=-1;
2877 for(int i=1;i<numplayers;i++){
2878 distance=findDistancefast(&player[i].coords,&player[0].coords);
2879 if(closestdist==-1||distance<closestdist){
2880 closestdist=distance;
2884 if(closestdist>0&&closest>=0){
2885 //player[closest]=player[numplayers-1];
2886 //player[closest].skeleton=player[numplayers-1].skeleton;
2891 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
2893 float closestdist=-1;
2896 for(int i=1;i<max_objects;i++){
2897 distance=findDistancefast(&objects.position[i],&player[0].coords);
2898 if(closestdist==-1||distance<closestdist){
2899 closestdist=distance;
2903 if(closestdist>0&&closest>=0){
2904 objects.position[closest].y-=500;
2908 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2910 //if(drawmode>2)drawmode=0;
2911 if(objects.numobjects<max_objects-1){
2913 boxcoords.x=player[0].coords.x;
2914 boxcoords.z=player[0].coords.z;
2915 boxcoords.y=player[0].coords.y-3;
2916 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
2917 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
2918 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
2919 float temprotat,temprotat2;
2920 temprotat=editorrotation;
2921 temprotat2=editorrotation2;
2922 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
2923 if(temprotat2<0)temprotat2=Random()%360;
2925 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
2926 if(editortype==treetrunktype)
2927 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
2931 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
2932 if(numplayers<maxplayers-1){
2933 player[numplayers].scale=.2*5*player[0].scale;
2934 player[numplayers].creature=rabbittype;
2935 player[numplayers].howactive=editoractive;
2936 player[numplayers].skeleton.id=numplayers;
2937 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);
2939 //texsize=512*512*3/texdetail/texdetail;
2940 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
2941 //player[numplayers].skeleton.skinText.resize(texsize);
2943 int k=abs(Random()%2)+1;
2945 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2946 player[numplayers].whichskin=0;
2949 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2950 player[numplayers].whichskin=1;
2953 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
2954 player[numplayers].whichskin=2;
2957 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
2958 player[numplayers].power=1;
2959 player[numplayers].speedmult=1;
2960 player[numplayers].currentanimation=bounceidleanim;
2961 player[numplayers].targetanimation=bounceidleanim;
2962 player[numplayers].currentframe=0;
2963 player[numplayers].targetframe=1;
2964 player[numplayers].target=0;
2965 player[numplayers].bled=0;
2966 player[numplayers].speed=1+(float)(Random()%100)/1000;
2968 player[numplayers].targetrotation=player[0].targetrotation;
2969 player[numplayers].rotation=player[0].rotation;
2971 player[numplayers].velocity=0;
2972 player[numplayers].coords=player[0].coords;
2973 player[numplayers].oldcoords=player[numplayers].coords;
2974 player[numplayers].realoldcoords=player[numplayers].coords;
2976 player[numplayers].id=numplayers;
2977 player[numplayers].skeleton.id=numplayers;
2978 player[numplayers].updatedelay=0;
2979 player[numplayers].normalsupdatedelay=0;
2981 player[numplayers].aitype=passivetype;
2983 if(player[0].creature==wolftype){
2984 headprop=player[0].proportionhead.x/1.1;
2985 bodyprop=player[0].proportionbody.x/1.1;
2986 armprop=player[0].proportionarms.x/1.1;
2987 legprop=player[0].proportionlegs.x/1.1;
2990 if(player[0].creature==rabbittype){
2991 headprop=player[0].proportionhead.x/1.2;
2992 bodyprop=player[0].proportionbody.x/1.05;
2993 armprop=player[0].proportionarms.x/1.00;
2994 legprop=player[0].proportionlegs.x/1.1;
2997 if(player[numplayers].creature==wolftype){
2998 player[numplayers].proportionhead=1.1*headprop;
2999 player[numplayers].proportionbody=1.1*bodyprop;
3000 player[numplayers].proportionarms=1.1*armprop;
3001 player[numplayers].proportionlegs=1.1*legprop;
3004 if(player[numplayers].creature==rabbittype){
3005 player[numplayers].proportionhead=1.2*headprop;
3006 player[numplayers].proportionbody=1.05*bodyprop;
3007 player[numplayers].proportionarms=1.00*armprop;
3008 player[numplayers].proportionlegs=1.1*legprop;
3009 player[numplayers].proportionlegs.y=1.05*legprop;
3012 player[numplayers].headless=0;
3013 player[numplayers].onfire=0;
3016 player[numplayers].proportionhead.z=0;
3017 player[numplayers].proportionbody.z=0;
3018 player[numplayers].proportionarms.z=0;
3019 player[numplayers].proportionlegs.z=0;
3022 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3024 player[numplayers].damagetolerance=200;
3026 player[numplayers].protectionhead=player[0].protectionhead;
3027 player[numplayers].protectionhigh=player[0].protectionhigh;
3028 player[numplayers].protectionlow=player[0].protectionlow;
3029 player[numplayers].armorhead=player[0].armorhead;
3030 player[numplayers].armorhigh=player[0].armorhigh;
3031 player[numplayers].armorlow=player[0].armorlow;
3032 player[numplayers].metalhead=player[0].metalhead;
3033 player[numplayers].metalhigh=player[0].metalhigh;
3034 player[numplayers].metallow=player[0].metallow;
3036 player[numplayers].immobile=player[0].immobile;
3038 player[numplayers].numclothes=player[0].numclothes;
3039 if(player[numplayers].numclothes)
3040 for(int i=0;i<player[numplayers].numclothes;i++){
3041 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3042 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3043 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3044 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3045 tintr=player[numplayers].clothestintr[i];
3046 tintg=player[numplayers].clothestintg[i];
3047 tintb=player[numplayers].clothestintb[i];
3048 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3050 if(player[numplayers].numclothes){
3051 player[numplayers].DoMipmaps();
3054 player[numplayers].power=player[0].power;
3055 player[numplayers].speedmult=player[0].speedmult;
3057 player[numplayers].damage=0;
3058 player[numplayers].permanentdamage=0;
3059 player[numplayers].superpermanentdamage=0;
3060 player[numplayers].deathbleeding=0;
3061 player[numplayers].bleeding=0;
3062 player[numplayers].numwaypoints=0;
3063 player[numplayers].waypoint=0;
3064 player[numplayers].jumppath=0;
3065 player[numplayers].weaponstuck=-1;
3066 player[numplayers].weaponactive=-1;
3067 player[numplayers].num_weapons=0;
3068 player[numplayers].bloodloss=0;
3069 player[numplayers].dead=0;
3071 player[numplayers].loaded=1;
3077 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3078 if(player[numplayers-1].numwaypoints<90){
3079 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3080 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3081 player[numplayers-1].numwaypoints++;
3085 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3086 if(numpathpoints<30){
3087 bool connected,alreadyconnected;
3090 for(int i=0;i<numpathpoints;i++){
3091 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3093 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3094 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3096 if(!alreadyconnected){
3097 numpathpointconnect[pathpointselected]++;
3099 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3105 pathpoint[numpathpoints-1]=player[0].coords;
3106 numpathpointconnect[numpathpoints-1]=0;
3107 if(numpathpoints>1&&pathpointselected!=-1){
3108 numpathpointconnect[pathpointselected]++;
3109 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3111 pathpointselected=numpathpoints-1;
3116 if(Input::isKeyPressed(SDLK_PERIOD)){
3117 pathpointselected++;
3118 if(pathpointselected>=numpathpoints)
3119 pathpointselected=-1;
3121 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3122 pathpointselected--;
3123 if(pathpointselected<=-2)
3124 pathpointselected=numpathpoints-1;
3126 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3127 if(pathpointselected!=-1){
3129 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3130 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3131 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3132 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3134 for(int i=0;i<numpathpoints;i++){
3135 for(int j=0;j<numpathpointconnect[i];j++){
3136 if(pathpointconnect[i][j]==pathpointselected){
3137 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3138 numpathpointconnect[i]--;
3140 if(pathpointconnect[i][j]==numpathpoints){
3141 pathpointconnect[i][j]=pathpointselected;
3145 pathpointselected=numpathpoints-1;
3149 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3151 if(editortype==treeleavestype||editortype==10)editortype--;
3152 if(editortype<0)editortype=firetype;
3155 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3157 if(editortype==treeleavestype||editortype==10)editortype++;
3158 if(editortype>firetype)editortype=0;
3161 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3162 editorrotation-=multiplier*100;
3163 if(editorrotation<-.01)editorrotation=-.01;
3166 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3167 editorrotation+=multiplier*100;
3170 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3171 editorsize+=multiplier;
3174 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3175 editorsize-=multiplier;
3176 if(editorsize<.1)editorsize=.1;
3180 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3181 mapradius-=multiplier*10;
3184 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3185 mapradius+=multiplier*10;
3187 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3188 editorrotation2+=multiplier*100;
3191 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3192 editorrotation2-=multiplier*100;
3193 if(editorrotation2<-.01)editorrotation2=-.01;
3195 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3197 float closestdist=-1;
3199 for(int i=0;i<objects.numobjects;i++){
3200 distance=findDistancefast(&objects.position[i],&player[0].coords);
3201 if(closestdist==-1||distance<closestdist){
3202 closestdist=distance;
3206 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3212 void Game::doJumpReversals(){
3213 for(int k=0;k<numplayers;k++)
3214 for(int i=k;i<numplayers;i++){
3216 if( player[k].skeleton.free==0&&
3217 player[i].skeleton.oldfree==0&&
3218 (player[i].targetanimation==jumpupanim||
3219 player[k].targetanimation==jumpupanim)&&
3220 (player[i].aitype==playercontrolled||
3221 player[k].aitype==playercontrolled)&&
3222 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3223 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3224 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3225 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3226 //TODO: refactor two huge similar ifs
3227 if(player[i].targetanimation==jumpupanim&&
3228 player[k].targetanimation!=getupfrombackanim&&
3229 player[k].targetanimation!=getupfromfrontanim&&
3230 animation[player[k].targetanimation].height==middleheight&&
3231 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3232 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3233 player[k].aitype!=playercontrolled)){
3234 player[i].victim=&player[k];
3235 player[i].velocity=0;
3236 player[i].currentanimation=jumpreversedanim;
3237 player[i].targetanimation=jumpreversedanim;
3238 player[i].currentframe=0;
3239 player[i].targetframe=1;
3240 player[i].targettilt2=0;
3241 player[k].victim=&player[i];
3242 player[k].velocity=0;
3243 player[k].currentanimation=jumpreversalanim;
3244 player[k].targetanimation=jumpreversalanim;
3245 player[k].currentframe=0;
3246 player[k].targetframe=1;
3247 player[k].targettilt2=0;
3248 if(player[i].coords.y<player[k].coords.y+1){
3249 player[i].currentanimation=rabbitkickreversedanim;
3250 player[i].targetanimation=rabbitkickreversedanim;
3251 player[i].currentframe=1;
3252 player[i].targetframe=2;
3253 player[k].currentanimation=rabbitkickreversalanim;
3254 player[k].targetanimation=rabbitkickreversalanim;
3255 player[k].currentframe=1;
3256 player[k].targetframe=2;
3259 player[k].oldcoords=player[k].coords;
3260 player[i].coords=player[k].coords;
3261 player[k].targetrotation=player[i].targetrotation;
3262 player[k].rotation=player[i].targetrotation;
3263 if(player[k].aitype==attacktypecutoff)
3264 player[k].stunned=.5;
3266 if(player[k].targetanimation==jumpupanim&&
3267 player[i].targetanimation!=getupfrombackanim&&
3268 player[i].targetanimation!=getupfromfrontanim&&
3269 animation[player[i].targetanimation].height==middleheight&&
3270 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3271 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3272 player[i].aitype!=playercontrolled)){
3273 player[k].victim=&player[i];
3274 player[k].velocity=0;
3275 player[k].currentanimation=jumpreversedanim;
3276 player[k].targetanimation=jumpreversedanim;
3277 player[k].currentframe=0;
3278 player[k].targetframe=1;
3279 player[k].targettilt2=0;
3280 player[i].victim=&player[k];
3281 player[i].velocity=0;
3282 player[i].currentanimation=jumpreversalanim;
3283 player[i].targetanimation=jumpreversalanim;
3284 player[i].currentframe=0;
3285 player[i].targetframe=1;
3286 player[i].targettilt2=0;
3287 if(player[k].coords.y<player[i].coords.y+1){
3288 player[k].targetanimation=rabbitkickreversedanim;
3289 player[k].currentanimation=rabbitkickreversedanim;
3290 player[i].currentanimation=rabbitkickreversalanim;
3291 player[i].targetanimation=rabbitkickreversalanim;
3292 player[k].currentframe=1;
3293 player[k].targetframe=2;
3294 player[i].currentframe=1;
3295 player[i].targetframe=2;
3298 player[i].oldcoords=player[i].coords;
3299 player[k].coords=player[i].coords;
3300 player[i].targetrotation=player[k].targetrotation;
3301 player[i].rotation=player[k].targetrotation;
3302 if(player[i].aitype==attacktypecutoff)
3303 player[i].stunned=.5;
3310 void Game::doAerialAcrobatics(){
3311 static XYZ facing,flatfacing;
3312 for(int k=0;k<numplayers;k++){
3313 player[k].turnspeed=500;
3315 if((player[k].isRun()&&
3316 ((player[k].targetrotation!=rabbitrunninganim&&
3317 player[k].targetrotation!=wolfrunninganim)||
3318 player[k].targetframe==4))||
3319 player[k].targetanimation==removeknifeanim||
3320 player[k].targetanimation==crouchremoveknifeanim||
3321 player[k].targetanimation==flipanim||
3322 player[k].targetanimation==fightsidestep||
3323 player[k].targetanimation==walkanim){
3324 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed);
3328 if(player[k].isStop()||
3329 player[k].isLanding()||
3330 player[k].targetanimation==staggerbackhighanim||
3331 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3332 player[k].targetanimation==staggerbackhardanim||
3333 player[k].targetanimation==backhandspringanim||
3334 player[k].targetanimation==dodgebackanim||
3335 player[k].targetanimation==rollanim||
3336 (animation[player[k].targetanimation].attack&&
3337 player[k].targetanimation!=rabbitkickanim&&
3338 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3339 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3340 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*2);
3343 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3344 player[k].rotation=stepTowardf(player[k].rotation, player[k].targetrotation, multiplier*player[k].turnspeed*4);
3347 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3348 player[k].DoStuff();
3349 if(player[k].immobile&&k!=0)
3350 player[k].coords=player[k].realoldcoords;
3352 //if player's position has changed (?)
3353 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3354 !player[k].skeleton.free&&
3355 player[k].targetanimation!=climbanim&&
3356 player[k].targetanimation!=hanganim){
3357 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3361 if(player[k].collide<-.3)
3362 player[k].collide=-.3;
3363 if(player[k].collide>1)
3364 player[k].collide=1;
3365 player[k].collide-=multiplier*30;
3368 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3370 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3371 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3372 if(objects.type[i]!=rocktype||
3373 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3374 objects.position[i].y>player[k].coords.y){
3375 lowpoint=player[k].coords;
3376 if(player[k].targetanimation!=jumpupanim&&
3377 player[k].targetanimation!=jumpdownanim&&
3378 !player[k].isFlip())
3382 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3383 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3384 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3385 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
3386 flatfacing=lowpoint-player[k].coords;
3387 player[k].coords=lowpoint;
3388 player[k].coords.y-=1.3;
3389 player[k].collide=1;
3392 //TODO: refactor four similar blocks
3393 if(player[k].aitype==playercontrolled&&
3394 (player[k].targetanimation==jumpupanim||
3395 player[k].targetanimation==jumpdownanim||
3396 player[k].isFlip())&&
3397 !player[k].jumptogglekeydown&&
3398 player[k].jumpkeydown){
3399 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3400 XYZ tempcoords1=lowpoint;
3401 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3402 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3403 player[k].setAnimation(walljumpleftanim);
3404 emit_sound_at(movewhooshsound, player[k].coords);
3406 pause_sound(whooshsound);
3408 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3409 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3410 if(lowpointtarget.z<0)
3411 player[k].rotation=180-player[k].rotation;
3412 player[k].targetrotation=player[k].rotation;
3413 player[k].lowrotation=player[k].rotation;
3419 lowpoint=tempcoords1;
3420 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3421 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3422 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3423 player[k].setAnimation(walljumprightanim);
3424 emit_sound_at(movewhooshsound, player[k].coords);
3425 if(k==0)pause_sound(whooshsound);
3427 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3428 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3429 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3430 player[k].targetrotation=player[k].rotation;
3431 player[k].lowrotation=player[k].rotation;
3432 if(k==0)numwallflipped++;
3436 lowpoint=tempcoords1;
3437 lowpointtarget=lowpoint+player[k].facing*2;
3438 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3439 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3440 player[k].setAnimation(walljumpbackanim);
3441 emit_sound_at(movewhooshsound, player[k].coords);
3442 if(k==0)pause_sound(whooshsound);
3444 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3445 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3446 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3447 player[k].targetrotation=player[k].rotation;
3448 player[k].lowrotation=player[k].rotation;
3449 if(k==0)numwallflipped++;
3453 lowpoint=tempcoords1;
3454 lowpointtarget=lowpoint-player[k].facing*2;
3455 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3456 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3457 player[k].setAnimation(walljumpfrontanim);
3458 emit_sound_at(movewhooshsound, player[k].coords);
3459 if(k==0)pause_sound(whooshsound);
3461 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3462 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3463 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
3464 player[k].rotation+=180;
3465 player[k].targetrotation=player[k].rotation;
3466 player[k].lowrotation=player[k].rotation;
3467 if(k==0)numwallflipped++;
3475 else if(objects.type[i]==rocktype){
3476 lowpoint2=player[k].coords;
3477 lowpoint=player[k].coords;
3479 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
3480 player[k].coords=colpoint;
3481 player[k].collide=1;
3484 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3485 //flipped into a rock
3486 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3487 player[k].RagDoll(0);
3489 if(player[k].targetanimation==jumpupanim){
3490 player[k].jumppower=-4;
3491 player[k].targetanimation=player[k].getIdle();
3494 player[k].targetframe=0;
3495 player[k].onterrain=1;
3497 if(player[k].id==0){
3498 pause_sound(whooshsound);
3499 OPENAL_SetVolume(channels[whooshsound], 0);
3503 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3504 if(player[k].isFlip())
3505 player[k].jumppower=-4;
3506 player[k].targetanimation=player[k].getLanding();
3507 emit_sound_at(landsound, player[k].coords, 128.);
3509 envsound[numenvsounds]=player[k].coords;
3510 envsoundvol[numenvsounds]=16;
3511 envsoundlife[numenvsounds]=.4;
3521 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3522 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3523 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3524 lowpoint=player[k].coords;
3526 if(objects.type[i]!=rocktype)
3527 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.rotation[i],&objects.model[i])!=-1){
3528 if(player[k].targetanimation!=jumpupanim&&
3529 player[k].targetanimation!=jumpdownanim&&
3530 player[k].onterrain)
3531 player[k].avoidcollided=1;
3532 player[k].coords=lowpoint;
3533 player[k].coords.y-=1.35;
3534 player[k].collide=1;
3536 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3537 (player[k].currentanimation!=climbanim&&
3538 player[k].currentanimation!=hanganim&&
3539 !player[k].isWallJump()||
3540 player[k].targetanimation==jumpupanim||
3541 player[k].targetanimation==jumpdownanim)){
3542 lowpoint=player[k].coords;
3543 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
3544 lowpoint=player[k].coords;
3548 facing=DoRotation(facing,0,player[k].targetrotation+180,0);
3549 lowpointtarget=lowpoint+facing*1.4;
3550 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3552 lowpoint=player[k].coords;
3554 lowpointtarget=lowpoint+facing*1.4;
3556 lowpointtarget2=lowpointtarget;
3558 lowpointtarget3=lowpointtarget;
3560 lowpointtarget4=lowpointtarget;
3562 lowpointtarget5=lowpointtarget;
3564 lowpointtarget6=lowpointtarget;
3566 lowpointtarget7=lowpoint;
3568 lowpointtarget2.x+=.1;
3570 lowpointtarget3.z+=.1;
3572 lowpointtarget4.x-=.1;
3574 lowpointtarget5.z-=.1;
3576 lowpointtarget6.y+=45/13;
3577 lowpointtarget6+=facing*.6;
3578 lowpointtarget7.y+=90/13;
3579 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
3580 if(objects.friction[i]>.5)
3582 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3583 player[k].collided=1;
3584 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3585 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3586 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3587 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3588 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3589 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3590 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3591 &colpoint,&objects.position[i],&objects.rotation[i])!=-1&&
3592 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3593 &colpoint,&objects.position[i],&objects.rotation[i])!=-1)
3594 for(int j=0;j<45;j++){
3595 lowpoint=player[k].coords;
3596 lowpoint.y+=(float)j/13;
3597 lowpointtarget=lowpoint+facing*1.4;
3598 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3599 &colpoint2,&objects.position[i],&objects.rotation[i])==-1){
3600 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3602 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3603 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
3604 lowpoint=player[k].coords;
3605 lowpoint.y+=(float)j/13;
3606 lowpointtarget=lowpoint+facing*1.3;
3607 flatfacing=player[k].coords;
3608 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
3609 player[k].coords.y=lowpointtarget.y-.07;
3610 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3612 if(j>10||!player[k].isRun()){
3613 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3615 pause_sound(whooshsound);
3617 emit_sound_at(jumpsound, player[k].coords, 128.);
3619 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
3620 player[k].rotation=-asin(0-lowpointtarget.x)*180/M_PI;
3621 if(lowpointtarget.z<0)
3622 player[k].rotation=180-player[k].rotation;
3623 player[k].targetrotation=player[k].rotation;
3624 player[k].lowrotation=player[k].rotation;
3626 //player[k].velocity=lowpointtarget*.03;
3627 player[k].velocity=0;
3630 if(player[k].targetanimation==jumpupanim){
3631 player[k].targetanimation=climbanim;
3632 player[k].jumppower=0;
3633 player[k].jumpclimb=1;
3635 player[k].transspeed=6;
3637 player[k].targetframe=1;
3640 player[k].setAnimation(hanganim);
3641 player[k].jumppower=0;
3653 if(player[k].collide<=0){
3655 if(!player[k].onterrain&&
3656 player[k].targetanimation!=jumpupanim&&
3657 player[k].targetanimation!=jumpdownanim&&
3658 player[k].targetanimation!=climbanim&&
3659 player[k].targetanimation!=hanganim&&
3660 !player[k].isWallJump()&&
3661 !player[k].isFlip()){
3662 if(player[k].currentanimation!=climbanim&&
3663 player[k].currentanimation!=tempanim&&
3664 player[k].targetanimation!=backhandspringanim&&
3665 (player[k].targetanimation!=rollanim||
3666 player[k].targetframe<2||
3667 player[k].targetframe>6)){
3668 //stagger off ledge (?)
3669 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3670 player[k].RagDoll(0);
3671 player[k].setAnimation(jumpdownanim);
3674 emit_sound_at(whooshsound, player[k].coords, 128.);
3677 player[k].velocity.y+=gravity;
3681 player[k].realoldcoords=player[k].coords;
3685 void Game::doAttacks(){
3686 static XYZ relative;
3687 static int randattack;
3688 static bool playerrealattackkeydown=0;
3690 if(!Input::isKeyDown(attackkey))
3693 player[0].attackkeydown=0;
3695 playerrealattackkeydown=0;
3697 playerrealattackkeydown=Input::isKeyDown(attackkey);
3698 if((player[0].parriedrecently<=0||
3699 player[0].weaponactive==-1)&&
3702 player[0].lastattack!=swordslashanim&&
3703 player[0].lastattack!=knifeslashstartanim&&
3704 player[0].lastattack!=staffhitanim&&
3705 player[0].lastattack!=staffspinhitanim)))
3706 player[0].attackkeydown=Input::isKeyDown(attackkey);
3707 if(Input::isKeyDown(attackkey)&&
3709 !player[0].backkeydown){
3710 for(int k=0;k<numplayers;k++){
3711 if((player[k].targetanimation==swordslashanim||
3712 player[k].targetanimation==staffhitanim||
3713 player[k].targetanimation==staffspinhitanim)&&
3714 player[0].currentanimation!=dodgebackanim&&
3715 !player[k].skeleton.free)
3716 player[k].Reverse();
3720 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3722 for(int k=0;k<numplayers;k++){
3723 if(indialogue!=-1)player[k].attackkeydown=0;
3724 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3725 if(player[k].aitype!=playercontrolled)
3726 player[k].victim=&player[0];
3727 //attack key pressed
3728 if(player[k].attackkeydown){
3730 if(player[k].backkeydown&&
3731 player[k].targetanimation!=backhandspringanim&&
3732 (player[k].isIdle()||
3733 player[k].isStop()||
3735 player[k].targetanimation==walkanim)){
3736 if(player[k].jumppower<=1){
3737 player[k].jumppower-=2;
3739 for(int i=0;i<numplayers;i++){
3741 if(player[i].targetanimation==swordslashanim||
3742 player[i].targetanimation==knifeslashstartanim||
3743 player[i].targetanimation==staffhitanim||
3744 player[i].targetanimation==staffspinhitanim)
3745 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3746 player[k].setAnimation(dodgebackanim);
3747 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
3748 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3751 if(player[k].targetanimation!=dodgebackanim){
3752 if(k==0)numflipped++;
3753 player[k].setAnimation(backhandspringanim);
3754 player[k].targetrotation=-rotation+180;
3755 if(player[k].leftkeydown)
3756 player[k].targetrotation-=45;
3757 if(player[k].rightkeydown)
3758 player[k].targetrotation+=45;
3759 player[k].rotation=player[k].targetrotation;
3760 player[k].jumppower-=2;
3765 if(!animation[player[k].targetanimation].attack&&
3766 !player[k].backkeydown&&
3767 (player[k].isIdle()||
3769 player[k].targetanimation==walkanim||
3770 player[k].targetanimation==sneakanim||
3771 player[k].isCrouch())){
3772 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3773 //normal attacks (?)
3774 player[k].hasvictim=0;
3776 for(int i=0;i<numplayers;i++){
3777 if(i==k||!(k==0||i==0))continue;
3778 if(!player[k].hasvictim)
3779 if(animation[player[k].targetanimation].attack!=reversal){
3781 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3783 !player[i].skeleton.free&&
3784 player[i].howactive<typedead1&&
3785 player[i].targetanimation!=jumpreversedanim&&
3786 player[i].targetanimation!=rabbitkickreversedanim&&
3787 player[i].targetanimation!=rabbitkickanim&&
3788 player[k].targetanimation!=rabbitkickanim&&
3789 player[i].targetanimation!=getupfrombackanim&&
3790 (player[i].targetanimation!=staggerbackhighanim&&
3791 (player[i].targetanimation!=staggerbackhardanim||
3792 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3793 player[i].targetanimation!=jumpdownanim&&
3794 player[i].targetanimation!=jumpupanim&&
3795 player[i].targetanimation!=getupfromfrontanim){
3796 player[k].victim=&player[i];
3797 player[k].hasvictim=1;
3798 if(player[k].aitype==playercontrolled){ //human player
3800 if(distance<2.5*sq(player[k].scale*5)&&
3801 player[k].crouchkeydown&&
3802 animation[player[i].targetanimation].height!=lowheight)
3803 player[k].targetanimation=sweepanim;
3805 else if(distance<1.5*sq(player[k].scale*5)&&
3806 animation[player[i].targetanimation].height!=lowheight&&
3807 !player[k].forwardkeydown&&
3808 !player[k].leftkeydown&&
3809 !player[k].rightkeydown&&
3810 !player[k].crouchkeydown&&
3813 player[k].targetanimation=winduppunchanim;
3815 else if(distance<2.5*sq(player[k].scale*5)&&
3816 animation[player[i].targetanimation].height!=lowheight&&
3817 !player[k].forwardkeydown&&
3818 !player[k].leftkeydown&&
3819 !player[k].rightkeydown&&
3820 !player[k].crouchkeydown&&
3822 player[k].targetanimation=upunchanim;
3824 else if(distance<2.5*sq(player[k].scale*5)&&
3825 player[i].staggerdelay>0&&
3826 attackweapon==knife&&
3827 player[i].bloodloss>player[i].damagetolerance/2)
3828 player[k].targetanimation=knifefollowanim;
3830 else if(distance<2.5*sq(player[k].scale*5)&&
3831 animation[player[i].targetanimation].height!=lowheight&&
3832 !player[k].forwardkeydown&&
3833 !player[k].leftkeydown&&
3834 !player[k].rightkeydown&&
3835 !player[k].crouchkeydown&&
3836 attackweapon==knife&&
3837 player[k].weaponmissdelay<=0)
3838 player[k].targetanimation=knifeslashstartanim;
3840 else if(distance<4.5*sq(player[k].scale*5)&&
3841 animation[player[i].targetanimation].height!=lowheight&&
3842 !player[k].crouchkeydown&&
3843 attackweapon==sword&&
3844 player[k].weaponmissdelay<=0)
3845 player[k].targetanimation=swordslashanim;
3847 else if(distance<4.5*sq(player[k].scale*5)&&
3848 animation[player[i].targetanimation].height!=lowheight&&
3849 !player[k].crouchkeydown&&
3850 attackweapon==staff&&
3851 player[k].weaponmissdelay<=0&&
3852 !player[k].leftkeydown&&
3853 !player[k].rightkeydown&&
3854 !player[k].forwardkeydown)
3855 player[k].targetanimation=staffhitanim;
3857 else if(distance<4.5*sq(player[k].scale*5)&&
3858 animation[player[i].targetanimation].height!=lowheight&&
3859 !player[k].crouchkeydown&&
3860 attackweapon==staff&&
3861 player[k].weaponmissdelay<=0)
3862 player[k].targetanimation=staffspinhitanim;
3864 else if(distance<2.5*sq(player[k].scale*5)&&
3865 animation[player[i].targetanimation].height!=lowheight)
3866 player[k].targetanimation=spinkickanim;
3868 else if(distance<2.5*sq(player[k].scale*5)&&
3869 animation[player[i].targetanimation].height==lowheight&&
3870 animation[player[k].targetanimation].attack!=normalattack)
3871 player[k].targetanimation=lowkickanim;
3872 } else { //AI player
3873 if(distance<4.5*sq(player[k].scale*5)){
3874 randattack=abs(Random()%5);
3875 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3877 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
3878 player[k].targetanimation=sweepanim;
3880 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
3882 player[k].targetanimation=upunchanim;
3884 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
3885 player[k].targetanimation=spinkickanim;
3887 else if(animation[player[i].targetanimation].height==lowheight)
3888 player[k].targetanimation=lowkickanim;
3892 if((tutoriallevel!=1||!attackweapon)&&
3893 distance<2.5*sq(player[k].scale*5)&&
3895 animation[player[i].targetanimation].height!=lowheight)
3896 player[k].targetanimation=sweepanim;
3898 else if(distance<2.5*sq(player[k].scale*5)&&
3899 attackweapon==knife&&
3900 player[k].weaponmissdelay<=0)
3901 player[k].targetanimation=knifeslashstartanim;
3903 else if(!(player[0].victim==&player[i]&&
3904 player[0].hasvictim&&
3905 player[0].targetanimation==swordslashanim)&&
3906 attackweapon==sword&&
3907 player[k].weaponmissdelay<=0)
3908 player[k].targetanimation=swordslashanim;
3910 else if(!(player[0].victim==&player[i]&&
3911 player[0].hasvictim&&
3912 player[0].targetanimation==swordslashanim)&&
3913 attackweapon==staff&&
3914 player[k].weaponmissdelay<=0&&
3916 player[k].targetanimation=staffhitanim;
3918 else if(!(player[0].victim==&player[i]&&
3919 player[0].hasvictim&&
3920 player[0].targetanimation==swordslashanim)&&
3921 attackweapon==staff&&
3922 player[k].weaponmissdelay<=0&&
3924 player[k].targetanimation=staffspinhitanim;
3926 else if((tutoriallevel!=1||!attackweapon)&&
3927 distance<2.5*sq(player[k].scale*5)&&
3929 animation[player[i].targetanimation].height!=lowheight)
3930 player[k].targetanimation=spinkickanim;
3932 else if(distance<2.5*sq(player[k].scale*5)&&
3933 animation[player[i].targetanimation].height==lowheight&&
3934 animation[player[k].targetanimation].attack!=normalattack)
3935 player[k].targetanimation=lowkickanim;
3939 //upunch becomes wolfslap
3940 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
3941 player[k].targetanimation=wolfslapanim;
3944 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
3945 player[i].howactive<typedead1&&
3946 distance<1.5*sq(player[k].scale*5)&&
3947 !player[i].skeleton.free&&
3948 player[i].targetanimation!=getupfrombackanim&&
3949 player[i].targetanimation!=getupfromfrontanim&&
3950 (player[i].stunned>0&&player[k].madskills||
3951 player[i].surprised>0||
3952 player[i].aitype==passivetype||
3953 attackweapon&&player[i].stunned>0)&&
3954 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
3957 player[k].currentanimation=sneakattackanim;
3958 player[k].targetanimation=sneakattackanim;
3959 player[i].currentanimation=sneakattackedanim;
3960 player[i].targetanimation=sneakattackedanim;
3961 player[k].oldcoords=player[k].coords;
3962 player[k].coords=player[i].coords;
3965 if(attackweapon==knife){
3966 player[k].currentanimation=knifesneakattackanim;
3967 player[k].targetanimation=knifesneakattackanim;
3968 player[i].currentanimation=knifesneakattackedanim;
3969 player[i].targetanimation=knifesneakattackedanim;
3970 player[i].oldcoords=player[i].coords;
3971 player[i].coords=player[k].coords;
3974 if(attackweapon==sword){
3975 player[k].currentanimation=swordsneakattackanim;
3976 player[k].targetanimation=swordsneakattackanim;
3977 player[i].currentanimation=swordsneakattackedanim;
3978 player[i].targetanimation=swordsneakattackedanim;
3979 player[i].oldcoords=player[i].coords;
3980 player[i].coords=player[k].coords;
3982 if(attackweapon!=staff){
3983 player[k].victim=&player[i];
3984 player[k].hasvictim=1;
3985 player[i].targettilt2=0;
3986 player[i].targetframe=1;
3987 player[i].currentframe=0;
3989 player[i].velocity=0;
3990 player[k].targettilt2=player[i].targettilt2;
3991 player[k].currentframe=player[i].currentframe;
3992 player[k].targetframe=player[i].targetframe;
3993 player[k].target=player[i].target;
3994 player[k].velocity=0;
3995 player[k].targetrotation=player[i].rotation;
3996 player[k].rotation=player[i].rotation;
3997 player[i].targetrotation=player[i].rotation;
4000 if(animation[player[k].targetanimation].attack==normalattack&&
4001 player[k].victim==&player[i]&&
4002 (!player[i].skeleton.free)){
4004 player[k].targetframe=0;
4007 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4008 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4009 player[k].lastattack3=player[k].lastattack2;
4010 player[k].lastattack2=player[k].lastattack;
4011 player[k].lastattack=player[k].targetanimation;
4013 if(player[k].targetanimation==knifefollowanim&&
4014 player[k].victim==&player[i]){
4016 player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
4017 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4018 player[k].victim=&player[i];
4019 player[k].hasvictim=1;
4020 player[i].targetanimation=knifefollowedanim;
4021 player[i].currentanimation=knifefollowedanim;
4022 player[i].targettilt2=0;
4023 player[i].targettilt2=player[k].targettilt2;
4024 player[i].targetframe=1;
4025 player[i].currentframe=0;
4027 player[i].velocity=0;
4028 player[k].currentanimation=knifefollowanim;
4029 player[k].targetanimation=knifefollowanim;
4030 player[k].targettilt2=player[i].targettilt2;
4031 player[k].currentframe=player[i].currentframe;
4032 player[k].targetframe=player[i].targetframe;
4033 player[k].target=player[i].target;
4034 player[k].velocity=0;
4035 player[k].oldcoords=player[k].coords;
4036 player[i].coords=player[k].coords;
4037 player[i].targetrotation=player[k].targetrotation;
4038 player[i].rotation=player[k].targetrotation;
4039 player[k].rotation=player[k].targetrotation;
4040 player[i].rotation=player[k].targetrotation;
4044 const bool hasstaff=attackweapon==staff;
4045 if(k==0&&numplayers>1)
4046 for(int i=0;i<numplayers;i++){
4048 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4049 animation[player[k].targetanimation].attack==neutral){
4050 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4051 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4052 if(player[i].skeleton.free)
4053 if(distance<3.5*sq(player[k].scale*5)&&
4055 player[i].skeleton.longdead>1000||
4059 (player[i].skeleton.longdead>2000||
4060 player[i].damage>player[i].damagetolerance/8||
4061 player[i].bloodloss>player[i].damagetolerance/2)&&
4062 distance<1.5*sq(player[k].scale*5)))){
4063 player[k].victim=&player[i];
4064 player[k].hasvictim=1;
4065 if(attackweapon&&tutoriallevel!=1){
4067 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4068 player[k].targetanimation=crouchstabanim;
4070 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4071 player[k].targetanimation=swordgroundstabanim;
4073 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4074 player[k].targetanimation=staffgroundsmashanim;
4077 player[k].crouchkeydown&&
4078 player[k].targetanimation!=crouchstabanim&&
4081 player[i].skeleton.free&&
4082 player[i].skeleton.longdead>1000){
4083 player[k].targetanimation=killanim;
4084 //TODO: refactor this out, what does it do?
4085 for(int j=0;j<terrain.numdecals;j++){
4086 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4087 terrain.decalalivetime[j]<2)
4088 terrain.DeleteDecal(j);
4090 for(int l=0;l<objects.numobjects;l++){
4091 if(objects.model[l].type==decalstype)
4092 for(int j=0;j<objects.model[l].numdecals;j++){
4093 if((objects.model[l].decaltype[j]==blooddecal||
4094 objects.model[l].decaltype[j]==blooddecalslow)&&
4095 objects.model[l].decalalivetime[j]<2)
4096 objects.model[l].DeleteDecal(j);
4100 if(!player[i].dead||musictype!=2)
4102 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4103 player[k].staggerdelay<=0&&
4105 player[i].skeleton.longdead<300&&
4106 player[k].lastattack!=spinkickanim&&
4107 player[i].skeleton.free)&&
4108 (!player[i].dead||musictype!=stream_fighttheme)){
4109 player[k].targetanimation=dropkickanim;
4110 for(int j=0;j<terrain.numdecals;j++){
4111 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4112 terrain.decalalivetime[j]<2){
4113 terrain.DeleteDecal(j);
4116 for(int l=0;l<objects.numobjects;l++){
4117 if(objects.model[l].type==decalstype)
4118 for(int j=0;j<objects.model[l].numdecals;j++){
4119 if((objects.model[l].decaltype[j]==blooddecal||
4120 objects.model[l].decaltype[j]==blooddecalslow)&&
4121 objects.model[l].decalalivetime[j]<2){
4122 objects.model[l].DeleteDecal(j);
4128 if(animation[player[k].targetanimation].attack==normalattack&&
4129 player[k].victim==&player[i]&&
4130 (!player[i].skeleton.free||
4131 player[k].targetanimation==killanim||
4132 player[k].targetanimation==crouchstabanim||
4133 player[k].targetanimation==swordgroundstabanim||
4134 player[k].targetanimation==staffgroundsmashanim||
4135 player[k].targetanimation==dropkickanim)){
4137 player[k].targetframe=0;
4140 XYZ targetpoint=player[i].coords;
4141 if(player[k].targetanimation==crouchstabanim||
4142 player[k].targetanimation==swordgroundstabanim||
4143 player[k].targetanimation==staffgroundsmashanim){
4144 targetpoint+=(player[i].getJointFor(abdomen).position+
4145 player[i].getJointFor(neck).position)/2*
4148 player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
4149 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4151 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4152 player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
4155 if(player[k].targetanimation==staffgroundsmashanim)
4156 player[k].targettilt2+=10;
4158 player[k].lastattack3=player[k].lastattack2;
4159 player[k].lastattack2=player[k].lastattack;
4160 player[k].lastattack=player[k].targetanimation;
4162 if(player[k].targetanimation==swordgroundstabanim){
4163 player[k].targetrotation+=30;
4168 if(!player[k].hasvictim){
4170 for(int i=0;i<numplayers;i++){
4171 if(i==k||!(i==0||k==0))continue;
4172 if(!player[i].skeleton.free){
4173 if(player[k].hasvictim){
4174 if(findDistancefast(&player[k].coords,&player[i].coords)<
4175 findDistancefast(&player[k].coords,&player[k].victim->coords))
4176 player[k].victim=&player[i];
4178 player[k].victim=&player[i];
4179 player[k].hasvictim=1;
4184 if(player[k].aitype==playercontrolled)
4186 if(player[k].attackkeydown&&
4188 player[k].wasRun()&&
4189 ((player[k].hasvictim&&
4190 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4191 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4192 !player[k].victim->skeleton.free&&
4193 player[k].victim->targetanimation!=getupfrombackanim&&
4194 player[k].victim->targetanimation!=getupfromfrontanim&&
4195 animation[player[k].victim->targetanimation].height!=lowheight&&
4196 player[k].aitype!=playercontrolled&& //wat???
4197 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4198 player[k].rabbitkickenabled)||
4199 player[k].jumpkeydown)){
4201 player[k].setAnimation(rabbitkickanim);
4204 if(animation[player[k].targetanimation].attack&&k==0){
4206 switch(attackweapon){
4207 case 0: numunarmedattack++; break;
4208 case knife: numknifeattack++; break;
4209 case sword: numswordattack++; break;
4210 case staff: numstaffattack++; break;
4219 void Game::doPlayerCollisions(){
4220 static XYZ rotatetarget;
4221 static float collisionradius;
4223 for(int k=0;k<numplayers;k++)
4224 for(int i=k+1;i<numplayers;i++){
4225 //neither player is part of a reversal
4226 if((animation[player[i].targetanimation].attack!=reversed&&
4227 animation[player[i].targetanimation].attack!=reversal&&
4228 animation[player[k].targetanimation].attack!=reversed&&
4229 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4230 if((animation[player[i].currentanimation].attack!=reversed&&
4231 animation[player[i].currentanimation].attack!=reversal&&
4232 animation[player[k].currentanimation].attack!=reversed&&
4233 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4234 //neither is sleeping
4235 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4236 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4237 //in same patch, neither is climbing
4238 if(player[i].whichpatchx==player[k].whichpatchx&&
4239 player[i].whichpatchz==player[k].whichpatchz&&
4240 player[k].skeleton.oldfree==player[k].skeleton.free&&
4241 player[i].skeleton.oldfree==player[i].skeleton.free&&
4242 player[i].targetanimation!=climbanim&&
4243 player[i].targetanimation!=hanganim&&
4244 player[k].targetanimation!=climbanim&&
4245 player[k].targetanimation!=hanganim)
4246 //players are close (bounding box test)
4247 if(player[i].coords.y>player[k].coords.y-3)
4248 if(player[i].coords.y<player[k].coords.y+3)
4249 if(player[i].coords.x>player[k].coords.x-3)
4250 if(player[i].coords.x<player[k].coords.x+3)
4251 if(player[i].coords.z>player[k].coords.z-3)
4252 if(player[i].coords.z<player[k].coords.z+3){
4253 //spread fire from player to player
4254 if(findDistancefast(&player[i].coords,&player[k].coords)
4255 <3*sq((player[i].scale+player[k].scale)*2.5)){
4256 if(player[i].onfire||player[k].onfire){
4257 if(!player[i].onfire)player[i].CatchFire();
4258 if(!player[k].onfire)player[k].CatchFire();
4262 XYZ tempcoords1=player[i].coords;
4263 XYZ tempcoords2=player[k].coords;
4264 if(!player[i].skeleton.oldfree)
4265 tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale;
4266 if(!player[k].skeleton.oldfree)
4267 tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale;
4268 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4269 if(player[0].hasvictim)
4270 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4272 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4273 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4274 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4275 //jump down on a dead body
4278 if(player[0].targetanimation==jumpdownanim&&
4279 !player[0].skeleton.oldfree&&
4280 !player[0].skeleton.free&&
4281 player[l].skeleton.oldfree&&
4282 player[l].skeleton.free&&
4284 player[0].lastcollide<=0&&
4285 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4286 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4287 player[0].coords.y=player[l].coords.y;
4288 player[l].velocity=player[0].velocity;
4289 player[l].skeleton.free=0;
4290 player[l].rotation=0;
4291 player[l].RagDoll(0);
4292 player[l].DoDamage(20);
4294 player[l].skeleton.longdead=0;
4295 player[0].lastcollide=1;
4299 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4300 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4301 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4302 rotatetarget=player[k].velocity-player[i].velocity;
4303 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4304 player[i].skeleton.free)&&
4305 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4306 player[k].skeleton.free))
4307 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4308 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4309 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4311 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4312 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4313 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4314 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4315 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4317 if( (i!=0||player[i].skeleton.free)&&
4318 (k!=0||player[k].skeleton.free)||
4319 (animation[player[i].targetanimation].height==highheight&&
4320 animation[player[k].targetanimation].height==highheight)){
4321 if(tutoriallevel!=1){
4322 emit_sound_at(heavyimpactsound, player[i].coords);
4325 player[i].RagDoll(0);
4326 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4327 award_bonus(0, aimbonus);
4329 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4330 player[k].RagDoll(0);
4331 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4332 award_bonus(0, aimbonus); // Huh, again?
4334 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4336 for(int j=0;j<player[i].skeleton.num_joints;j++){
4337 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4339 for(int j=0;j<player[k].skeleton.num_joints;j++){
4340 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4345 if( (animation[player[i].targetanimation].attack==neutral||
4346 animation[player[i].targetanimation].attack==normalattack)&&
4347 (animation[player[k].targetanimation].attack==neutral||
4348 animation[player[k].targetanimation].attack==normalattack)){
4350 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4351 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4352 rotatetarget=player[k].coords-player[i].coords;
4353 Normalise(&rotatetarget);
4354 player[k].coords=(player[k].coords+player[i].coords)/2;
4355 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4356 *sq((player[i].scale+player[k].scale)*2.5);
4357 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4358 if(player[k].howactive==typeactive||hostile)
4359 if(player[k].isIdle()){
4360 if(player[k].howactive<typesleeping)
4361 player[k].setAnimation(player[k].getStop());
4362 else if(player[k].howactive==typesleeping)
4363 player[k].setAnimation(getupfromfrontanim);
4365 player[k].howactive=typeactive;
4367 if(player[i].howactive==typeactive||hostile)
4368 if(player[i].isIdle()){
4369 if(player[i].howactive<typesleeping)
4370 player[i].setAnimation(player[k].getStop());
4372 player[i].setAnimation(getupfromfrontanim);
4374 player[i].howactive=typeactive;
4377 //jump down on player
4379 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4380 !player[i].isCrouch()&&
4381 player[i].targetanimation!=rollanim&&
4382 !player[k].skeleton.oldfree&&!
4383 player[k].skeleton.free&&
4384 player[k].lastcollide<=0&&
4385 player[k].velocity.y<-10){
4386 player[i].velocity=player[k].velocity;
4387 player[k].velocity=player[k].velocity*-.5;
4388 player[k].velocity.y=player[i].velocity.y;
4389 player[i].DoDamage(20);
4390 player[i].RagDoll(0);
4391 player[k].lastcollide=1;
4392 award_bonus(k, AboveBonus);
4394 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4395 !player[k].isCrouch()&&
4396 player[k].targetanimation!=rollanim&&
4397 !player[i].skeleton.oldfree&&
4398 !player[i].skeleton.free&&
4399 player[i].lastcollide<=0&&
4400 player[i].velocity.y<-10){
4401 player[k].velocity=player[i].velocity;
4402 player[i].velocity=player[i].velocity*-.3;
4403 player[i].velocity.y=player[k].velocity.y;
4404 player[k].DoDamage(20);
4405 player[k].RagDoll(0);
4406 player[i].lastcollide=1;
4407 award_bonus(i, AboveBonus);
4413 player[i].CheckKick();
4414 player[k].CheckKick();
4420 void Game::doAI(int i){
4421 static bool connected;
4422 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4423 player[i].jumpclimb=0;
4424 //disable movement in editor
4426 player[i].stunned=1;
4429 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4430 player[0].coords.y>player[i].coords.y+2&&
4431 !player[0].onterrain)
4435 if(player[i].aitype==pathfindtype){
4436 if(player[i].finalpathfindpoint==-1){
4437 float closestdistance;
4443 for(int j=0;j<numpathpoints;j++)
4444 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4445 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4447 player[i].finaltarget=pathpoint[j];
4449 player[i].finalpathfindpoint=closest;
4450 for(int j=0;j<numpathpoints;j++)
4451 for(int k=0;k<numpathpointconnect[j];k++){
4452 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4453 if(sq(tempdist)<closestdistance)
4454 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4455 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4456 closestdistance=sq(tempdist);
4458 player[i].finaltarget=colpoint;
4461 player[i].finalpathfindpoint=closest;
4464 if(player[i].targetpathfindpoint==-1){
4465 float closestdistance;
4471 if(player[i].lastpathfindpoint==-1){
4472 for(int j=0;j<numpathpoints;j++){
4473 if(j!=player[i].lastpathfindpoint)
4474 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4475 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4479 player[i].targetpathfindpoint=closest;
4480 for(int j=0;j<numpathpoints;j++)
4481 if(j!=player[i].lastpathfindpoint)
4482 for(int k=0;k<numpathpointconnect[j];k++){
4483 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4484 if(sq(tempdist)<closestdistance){
4485 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4486 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4487 closestdistance=sq(tempdist);
4492 player[i].targetpathfindpoint=closest;
4496 for(int j=0;j<numpathpoints;j++)
4497 if(j!=player[i].lastpathfindpoint&&
4498 j!=player[i].lastpathfindpoint2&&
4499 j!=player[i].lastpathfindpoint3&&
4500 j!=player[i].lastpathfindpoint4){
4502 if(numpathpointconnect[j])
4503 for(int k=0;k<numpathpointconnect[j];k++)
4504 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4507 if(numpathpointconnect[player[i].lastpathfindpoint])
4508 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4509 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4512 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4513 if(closest==-1||tempdist<closestdistance){
4514 closestdistance=tempdist;
4519 player[i].targetpathfindpoint=closest;
4522 player[i].losupdatedelay-=multiplier;
4524 player[i].targetrotation=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4525 player[i].lookrotation=player[i].targetrotation;
4527 //reached target point
4528 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4529 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4530 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4531 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4532 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4533 if(player[i].lastpathfindpoint2==-1)
4534 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4535 if(player[i].lastpathfindpoint3==-1)
4536 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4537 if(player[i].lastpathfindpoint4==-1)
4538 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4539 player[i].targetpathfindpoint=-1;
4541 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4542 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4543 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4544 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4545 player[i].aitype=passivetype;
4548 player[i].forwardkeydown=1;
4549 player[i].leftkeydown=0;
4550 player[i].backkeydown=0;
4551 player[i].rightkeydown=0;
4552 player[i].crouchkeydown=0;
4553 player[i].attackkeydown=0;
4554 player[i].throwkeydown=0;
4556 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4557 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4559 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4560 player[i].jumpkeydown=0;
4561 if((player[i].collided>.8&&player[i].jumppower>=5))
4562 player[i].jumpkeydown=1;
4564 if((tutoriallevel!=1||cananger)&&
4567 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4568 player[i].occluded<25){
4569 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4570 animation[player[0].targetanimation].height!=lowheight&&
4572 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4573 player[i].aitype=attacktypecutoff;
4574 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4575 animation[player[0].targetanimation].height==highheight&&
4577 player[i].aitype=attacktypecutoff;
4579 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4580 player[i].losupdatedelay=.2;
4581 for(int j=0;j<numplayers;j++)
4582 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4583 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4584 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4585 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4586 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4587 if(!player[j].isWallJump()&&-1==checkcollide(
4588 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)
4589 *player[i].scale+player[i].coords,
4590 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)
4591 *player[j].scale+player[j].coords)||
4592 (player[j].targetanimation==hanganim&&
4593 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4594 player[i].aitype=searchtype;
4595 player[i].lastchecktime=12;
4596 player[i].lastseen=player[j].coords;
4597 player[i].lastseentime=12;
4601 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4602 if(player[i].creature!=wolftype){
4603 player[i].stunned=.6;
4604 player[i].surprised=.6;
4608 if(player[i].aitype!=passivetype&&leveltime>.5)
4609 player[i].howactive=typeactive;
4611 if(player[i].aitype==passivetype){
4612 player[i].aiupdatedelay-=multiplier;
4613 player[i].losupdatedelay-=multiplier;
4614 player[i].lastseentime+=multiplier;
4615 player[i].pausetime-=multiplier;
4616 if(player[i].lastseentime>1)
4617 player[i].lastseentime=1;
4619 if(player[i].aiupdatedelay<0){
4620 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4621 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4622 player[i].lookrotation=player[i].targetrotation;
4623 player[i].aiupdatedelay=.05;
4625 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4626 if(player[i].waypointtype[player[i].waypoint]==wppause)
4627 player[i].pausetime=4;
4628 player[i].waypoint++;
4629 if(player[i].waypoint>player[i].numwaypoints-1)
4630 player[i].waypoint=0;
4635 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4636 player[i].forwardkeydown=1;
4638 player[i].forwardkeydown=0;
4639 player[i].leftkeydown=0;
4640 player[i].backkeydown=0;
4641 player[i].rightkeydown=0;
4642 player[i].crouchkeydown=0;
4643 player[i].attackkeydown=0;
4644 player[i].throwkeydown=0;
4646 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4647 if(!player[i].avoidsomething)
4648 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4650 XYZ leftpos,rightpos;
4651 float leftdist,rightdist;
4652 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4653 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4654 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4655 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4656 if(leftdist<rightdist)
4657 player[i].targetrotation+=90;
4659 player[i].targetrotation-=90;
4663 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4664 player[i].jumpkeydown=0;
4665 if((player[i].collided>.8&&player[i].jumppower>=5))
4666 player[i].jumpkeydown=1;
4671 if(player[i].howactive<=typesleeping)
4672 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4673 for(int j=0;j<numenvsounds;j++){
4674 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4675 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4676 2*(vol+vol*(player[i].creature==rabbittype)*3))
4677 player[i].aitype=attacktypecutoff;
4680 if(player[i].aitype!=passivetype){
4681 if(player[i].howactive==typesleeping)
4682 player[i].setAnimation(getupfromfrontanim);
4683 player[i].howactive=typeactive;
4687 if(player[i].howactive<typesleeping&&
4688 ((tutoriallevel!=1||cananger)&&hostile)&&
4690 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4691 player[i].occluded<25){
4692 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4693 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4694 player[i].aitype=attacktypecutoff;
4695 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4696 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4697 player[i].aitype=attacktypecutoff;
4700 if(player[i].creature==wolftype){
4702 for(int j=0;j<numplayers;j++){
4703 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4704 float smelldistance=50;
4705 if(j==0&&player[j].num_weapons>0){
4706 if(weapons[player[j].weaponids[0]].bloody)
4708 if(player[j].num_weapons==2)
4709 if(weapons[player[j].weaponids[1]].bloody)
4714 windsmell=windvector;
4715 Normalise(&windsmell);
4716 windsmell=windsmell*2+player[j].coords;
4717 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4718 player[i].aitype=attacktypecutoff;
4723 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4724 player[i].losupdatedelay=.2;
4725 for(int j=0;j<numplayers;j++){
4726 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4727 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4728 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4729 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4730 if((-1==checkcollide(
4731 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4732 player[i].scale+player[i].coords,
4733 DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*
4734 player[j].scale+player[j].coords)&&
4735 !player[j].isWallJump())||
4736 (player[j].targetanimation==hanganim&&
4737 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4738 player[i].lastseentime-=.2;
4739 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4740 player[i].lastseentime-=.4;
4742 player[i].lastseentime-=.6;
4744 if(player[i].lastseentime<=0){
4745 player[i].aitype=searchtype;
4746 player[i].lastchecktime=12;
4747 player[i].lastseen=player[j].coords;
4748 player[i].lastseentime=12;
4755 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4756 if(player[i].creature!=wolftype){
4757 player[i].stunned=.6;
4758 player[i].surprised=.6;
4760 if(player[i].creature==wolftype){
4761 player[i].stunned=.47;
4762 player[i].surprised=.47;
4770 if(player[i].aitype==searchtype){
4771 player[i].aiupdatedelay-=multiplier;
4772 player[i].losupdatedelay-=multiplier;
4773 if(!player[i].pause)
4774 player[i].lastseentime-=multiplier;
4775 player[i].lastchecktime-=multiplier;
4777 if(player[i].isRun()&&!player[i].onground){
4778 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4779 XYZ test2=player[i].coords+player[i].facing;
4781 XYZ test=player[i].coords+player[i].facing;
4783 j=checkcollide(test2,test,player[i].laststanding);
4785 j=checkcollide(test2,test);
4787 player[i].velocity=0;
4788 player[i].setAnimation(player[i].getStop());
4789 player[i].targetrotation+=180;
4790 player[i].stunned=.5;
4791 //player[i].aitype=passivetype;
4792 player[i].aitype=pathfindtype;
4793 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4794 player[i].finalpathfindpoint=-1;
4795 player[i].targetpathfindpoint=-1;
4796 player[i].lastpathfindpoint=-1;
4797 player[i].lastpathfindpoint2=-1;
4798 player[i].lastpathfindpoint3=-1;
4799 player[i].lastpathfindpoint4=-1;
4801 else player[i].laststanding=j;
4804 //check out last seen location
4805 if(player[i].aiupdatedelay<0){
4806 player[i].targetrotation=roughDirectionTo(player[i].coords,player[i].lastseen);
4807 player[i].lookrotation=player[i].targetrotation;
4808 player[i].aiupdatedelay=.05;
4809 player[i].forwardkeydown=1;
4811 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4812 player[i].forwardkeydown=0;
4813 player[i].aiupdatedelay=1;
4814 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4815 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4816 player[i].lastchecktime=3;
4819 player[i].leftkeydown=0;
4820 player[i].backkeydown=0;
4821 player[i].rightkeydown=0;
4822 player[i].crouchkeydown=0;
4823 player[i].attackkeydown=0;
4824 player[i].throwkeydown=0;
4826 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4827 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4829 XYZ leftpos,rightpos;
4830 float leftdist,rightdist;
4831 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4832 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4833 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4834 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4835 if(leftdist<rightdist)player[i].targetrotation+=90;
4836 else player[i].targetrotation-=90;
4840 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4841 player[i].jumpkeydown=0;
4842 if((player[i].collided>.8&&player[i].jumppower>=5))
4843 player[i].jumpkeydown=1;
4845 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4846 for(int k=0;k<numenvsounds;k++){
4847 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4848 player[i].aitype=attacktypecutoff;
4852 if(!player[0].dead&&
4853 player[i].losupdatedelay<0&&
4855 player[i].occluded<2&&
4856 ((tutoriallevel!=1||cananger)&&hostile)){
4857 player[i].losupdatedelay=.2;
4858 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
4859 player[i].aitype=attacktypecutoff;
4860 player[i].lastseentime=1;
4862 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
4863 //TODO: factor out canSeePlayer()
4864 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
4865 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4867 DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*
4868 player[i].scale+player[i].coords,
4869 DoRotation(player[0].getJointFor(head).position,0,player[0].rotation,0)*
4870 player[0].scale+player[0].coords)==-1)||
4871 (player[0].targetanimation==hanganim&&normaldotproduct(
4872 player[0].facing,player[i].coords-player[0].coords)<0)){
4873 /* //TODO: changed j to 0 on a whim, make sure this is correct
4874 (player[j].targetanimation==hanganim&&normaldotproduct(
4875 player[j].facing,player[i].coords-player[j].coords)<0)
4877 player[i].aitype=attacktypecutoff;
4878 player[i].lastseentime=1;
4882 if(player[i].lastseentime<0){
4883 //player[i].aitype=passivetype;
4885 player[i].aitype=pathfindtype;
4886 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4887 player[i].finalpathfindpoint=-1;
4888 player[i].targetpathfindpoint=-1;
4889 player[i].lastpathfindpoint=-1;
4890 player[i].lastpathfindpoint2=-1;
4891 player[i].lastpathfindpoint3=-1;
4892 player[i].lastpathfindpoint4=-1;
4896 if(player[i].aitype!=gethelptype)
4897 player[i].runninghowlong=0;
4899 //get help from buddies
4900 if(player[i].aitype==gethelptype) {
4901 player[i].runninghowlong+=multiplier;
4902 player[i].aiupdatedelay-=multiplier;
4904 if(player[i].aiupdatedelay<0||player[i].ally==0) {
4905 player[i].aiupdatedelay=.2;
4908 //TODO: factor out closest search somehow
4909 if(!player[i].ally) {
4911 float closestdist=-1;
4912 for(int k=0;k<numplayers;k++) {
4913 if(k!=i&&k!=0&&!player[k].dead&&
4914 player[k].howactive<typedead1&&
4915 !player[k].skeleton.free&&
4916 player[k].aitype==passivetype) {
4917 float distance=findDistancefast(&player[i].coords,&player[k].coords);
4918 if(closestdist==-1||distance<closestdist) {
4919 closestdist=distance;
4926 player[i].ally=closest;
4929 player[i].lastseen=player[0].coords;
4930 player[i].lastseentime=12;
4934 player[i].lastchecktime=12;
4936 XYZ facing=player[i].coords;
4937 XYZ flatfacing=player[player[i].ally].coords;
4938 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
4939 flatfacing.y+=player[player[i].ally].getJointFor(head).position.y*player[player[i].ally].scale;
4940 if(-1!=checkcollide(facing,flatfacing))
4941 player[i].lastseentime-=.1;
4943 //no available ally, run back to player
4944 if(player[i].ally<=0||
4945 player[player[i].ally].skeleton.free||
4946 player[player[i].ally].aitype!=passivetype||
4947 player[i].lastseentime<=0){
4948 player[i].aitype=searchtype;
4949 player[i].lastseentime=12;
4953 if(player[i].ally>0){
4954 player[i].targetrotation=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
4955 player[i].lookrotation=player[i].targetrotation;
4956 player[i].aiupdatedelay=.05;
4957 player[i].forwardkeydown=1;
4959 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
4960 player[i].aitype=searchtype;
4961 player[i].lastseentime=12;
4962 player[player[i].ally].aitype=searchtype;
4963 if(player[player[i].ally].lastseentime<player[i].lastseentime){
4964 player[player[i].ally].lastseen=player[i].lastseen;
4965 player[player[i].ally].lastseentime=player[i].lastseentime;
4966 player[player[i].ally].lastchecktime=player[i].lastchecktime;
4970 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4971 if(!player[i].avoidsomething)
4972 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
4974 XYZ leftpos,rightpos;
4975 float leftdist,rightdist;
4976 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4977 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4978 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4979 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4980 if(leftdist<rightdist)
4981 player[i].targetrotation+=90;
4983 player[i].targetrotation-=90;
4988 player[i].leftkeydown=0;
4989 player[i].backkeydown=0;
4990 player[i].rightkeydown=0;
4991 player[i].crouchkeydown=0;
4992 player[i].attackkeydown=0;
4994 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4995 player[i].jumpkeydown=0;
4996 if(player[i].collided>.8&&player[i].jumppower>=5)
4997 player[i].jumpkeydown=1;
5000 //retreiving a weapon on the ground
5001 if(player[i].aitype==getweapontype){
5002 player[i].aiupdatedelay-=multiplier;
5003 player[i].lastchecktime-=multiplier;
5005 if(player[i].aiupdatedelay<0){
5006 player[i].aiupdatedelay=.2;
5009 if(player[i].ally<0){
5011 float closestdist=-1;
5012 for(int k=0;k<weapons.size();k++)
5013 if(weapons[k].owner==-1){
5014 float distance=findDistancefast(&player[i].coords,&weapons[k].position);
5015 if(closestdist==-1||distance<closestdist){
5016 closestdist=distance;
5022 player[i].ally=closest;
5027 player[i].lastseentime=12;
5029 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5030 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5031 player[i].aitype=attacktypecutoff;
5032 player[i].lastseentime=1;
5035 if(player[i].ally>=0){
5036 if(weapons[player[i].ally].owner!=-1||
5037 findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
5038 player[i].aitype=attacktypecutoff;
5039 player[i].lastseentime=1;
5041 //TODO: factor these out as moveToward()
5042 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5043 player[i].lookrotation=player[i].targetrotation;
5044 player[i].aiupdatedelay=.05;
5045 player[i].forwardkeydown=1;
5048 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5049 if(!player[i].avoidsomething)
5050 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5052 XYZ leftpos,rightpos;
5053 float leftdist,rightdist;
5054 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5055 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5056 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5057 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5058 if(leftdist<rightdist)
5059 player[i].targetrotation+=90;
5061 player[i].targetrotation-=90;
5066 player[i].leftkeydown=0;
5067 player[i].backkeydown=0;
5068 player[i].rightkeydown=0;
5069 player[i].attackkeydown=0;
5070 player[i].throwkeydown=1;
5071 player[i].crouchkeydown=0;
5072 if(player[i].targetanimation!=crouchremoveknifeanim&&
5073 player[i].targetanimation!=removeknifeanim)
5074 player[i].throwtogglekeydown=0;
5075 player[i].drawkeydown=0;
5077 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5078 player[i].jumpkeydown=0;
5079 if((player[i].collided>.8&&player[i].jumppower>=5))
5080 player[i].jumpkeydown=1;
5083 if(player[i].aitype==attacktypecutoff){
5084 player[i].aiupdatedelay-=multiplier;
5085 //dodge or reverse rabbit kicks, knife throws, flips
5086 if(player[i].damage<player[i].damagetolerance*2/3)
5087 if((player[0].targetanimation==rabbitkickanim||
5088 player[0].targetanimation==knifethrowanim||
5089 (player[0].isFlip()&&
5090 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5091 !player[0].skeleton.free&&
5092 (player[i].aiupdatedelay<.1)){
5093 player[i].attackkeydown=0;
5094 if(player[i].isIdle())
5095 player[i].crouchkeydown=1;
5096 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5097 if(weapons[player[0].weaponids[0]].getType()==knife){
5098 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5099 if(abs(Random()%2==0))
5100 player[i].setAnimation(backhandspringanim);
5102 player[i].setAnimation(rollanim);
5103 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
5104 player[i].wentforweapon=0;
5106 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5107 player[i].setAnimation(flipanim);
5110 player[i].forwardkeydown=0;
5111 player[i].aiupdatedelay=.02;
5113 //get confused by flips
5114 if(player[0].isFlip()&&
5115 !player[0].skeleton.free&&
5116 player[0].targetanimation!=walljumprightkickanim&&
5117 player[0].targetanimation!=walljumpleftkickanim){
5118 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5119 if((1-player[i].damage/player[i].damagetolerance)>.5)
5120 player[i].stunned=1;
5122 //go for weapon on the ground
5123 if(player[i].wentforweapon<3)
5124 for(int k=0;k<weapons.size();k++)
5125 if(player[i].creature!=wolftype)
5126 if(player[i].num_weapons==0&&
5127 weapons[k].owner==-1&&
5128 weapons[i].velocity.x==0&&
5129 weapons[i].velocity.z==0&&
5130 weapons[i].velocity.y==0){
5131 if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
5132 player[i].wentforweapon++;
5133 player[i].lastchecktime=6;
5134 player[i].aitype=getweapontype;
5138 //dodge/reverse walljump kicks
5139 if(player[i].damage<player[i].damagetolerance/2)
5140 if(animation[player[i].targetanimation].height!=highheight)
5141 if(player[i].damage<player[i].damagetolerance*.5&&
5142 ((player[0].targetanimation==walljumprightkickanim||
5143 player[0].targetanimation==walljumpleftkickanim)&&
5144 ((player[i].aiupdatedelay<.15&&
5146 (player[i].aiupdatedelay<.08&&
5148 player[i].crouchkeydown=1;
5150 //walked off a ledge (?)
5151 if(player[i].isRun()&&!player[i].onground)
5152 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5153 XYZ test2=player[i].coords+player[i].facing;
5155 XYZ test=player[i].coords+player[i].facing;
5157 j=checkcollide(test2,test,player[i].laststanding);
5159 j=checkcollide(test2,test);
5161 player[i].velocity=0;
5162 player[i].setAnimation(player[i].getStop());
5163 player[i].targetrotation+=180;
5164 player[i].stunned=.5;
5165 player[i].aitype=pathfindtype;
5166 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5167 player[i].finalpathfindpoint=-1;
5168 player[i].targetpathfindpoint=-1;
5169 player[i].lastpathfindpoint=-1;
5170 player[i].lastpathfindpoint2=-1;
5171 player[i].lastpathfindpoint3=-1;
5172 player[i].lastpathfindpoint4=-1;
5174 player[i].laststanding=j;
5176 //lose sight of player in the air (?)
5177 if(player[0].coords.y>player[i].coords.y+5&&
5178 animation[player[0].targetanimation].height!=highheight&&
5179 !player[0].onterrain){
5180 player[i].aitype=pathfindtype;
5181 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5182 player[i].finalpathfindpoint=-1;
5183 player[i].targetpathfindpoint=-1;
5184 player[i].lastpathfindpoint=-1;
5185 player[i].lastpathfindpoint2=-1;
5186 player[i].lastpathfindpoint3=-1;
5187 player[i].lastpathfindpoint4=-1;
5189 //it's time to think (?)
5190 if(player[i].aiupdatedelay<0&&
5191 !animation[player[i].targetanimation].attack&&
5192 player[i].targetanimation!=staggerbackhighanim&&
5193 player[i].targetanimation!=staggerbackhardanim&&
5194 player[i].targetanimation!=backhandspringanim&&
5195 player[i].targetanimation!=dodgebackanim){
5197 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5198 player[i].drawkeydown=Random()%2;
5200 player[i].drawkeydown=0;
5201 player[i].rabbitkickenabled=Random()%2;
5203 XYZ rotatetarget=player[0].coords+player[0].velocity;
5204 XYZ targetpoint=player[0].coords;
5205 if(findDistancefast(&player[0].coords,&player[i].coords)<
5206 findDistancefast(&rotatetarget,&player[i].coords))
5207 targetpoint+=player[0].velocity*
5208 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5209 player[i].targetrotation=roughDirectionTo(player[i].coords,targetpoint);
5210 player[i].lookrotation=player[i].targetrotation;
5211 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5213 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5214 player[i].forwardkeydown=1;
5215 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5216 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5217 player[0].weaponactive!=-1)
5218 player[i].forwardkeydown=1;
5219 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5220 player[i].forwardkeydown=1;
5222 player[i].forwardkeydown=0;
5223 //chill out around the corpse
5225 player[i].forwardkeydown=0;
5227 player[i].forwardkeydown=1;
5228 if(Random()%100==0){
5229 player[i].aitype=pathfindtype;
5230 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5231 player[i].finalpathfindpoint=-1;
5232 player[i].targetpathfindpoint=-1;
5233 player[i].lastpathfindpoint=-1;
5234 player[i].lastpathfindpoint2=-1;
5235 player[i].lastpathfindpoint3=-1;
5236 player[i].lastpathfindpoint4=-1;
5239 player[i].leftkeydown=0;
5240 player[i].backkeydown=0;
5241 player[i].rightkeydown=0;
5242 player[i].crouchkeydown=0;
5243 player[i].throwkeydown=0;
5245 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5246 player[i].targetrotation+=90*(player[i].whichdirection*2-1);
5248 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5249 player[i].attackkeydown=1;
5251 player[i].attackkeydown=0;
5252 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5253 player[i].attackkeydown=0;
5256 if(player[i].aitype!=playercontrolled&&
5257 (player[i].isIdle()||
5258 player[i].isCrouch()||
5259 player[i].isRun())){
5261 for(int j=0;j<numplayers;j++)
5262 if(j!=i&&!player[j].skeleton.free&&
5263 player[j].hasvictim&&
5264 (tutoriallevel==1&&reversaltrain||
5265 Random()%2==0&&difficulty==2||
5266 Random()%4==0&&difficulty==1||
5267 Random()%8==0&&difficulty==0||
5268 player[j].lastattack2==player[j].targetanimation&&
5269 player[j].lastattack3==player[j].targetanimation&&
5270 (Random()%2==0||difficulty==2)||
5271 (player[i].isIdle()||player[i].isRun())&&
5272 player[j].weaponactive!=-1||
5273 player[j].targetanimation==swordslashanim&&
5274 player[i].weaponactive!=-1||
5275 player[j].targetanimation==staffhitanim||
5276 player[j].targetanimation==staffspinhitanim))
5277 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5278 player[j].victim==&player[i]&&
5279 (player[j].targetanimation==sweepanim||
5280 player[j].targetanimation==spinkickanim||
5281 player[j].targetanimation==staffhitanim||
5282 player[j].targetanimation==staffspinhitanim||
5283 player[j].targetanimation==winduppunchanim||
5284 player[j].targetanimation==upunchanim||
5285 player[j].targetanimation==wolfslapanim||
5286 player[j].targetanimation==knifeslashstartanim||
5287 player[j].targetanimation==swordslashanim&&
5288 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5289 player[i].weaponactive!=-1))){
5296 player[target].Reverse();
5299 if(player[i].collided<1)
5300 player[i].jumpkeydown=0;
5301 if(player[i].collided>.8&&player[i].jumppower>=5||
5302 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5303 player[i].onterrain&&
5304 player[i].creature==rabbittype)
5305 player[i].jumpkeydown=1;
5306 //TODO: why are we controlling the human?
5307 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5308 player[0].jumpkeydown=0;
5309 if(player[0].targetanimation==jumpdownanim&&
5310 findDistancefast(&player[0].coords,&player[i].coords)<40)
5311 player[i].crouchkeydown=1;
5312 if(player[i].jumpkeydown)
5313 player[i].attackkeydown=0;
5315 if(tutoriallevel==1)
5317 player[i].attackkeydown=0;
5320 XYZ facing=player[i].coords;
5321 XYZ flatfacing=player[0].coords;
5322 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
5323 flatfacing.y+=player[0].getJointFor(head).position.y*player[0].scale;
5324 if(player[i].occluded>=2)
5325 if(-1!=checkcollide(facing,flatfacing)){
5326 if(!player[i].pause)
5327 player[i].lastseentime-=.2;
5328 if(player[i].lastseentime<=0&&
5329 (player[i].creature!=wolftype||
5330 player[i].weaponstuck==-1)){
5331 player[i].aitype=searchtype;
5332 player[i].lastchecktime=12;
5333 player[i].lastseen=player[0].coords;
5334 player[i].lastseentime=12;
5337 player[i].lastseentime=1;
5340 if(animation[player[0].targetanimation].height==highheight&&
5341 (player[i].aitype==attacktypecutoff||
5342 player[i].aitype==searchtype))
5343 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5344 XYZ test=player[0].coords;
5346 if(-1==checkcollide(player[0].coords,test))
5347 player[i].stunned=1;
5350 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5351 player[i].stunned>0||
5352 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5354 player[i].lastseentime=1;
5355 player[i].targetrotation=player[i].rotation;
5356 player[i].forwardkeydown=0;
5357 player[i].leftkeydown=0;
5358 player[i].backkeydown=0;
5359 player[i].rightkeydown=0;
5360 player[i].jumpkeydown=0;
5361 player[i].attackkeydown=0;
5362 player[i].crouchkeydown=0;
5363 player[i].throwkeydown=0;
5371 XYZ flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
5374 if(player[i].aitype==attacktypecutoff){
5375 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[0].coords);
5376 player[i].targetheadrotation2=pitchTo(player[i].coords,player[0].coords);
5377 }else if(player[i].howactive>=typesleeping){
5378 player[i].targetheadrotation=player[i].targetrotation;
5379 player[i].targetheadrotation2=0;
5381 if(player[i].interestdelay<=0){
5382 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5383 player[i].headtarget=player[i].coords;
5384 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5385 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5386 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5387 player[i].headtarget+=player[i].facing*1.5;
5389 player[i].targetheadrotation=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5390 player[i].targetheadrotation2=pitchTo(player[i].coords,player[i].headtarget);
5396 Values of mainmenu :
5398 2 Menu pause (resume/end game)
5400 4 Controls configuration menu
5401 5 Main game menu (choose level or challenge)
5402 6 Deleting user menu
5403 7 User managment menu (select/add)
5404 8 Choose difficulty menu
5405 9 Challenge level selection menu
5406 10 End of the campaign congratulation (is that really a menu?)
5407 11 Same that 9 ??? => unused
5408 18 stereo configuration
5411 void Game::MenuTick(){
5414 // some specific case where we do something even if the left mouse button is not pressed.
5415 if((mainmenu==5) && (endgame==2)) {
5416 accountactive->endGame();
5421 if( (mainmenu==18) && Input::isKeyPressed(MOUSEBUTTON2) && (selected==1) )
5422 stereoseparation-=0.001;
5424 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5430 if(gameon) { //resume
5432 pause_sound(stream_menutheme);
5433 resume_stream(leveltheme);
5435 fireSound(firestartsound);
5437 mainmenu=(accountactive?5:7);
5445 if(newdetail>2) newdetail=detail;
5446 if(newdetail<0) newdetail=detail;
5447 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5448 if(newscreenwidth<0) newscreenwidth=screenwidth;
5449 if(newscreenheight>3000) newscreenheight=screenheight;
5450 if(newscreenheight<0) newscreenheight=screenheight;
5455 if(gameon){ //end game
5460 pause_sound(stream_menutheme);
5467 bool isCustomResolution,found;
5470 extern SDL_Rect **resolutions;
5471 isCustomResolution = true;
5473 for(int i = 0; (!found) && (resolutions[i]); i++) {
5474 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5475 isCustomResolution = false;
5477 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5479 if(resolutions[i] != NULL) {
5480 newscreenwidth = (int) resolutions[i]->w;
5481 newscreenheight = (int) resolutions[i]->h;
5482 } else if(isCustomResolution){
5483 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5484 newscreenwidth = (int) resolutions[0]->w;
5485 newscreenheight = (int) resolutions[0]->h;
5487 newscreenwidth = screenwidth;
5488 newscreenheight = screenheight;
5491 newscreenwidth = (int) resolutions[0]->w;
5492 newscreenheight = (int) resolutions[0]->h;
5499 newscreenwidth = (int) resolutions[0]->w;
5500 newscreenheight = (int) resolutions[0]->h;
5505 if(newdetail>2) newdetail=0;
5509 if(bloodtoggle>2) bloodtoggle=0;
5513 if(difficulty>2) difficulty=0;
5516 ismotionblur = !ismotionblur;
5522 musictoggle = !musictoggle;
5525 emit_stream_np(stream_menutheme);
5527 pause_sound(leveltheme);
5528 pause_sound(stream_fighttheme);
5529 pause_sound(stream_menutheme);
5531 for(int i=0;i<4;i++){
5532 oldmusicvolume[i]=0;
5547 SaveSettings(*this);
5548 mainmenu=gameon?2:1;
5551 invertmouse = !invertmouse;
5554 usermousesensitivity+=.2;
5555 if(usermousesensitivity>2) usermousesensitivity=.2;
5559 if(volume>1.0001f) volume=0;
5560 OPENAL_SetSFXMasterVolume((int)(volume*255));
5565 newstereomode = stereomode;
5570 showdamagebar = !showdamagebar;
5577 if(selected<nummenuitems-1 && keyselect==-1)
5581 if(selected==nummenuitems-1){
5591 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5601 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5602 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5605 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5609 pause_sound(stream_menutheme);
5626 pause_sound(stream_menutheme);
5635 mainmenu=(gameon?2:1);
5641 vector<string> campaigns = ListCampaigns();
5642 vector<string>::iterator c;
5643 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5644 if(!campaigns.empty())
5645 accountactive->setCurrentCampaign(campaigns.front());
5648 if(c==campaigns.end())
5649 c=campaigns.begin();
5650 accountactive->setCurrentCampaign(*c);
5660 accountactive = Account::destroy(accountactive);
5662 } else if(selected==2) {
5669 if(selected==0 && Account::getNbAccounts()<8){
5671 } else if (selected < Account::getNbAccounts()+1) {
5674 accountactive=Account::get(selected-1);
5675 } else if (selected == Account::getNbAccounts()+1) {
5678 for(int j=0;j<255;j++){
5679 displaytext[0][j]=0;
5690 accountactive->setDifficulty(selected);
5694 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
5702 targetlevel=selected;
5707 Loadlevel(selected);
5712 pause_sound(stream_menutheme);
5714 if(selected==numchallengelevels){
5729 stereoseparation+=0.001;
5733 newstereomode = (StereoMode)(newstereomode + 1);
5734 while(!CanInitStereo(newstereomode)){
5735 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
5736 newstereomode = (StereoMode)(newstereomode + 1);
5737 if(newstereomode >= stereoCount)
5738 newstereomode = stereoNone;
5740 } else if(selected==2) {
5741 stereoreverse = !stereoreverse;
5742 } else if(selected==3) {
5746 stereomode = newstereomode;
5747 InitStereo(stereomode);
5754 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
5757 SaveSettings(*this);
5761 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
5764 inputText(displaytext[0],&displayselected,&displaychars[0]);
5765 if(!waiting) { // the input as finished
5766 if(displaychars[0]){ // with enter
5767 accountactive = Account::add(string(displaytext[0]));
5773 fireSound(firestartsound);
5775 for(int i=0;i<255;i++){
5776 displaytext[0][i]=0;
5785 displayblinkdelay-=multiplier;
5786 if(displayblinkdelay<=0){
5787 displayblinkdelay=.3;
5788 displayblink=1-displayblink;
5794 static XYZ facing,flatfacing;
5797 for(int i=0;i<15;i++){
5798 displaytime[i]+=multiplier;
5801 keyboardfrozen=false;
5804 if(Input::isKeyPressed(SDLK_F6)){
5805 if(Input::isKeyDown(SDLK_LSHIFT))
5808 stereoreverse=false;
5811 printf("Stereo reversed\n");
5813 printf("Stereo unreversed\n");
5816 if(Input::isKeyDown(SDLK_F7)){
5817 if(Input::isKeyDown(SDLK_LSHIFT))
5818 stereoseparation -= 0.001;
5820 stereoseparation -= 0.010;
5821 printf("Stereo decreased increased to %f\n", stereoseparation);
5824 if(Input::isKeyDown(SDLK_F8)){
5825 if(Input::isKeyDown(SDLK_LSHIFT))
5826 stereoseparation += 0.001;
5828 stereoseparation += 0.010;
5829 printf("Stereo separation increased to %f\n", stereoseparation);
5833 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
5834 if(tutorialstage!=51)
5835 tutorialstagetime=tutorialmaxtime;
5836 emit_sound_np(consolefailsound, 128.);
5840 Values of mainmenu :
5842 2 Menu pause (resume/end game)
5844 4 Controls configuration menu
5845 5 Main game menu (choose level or challenge)
5846 6 Deleting user menu
5847 7 User managment menu (select/add)
5848 8 Choose difficulty menu
5849 9 Challenge level selection menu
5850 10 End of the campaign congratulation (is that really a menu?)
5851 11 Same that 9 ??? => unused
5852 18 stereo configuration
5857 if(mainmenu&&endgame==1)
5859 //go to level select after completing a campaign level
5860 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
5867 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5868 emit_stream_np(stream_menutheme);
5869 pause_sound(leveltheme);
5873 //escape key pressed
5874 //TODO: there must be code somewhere else that handles clicking the Back button, merge it with this
5875 if(Input::isKeyPressed(SDLK_ESCAPE)&&
5876 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
5878 if(mainmenu==0&&!winfreeze)
5880 else if(mainmenu==1||mainmenu==2){
5881 mainmenu=0; //unpause
5884 if(musictoggle&&(mainmenu==1||mainmenu==2)){
5885 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5886 emit_stream_np(stream_menutheme);
5887 pause_sound(leveltheme);
5889 //on resume, play level music
5891 pause_sound(stream_menutheme);
5892 resume_stream(leveltheme);
5894 //finished with settings menu
5896 SaveSettings(*this);
5899 if(mainmenu>=3&&mainmenu!=8){
5906 mainmenu=gameon?2:1; break;
5909 case 6: case 7: case 9: case 10:
5920 if(hostile==1)hostiletime+=multiplier;
5922 if(!winfreeze)leveltime+=multiplier;
5925 if(Input::isKeyPressed(SDLK_v)&&debugmode){
5928 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5932 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
5936 inputText(displaytext[0],&displayselected,&displaychars[0]);
5938 if(displaychars[0]){
5939 for(int j=0;j<255;j++)
5940 displaytext[0][j]=0;
5947 displayblinkdelay-=multiplier;
5948 if(displayblinkdelay<=0){
5949 displayblinkdelay=.3;
5950 displayblink=1-displayblink;
5954 keyboardfrozen=true;
5956 if(Input::isKeyPressed(consolekey)&&debugmode) {
5959 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5968 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
5969 inputText(consoletext[0],&consoleselected,&consolechars[0]);
5972 if(consolechars[0]>0) {
5973 consoletext[0][consolechars[0]]='\0';
5974 cmd_dispatch(this, consoletext[0]);
5975 for(int k=14;k>=1;k--) {
5976 for(int j=0;j<255;j++)
5977 consoletext[k][j]=consoletext[k-1][j];
5978 consolechars[k]=consolechars[k-1];
5980 for(int j=0;j<255;j++)
5981 consoletext[0][j]=0;
5987 consoleblinkdelay-=multiplier;
5988 if(consoleblinkdelay<=0) {
5989 consoleblinkdelay=.3;
5990 consoleblink=1-consoleblink;
5996 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
5999 SaveSettings(*this);
6003 static int oldwinfreeze;
6004 if(winfreeze&&!oldwinfreeze){
6005 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6006 emit_sound_np(consolesuccesssound);
6009 oldwinfreeze=winfreeze;
6013 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6016 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6020 } else if(winfreeze) {
6028 //TODO: what is this test?
6029 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6034 talkdelay-=multiplier;
6036 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6037 for(int i=0;i<numdialogues;i++){
6038 int realdialoguetype;
6040 if(dialoguetype[i]>49){
6041 realdialoguetype=dialoguetype[i]-50;
6044 else if(dialoguetype[i]>39){
6045 realdialoguetype=dialoguetype[i]-40;
6048 else if(dialoguetype[i]>29){
6049 realdialoguetype=dialoguetype[i]-30;
6052 else if(dialoguetype[i]>19){
6053 realdialoguetype=dialoguetype[i]-20;
6056 else if(dialoguetype[i]>9){
6057 realdialoguetype=dialoguetype[i]-10;
6061 realdialoguetype=dialoguetype[i];
6064 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6065 realdialoguetype<numplayers&&
6066 realdialoguetype>0&&
6067 (dialoguegonethrough[i]==0||!special)&&
6068 (special||Input::isKeyPressed(attackkey))){
6069 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6070 player[realdialoguetype].howactive>=typedead1||
6071 dialoguetype[i]>40&&dialoguetype[i]<50){
6073 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6074 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6075 player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6076 player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
6077 player[participantfocus[whichdialogue][j]].velocity=0;
6078 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6079 player[participantfocus[whichdialogue][j]].targetframe=0;
6084 dialoguegonethrough[i]++;
6085 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6086 playdialogueboxsound();
6092 windvar+=multiplier;
6093 smoketex+=multiplier;
6094 tutorialstagetime+=multiplier;
6097 static float hotspotvisual[40];
6101 for(int i=0;i<numhotspots;i++)
6102 hotspotvisual[i]-=multiplier/320;
6104 for(int i=0;i<numhotspots;i++){
6105 //if(hotspottype[i]<=10)
6106 while(hotspotvisual[i]<0){
6108 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6109 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6110 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6111 hotspotsprite+=hotspot[i];
6112 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6113 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6117 for(int i=0;i<numhotspots;i++){
6118 if(hotspottype[i]<=10&&hotspottype[i]>0){
6119 hotspot[i]=player[hotspottype[i]].coords;
6130 if(tutoriallevel!=1){
6133 bonus!=spinecrusher&&
6134 bonus!=tracheotomy&&
6137 emit_sound_np(consolesuccesssound);
6139 } else if(bonustime==0){
6140 emit_sound_np(fireendsound);
6143 if(bonus!=solidhit&&
6145 bonus!=threexcombo&&
6150 bonusnum[bonus]+=0.15;
6153 bonusvalue/=bonusnum[bonus];
6154 bonustotal+=bonusvalue;
6156 bonustime+=multiplier;
6159 if(environment==snowyenvironment){
6160 precipdelay-=multiplier;
6161 while(precipdelay<0){
6165 XYZ footvel,footpoint;
6168 footpoint=viewer+viewerfacing*6;
6169 footpoint.y+=((float)abs(Random()%1200))/100-6;
6170 footpoint.x+=((float)abs(Random()%1200))/100-6;
6171 footpoint.z+=((float)abs(Random()%1200))/100-6;
6172 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6177 doAerialAcrobatics();
6180 static XYZ oldviewer;
6184 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6185 player[0].leftkeydown=Input::isKeyDown(leftkey);
6186 player[0].backkeydown=Input::isKeyDown(backkey);
6187 player[0].rightkeydown=Input::isKeyDown(rightkey);
6188 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6189 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6190 player[0].drawkeydown=Input::isKeyDown(drawkey);
6191 player[0].throwkeydown=Input::isKeyDown(throwkey);
6195 player[0].forwardkeydown=0;
6196 player[0].leftkeydown=0;
6197 player[0].backkeydown=0;
6198 player[0].rightkeydown=0;
6199 player[0].jumpkeydown=0;
6200 player[0].crouchkeydown=0;
6201 player[0].drawkeydown=0;
6202 player[0].throwkeydown=0;
6205 if(!player[0].jumpkeydown)
6206 player[0].jumpclimb=0;
6215 facing=DoRotation(facing,-rotation2,0,0);
6216 facing=DoRotation(facing,0,0-rotation,0);
6221 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6223 if(Input::isKeyDown(forwardkey))
6224 viewer+=facing*multiplier*4;
6225 if(Input::isKeyDown(backkey))
6226 viewer-=facing*multiplier*4;
6227 if(Input::isKeyDown(leftkey))
6228 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6229 if(Input::isKeyDown(rightkey))
6230 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6231 if(Input::isKeyDown(jumpkey))
6232 viewer.y+=multiplier*4;
6233 if(Input::isKeyDown(crouchkey))
6234 viewer.y-=multiplier*4;
6235 if( Input::isKeyPressed(SDLK_1)||
6236 Input::isKeyPressed(SDLK_2)||
6237 Input::isKeyPressed(SDLK_3)||
6238 Input::isKeyPressed(SDLK_4)||
6239 Input::isKeyPressed(SDLK_5)||
6240 Input::isKeyPressed(SDLK_6)||
6241 Input::isKeyPressed(SDLK_7)||
6242 Input::isKeyPressed(SDLK_8)||
6243 Input::isKeyPressed(SDLK_9)||
6244 Input::isKeyPressed(SDLK_0)||
6245 Input::isKeyPressed(SDLK_MINUS)){
6247 if(Input::isKeyPressed(SDLK_1))whichend=1;
6248 if(Input::isKeyPressed(SDLK_2))whichend=2;
6249 if(Input::isKeyPressed(SDLK_3))whichend=3;
6250 if(Input::isKeyPressed(SDLK_4))whichend=4;
6251 if(Input::isKeyPressed(SDLK_5))whichend=5;
6252 if(Input::isKeyPressed(SDLK_6))whichend=6;
6253 if(Input::isKeyPressed(SDLK_7))whichend=7;
6254 if(Input::isKeyPressed(SDLK_8))whichend=8;
6255 if(Input::isKeyPressed(SDLK_9))whichend=9;
6256 if(Input::isKeyPressed(SDLK_0))whichend=0;
6257 if(Input::isKeyPressed(SDLK_MINUS))
6260 participantfocus[whichdialogue][indialogue]=whichend;
6261 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6262 participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6265 participantfocus[whichdialogue][indialogue]=-1;
6267 if(player[participantfocus[whichdialogue][indialogue]].dead){
6272 dialoguecamera[whichdialogue][indialogue]=viewer;
6273 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6274 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6276 if(indialogue<numdialogueboxes[whichdialogue]){
6277 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6278 playdialogueboxsound();
6282 for(int j=0;j<numplayers;j++){
6283 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6286 //TODO: should these be KeyDown or KeyPressed?
6287 if( Input::isKeyDown(SDLK_KP1)||
6288 Input::isKeyDown(SDLK_KP2)||
6289 Input::isKeyDown(SDLK_KP3)||
6290 Input::isKeyDown(SDLK_KP4)||
6291 Input::isKeyDown(SDLK_KP5)||
6292 Input::isKeyDown(SDLK_KP6)||
6293 Input::isKeyDown(SDLK_KP7)||
6294 Input::isKeyDown(SDLK_KP8)||
6295 Input::isKeyDown(SDLK_KP9)||
6296 Input::isKeyDown(SDLK_KP0)){
6298 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6299 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6300 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6301 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6302 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6303 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6304 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6305 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6306 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6307 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6308 participantfacing[whichdialogue][indialogue][whichend]=facing;
6310 if(indialogue>=numdialogueboxes[whichdialogue]){
6317 pause_sound(whooshsound);
6318 viewer=dialoguecamera[whichdialogue][indialogue];
6319 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6320 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6321 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6322 if(dialoguetime>0.5)
6323 if( Input::isKeyPressed(SDLK_1)||
6324 Input::isKeyPressed(SDLK_2)||
6325 Input::isKeyPressed(SDLK_3)||
6326 Input::isKeyPressed(SDLK_4)||
6327 Input::isKeyPressed(SDLK_5)||
6328 Input::isKeyPressed(SDLK_6)||
6329 Input::isKeyPressed(SDLK_7)||
6330 Input::isKeyPressed(SDLK_8)||
6331 Input::isKeyPressed(SDLK_9)||
6332 Input::isKeyPressed(SDLK_0)||
6333 Input::isKeyPressed(SDLK_MINUS)||
6334 Input::isKeyPressed(attackkey)){
6336 if(indialogue<numdialogueboxes[whichdialogue]){
6337 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6338 playdialogueboxsound();
6339 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6340 hotspot[numhotspots]=player[0].coords;
6341 hotspotsize[numhotspots]=10;
6342 hotspottype[numhotspots]=-1;
6346 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6350 if(player[participantfocus[whichdialogue][indialogue]].dead){
6358 if(indialogue>=numdialogueboxes[whichdialogue]){
6362 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6365 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6368 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6370 for(int i=1;i<numplayers;i++){
6371 player[i].aitype = attacktypecutoff;
6378 if(!player[0].jumpkeydown){
6379 player[0].jumptogglekeydown=0;
6381 if(player[0].jumpkeydown&&
6382 player[0].targetanimation!=jumpupanim&&
6383 player[0].targetanimation!=jumpdownanim&&
6384 !player[0].isFlip())
6385 player[0].jumptogglekeydown=1;
6388 dialoguetime+=multiplier;
6389 hawkrotation+=multiplier*25;
6391 realhawkcoords.x=25;
6392 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6393 hawkcalldelay-=multiplier/2;
6395 if(hawkcalldelay<=0){
6396 emit_sound_at(hawksound, realhawkcoords);
6398 hawkcalldelay=16+abs(Random()%8);
6405 doPlayerCollisions();
6409 for(int k=0;k<numplayers;k++)
6410 if(k!=0&&player[k].immobile)
6411 player[k].coords=player[k].realoldcoords;
6413 for(int k=0;k<numplayers;k++){
6414 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6415 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6416 player[k].DoDamage(1000);
6422 static bool respawnkeydown;
6425 (Input::isKeyDown(SDLK_z)&&
6426 Input::isKeyDown(SDLK_LMETA)&&
6428 (Input::isKeyDown(jumpkey)&&
6432 targetlevel=whichlevel;
6436 if(!Input::isKeyDown(jumpkey))
6438 if(Input::isKeyDown(jumpkey))
6444 static bool movekey;
6447 for(int i=0;i<numplayers;i++){
6448 static float oldtargetrotation;
6449 if(!player[i].skeleton.free){
6450 oldtargetrotation=player[i].targetrotation;
6451 if(i==0&&indialogue==-1){
6452 //TODO: refactor repetitive code
6453 if(!animation[player[0].targetanimation].attack&&
6454 player[0].targetanimation!=staggerbackhighanim&&
6455 player[0].targetanimation!=staggerbackhardanim&&
6456 player[0].targetanimation!=crouchremoveknifeanim&&
6457 player[0].targetanimation!=removeknifeanim&&
6458 player[0].targetanimation!=backhandspringanim&&
6459 player[0].targetanimation!=dodgebackanim&&
6460 player[0].targetanimation!=walljumprightkickanim&&
6461 player[0].targetanimation!=walljumpleftkickanim){
6463 player[0].targetrotation=0;
6465 player[0].targetrotation=-rotation+180;
6471 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6475 facing=DoRotation(facing,-rotation2,0,0);
6476 facing=DoRotation(facing,0,0-rotation,0);
6479 player[0].lookrotation=-rotation;
6481 player[i].targetheadrotation=rotation;
6482 player[i].targetheadrotation2=rotation2;
6484 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6485 if(!animation[player[i].targetanimation].attack&&
6486 player[i].targetanimation!=staggerbackhighanim&&
6487 player[i].targetanimation!=staggerbackhardanim&&
6488 player[i].targetanimation!=crouchremoveknifeanim&&
6489 player[i].targetanimation!=removeknifeanim&&
6490 player[i].targetanimation!=backhandspringanim&&
6491 player[i].targetanimation!=dodgebackanim&&
6492 player[i].targetanimation!=walljumprightkickanim&&
6493 player[i].targetanimation!=walljumpleftkickanim){
6494 player[i].targetrotation=-player[i].lookrotation+180;
6500 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
6502 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
6503 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
6505 player[i].targetheadrotation=player[i].lookrotation;
6506 player[i].targetheadrotation2=player[i].lookrotation2;
6509 player[i].targetheadrotation=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6510 player[i].targetheadrotation2=pitch(participantfacing[whichdialogue][indialogue][i]);
6516 player[i].avoidsomething=0;
6518 //avoid flaming things
6519 for(int j=0;j<objects.numobjects;j++)
6520 if(objects.onfire[j])
6521 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6522 if( findDistancefast(&player[i].coords,&objects.position[j])<
6523 findDistancefast(&player[i].coords,&player[0].coords)){
6524 player[i].collided=0;
6525 player[i].avoidcollided=1;
6526 if(player[i].avoidsomething==0||
6527 findDistancefast(&player[i].coords,&objects.position[j])<
6528 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6529 player[i].avoidwhere=objects.position[j];
6530 player[i].avoidsomething=1;
6534 //avoid flaming players
6535 for(int j=0;j<numplayers;j++)
6536 if(player[j].onfire)
6537 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6538 if( findDistancefast(&player[i].coords,&player[j].coords)<
6539 findDistancefast(&player[i].coords,&player[0].coords)){
6540 player[i].collided=0;
6541 player[i].avoidcollided=1;
6542 if(player[i].avoidsomething==0||
6543 findDistancefast(&player[i].coords,&player[j].coords)<
6544 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6545 player[i].avoidwhere=player[j].coords;
6546 player[i].avoidsomething=1;
6550 if(player[i].collided>.8)
6551 player[i].avoidcollided=0;
6555 if(animation[player[i].targetanimation].attack==reversed){
6556 //player[i].targetrotation=player[i].rotation;
6557 player[i].forwardkeydown=0;
6558 player[i].leftkeydown=0;
6559 player[i].backkeydown=0;
6560 player[i].rightkeydown=0;
6561 player[i].jumpkeydown=0;
6562 player[i].attackkeydown=0;
6563 //player[i].crouchkeydown=0;
6564 player[i].throwkeydown=0;
6568 player[i].forwardkeydown=0;
6569 player[i].leftkeydown=0;
6570 player[i].backkeydown=0;
6571 player[i].rightkeydown=0;
6572 player[i].jumpkeydown=0;
6573 player[i].crouchkeydown=0;
6574 player[i].drawkeydown=0;
6575 player[i].throwkeydown=0;
6578 if(player[i].collided<-.3)
6579 player[i].collided=-.3;
6580 if(player[i].collided>1)
6581 player[i].collided=1;
6582 player[i].collided-=multiplier*4;
6583 player[i].whichdirectiondelay-=multiplier;
6584 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6585 player[i].avoidcollided=-.3;
6586 player[i].whichdirection=abs(Random()%2);
6587 player[i].whichdirectiondelay=.4;
6589 if(player[i].avoidcollided>1)
6590 player[i].avoidcollided=1;
6591 player[i].avoidcollided-=multiplier/4;
6592 if(!player[i].skeleton.free){
6593 player[i].stunned-=multiplier;
6594 player[i].surprised-=multiplier;
6596 if(i!=0&&player[i].surprised<=0&&
6597 player[i].aitype==attacktypecutoff&&
6599 !player[i].skeleton.free&&
6600 animation[player[i].targetanimation].attack==neutral)
6603 if(!player[i].throwkeydown)
6604 player[i].throwtogglekeydown=0;
6607 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6608 if(player[i].weaponactive==-1&&
6609 player[i].num_weapons<2&&
6610 (player[i].isIdle()||
6611 player[i].isCrouch()||
6612 player[i].targetanimation==sneakanim||
6613 player[i].targetanimation==rollanim||
6614 player[i].targetanimation==backhandspringanim||
6615 player[i].isFlip()||
6616 player[i].isFlip()||
6617 player[i].aitype!=playercontrolled)){
6618 for(int j=0;j<weapons.size();j++){
6619 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6620 player[i].aitype==playercontrolled)&&
6621 weapons[j].owner==-1&&
6622 player[i].weaponactive==-1)
6623 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
6624 if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
6625 if(player[i].isCrouch()||
6626 player[i].targetanimation==sneakanim||
6628 player[i].isIdle()||
6629 player[i].aitype!=playercontrolled){
6630 player[i].throwtogglekeydown=1;
6631 player[i].setAnimation(crouchremoveknifeanim);
6632 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6633 player[i].hasvictim=0;
6635 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6636 player[i].throwtogglekeydown=1;
6637 player[i].hasvictim=0;
6639 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6640 player[i].aitype==playercontrolled)&&
6641 weapons[j].owner==-1||
6643 weapons[j].owner==player[i].victim->id)
6644 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
6645 if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
6646 if(weapons[j].getType()!=staff)
6647 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6649 player[i].weaponactive=0;
6650 weapons[j].owner=player[i].id;
6651 if(player[i].num_weapons>0)
6652 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6653 player[i].num_weapons++;
6654 player[i].weaponids[0]=j;
6657 }else if((player[i].isIdle()||
6658 player[i].isFlip()||
6659 player[i].aitype!=playercontrolled)&&
6660 findDistancefast(&player[i].coords,&weapons[j].position)<5&&
6661 player[i].coords.y<weapons[j].position.y){
6662 if(!player[i].isFlip()){
6663 player[i].throwtogglekeydown=1;
6664 player[i].setAnimation(removeknifeanim);
6665 player[i].targetrotation=roughDirectionTo(player[i].coords,weapons[j].position);
6667 if(player[i].isFlip()){
6668 player[i].throwtogglekeydown=1;
6669 player[i].hasvictim=0;
6671 for(int k=0;k<weapons.size();k++){
6672 if(player[i].weaponactive==-1)
6673 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
6674 player[i].aitype==playercontrolled)&&
6675 weapons[k].owner==-1||
6677 weapons[k].owner==player[i].victim->id)
6678 if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
6679 player[i].weaponactive==-1){
6680 if(weapons[k].getType()!=staff)
6681 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6683 player[i].weaponactive=0;
6684 weapons[k].owner=player[i].id;
6685 if(player[i].num_weapons>0)
6686 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6687 player[i].num_weapons++;
6688 player[i].weaponids[0]=k;
6695 if(player[i].isCrouch()||
6696 player[i].targetanimation==sneakanim||
6698 player[i].isIdle()||player[i].targetanimation==rollanim||
6699 player[i].targetanimation==backhandspringanim){
6701 for(int j=0;j<numplayers;j++){
6702 if(player[i].weaponactive==-1)
6704 if(player[j].num_weapons&&
6705 player[j].skeleton.free&&
6706 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
6707 (((player[j].skeleton.forward.y<0&&
6708 player[j].weaponstuckwhere==0)||
6709 (player[j].skeleton.forward.y>0&&
6710 player[j].weaponstuckwhere==1))||
6711 player[j].weaponstuck==-1||
6712 player[j].num_weapons>1)){
6713 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
6714 player[i].throwtogglekeydown=1;
6715 player[i].victim=&player[j];
6716 player[i].hasvictim=1;
6717 player[i].setAnimation(crouchremoveknifeanim);
6718 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6720 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
6721 player[i].throwtogglekeydown=1;
6722 player[i].victim=&player[j];
6723 player[i].hasvictim=1;
6724 int k = player[j].weaponids[0];
6725 if(player[i].hasvictim){
6728 if(player[i].victim->weaponstuck!=-1){
6729 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6734 if(weapons[k].getType()!=staff)
6735 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6738 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
6740 player[i].weaponactive=0;
6741 if(weapons[k].owner!=-1){
6742 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
6743 else player[i].victim->num_weapons=1;
6745 player[i].victim->skeleton.longdead=0;
6746 player[i].victim->skeleton.free=1;
6747 player[i].victim->skeleton.broken=0;
6749 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
6750 player[i].victim->skeleton.joints[l].velchange=0;
6751 player[i].victim->skeleton.joints[l].locked=0;
6757 Normalise(&relative);
6758 XYZ footvel,footpoint;
6760 footpoint=weapons[k].position;
6761 if(player[i].victim->weaponstuck!=-1){
6762 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
6763 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
6764 weapons[k].bloody=2;
6765 weapons[k].blooddrip=5;
6766 player[i].victim->weaponstuck=-1;
6767 player[i].victim->bloodloss+=2000;
6768 player[i].victim->DoDamage(2000);
6771 if(player[i].victim->num_weapons>0){
6772 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
6773 if(player[i].victim->weaponids[0]==k)
6774 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
6777 player[i].victim->weaponactive=-1;
6779 player[i].victim->getJointFor(abdomen).velocity+=relative*6;
6780 player[i].victim->getJointFor(neck).velocity+=relative*6;
6781 player[i].victim->getJointFor(rightshoulder).velocity+=relative*6;
6782 player[i].victim->getJointFor(leftshoulder).velocity+=relative*6;
6785 if(player[i].num_weapons>0){
6786 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6788 player[i].num_weapons++;
6789 player[i].weaponids[0]=k;
6796 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6797 if(weapons[player[i].weaponids[0]].getType()==knife){
6798 if(player[i].isIdle()||
6800 player[i].isCrouch()||
6801 player[i].targetanimation==sneakanim||
6804 for(int j=0;j<numplayers;j++){
6806 if(tutoriallevel!=1||tutorialstage==49)
6808 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
6809 findDistancefast(&player[i].coords,&player[j].coords)<100&&
6810 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
6811 !player[j].skeleton.free&&
6812 -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].rotation,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].rotation,0)*player[i].scale+player[i].coords)){
6813 if(!player[i].isFlip()){
6814 player[i].throwtogglekeydown=1;
6815 player[i].victim=&player[j];
6816 player[i].setAnimation(knifethrowanim);
6817 player[i].targetrotation=roughDirectionTo(player[i].coords,player[j].coords);
6818 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
6820 if(player[i].isFlip()){
6821 if(player[i].weaponactive!=-1){
6822 player[i].throwtogglekeydown=1;
6823 player[i].victim=&player[j];
6825 weapons[player[i].weaponids[0]].owner=-1;
6826 aim=player[i].victim->coords+DoRotation(player[i].victim->getJointFor(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(player[i].getJointFor(righthand).position,0,player[i].rotation,0)*player[i].scale);
6829 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
6831 weapons[player[i].weaponids[0]].velocity=aim*50;
6832 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
6833 weapons[player[i].weaponids[0]].missed=0;
6834 weapons[player[i].weaponids[0]].freetime=0;
6835 weapons[player[i].weaponids[0]].firstfree=1;
6836 weapons[player[i].weaponids[0]].physics=0;
6837 player[i].num_weapons--;
6838 if(player[i].num_weapons){
6839 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6841 player[i].weaponactive=-1;
6848 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
6849 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
6850 player[i].throwtogglekeydown=1;
6851 weapons[player[i].weaponids[0]].owner=-1;
6852 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
6853 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
6854 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
6855 weapons[player[i].weaponids[0]].missed=1;
6856 weapons[player[i].weaponids[0]].freetime=0;
6857 weapons[player[i].weaponids[0]].firstfree=1;
6858 weapons[player[i].weaponids[0]].physics=1;
6859 player[i].num_weapons--;
6860 if(player[i].num_weapons){
6861 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
6862 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
6865 player[i].weaponactive=-1;
6866 for(int j=0;j<numplayers;j++){
6867 player[j].wentforweapon=0;
6875 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
6876 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
6877 player[i].num_weapons==2&&
6878 player[i].weaponactive==-1&&
6879 player[i].isIdle()||
6881 player[i].weaponactive!=-1&&
6884 if(player[i].weaponactive!=-1)
6885 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
6887 if(isgood&&player[i].creature!=wolftype){
6888 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6889 player[i].setAnimation(drawrightanim);
6890 player[i].drawtogglekeydown=1;
6892 if((player[i].isIdle()||
6893 (player[i].aitype!=playercontrolled&&
6894 player[0].weaponactive!=-1&&
6895 player[i].isRun()))&&
6896 player[i].num_weapons&&
6897 weapons[player[i].weaponids[0]].getType()==sword){
6898 player[i].setAnimation(drawleftanim);
6899 player[i].drawtogglekeydown=1;
6901 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
6902 player[i].setAnimation(crouchdrawrightanim);
6903 player[i].drawtogglekeydown=1;
6910 if(player[i].weaponactive!=-1) {
6911 if (player[i].isCrouch()&&
6912 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
6914 player[i].onterrain&&
6915 player[i].num_weapons&&
6916 player[i].attackkeydown&&
6917 musictype!=stream_fighttheme) {
6918 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
6919 player[i].setAnimation(crouchstabanim);
6920 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
6921 player[i].setAnimation(swordgroundstabanim);
6922 player[i].hasvictim=0;
6926 if(!player[i].drawkeydown)
6927 player[i].drawtogglekeydown=0;
6934 absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
6936 absflatfacing=flatfacing;
6939 player[i].forwardkeydown=0;
6940 player[i].leftkeydown=0;
6941 player[i].backkeydown=0;
6942 player[i].rightkeydown=0;
6943 player[i].jumpkeydown=0;
6944 player[i].crouchkeydown=0;
6945 player[i].drawkeydown=0;
6946 player[i].throwkeydown=0;
6950 if(!animation[player[i].targetanimation].attack&&
6951 player[i].targetanimation!=staggerbackhighanim&&
6952 player[i].targetanimation!=staggerbackhardanim&&
6953 player[i].targetanimation!=backhandspringanim&&
6954 player[i].targetanimation!=dodgebackanim){
6955 if(!player[i].forwardkeydown)
6956 player[i].forwardstogglekeydown=0;
6957 if(player[i].crouchkeydown){
6961 player[i].superruntoggle=1;
6963 for(int j=0;j<numplayers;j++)
6964 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
6965 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
6966 player[i].superruntoggle=0;
6970 for(int j=0;j<numplayers;j++){
6971 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
6972 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
6973 player[j].victim==&player[i]&&
6974 (player[j].targetanimation==sweepanim||
6975 player[j].targetanimation==upunchanim||
6976 player[j].targetanimation==wolfslapanim||
6977 ((player[j].targetanimation==swordslashanim||
6978 player[j].targetanimation==knifeslashstartanim||
6979 player[j].targetanimation==staffhitanim||
6980 player[j].targetanimation==staffspinhitanim)&&
6981 findDistancefast(&player[j].coords,&player[i].coords)<2))){
6990 player[target].Reverse();
6991 player[i].lowreversaldelay=.5;
6993 if(player[i].isIdle()){
6994 player[i].setAnimation(player[i].getCrouch());
6995 player[i].transspeed=10;
6997 if(player[i].isRun()||
6998 (player[i].isStop()&&
6999 (player[i].leftkeydown||
7000 player[i].rightkeydown||
7001 player[i].forwardkeydown||
7002 player[i].backkeydown))){
7003 player[i].setAnimation(rollanim);
7004 player[i].transspeed=20;
7007 if(!player[i].crouchkeydown){
7009 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7011 if(player[i].isCrouch()){
7013 for(int j=0;j<numplayers;j++){
7015 !player[j].skeleton.free&&
7017 player[i].highreversaldelay<=0){
7018 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7019 player[j].victim==&player[i]&&
7020 (player[j].targetanimation==spinkickanim)&&
7021 player[i].isCrouch()){
7030 player[target].Reverse();
7031 player[i].highreversaldelay=.5;
7033 if(player[i].isCrouch()){
7034 if(!player[i].wasCrouch()){
7035 player[i].currentanimation=player[i].getCrouch();
7036 player[i].currentframe=0;
7038 player[i].setAnimation(player[i].getIdle());
7039 player[i].transspeed=10;
7042 if(player[i].targetanimation==sneakanim){
7043 player[i].setAnimation(player[i].getIdle());
7044 player[i].transspeed=10;
7047 if(player[i].forwardkeydown){
7048 if(player[i].isIdle()||
7049 (player[i].isStop()&&
7050 player[i].targetrotation==player[i].rotation)||
7051 (player[i].isLanding()&&
7052 player[i].targetframe>0&&
7053 !player[i].jumpkeydown)||
7054 (player[i].isLandhard()&&
7055 player[i].targetframe>0&&
7056 !player[i].jumpkeydown&&
7057 player[i].crouchkeydown)){
7058 if(player[i].aitype==passivetype)
7059 player[i].setAnimation(walkanim);
7061 player[i].setAnimation(player[i].getRun());
7063 if(player[i].isCrouch()){
7064 player[i].targetanimation=sneakanim;
7065 if(player[i].wasCrouch())
7067 player[i].targetframe=0;
7069 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7070 player[i].setAnimation(climbanim);
7071 player[i].targetframe=1;
7072 player[i].jumpclimb=1;
7074 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7075 player[i].velocity+=absflatfacing*5*multiplier;
7077 player[i].forwardstogglekeydown=1;
7080 if (player[i].rightkeydown){
7081 if(player[i].isIdle()||
7082 (player[i].isStop()&&
7083 player[i].targetrotation==player[i].rotation)||
7084 (player[i].isLanding()&&
7085 player[i].targetframe>0&&
7086 !player[i].jumpkeydown)||
7087 (player[i].isLandhard()&&
7088 player[i].targetframe>0&&
7089 !player[i].jumpkeydown&&
7090 player[i].crouchkeydown)){
7091 player[i].setAnimation(player[i].getRun());
7093 if(player[i].isCrouch()){
7094 player[i].targetanimation=sneakanim;
7095 if(player[i].wasCrouch())
7097 player[i].targetframe=0;
7099 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7100 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7102 player[i].targetrotation-=90;
7103 if(player[i].forwardkeydown)player[i].targetrotation+=45;
7104 if(player[i].backkeydown)player[i].targetrotation-=45;
7107 if ( player[i].leftkeydown){
7108 if(player[i].isIdle()||
7109 (player[i].isStop()&&
7110 player[i].targetrotation==player[i].rotation)||
7111 (player[i].isLanding()&&
7112 player[i].targetframe>0&&
7113 !player[i].jumpkeydown)||
7114 (player[i].isLandhard()&&
7115 player[i].targetframe>0&&
7116 !player[i].jumpkeydown&&
7117 player[i].crouchkeydown)){
7118 player[i].setAnimation(player[i].getRun());
7120 if(player[i].isCrouch()){
7121 player[i].targetanimation=sneakanim;
7122 if(player[i].wasCrouch())
7124 player[i].targetframe=0;
7126 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7127 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7129 player[i].targetrotation+=90;
7130 if(player[i].forwardkeydown)player[i].targetrotation-=45;
7131 if(player[i].backkeydown)player[i].targetrotation+=45;
7134 if(player[i].backkeydown){
7135 if(player[i].isIdle()||
7136 (player[i].isStop()&&
7137 player[i].targetrotation==player[i].rotation)||
7138 (player[i].isLanding()&&
7139 player[i].targetframe>0&&
7140 !player[i].jumpkeydown)||
7141 (player[i].isLandhard()&&
7142 player[i].targetframe>0&&
7143 !player[i].jumpkeydown&&
7144 player[i].crouchkeydown)){
7145 player[i].setAnimation(player[i].getRun());
7147 if(player[i].isCrouch()){
7148 player[i].targetanimation=sneakanim;
7149 if(player[i].wasCrouch())
7151 player[i].targetframe=0;
7153 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7154 player[i].velocity-=absflatfacing*5*multiplier;
7156 if(player[i].targetanimation==hanganim){
7157 player[i].currentanimation=jumpdownanim;
7158 player[i].targetanimation=jumpdownanim;
7160 player[i].currentframe=0;
7161 player[i].targetframe=1;
7162 player[i].velocity=0;
7163 player[i].velocity.y+=gravity;
7164 player[i].coords.y-=1.4;
7165 player[i].grabdelay=1;
7167 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7168 player[i].targetrotation+=180;
7171 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7172 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7174 player[i].targetanimation==walkanim||
7175 player[i].isCrouch()||
7176 player[i].targetanimation==sneakanim)&&
7177 player[i].jumppower>1)&&
7178 ((player[i].targetanimation!=rabbitrunninganim&&
7179 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7180 player[i].jumpstart=0;
7181 player[i].setAnimation(jumpupanim);
7182 player[i].rotation=player[i].targetrotation;
7183 player[i].transspeed=20;
7184 player[i].FootLand(0,1);
7185 player[i].FootLand(1,1);
7189 flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
7191 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7192 if(!movekey)player[i].velocity=0;
7197 for(int j=0;j<numplayers;j++){
7198 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7199 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7200 player[j].victim==&player[i]&&
7201 (player[j].targetanimation==sweepanim)){
7202 if(target>=0)target=-1;
7207 if(target>=0)player[i].velocity.y=1;
7208 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7209 player[i].velocity.y=7;
7210 player[i].crouchtogglekeydown=1;
7212 else player[i].velocity.y=5;
7214 if(mousejump&&i==0&&debugmode){
7215 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7216 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7219 player[i].coords.y+=.2;
7220 player[i].jumppower-=1;
7223 emit_sound_at(whooshsound, player[i].coords, 128.);
7225 emit_sound_at(jumpsound, player[i].coords, 128.);
7227 if((player[i].isIdle())&&player[i].jumppower>1){
7228 player[i].setAnimation(player[i].getLanding());
7229 player[i].targetframe=2;
7230 player[i].landhard=0;
7231 player[i].jumpstart=1;
7232 player[i].tempdeltav=deltav;
7234 if(player[i].targetanimation==jumpupanim&&
7238 player[i].aitype!=playercontrolled)){
7239 if(player[i].jumppower>multiplier*6){
7240 player[i].velocity.y+=multiplier*6;
7241 player[i].jumppower-=multiplier*6;
7243 if(player[i].jumppower<=multiplier*6){
7244 player[i].velocity.y+=player[i].jumppower;
7245 player[i].jumppower=0;
7248 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7252 if(player[i].isRun()||player[i].targetanimation==walkanim)
7253 player[i].setAnimation(player[i].getStop());
7254 if(player[i].targetanimation==sneakanim){
7255 player[i].targetanimation=player[i].getCrouch();
7256 if(player[i].currentanimation==sneakanim)
7258 player[i].targetframe=0;
7261 if(player[i].targetanimation==walkanim&&
7262 (player[i].aitype==attacktypecutoff||
7263 player[i].aitype==searchtype||
7264 (player[i].aitype==passivetype&&
7265 player[i].numwaypoints<=1)))
7266 player[i].setAnimation(player[i].getStop());
7267 if(player[i].isRun()&&(player[i].aitype==passivetype))
7268 player[i].setAnimation(player[i].getStop());
7271 if(player[i].targetanimation==rollanim)
7272 player[i].targetrotation=oldtargetrotation;
7276 for(int k=0;k<numplayers;k++){
7277 if(fabs(player[k].rotation-player[k].targetrotation)>180){
7278 if(player[k].rotation>player[k].targetrotation)
7279 player[k].rotation-=360;
7281 player[k].rotation+=360;
7284 //stop to turn in right direction
7285 if(fabs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7286 player[k].setAnimation(player[k].getStop());
7288 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7289 player[k].targettilt=0;
7291 if(player[k].targetanimation!=jumpupanim&&
7292 player[k].targetanimation!=backhandspringanim&&
7293 player[k].targetanimation!=jumpdownanim&&
7294 !player[k].isFlip()){
7295 player[k].targettilt=0;
7296 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7297 player[k].jumppower=0;
7298 player[k].jumppower+=multiplier*7;
7299 if(player[k].isCrouch())
7300 player[k].jumppower+=multiplier*7;
7301 if(player[k].jumppower>5)
7302 player[k].jumppower=5;
7305 if(player[k].isRun())
7306 player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
7308 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7309 player[k].grabdelay-=multiplier;
7313 for(int k=0;k<numplayers;k++){
7314 player[k].DoAnimations();
7315 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7316 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7322 for(int j=numenvsounds-1;j>=0;j--){
7323 envsoundlife[j]-=multiplier;
7324 if(envsoundlife[j]<0){
7326 envsoundlife[j]=envsoundlife[numenvsounds];
7327 envsound[j]=envsound[numenvsounds];
7331 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7333 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7335 if(tutoriallevel==1){
7352 if(tutorialstage>=51)
7353 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7354 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7355 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7357 emit_stream_np(stream_menutheme);
7366 if(tutorialstage<51)
7367 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7368 emit_sound_at(fireendsound, player[0].coords);
7370 player[0].coords=(oldtemp+oldtemp2)/2;
7374 if(tutorialstage>=14&&tutorialstage<50)
7375 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7376 emit_sound_at(fireendsound, player[1].coords);
7378 for(int i=0;i<player[1].skeleton.num_joints;i++){
7380 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7381 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7382 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;
7383 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7384 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7388 player[1].coords=(oldtemp+oldtemp2)/2;
7389 for(int i=0;i<player[1].skeleton.num_joints;i++){
7390 player[1].skeleton.joints[i].velocity=0;
7392 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7393 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7394 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;
7395 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7396 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7404 static float gLoc[3];
7408 static float vel[3];
7409 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7410 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7411 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7413 //Set orientation with forward and up vectors
7414 static XYZ upvector;
7418 upvector=DoRotation(upvector,-rotation2+90,0,0);
7419 upvector=DoRotation(upvector,0,0-rotation,0);
7424 facing=DoRotation(facing,-rotation2,0,0);
7425 facing=DoRotation(facing,0,0-rotation,0);
7428 static float ori[6];
7432 ori[3] = -upvector.x;
7433 ori[4] = upvector.y;
7434 ori[5] = -upvector.z;
7436 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7443 if(Input::isKeyPressed(SDLK_F1))
7447 void Game::TickOnce(){
7449 rotation+=multiplier*5;
7451 if(directing||indialogue==-1) {
7452 rotation+=deltah*.7;
7454 rotation2+=deltav*.7;
7456 rotation2-=deltav*.7;
7464 void Game::TickOnceAfter(){
7465 static XYZ colviewer;
7466 static XYZ coltarget;
7470 static float changedelay;
7471 static bool alldead;
7472 static float unseendelay;
7473 static float cameraspeed;
7477 if(environment==snowyenvironment)
7478 leveltheme=stream_snowtheme;
7479 if(environment==grassyenvironment)
7480 leveltheme=stream_grasstheme;
7481 if(environment==desertenvironment)
7482 leveltheme=stream_deserttheme;
7486 musictype=leveltheme;
7487 for(int i=0;i<numplayers;i++){
7488 if((player[i].aitype==attacktypecutoff||
7489 player[i].aitype==getweapontype||
7490 player[i].aitype==gethelptype||
7491 player[i].aitype==searchtype)&&
7492 !player[i].dead/*&&player[i].surprised<=0*/&&
7493 (player[i].targetanimation!=sneakattackedanim&&
7494 player[i].targetanimation!=knifesneakattackedanim&&
7495 player[i].targetanimation!=swordsneakattackedanim)){
7496 musictype=stream_fighttheme;
7501 musictype=stream_menutheme;
7504 if(musictype==stream_fighttheme)
7507 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7508 unseendelay-=multiplier;
7510 musictype=stream_fighttheme;
7515 musictype=stream_menutheme;
7523 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7524 emit_sound_np(alarmsound);
7525 musicselected=musictype;
7527 if(musicselected==leveltheme)
7528 musicvolume[0]+=multiplier*450;
7530 musicvolume[0]-=multiplier*450;
7531 if(musicselected==stream_fighttheme)
7532 musicvolume[1]+=multiplier*450;
7534 musicvolume[1]-=multiplier*450;
7535 if(musicselected==stream_menutheme)
7536 musicvolume[2]+=multiplier*450;
7538 musicvolume[2]-=multiplier*450;
7540 for(int i=0;i<3;i++){
7541 if(musicvolume[i]<0)
7543 if(musicvolume[i]>512)
7547 if(musicvolume[2]>128&&!loading&&!mainmenu)
7551 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7552 emit_stream_np(leveltheme, musicvolume[0]);
7553 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7554 emit_stream_np(stream_fighttheme, musicvolume[1]);
7555 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7556 emit_stream_np(stream_menutheme, musicvolume[2]);
7557 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7558 pause_sound(leveltheme);
7559 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7560 pause_sound(stream_fighttheme);
7561 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7562 pause_sound(stream_menutheme);
7564 if(musicvolume[0]!=oldmusicvolume[0])
7565 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7566 if(musicvolume[1]!=oldmusicvolume[1])
7567 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7568 if(musicvolume[2]!=oldmusicvolume[2])
7569 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7571 for(int i=0;i<3;i++)
7572 oldmusicvolume[i]=musicvolume[i];
7574 pause_sound(leveltheme);
7575 pause_sound(stream_fighttheme);
7576 pause_sound(stream_menutheme);
7578 for(int i=0;i<4;i++){
7579 oldmusicvolume[i]=0;
7585 for(int i=0;i<numhotspots;i++){
7586 if(hotspottype[i]>10&&hotspottype[i]<20){
7587 if(player[hotspottype[i]-10].dead==0)
7589 else if(killhotspot==2)
7598 for(int i=0;i<numhotspots;i++)
7599 if(hotspottype[i]==-1)
7600 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
7604 for(int i=1;i<numplayers;i++)
7605 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7607 if(numalarmed>maxalarmed)
7608 maxalarmed=numalarmed;
7610 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7611 if(player[0].dead&&changedelay<=0){
7613 targetlevel=whichlevel;
7616 for(int i=1;i<numplayers;i++) {
7617 if(!player[i].dead&&player[i].howactive<typedead1) {
7624 if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
7626 targetlevel=whichlevel+1;
7627 if(targetlevel>numchallengelevels-1)targetlevel=0;
7629 if(winhotspot||windialogue) {
7631 targetlevel=whichlevel+1;
7632 if(targetlevel>numchallengelevels-1)targetlevel=0;
7638 targetlevel=whichlevel+1;
7639 if(targetlevel>numchallengelevels-1)targetlevel=0;
7642 if(changedelay>0&&!player[0].dead&&!won) {
7643 //high scores, awards, win
7645 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7648 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7664 if(!editorenabled&&gameon&&!mainmenu) {
7665 if(changedelay!=-999)
7666 changedelay-=multiplier/7;
7668 targetlevel=whichlevel;
7669 if(loading==2&&!campaign){
7672 fireSound(firestartsound);
7674 if(!player[0].dead&&targetlevel!=whichlevel)
7675 startbonustotal=bonustotal;
7677 Loadlevel(whichlevel);
7679 Loadlevel(targetlevel);
7685 if(loading==2&&targetlevel==whichlevel){
7689 fireSound(firestartsound);
7691 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
7697 if(changedelay<=-999&&
7701 (alldead&&maptype==mapkilleveryone)||
7705 if((player[0].dead||
7706 (alldead&&maptype==mapkilleveryone)||
7711 if(whichlevel!=-2&&!loading&&!player[0].dead) {
7721 // campaignchoosenext determines what to do when the level is complete:
7722 // 0 = load next level
7723 // 1 = go back to level select screen
7724 // 2 = stealthload next level
7725 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
7726 if(campaignlevels[actuallevel].nextlevel.empty())
7728 } else if(mainmenu==0&&winfreeze) {
7729 stealthloading = (campaignlevels[actuallevel].choosenext==2);
7731 if(!stealthloading){
7732 fireSound(firestartsound);
7747 actuallevel=campaignlevels[actuallevel].nextlevel.front();
7750 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
7754 pause_sound(stream_menutheme);
7765 oldmusictype=musictype;
7771 facing=DoRotation(facing,-rotation2,0,0);
7772 facing=DoRotation(facing,0,0-rotation,0);
7773 viewerfacing=facing;
7776 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;
7777 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;
7779 if(player[0].skeleton.free){
7780 for(int i=0;i<player[0].skeleton.num_joints;i++){
7781 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
7782 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
7786 if(player[0].skeleton.free!=2&&!autocam){
7788 if(findLengthfast(&player[0].velocity)>400){
7789 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7791 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7792 coltarget=target-cameraloc;
7793 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7795 Normalise(&coltarget);
7796 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7797 else cameraloc=cameraloc+coltarget*multiplier*8;
7799 if(editorenabled)cameraloc=target;
7800 cameradist+=multiplier*5;
7801 if(cameradist>2.3)cameradist=2.3;
7802 viewer=cameraloc-facing*cameradist;
7804 coltarget=cameraloc;
7805 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7806 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7807 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7808 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7810 coltarget=cameraloc;
7811 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7813 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7814 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7815 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7817 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7821 cameradist=findDistance(&viewer,&target);
7822 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7823 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7824 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7827 if(player[0].skeleton.free!=2&&autocam){
7829 if(findLengthfast(&player[0].velocity)>400){
7830 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
7832 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
7833 cameradist+=multiplier*5;
7834 if(cameradist>3.3)cameradist=3.3;
7835 coltarget=target-cameraloc;
7836 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
7837 else if(findLengthfast(&coltarget)>1)
7839 Normalise(&coltarget);
7840 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
7841 else cameraloc=cameraloc+coltarget*multiplier*8;
7843 if(editorenabled)cameraloc=target;
7846 coltarget=cameraloc;
7847 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
7848 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7849 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7850 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7852 coltarget=cameraloc;
7853 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
7855 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
7856 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
7857 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
7859 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
7863 cameradist=findDistance(&viewer,&target);
7864 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
7865 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
7866 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
7869 if(camerashake>.8)camerashake=.8;
7870 //if(woozy>10)woozy=10;
7871 //woozy+=multiplier;
7873 if(player[0].dead)camerashake=0;
7874 if(player[0].dead)woozy=0;
7875 camerashake-=multiplier*2;
7876 blackout-=multiplier*2;
7877 //if(player[0].isCrouch())woozy-=multiplier*8;
7878 if(camerashake<0)camerashake=0;
7879 if(blackout<0)blackout=0;
7880 //if(woozy<0)woozy=0;
7882 viewer.x+=(float)(Random()%100)*.0005*camerashake;
7883 viewer.y+=(float)(Random()%100)*.0005*camerashake;
7884 viewer.z+=(float)(Random()%100)*.0005*camerashake;