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>
34 #include "openal_wrapper.h"
37 #include "Animation.h"
46 // Added more evilness needed for MSVC
48 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
49 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
53 extern float multiplier;
55 extern int environment;
56 extern Terrain terrain;
57 extern float screenwidth,screenheight;
60 extern float texdetail;
61 extern Objects objects;
63 extern float slomodelay;
64 extern bool floatjump;
67 extern float camerashake;
69 extern float blackout;
70 extern bool cellophane;
71 extern bool musictoggle;
72 extern int difficulty;
73 extern int bloodtoggle;
74 extern bool invertmouse;
76 extern float precipdelay;
77 extern XYZ viewerfacing;
78 extern bool ambientsound;
79 extern bool mousejump;
80 extern float viewdistance;
82 extern bool keyboardfrozen;
83 extern bool loadingstuff;
84 extern XYZ windvector;
85 extern bool debugmode;
86 static int leveltheme;
88 extern int oldmainmenu;
89 extern bool visibleloading;
90 extern XYZ envsound[30];
91 extern float envsoundvol[30];
92 extern int numenvsounds;
93 extern float envsoundlife[30];
94 extern float usermousesensitivity;
95 extern bool ismotionblur;
96 extern bool showdamagebar; // (des)activate the damage bar
98 extern float tintr,tintg,tintb;
99 extern bool skyboxtexture;
100 extern float skyboxr;
101 extern float skyboxg;
102 extern float skyboxb;
103 extern float skyboxlightr;
104 extern float skyboxlightg;
105 extern float skyboxlightb;
106 extern float fadestart;
107 extern float slomospeed;
108 extern float slomofreq;
109 extern int tutoriallevel;
110 extern float smoketex;
111 extern float tutorialstagetime;
112 extern int tutorialstage;
113 extern float tutorialmaxtime;
114 extern float tutorialsuccess;
115 extern bool againbonus;
116 extern bool reversaltrain;
117 extern bool canattack;
118 extern bool cananger;
119 extern float damagedealt;
121 extern int editoractive;
122 extern int editorpathtype;
123 extern TGAImageRec texture;
125 extern float hostiletime;
127 extern bool gamestarted;
129 extern int numhotspots;
130 extern int killhotspot;
131 extern XYZ hotspot[40];
132 extern int hotspottype[40];
133 extern float hotspotsize[40];
134 extern char hotspottext[40][256];
135 extern int currenthotspot;
139 extern bool stillloading;
140 extern bool winfreeze;
142 extern bool campaign;
146 void Loadlevel(int which);
147 void Loadlevel(const char *name);
151 class CampaignLevel {
154 struct Position { int x,y; };
157 std::string description;
160 0 = Immediately load next level at the end of this one.
161 1 = Go back to the world map.
162 2 = Don't bring up the Fiery loading screen. Maybe other things, I've not investigated.
164 //int numnext; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't.
165 std::vector<int> nextlevel;
167 CampaignLevel() : width(10) {
172 int getStartX() { return 30+120+location.x*400/512; }
173 int getStartY() { return 30+30+(512-location.y)*400/512; }
174 int getEndX() { return getStartX()+width; }
175 int getEndY() { return getStartY()+width; }
178 center.x=getStartX()+width/2;
179 center.y=getStartY()+width/2;
182 int getWidth() { return width; }
183 istream& operator<< (istream& is) {
190 for(int pos = description.find('_');pos!=string::npos;pos = description.find('_',pos)) {
191 description.replace(pos,1,1,' ');
198 for(int j=0;j<numnext;j++) {
201 nextlevel.push_back(next-1);
209 friend istream& operator>> (istream& is, CampaignLevel& cl) {
217 vector<CampaignLevel> campaignlevels;
220 bool winhotspot = false;
221 bool windialogue = false;
224 float cameradist = 0;
225 bool oldattackkey = 0;
227 float musicvolume[4] = {};
228 float oldmusicvolume[4] = {};
229 int musicselected = 0;
233 static const char *rabbitskin[] = {
234 ":Data:Textures:Fur3.jpg",
235 ":Data:Textures:Fur.jpg",
236 ":Data:Textures:Fur2.jpg",
237 ":Data:Textures:Lynx.jpg",
238 ":Data:Textures:Otter.jpg",
239 ":Data:Textures:Opal.jpg",
240 ":Data:Textures:Sable.jpg",
241 ":Data:Textures:Chocolate.jpg",
242 ":Data:Textures:BW2.jpg",
243 ":Data:Textures:WB2.jpg"
246 static const char *wolfskin[] = {
247 ":Data:Textures:Wolf.jpg",
248 ":Data:Textures:Darkwolf.jpg",
249 ":Data:Textures:Snowwolf.jpg"
252 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
253 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
255 static const char **creatureskin[] = {rabbitskin, wolfskin};
257 /* Return true if PFX is a prefix of STR (case-insensitive). */
258 static bool stripfx(const char *str, const char *pfx)
260 return !strncasecmp(str, pfx, strlen(pfx));
263 static const char *cmd_names[] = {
264 #define DECLARE_COMMAND(cmd) #cmd,
265 #include "ConsoleCmds.h"
266 #undef DECLARE_COMMAND
269 typedef void (*console_handler)(const char *args);
271 #define DECLARE_COMMAND(cmd) static void ch_##cmd(const char *args);
272 #include "ConsoleCmds.h"
273 #undef DECLARE_COMMAND
275 static console_handler cmd_handlers[] = {
276 #define DECLARE_COMMAND(cmd) ch_##cmd,
277 #include "ConsoleCmds.h"
278 #undef DECLARE_COMMAND
285 // TODO: this is slightly incorrect
286 inline float roughDirection(XYZ vec){
288 float angle=-asin(-vec.x)*180/M_PI;
293 inline float roughDirectionTo(XYZ start, XYZ end){
294 return roughDirection(end-start);
296 inline float pitchOf(XYZ vec){
298 return -asin(vec.y)*180/M_PI;
300 inline float pitchTo(XYZ start, XYZ end){
301 return pitchOf(end-start);
303 inline float sq(float n) { return n*n; }
304 inline float stepTowardf(float from, float to, float by){
305 if(fabs(from-to)<by) return to;
306 else if(from>to) return from-by;
310 void playdialogueboxsound(){
312 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
313 temppos=temppos-viewer;
318 switch(dialogueboxsound[whichdialogue][indialogue]){
319 case -6: sound=alarmsound; break;
320 case -4: sound=consolefailsound; break;
321 case -3: sound=consolesuccesssound; break;
322 case -2: sound=firestartsound; break;
323 case -1: sound=fireendsound; break;
324 case 1: sound=rabbitchitter; break;
325 case 2: sound=rabbitchitter2; break;
326 case 3: sound=rabbitpainsound; break;
327 case 4: sound=rabbitpain1sound; break;
328 case 5: sound=rabbitattacksound; break;
329 case 6: sound=rabbitattack2sound; break;
330 case 7: sound=rabbitattack3sound; break;
331 case 8: sound=rabbitattack4sound; break;
332 case 9: sound=growlsound; break;
333 case 10: sound=growl2sound; break;
334 case 11: sound=snarlsound; break;
335 case 12: sound=snarl2sound; break;
336 case 13: sound=barksound; break;
337 case 14: sound=bark2sound; break;
338 case 15: sound=bark3sound; break;
339 case 16: sound=barkgrowlsound; break;
343 emit_sound_at(sound, temppos);
346 // ================================================================
348 bool AddClothes(const char *fileName, GLubyte *array) {
351 unsigned char fileNamep[256];
352 CopyCStringToPascal(fileName,fileNamep);
354 opened=upload_image( fileNamep ,1);
367 int bytesPerPixel=texture.bpp/8;
371 for(int i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
372 if(bytesPerPixel==3)alphanum=255;
373 else if((i+1)%4==0)alphanum=texture.data[i];
375 if((i+1)%4||bytesPerPixel==3){
376 if((i%4)==0)texture.data[i]*=tintr;
377 if((i%4)==1)texture.data[i]*=tintg;
378 if((i%4)==2)texture.data[i]*=tintb;
379 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
390 static void ch_quit(const char *args)
395 static void ch_map(const char *args)
402 static void ch_save(const char *args){
404 snprintf(buf, 63, ":Data:Maps:%s", args);
409 tfile=fopen( ConvertFileName(buf), "wb" );
410 fpackf(tfile, "Bi", mapvers);
411 fpackf(tfile, "Bi", maptype);
412 fpackf(tfile, "Bi", hostile);
413 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
414 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
415 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
416 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", player[0].coords.x, player[0].coords.y, player[0].coords.z,
417 player[0].yaw, player[0].targetyaw, player[0].num_weapons);
418 if(player[0].num_weapons>0&&player[0].num_weapons<5)
419 for(int j=0;j<player[0].num_weapons;j++)
420 fpackf(tfile, "Bi", weapons[player[0].weaponids[j]].getType());
422 fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
423 fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
424 fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
425 fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
427 fpackf(tfile, "Bi", player[0].numclothes);
429 fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
431 fpackf(tfile, "Bi", numdialogues);
433 for(int k=0;k<numdialogues;k++){
434 fpackf(tfile, "Bi", numdialogueboxes[k]);
435 fpackf(tfile, "Bi", dialoguetype[k]);
436 for(int l=0;l<10;l++){
437 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
438 fpackf(tfile, "Bf", participantyaw[k][l]);
440 for(int l=0;l<numdialogueboxes[k];l++){
441 fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
442 fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
443 fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
444 fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
445 fpackf(tfile, "Bi", dialogueboxsound[k][l]);
447 int templength=strlen(dialoguetext[k][l]);
448 fpackf(tfile, "Bi",(templength));
449 for(int m=0;m<templength;m++){
450 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
451 if(dialoguetext[k][l][m]=='\0')
455 templength=strlen(dialoguename[k][l]);
456 fpackf(tfile, "Bi",templength);
457 for(int m=0;m<templength;m++){
458 fpackf(tfile, "Bb", dialoguename[k][l][m]);
459 if(dialoguename[k][l][m]=='\0')
463 fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
464 fpackf(tfile, "Bi", participantfocus[k][l]);
465 fpackf(tfile, "Bi", participantaction[k][l]);
467 for(int m=0;m<10;m++)
468 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
470 fpackf(tfile, "Bf Bf",dialoguecamerayaw[k][l],dialoguecamerapitch[k][l]);
474 for(int k=0;k<player[0].numclothes;k++){
475 int templength=strlen(player[0].clothes[k]);
476 fpackf(tfile, "Bi", templength);
477 for(int l=0;l<templength;l++)
478 fpackf(tfile, "Bb", player[0].clothes[k][l]);
479 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
482 fpackf(tfile, "Bi", environment);
484 fpackf(tfile, "Bi", objects.numobjects);
486 for(int k=0;k<objects.numobjects;k++)
487 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.yaw[k], objects.pitch[k],
488 objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
490 fpackf(tfile, "Bi", numhotspots);
491 for(int i=0;i<numhotspots;i++){
492 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
493 int templength=strlen(hotspottext[i]);
494 fpackf(tfile, "Bi",templength);
495 for(int l=0;l<templength;l++)
496 fpackf(tfile, "Bb", hotspottext[i][l]);
499 fpackf(tfile, "Bi", numplayers);
500 if(numplayers<maxplayers)
501 for(int j=1;j<numplayers;j++){
502 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature,
503 player[j].coords.x, player[j].coords.y, player[j].coords.z,
504 player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].yaw);
505 if(player[j].num_weapons<5)
506 for(int k=0;k<player[j].num_weapons;k++)
507 fpackf(tfile, "Bi", weapons[player[j].weaponids[k]].getType());
508 if(player[j].numwaypoints<30){
509 fpackf(tfile, "Bi", player[j].numwaypoints);
510 for(int k=0;k<player[j].numwaypoints;k++){
511 fpackf(tfile, "Bf", player[j].waypoints[k].x);
512 fpackf(tfile, "Bf", player[j].waypoints[k].y);
513 fpackf(tfile, "Bf", player[j].waypoints[k].z);
514 fpackf(tfile, "Bi", player[j].waypointtype[k]);
516 fpackf(tfile, "Bi", player[j].waypoint);
518 player[j].numwaypoints=0;
519 player[j].waypoint=0;
520 fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
523 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
524 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
525 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
526 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
528 float headprop, bodyprop, armprop, legprop;
529 if(player[j].creature==wolftype){
530 headprop=player[j].proportionhead.x/1.1;
531 bodyprop=player[j].proportionbody.x/1.1;
532 armprop=player[j].proportionarms.x/1.1;
533 legprop=player[j].proportionlegs.x/1.1;
534 }else if(player[j].creature==rabbittype){
535 headprop=player[j].proportionhead.x/1.2;
536 bodyprop=player[j].proportionbody.x/1.05;
537 armprop=player[j].proportionarms.x/1.00;
538 legprop=player[j].proportionlegs.x/1.1;
541 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
543 fpackf(tfile, "Bi", player[j].numclothes);
544 if(player[j].numclothes)
545 for(int k=0;k<player[j].numclothes;k++){
547 templength=strlen(player[j].clothes[k]);
548 fpackf(tfile, "Bi", templength);
549 for(int l=0;l<templength;l++)
550 fpackf(tfile, "Bb", player[j].clothes[k][l]);
551 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
555 fpackf(tfile, "Bi", numpathpoints);
556 for(int j=0;j<numpathpoints;j++){
557 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
558 for(int k=0;k<numpathpointconnect[j];k++)
559 fpackf(tfile, "Bi", pathpointconnect[j][k]);
562 fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
567 static void ch_cellar(const char *args)
569 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
572 static void ch_tint(const char *args)
574 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
577 static void ch_tintr(const char *args)
582 static void ch_tintg(const char *args)
587 static void ch_tintb(const char *args)
592 static void ch_speed(const char *args)
594 player[0].speedmult = atof(args);
597 static void ch_strength(const char *args)
599 player[0].power = atof(args);
602 static void ch_power(const char *args)
604 player[0].power = atof(args);
607 static void ch_size(const char *args)
609 player[0].scale = atof(args) * .2;
612 static int find_closest()
615 float closestdist = std::numeric_limits<float>::max();
617 for (int i = 1; i < numplayers; i++) {
619 distance = findDistancefast(&player[i].coords,&player[0].coords);
620 if (distance < closestdist) {
621 closestdist = distance;
628 static void ch_sizenear(const char *args)
630 int closest = find_closest();
633 player[closest].scale = atof(args) * .2;
636 static void set_proportion(int pnum, const char *args)
638 float headprop,bodyprop,armprop,legprop;
640 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
642 if(player[pnum].creature==wolftype){
643 player[pnum].proportionhead=1.1*headprop;
644 player[pnum].proportionbody=1.1*bodyprop;
645 player[pnum].proportionarms=1.1*armprop;
646 player[pnum].proportionlegs=1.1*legprop;
647 } else if(player[pnum].creature==rabbittype){
648 player[pnum].proportionhead=1.2*headprop;
649 player[pnum].proportionbody=1.05*bodyprop;
650 player[pnum].proportionarms=1.00*armprop;
651 player[pnum].proportionlegs=1.1*legprop;
652 player[pnum].proportionlegs.y=1.05*legprop;
656 static void ch_proportion(const char *args)
658 set_proportion(0, args);
661 static void ch_proportionnear(const char *args)
663 int closest = find_closest();
665 set_proportion(closest, args);
668 static void set_protection(int pnum, const char *args)
670 float head, high, low;
671 sscanf(args, "%f%f%f", &head, &high, &low);
673 player[pnum].protectionhead = head;
674 player[pnum].protectionhigh = high;
675 player[pnum].protectionlow = low;
678 static void ch_protection(const char *args)
680 set_protection(0, args);
683 static void ch_protectionnear(const char *args)
685 int closest = find_closest();
687 set_protection(closest, args);
690 static void set_armor(int pnum, const char *args)
692 float head, high, low;
693 sscanf(args, "%f%f%f", &head, &high, &low);
695 player[pnum].armorhead = head;
696 player[pnum].armorhigh = high;
697 player[pnum].armorlow = low;
700 static void ch_armor(const char *args)
705 static void ch_armornear(const char *args)
707 int closest = find_closest();
709 set_armor(closest, args);
712 static void ch_protectionreset(const char *args)
714 set_protection(0, "1 1 1");
715 set_armor(0, "1 1 1");
718 static void set_metal(int pnum, const char *args)
720 float head, high, low;
721 sscanf(args, "%f%f%f", &head, &high, &low);
723 player[pnum].metalhead = head;
724 player[pnum].metalhigh = high;
725 player[pnum].metallow = low;
728 static void ch_metal(const char *args)
733 static void set_noclothes(int pnum, const char *args)
735 player[pnum].numclothes = 0;
736 LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
737 &player[pnum].skeleton.drawmodel.textureptr,1,
738 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
741 static void ch_noclothes(const char *args)
743 set_noclothes(0, args);
746 static void ch_noclothesnear(const char *args)
748 int closest = find_closest();
750 set_noclothes(closest, args);
754 static void set_clothes(int pnum, const char *args)
757 snprintf(buf, 63, ":Data:Textures:%s.png", args);
759 if (!AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
762 player[pnum].DoMipmaps();
763 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
764 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
765 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
766 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
767 player[pnum].numclothes++;
770 static void ch_clothes(const char *args)
772 set_clothes(0, args);
775 static void ch_clothesnear(const char *args)
777 int closest = find_closest();
779 set_clothes(closest, args);
782 static void ch_belt(const char *args)
784 player[0].skeleton.clothes = !player[0].skeleton.clothes;
788 static void ch_cellophane(const char *args)
790 cellophane = !cellophane;
791 float mul = cellophane ? 0 : 1;
793 for (int i = 0; i < numplayers; i++) {
794 player[i].proportionhead.z = player[i].proportionhead.x * mul;
795 player[i].proportionbody.z = player[i].proportionbody.x * mul;
796 player[i].proportionarms.z = player[i].proportionarms.x * mul;
797 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
801 static void ch_funnybunny(const char *args)
803 player[0].skeleton.id=0;
804 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
805 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
806 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
807 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
808 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
809 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
810 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
811 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
812 player[0].creature=rabbittype;
814 player[0].headless=0;
815 player[0].damagetolerance=200;
816 set_proportion(0, "1 1 1 1");
819 static void ch_wolfie(const char *args)
821 player[0].skeleton.id=0;
822 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
823 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
824 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
825 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
826 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
827 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
828 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
829 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
830 player[0].creature=wolftype;
831 player[0].damagetolerance=300;
832 set_proportion(0, "1 1 1 1");
835 static void ch_wolfieisgod(const char *args)
840 static void ch_wolf(const char *args)
842 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
843 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
846 static void ch_snowwolf(const char *args)
848 LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
849 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
852 static void ch_darkwolf(const char *args)
854 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
855 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
858 static void ch_lizardwolf(const char *args)
860 LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
861 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
864 static void ch_white(const char *args)
866 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
867 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
870 static void ch_brown(const char *args)
872 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
873 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
876 static void ch_black(const char *args)
878 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
879 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
882 static void ch_sizemin(const char *args)
884 for (int i = 1; i < numplayers; i++)
885 if (player[i].scale < 0.8 * 0.2)
886 player[i].scale = 0.8 * 0.2;
889 static void ch_tutorial(const char *args)
891 tutoriallevel = atoi(args);
894 static void ch_hostile(const char *args)
896 hostile = atoi(args);
899 static void ch_indemo(const char *args)
902 hotspot[numhotspots]=player[0].coords;
903 hotspotsize[numhotspots]=0;
904 hotspottype[numhotspots]=-111;
905 strcpy(hotspottext[numhotspots],"mapname");
909 static void ch_notindemo(const char *args)
915 static void ch_type(const char *args)
917 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
918 for (int i = 0; i < n; i++)
919 if (stripfx(args, editortypenames[i])) {
925 static void ch_path(const char *args)
927 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
928 for (int i = 0; i < n; i++)
929 if (stripfx(args, pathtypenames[i])) {
935 static void ch_hs(const char *args)
937 hotspot[numhotspots]=player[0].coords;
941 sscanf(args, "%f%d %n", &size, &type, &shift);
943 hotspotsize[numhotspots] = size;
944 hotspottype[numhotspots] = type;
946 strcpy(hotspottext[numhotspots], args + shift);
947 strcat(hotspottext[numhotspots], "\n");
952 static void ch_dialogue(const char *args)
955 char buf1[32], buf2[64];
957 sscanf(args, "%d %31s", &dlg, buf1);
958 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
960 dialoguetype[numdialogues] = dlg;
962 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
963 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
965 ifstream ipstream(ConvertFileName(buf2));
966 ipstream.ignore(256,':');
967 ipstream >> numdialogueboxes[numdialogues];
968 for(int i=0;i<numdialogueboxes[numdialogues];i++){
969 ipstream.ignore(256,':');
970 ipstream.ignore(256,':');
971 ipstream.ignore(256,' ');
972 ipstream >> dialogueboxlocation[numdialogues][i];
973 ipstream.ignore(256,':');
974 ipstream >> dialogueboxcolor[numdialogues][i][0];
975 ipstream >> dialogueboxcolor[numdialogues][i][1];
976 ipstream >> dialogueboxcolor[numdialogues][i][2];
977 ipstream.ignore(256,':');
978 ipstream.getline(dialoguename[numdialogues][i],64);
979 ipstream.ignore(256,':');
980 ipstream.ignore(256,' ');
981 ipstream.getline(dialoguetext[numdialogues][i],128);
982 for(int j=0;j<128;j++){
983 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
985 ipstream.ignore(256,':');
986 ipstream >> dialogueboxsound[numdialogues][i];
989 for(int i=0;i<numdialogueboxes[numdialogues];i++){
990 for(int j=0;j<numplayers;j++){
991 participantfacing[numdialogues][i][j]=player[j].facing;
998 whichdialogue=numdialogues;
1003 static void ch_fixdialogue(const char *args)
1005 char buf1[32], buf2[64];
1008 sscanf(args, "%d %31s", &whichdi, buf1);
1009 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
1011 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
1012 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
1014 ifstream ipstream(ConvertFileName(buf2));
1015 ipstream.ignore(256,':');
1016 ipstream >> numdialogueboxes[whichdi];
1017 for(int i=0;i<numdialogueboxes[whichdi];i++){
1018 ipstream.ignore(256,':');
1019 ipstream.ignore(256,':');
1020 ipstream.ignore(256,' ');
1021 ipstream >> dialogueboxlocation[whichdi][i];
1022 ipstream.ignore(256,':');
1023 ipstream >> dialogueboxcolor[whichdi][i][0];
1024 ipstream >> dialogueboxcolor[whichdi][i][1];
1025 ipstream >> dialogueboxcolor[whichdi][i][2];
1026 ipstream.ignore(256,':');
1027 ipstream.getline(dialoguename[whichdi][i],64);
1028 ipstream.ignore(256,':');
1029 ipstream.ignore(256,' ');
1030 ipstream.getline(dialoguetext[whichdi][i],128);
1031 for(int j=0;j<128;j++){
1032 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
1034 ipstream.ignore(256,':');
1035 ipstream >> dialogueboxsound[whichdi][i];
1041 static void ch_fixtype(const char *args)
1044 sscanf(args, "%d", &dlg);
1045 dialoguetype[0] = dlg;
1048 static void ch_fixrotation(const char *args)
1050 participantyaw[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].yaw;
1053 static void ch_ddialogue(const char *args)
1059 static void ch_dhs(const char *args)
1065 static void ch_immobile(const char *args)
1067 player[0].immobile = 1;
1070 static void ch_allimmobile(const char *args)
1072 for (int i = 1; i < numplayers; i++)
1073 player[i].immobile = 1;
1076 static void ch_mobile(const char *args)
1078 player[0].immobile = 0;
1081 static void ch_default(const char *args)
1083 player[0].armorhead=1;
1084 player[0].armorhigh=1;
1085 player[0].armorlow=1;
1086 player[0].protectionhead=1;
1087 player[0].protectionhigh=1;
1088 player[0].protectionlow=1;
1089 player[0].metalhead=1;
1090 player[0].metalhigh=1;
1091 player[0].metallow=1;
1093 player[0].speedmult=1;
1096 if(player[0].creature==wolftype){
1097 player[0].proportionhead=1.1;
1098 player[0].proportionbody=1.1;
1099 player[0].proportionarms=1.1;
1100 player[0].proportionlegs=1.1;
1101 } else if(player[0].creature==rabbittype){
1102 player[0].proportionhead=1.2;
1103 player[0].proportionbody=1.05;
1104 player[0].proportionarms=1.00;
1105 player[0].proportionlegs=1.1;
1106 player[0].proportionlegs.y=1.05;
1109 player[0].numclothes=0;
1110 LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
1111 &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
1112 &player[0].skeleton.skinsize);
1114 editoractive=typeactive;
1115 player[0].immobile=0;
1118 static void ch_play(const char *args)
1121 sscanf(args, "%d", &dlg);
1122 whichdialogue = dlg;
1124 if (whichdialogue >= numdialogues)
1127 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1128 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1129 player[participantfocus[whichdialogue][i]].yaw=participantyaw[whichdialogue][participantfocus[whichdialogue][i]];
1130 player[participantfocus[whichdialogue][i]].targetyaw=participantyaw[whichdialogue][participantfocus[whichdialogue][i]];
1131 player[participantfocus[whichdialogue][i]].velocity=0;
1132 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
1133 player[participantfocus[whichdialogue][i]].targetframe=0;
1139 playdialogueboxsound();
1142 static void ch_mapkilleveryone(const char *args)
1144 maptype = mapkilleveryone;
1147 static void ch_mapkillmost(const char *args)
1149 maptype = mapkillmost;
1152 static void ch_mapkillsomeone(const char *args)
1154 maptype = mapkillsomeone;
1157 static void ch_mapgosomewhere(const char *args)
1159 maptype = mapgosomewhere;
1162 static void ch_viewdistance(const char *args)
1164 viewdistance = atof(args)*100;
1167 static void ch_fadestart(const char *args)
1169 fadestart = atof(args);
1172 static void ch_slomo(const char *args)
1174 slomospeed = atof(args);
1179 static void ch_slofreq(const char *args)
1181 slomofreq = atof(args);
1184 static void ch_skytint(const char *args)
1186 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1188 skyboxlightr=skyboxr;
1189 skyboxlightg=skyboxg;
1190 skyboxlightb=skyboxb;
1194 terrain.DoShadows();
1195 objects.DoShadows();
1198 static void ch_skylight(const char *args)
1200 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1204 terrain.DoShadows();
1205 objects.DoShadows();
1208 static void ch_skybox(const char *args)
1210 skyboxtexture = !skyboxtexture;
1214 terrain.DoShadows();
1215 objects.DoShadows();
1218 static void cmd_dispatch(const string cmd)
1220 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1222 for (i = 0; i < n_cmds; i++)
1223 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1225 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1226 cmd_handlers[i](cmd.substr(cmd.find(' ')+1).c_str());
1229 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1232 /********************> Tick() <*****/
1233 extern bool save_image(const char * fname);
1234 void Screenshot (void)
1237 time_t t = time(NULL);
1238 struct tm *tme = localtime(&t);
1239 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);
1242 mkdir("Screenshots");
1244 mkdir("Screenshots", S_IRWXU);
1250 void Game::SetUpLighting(){
1251 if(environment==snowyenvironment)
1252 light.setColors(.65,.65,.7,.4,.4,.44);
1253 if(environment==desertenvironment)
1254 light.setColors(.95,.95,.95,.4,.35,.3);
1255 if(environment==grassyenvironment)
1256 light.setColors(.95,.95,1,.4,.4,.44);
1258 light.setColors(1,1,1,.4,.4,.4);
1260 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1261 light.color[0]*=(skyboxlightr+average)/2;
1262 light.color[1]*=(skyboxlightg+average)/2;
1263 light.color[2]*=(skyboxlightb+average)/2;
1264 light.ambient[0]*=(skyboxlightr+average)/2;
1265 light.ambient[1]*=(skyboxlightg+average)/2;
1266 light.ambient[2]*=(skyboxlightb+average)/2;
1269 int findPathDist(int start,int end){
1270 int smallestcount,count,connected;
1271 int last,last2,last3,last4;
1275 for(int i=0;i<50;i++){
1281 while(last!=end&&count<30){
1283 for(int j=0;j<numpathpoints;j++){
1284 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1287 if(numpathpointconnect[j])
1288 for(int k=0;k<numpathpointconnect[j];k++){
1289 if(pathpointconnect[j][k]==last)connected=1;
1292 if(numpathpointconnect[last])
1293 for(int k=0;k<numpathpointconnect[last];k++){
1294 if(pathpointconnect[last][k]==j)connected=1;
1297 if(closest==-1||Random()%2==0){
1308 if(count<smallestcount)smallestcount=count;
1310 return smallestcount;
1313 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1314 static XYZ colpoint,colviewer,coltarget;
1315 static float minx,minz,maxx,maxz,miny,maxy;
1317 minx=min(startpoint.x,endpoint.x)-1;
1318 miny=min(startpoint.y,endpoint.y)-1;
1319 minz=min(startpoint.z,endpoint.z)-1;
1320 maxx=max(startpoint.x,endpoint.x)+1;
1321 maxy=max(startpoint.y,endpoint.y)+1;
1322 maxz=max(startpoint.z,endpoint.z)+1;
1324 for(int i=0;i<objects.numobjects;i++){
1325 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1326 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1327 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1328 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1329 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1330 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1331 if( objects.type[i]!=treeleavestype&&
1332 objects.type[i]!=bushtype&&
1333 objects.type[i]!=firetype){
1334 colviewer=startpoint;
1336 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.yaw[i])!=-1)return i;
1341 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1346 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1347 static XYZ colpoint,colviewer,coltarget;
1348 static float minx,minz,maxx,maxz,miny,maxy;
1349 static int i; //FIXME: see below
1351 minx=min(startpoint.x,endpoint.x)-1;
1352 miny=min(startpoint.y,endpoint.y)-1;
1353 minz=min(startpoint.z,endpoint.z)-1;
1354 maxx=max(startpoint.x,endpoint.x)+1;
1355 maxy=max(startpoint.y,endpoint.y)+1;
1356 maxz=max(startpoint.z,endpoint.z)+1;
1359 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1360 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1361 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1362 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1363 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1364 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1365 if( objects.type[what]!=treeleavestype&&
1366 objects.type[what]!=bushtype&&
1367 objects.type[what]!=firetype){
1368 colviewer=startpoint;
1371 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.yaw[what])!=-1)return i;
1376 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1381 void Setenvironment(int which)
1385 LOG(" Setting environment...");
1387 float temptexdetail;
1390 pause_sound(stream_snowtheme);
1391 pause_sound(stream_grasstheme);
1392 pause_sound(stream_deserttheme);
1393 pause_sound(stream_wind);
1394 pause_sound(stream_desertambient);
1397 if(environment==snowyenvironment){
1401 emit_stream_np(stream_wind);
1403 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
1404 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
1405 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
1406 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
1408 footstepsound = footstepsn1;
1409 footstepsound2 = footstepsn2;
1410 footstepsound3 = footstepst1;
1411 footstepsound4 = footstepst2;
1413 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
1415 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
1417 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1422 temptexdetail=texdetail;
1423 if(texdetail>1)texdetail=4;
1424 skybox->load( ":Data:Textures:Skybox(snow):Front.jpg",
1425 ":Data:Textures:Skybox(snow):Left.jpg",
1426 ":Data:Textures:Skybox(snow):Back.jpg",
1427 ":Data:Textures:Skybox(snow):Right.jpg",
1428 ":Data:Textures:Skybox(snow):Up.jpg",
1429 ":Data:Textures:Skybox(snow):Down.jpg");
1434 texdetail=temptexdetail;
1435 } else if(environment==desertenvironment){
1438 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
1439 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
1440 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
1441 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
1445 emit_stream_np(stream_desertambient);
1447 footstepsound = footstepsn1;
1448 footstepsound2 = footstepsn2;
1449 footstepsound3 = footstepsn1;
1450 footstepsound4 = footstepsn2;
1452 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
1454 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
1456 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1460 temptexdetail=texdetail;
1461 if(texdetail>1)texdetail=4;
1462 skybox->load( ":Data:Textures:Skybox(sand):Front.jpg",
1463 ":Data:Textures:Skybox(sand):Left.jpg",
1464 ":Data:Textures:Skybox(sand):Back.jpg",
1465 ":Data:Textures:Skybox(sand):Right.jpg",
1466 ":Data:Textures:Skybox(sand):Up.jpg",
1467 ":Data:Textures:Skybox(sand):Down.jpg");
1472 texdetail=temptexdetail;
1473 } else if(environment==grassyenvironment){
1476 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
1477 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
1478 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
1479 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
1482 emit_stream_np(stream_wind, 100.);
1484 footstepsound = footstepgr1;
1485 footstepsound2 = footstepgr2;
1486 footstepsound3 = footstepst1;
1487 footstepsound4 = footstepst2;
1489 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
1491 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
1493 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1497 temptexdetail=texdetail;
1498 if(texdetail>1)texdetail=4;
1499 skybox->load( ":Data:Textures:Skybox(grass):Front.jpg",
1500 ":Data:Textures:Skybox(grass):Left.jpg",
1501 ":Data:Textures:Skybox(grass):Back.jpg",
1502 ":Data:Textures:Skybox(grass):Right.jpg",
1503 ":Data:Textures:Skybox(grass):Up.jpg",
1504 ":Data:Textures:Skybox(grass):Down.jpg");
1508 texdetail=temptexdetail;
1510 temptexdetail=texdetail;
1512 terrain.load(":Data:Textures:heightmap.png");
1514 texdetail=temptexdetail;
1517 void LoadCampaign() {
1520 ifstream ipstream(ConvertFileName((":Data:Campaigns:"+accountactive->getCurrentCampaign()+".txt").c_str()));
1521 ipstream.ignore(256,':');
1523 ipstream >> numlevels;
1524 campaignlevels.clear();
1525 for(int i=0;i<numlevels;i++) {
1528 campaignlevels.push_back(cl);
1532 ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
1534 LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
1536 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
1539 if(accountactive->getCampaignChoicesMade()==0) {
1540 accountactive->setCampaignScore(0);
1541 accountactive->resetFasttime();
1545 vector<string> ListCampaigns() {
1546 DIR *campaigns = opendir(ConvertFileName(":Data:Campaigns"));
1547 struct dirent *campaign = NULL;
1549 perror("Problem while loading campaigns");
1550 cerr << "campaign folder was : " << ConvertFileName(":Data:Campaigns") << endl;
1553 vector<string> campaignNames;
1554 while ((campaign = readdir(campaigns)) != NULL) {
1555 string name(campaign->d_name);
1558 if(!name.compare(name.length()-4,4,".txt")) {
1559 campaignNames.push_back(name.substr(0,name.length()-4));
1562 closedir(campaigns);
1563 return campaignNames;
1566 void Loadlevel(int which) {
1572 Loadlevel("tutorial");
1573 } else if(which >= 0 && which <= 15) {
1575 snprintf(buf, 32, "map%d", which + 1); // challenges
1578 Loadlevel("mapsave");
1581 void Loadlevel(const char *name) {
1584 static const char *pfx = ":Data:Maps:";
1587 float headprop,legprop,armprop,bodyprop;
1591 LOG(std::string("Loading level...") + name);
1603 if(tutoriallevel!=-1)
1608 if(tutoriallevel==1)
1610 if(tutorialstage==0) {
1611 tutorialstagetime=0;
1615 pause_sound(whooshsound);
1616 pause_sound(stream_firesound);
1618 // Change the map filename into something that is os specific
1619 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1620 sprintf(buf, "%s%s", pfx, name);
1621 const char *FixedFN = ConvertFileName(buf);
1625 //~ char* buff=getcwd(NULL,0);
1626 //~ cout << buff << " " << FixedFN << endl;
1628 tfile=fopen( FixedFN, "rb" );
1630 pause_sound(stream_firesound);
1636 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1640 for(int i=0;i<20;i++)
1641 dialoguegonethrough[i]=0;
1650 difficulty=accountactive->getDifficulty();
1664 for(int i=0;i<100;i++)
1684 bonustotal=startbonustotal;
1689 emit_sound_np(consolesuccesssound);
1694 if(!stealthloading){
1695 terrain.numdecals=0;
1696 Sprite::deleteSprites();
1697 for(int i=0;i<objects.numobjects;i++)
1698 objects.model[i].numdecals=0;
1700 int j=objects.numobjects;
1701 for(int i=0;i<j;i++){
1702 objects.DeleteObject(0);
1707 for(int i=0;i<subdivision;i++)
1708 for(int j=0;j<subdivision;j++)
1709 terrain.patchobjectnum[i][j]=0;
1716 funpackf(tfile, "Bi", &mapvers);
1718 funpackf(tfile, "Bi", &indemo);
1722 funpackf(tfile, "Bi", &maptype);
1724 maptype=mapkilleveryone;
1726 funpackf(tfile, "Bi", &hostile);
1730 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1736 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1744 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1746 skyboxlightr=skyboxr;
1747 skyboxlightg=skyboxg;
1748 skyboxlightb=skyboxb;
1751 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].yaw,&player[0].targetyaw, &player[0].num_weapons);
1753 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1754 player[0].originalcoords=player[0].coords;
1755 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1756 for(int j=0;j<player[0].num_weapons;j++){
1757 player[0].weaponids[j]=weapons.size();
1759 funpackf(tfile, "Bi", &type);
1760 weapons.push_back(Weapon(type,0));
1766 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1767 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1768 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1769 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1771 funpackf(tfile, "Bi", &player[0].numclothes);
1774 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1776 player[0].whichskin=0;
1777 player[0].creature=rabbittype;
1780 player[0].lastattack=-1;
1781 player[0].lastattack2=-1;
1782 player[0].lastattack3=-1;
1786 funpackf(tfile, "Bi", &numdialogues);
1787 for(int k=0;k<numdialogues;k++){
1788 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1789 funpackf(tfile, "Bi", &dialoguetype[k]);
1790 for(int l=0;l<10;l++){
1791 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1792 funpackf(tfile, "Bf", &participantyaw[k][l]);
1794 for(int l=0;l<numdialogueboxes[k];l++){
1795 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1796 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1797 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1798 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1799 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1801 funpackf(tfile, "Bi",&templength);
1802 if(templength>128||templength<=0)
1805 for(m=0;m<templength;m++){
1806 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1807 if(dialoguetext[k][l][m]=='\0')
1810 dialoguetext[k][l][m] = 0;
1812 funpackf(tfile, "Bi",&templength);
1813 if(templength>64||templength<=0)templength=64;
1814 for(m=0;m<templength;m++){
1815 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1816 if(dialoguename[k][l][m]=='\0')
1819 dialoguename[k][l][m] = 0;
1820 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1821 funpackf(tfile, "Bi", &participantfocus[k][l]);
1822 funpackf(tfile, "Bi", &participantaction[k][l]);
1825 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1827 funpackf(tfile, "Bf Bf",&dialoguecamerayaw[k][l],&dialoguecamerapitch[k][l]);
1833 for(int k=0;k<player[0].numclothes;k++){
1834 funpackf(tfile, "Bi", &templength);
1835 for(int l=0;l<templength;l++)
1836 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1837 player[0].clothes[k][templength]='\0';
1838 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1841 funpackf(tfile, "Bi", &environment);
1843 funpackf(tfile, "Bi", &objects.numobjects);
1844 for(int i=0;i<objects.numobjects;i++){
1845 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.yaw[i],&objects.pitch[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1846 if(objects.type[i]==treeleavestype)
1847 objects.scale[i]=objects.scale[i-1];
1851 funpackf(tfile, "Bi", &numhotspots);
1852 for(int i=0;i<numhotspots;i++){
1853 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1854 funpackf(tfile, "Bi", &templength);
1856 for(int l=0;l<templength;l++)
1857 funpackf(tfile, "Bb", &hotspottext[i][l]);
1858 hotspottext[i][templength]='\0';
1859 if(hotspottype[i]==-111)
1868 if(!stealthloading){
1870 for(int i=0;i<objects.numobjects;i++)
1871 objects.center+=objects.position[i];
1872 objects.center/=objects.numobjects;
1878 float maxdistance=0;
1880 //~ int whichclosest;
1881 for(int i=0;i<objects.numobjects;i++){
1882 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1883 if(tempdist>maxdistance){
1885 maxdistance=tempdist;
1888 objects.radius=fast_sqrt(maxdistance);
1893 //mapcenter=objects.center;
1894 //mapradius=objects.radius;
1896 funpackf(tfile, "Bi", &numplayers);
1897 int howmanyremoved=0;
1898 bool removeanother=0;
1899 if(numplayers>1&&numplayers<maxplayers){
1900 for(int i=1;i<numplayers;i++){
1905 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);
1907 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1909 player[i-howmanyremoved].howactive=typeactive;
1911 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1913 player[i-howmanyremoved].scale=-1;
1915 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1917 player[i-howmanyremoved].immobile=0;
1919 funpackf(tfile, "Bf",&player[i-howmanyremoved].yaw);
1921 player[i-howmanyremoved].yaw=0;
1922 player[i-howmanyremoved].targetyaw=player[i-howmanyremoved].yaw;
1923 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1928 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1929 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1930 player[i-howmanyremoved].weaponids[j]=weapons.size();
1932 funpackf(tfile, "Bi", &type);
1933 weapons.push_back(Weapon(type,i));
1936 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1937 //player[i-howmanyremoved].numwaypoints=10;
1938 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1939 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1940 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1941 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1943 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1945 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1948 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1949 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1950 player[i-howmanyremoved].waypoint=0;
1952 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1953 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1954 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1955 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1958 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1965 if(player[i-howmanyremoved].creature==wolftype){
1966 player[i-howmanyremoved].proportionhead=1.1*headprop;
1967 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1968 player[i-howmanyremoved].proportionarms=1.1*armprop;
1969 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1972 if(player[i-howmanyremoved].creature==rabbittype){
1973 player[i-howmanyremoved].proportionhead=1.2*headprop;
1974 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1975 player[i-howmanyremoved].proportionarms=1.00*armprop;
1976 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1977 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1980 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1981 if(player[i-howmanyremoved].numclothes){
1982 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1984 funpackf(tfile, "Bi", &templength);
1985 for(int l=0;l<templength;l++)
1986 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1987 player[i-howmanyremoved].clothes[k][templength]='\0';
1988 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1997 numplayers-=howmanyremoved;
1998 funpackf(tfile, "Bi", &numpathpoints);
1999 if(numpathpoints>30||numpathpoints<0)
2001 for(int j=0;j<numpathpoints;j++){
2002 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
2003 for(int k=0;k<numpathpointconnect[j];k++){
2004 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
2010 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
2013 if(environment!=oldenvironment)
2014 Setenvironment(environment);
2015 oldenvironment=environment;
2017 if(!stealthloading){
2018 int j=objects.numobjects;
2019 objects.numobjects=0;
2020 for(int i=0;i<j;i++){
2021 objects.MakeObject(objects.type[i],objects.position[i],objects.yaw[i],objects.pitch[i],objects.scale[i]);
2026 terrain.DoShadows();
2029 objects.DoShadows();
2036 if(numplayers>maxplayers-1)
2037 numplayers=maxplayers-1;
2038 for(int i=0;i<numplayers;i++){
2044 if(i==0||player[i].scale<0)
2046 player[i].skeleton.free=0;
2047 player[i].skeleton.id=i;
2049 player[i].creature=rabbittype;
2050 if(player[i].creature!=wolftype){
2051 player[i].skeleton.Load(
2052 (char *)":Data:Skeleton:Basic Figure",
2053 (char *)":Data:Skeleton:Basic Figurelow",
2054 (char *)":Data:Skeleton:Rabbitbelt",
2055 (char *)":Data:Models:Body.solid",
2056 (char *)":Data:Models:Body2.solid",
2057 (char *)":Data:Models:Body3.solid",
2058 (char *)":Data:Models:Body4.solid",
2059 (char *)":Data:Models:Body5.solid",
2060 (char *)":Data:Models:Body6.solid",
2061 (char *)":Data:Models:Body7.solid",
2062 (char *)":Data:Models:Bodylow.solid",
2063 (char *)":Data:Models:Belt.solid",0);
2065 if(player[i].creature!=wolftype){
2066 player[i].skeleton.Load(
2067 (char *)":Data:Skeleton:Basic Figure",
2068 (char *)":Data:Skeleton:Basic Figurelow",
2069 (char *)":Data:Skeleton:Rabbitbelt",
2070 (char *)":Data:Models:Body.solid",
2071 (char *)":Data:Models:Body2.solid",
2072 (char *)":Data:Models:Body3.solid",
2073 (char *)":Data:Models:Body4.solid",
2074 (char *)":Data:Models:Body5.solid",
2075 (char *)":Data:Models:Body6.solid",
2076 (char *)":Data:Models:Body7.solid",
2077 (char *)":Data:Models:Bodylow.solid",
2078 (char *)":Data:Models:Belt.solid",1);
2079 LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
2081 if(player[i].creature==wolftype){
2082 player[i].skeleton.Load(
2083 (char *)":Data:Skeleton:Basic Figure Wolf",
2084 (char *)":Data:Skeleton:Basic Figure Wolf Low",
2085 (char *)":Data:Skeleton:Rabbitbelt",
2086 (char *)":Data:Models:Wolf.solid",
2087 (char *)":Data:Models:Wolf2.solid",
2088 (char *)":Data:Models:Wolf3.solid",
2089 (char *)":Data:Models:Wolf4.solid",
2090 (char *)":Data:Models:Wolf5.solid",
2091 (char *)":Data:Models:Wolf6.solid",
2092 (char *)":Data:Models:Wolf7.solid",
2093 (char *)":Data:Models:Wolflow.solid",
2094 (char *)":Data:Models:Belt.solid",0);
2100 //~ texsize=512*512*3/texdetail/texdetail;
2102 LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2104 if(player[i].numclothes){
2105 for(int j=0;j<player[i].numclothes;j++){
2106 tintr=player[i].clothestintr[j];
2107 tintg=player[i].clothestintg[j];
2108 tintb=player[i].clothestintb[j];
2109 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
2111 player[i].DoMipmaps();
2114 player[i].currentanimation=bounceidleanim;
2115 player[i].targetanimation=bounceidleanim;
2116 player[i].currentframe=0;
2117 player[i].targetframe=1;
2119 player[i].speed=1+(float)(Random()%100)/1000;
2121 player[i].speed-=.2;
2123 player[i].speed-=.1;
2125 player[i].velocity=0;
2126 player[i].oldcoords=player[i].coords;
2127 player[i].realoldcoords=player[i].coords;
2130 player[i].skeleton.id=i;
2131 player[i].updatedelay=0;
2132 player[i].normalsupdatedelay=0;
2134 player[i].aitype=passivetype;
2135 player[i].madskills=0;
2138 player[i].proportionhead=1.2;
2139 player[i].proportionbody=1.05;
2140 player[i].proportionarms=1.00;
2141 player[i].proportionlegs=1.1;
2142 player[i].proportionlegs.y=1.05;
2144 player[i].headless=0;
2145 player[i].currentoffset=0;
2146 player[i].targetoffset=0;
2148 player[i].damagetolerance=200;
2150 if(player[i].creature==wolftype){
2151 if(i==0||player[i].scale<0)
2152 player[i].scale=.23;
2153 player[i].damagetolerance=300;
2159 player[i].proportionhead.z=0;
2160 player[i].proportionbody.z=0;
2161 player[i].proportionarms.z=0;
2162 player[i].proportionlegs.z=0;
2165 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2167 player[i].headmorphness=0;
2168 player[i].targetheadmorphness=1;
2169 player[i].headmorphstart=0;
2170 player[i].headmorphend=0;
2172 player[i].pausetime=0;
2175 player[i].jumppower=5;
2177 player[i].permanentdamage=0;
2178 player[i].superpermanentdamage=0;
2180 player[i].forwardkeydown=0;
2181 player[i].leftkeydown=0;
2182 player[i].backkeydown=0;
2183 player[i].rightkeydown=0;
2184 player[i].jumpkeydown=0;
2185 player[i].crouchkeydown=0;
2186 player[i].throwkeydown=0;
2188 player[i].collided=-10;
2190 player[i].bloodloss=0;
2191 player[i].weaponactive=-1;
2192 player[i].weaponstuck=-1;
2193 player[i].bleeding=0;
2194 player[i].deathbleeding=0;
2195 player[i].stunned=0;
2196 player[i].hasvictim=0;
2197 player[i].wentforweapon=0;
2200 player[0].aitype=playercontrolled;
2201 player[0].weaponactive=-1;
2204 player[0].power=1/.9;
2207 player[0].power=1/.8;
2210 player[0].damagetolerance=250;
2212 player[0].damagetolerance=300;
2214 player[0].armorhead*=1.5;
2216 player[0].armorhigh*=1.5;
2218 player[0].armorlow*=1.5;
2219 cameraloc=player[0].coords;
2223 hawkcoords=player[0].coords;
2228 //~ for(int i=0;i<weapons.size();i++){
2231 LOG("Starting background music...");
2233 OPENAL_StopSound(OPENAL_ALL);
2234 if(environment==snowyenvironment){
2236 emit_stream_np(stream_wind);
2237 }else if(environment==desertenvironment){
2239 emit_stream_np(stream_desertambient);
2240 }else if(environment==grassyenvironment){
2242 emit_stream_np(stream_wind, 100.);
2244 oldmusicvolume[0]=0;
2245 oldmusicvolume[1]=0;
2246 oldmusicvolume[2]=0;
2247 oldmusicvolume[3]=0;
2260 if(tutorialstagetime>tutorialmaxtime){
2263 if(tutorialstage<=1){
2268 switch(tutorialstage){
2274 tutorialmaxtime=600;
2276 tutorialmaxtime=1000;
2278 tutorialmaxtime=600;
2280 tutorialmaxtime=600;
2282 tutorialmaxtime=600;
2284 tutorialmaxtime=600;
2286 tutorialmaxtime=600;
2290 tutorialmaxtime=1000;
2292 tutorialmaxtime=1000;
2307 player[1].coords=(temp+temp2)/2;
2309 emit_sound_at(fireendsound, player[1].coords);
2311 for(int i=0;i<player[1].skeleton.num_joints;i++){
2313 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2314 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2315 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].yaw,0)*player[1].scale+player[1].coords;
2316 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2317 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2322 tutorialmaxtime=500;
2324 tutorialmaxtime=500;
2326 tutorialmaxtime=500;
2328 tutorialmaxtime=500;
2331 //tutorialmaxtime=500;
2333 tutorialmaxtime=500;
2335 tutorialmaxtime=500;
2342 tutorialmaxtime=500;
2344 tutorialmaxtime=500;
2346 tutorialmaxtime=500;
2348 tutorialmaxtime=500;
2355 player[1].aitype=attacktypecutoff;
2357 tutorialmaxtime=400;
2359 tutorialmaxtime=400;
2360 player[0].escapednum=0;
2365 player[1].aitype=passivetype;
2371 tutorialmaxtime=400;
2374 player[1].aitype=attacktypecutoff;
2376 tutorialmaxtime=400;
2378 tutorialmaxtime=400;
2383 player[1].aitype=passivetype;
2390 player[1].aitype=attacktypecutoff;
2395 player[1].aitype=passivetype;
2407 w.position=(temp+temp2)/2;
2408 w.tippoint=(temp+temp2)/2;
2418 weapons.push_back(w);
2421 tutorialmaxtime=300;
2423 tutorialmaxtime=300;
2427 tutorialmaxtime=300;
2430 player[0].weaponactive=-1;
2431 player[0].num_weapons=0;
2432 player[1].weaponactive=0;
2433 player[1].num_weapons=1;
2434 player[1].weaponids[0]=0;
2438 player[1].aitype=attacktypecutoff;
2440 tutorialmaxtime=300;
2443 player[0].weaponactive=-1;
2444 player[0].num_weapons=0;
2445 player[1].weaponactive=0;
2446 player[1].num_weapons=1;
2447 player[1].weaponids[0]=0;
2449 tutorialmaxtime=300;
2452 player[0].weaponactive=-1;
2453 player[0].num_weapons=0;
2454 player[1].weaponactive=0;
2455 player[1].num_weapons=1;
2456 player[1].weaponids[0]=0;
2458 weapons[0].setType(sword);
2460 tutorialmaxtime=300;
2474 w.position=(temp+temp2)/2;
2475 w.tippoint=(temp+temp2)/2;
2485 weapons.push_back(w);
2489 player[0].weaponactive=0;
2490 player[0].num_weapons=1;
2491 player[0].weaponids[0]=1;
2492 player[1].weaponactive=0;
2493 player[1].num_weapons=1;
2494 player[1].weaponids[0]=0;
2500 player[1].aitype=passivetype;
2506 player[0].weaponactive=0;
2507 player[0].num_weapons=1;
2508 player[0].weaponids[0]=1;
2509 player[1].weaponactive=0;
2510 player[1].num_weapons=1;
2511 player[1].weaponids[0]=0;
2513 if(player[0].weaponactive!=-1)
2514 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2516 weapons[0].setType(staff);
2520 player[1].aitype=passivetype;
2522 tutorialmaxtime=200;
2524 weapons[1].position=1000;
2525 weapons[1].tippoint=1000;
2527 weapons[0].setType(knife);
2530 player[1].weaponactive=-1;
2531 player[1].num_weapons=0;
2532 player[0].weaponactive=0;
2533 player[0].num_weapons=1;
2534 player[0].weaponids[0]=0;
2540 emit_sound_at(fireendsound, player[1].coords);
2542 for(int i=0;i<player[1].skeleton.num_joints;i++){
2544 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2545 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2546 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].yaw,0)*player[1].scale+player[1].coords;
2547 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2548 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2552 player[1].num_weapons=0;
2553 player[1].weaponstuck=-1;
2554 player[1].weaponactive=-1;
2559 tutorialmaxtime=80000;
2560 break; default: break;
2562 if(tutorialstage<=51)tutorialstagetime=0;
2566 if(tutorialstagetime<tutorialmaxtime-3){
2567 switch(tutorialstage){
2568 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2569 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2570 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2571 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2572 break; case 7: if(player[0].targetanimation==rollanim)tutorialsuccess=1;
2573 break; case 8: if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
2574 break; case 9: if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
2575 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2576 break; case 12: if(player[0].targetanimation==flipanim)tutorialsuccess=1;
2577 break; case 15: if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2578 break; case 16: if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
2579 break; case 17: if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
2580 break; case 18: if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
2581 break; case 19: if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
2582 break; case 20: if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
2583 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2584 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2585 break; case 23: if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
2586 break; case 24: if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
2587 break; case 25: if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
2588 break; case 28: if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
2590 if(player[0].escapednum==2) {
2594 player[1].aitype=passivetype;
2596 break; case 33: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2597 break; case 34: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2599 if(animation[player[0].targetanimation].attack==reversal){
2603 player[1].aitype=passivetype;
2605 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2606 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2607 break; case 43: if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
2608 break; case 44: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2609 break; case 45: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2610 break; case 46: if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
2611 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2612 break; default: break;
2614 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2617 if(tutorialstagetime==tutorialmaxtime-3){
2618 emit_sound_np(consolesuccesssound);
2621 if(tutorialsuccess>=1){
2622 if(tutorialstage==34||tutorialstage==35)
2623 tutorialstagetime=tutorialmaxtime-1;
2627 if(tutorialstage<14||tutorialstage>=50){
2628 player[1].coords.y=300;
2629 player[1].velocity=0;
2634 float headprop,bodyprop,armprop,legprop;
2636 if(Input::isKeyPressed(SDLK_h)){
2637 player[0].damagetolerance=200000;
2640 player[0].permanentdamage=0;
2641 player[0].superpermanentdamage=0;
2644 if(Input::isKeyPressed(SDLK_j)){
2648 Setenvironment(environment);
2651 if(Input::isKeyPressed(SDLK_c)){
2652 cameramode=1-cameramode;
2655 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2656 if(player[0].num_weapons>0){
2657 if(weapons[player[0].weaponids[0]].getType()==sword)
2658 weapons[player[0].weaponids[0]].setType(staff);
2659 else if(weapons[player[0].weaponids[0]].getType()==staff)
2660 weapons[player[0].weaponids[0]].setType(knife);
2662 weapons[player[0].weaponids[0]].setType(sword);
2666 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2668 float closestdist=-1;
2671 for(int i=1;i<numplayers;i++){
2672 distance=findDistancefast(&player[i].coords,&player[0].coords);
2673 if(closestdist==-1||distance<closestdist){
2674 closestdist=distance;
2679 if(player[closest].num_weapons){
2680 if(weapons[player[closest].weaponids[0]].getType()==sword)
2681 weapons[player[closest].weaponids[0]].setType(staff);
2682 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2683 weapons[player[closest].weaponids[0]].setType(knife);
2685 weapons[player[closest].weaponids[0]].setType(sword);
2687 if(!player[closest].num_weapons){
2688 player[closest].weaponids[0]=weapons.size();
2690 weapons.push_back(Weapon(knife,closest));
2692 player[closest].num_weapons=1;
2697 if(Input::isKeyDown(SDLK_u)){
2699 float closestdist=-1;
2702 for(int i=1;i<numplayers;i++){
2703 distance=findDistancefast(&player[i].coords,&player[0].coords);
2704 if(closestdist==-1||distance<closestdist){
2705 closestdist=distance;
2709 player[closest].yaw+=multiplier*50;
2710 player[closest].targetyaw=player[closest].yaw;
2714 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2716 float closestdist=-1;
2719 for(int i=1;i<numplayers;i++){
2720 distance=findDistancefast(&player[i].coords,&player[0].coords);
2721 if(closestdist==-1||distance<closestdist){
2722 closestdist=distance;
2726 if(Input::isKeyDown(SDLK_LCTRL))closest=0;
2729 player[closest].whichskin++;
2730 if(player[closest].whichskin>9)
2731 player[closest].whichskin=0;
2732 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2733 player[closest].whichskin=0;
2735 LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
2736 &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2739 if(player[closest].numclothes){
2740 for(int i=0;i<player[closest].numclothes;i++){
2741 tintr=player[closest].clothestintr[i];
2742 tintg=player[closest].clothestintg[i];
2743 tintb=player[closest].clothestintb[i];
2744 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2746 player[closest].DoMipmaps();
2750 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2752 float closestdist=-1;
2755 for(int i=1;i<numplayers;i++){
2756 distance=findDistancefast(&player[i].coords,&player[0].coords);
2757 if(closestdist==-1||distance<closestdist){
2758 closestdist=distance;
2763 if(player[closest].creature==wolftype){
2764 headprop=player[closest].proportionhead.x/1.1;
2765 bodyprop=player[closest].proportionbody.x/1.1;
2766 armprop=player[closest].proportionarms.x/1.1;
2767 legprop=player[closest].proportionlegs.x/1.1;
2770 if(player[closest].creature==rabbittype){
2771 headprop=player[closest].proportionhead.x/1.2;
2772 bodyprop=player[closest].proportionbody.x/1.05;
2773 armprop=player[closest].proportionarms.x/1.00;
2774 legprop=player[closest].proportionlegs.x/1.1;
2778 if(player[closest].creature==rabbittype){
2779 player[closest].skeleton.id=closest;
2780 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);
2781 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2782 player[closest].whichskin=0;
2783 player[closest].creature=wolftype;
2785 player[closest].proportionhead=1.1;
2786 player[closest].proportionbody=1.1;
2787 player[closest].proportionarms=1.1;
2788 player[closest].proportionlegs=1.1;
2789 player[closest].proportionlegs.y=1.1;
2790 player[closest].scale=.23*5*player[0].scale;
2792 player[closest].damagetolerance=300;
2796 player[closest].skeleton.id=closest;
2797 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);
2798 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2799 player[closest].whichskin=0;
2800 player[closest].creature=rabbittype;
2802 player[closest].proportionhead=1.2;
2803 player[closest].proportionbody=1.05;
2804 player[closest].proportionarms=1.00;
2805 player[closest].proportionlegs=1.1;
2806 player[closest].proportionlegs.y=1.05;
2807 player[closest].scale=.2*5*player[0].scale;
2809 player[closest].damagetolerance=200;
2812 if(player[closest].creature==wolftype){
2813 player[closest].proportionhead=1.1*headprop;
2814 player[closest].proportionbody=1.1*bodyprop;
2815 player[closest].proportionarms=1.1*armprop;
2816 player[closest].proportionlegs=1.1*legprop;
2819 if(player[closest].creature==rabbittype){
2820 player[closest].proportionhead=1.2*headprop;
2821 player[closest].proportionbody=1.05*bodyprop;
2822 player[closest].proportionarms=1.00*armprop;
2823 player[closest].proportionlegs=1.1*legprop;
2824 player[closest].proportionlegs.y=1.05*legprop;
2830 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2836 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2838 float closestdist=-1;
2840 XYZ flatfacing2,flatvelocity2;
2843 for(int i=1;i<numplayers;i++){
2844 distance=findDistancefast(&player[i].coords,&player[0].coords);
2845 if(distance<144&&!player[i].headless)
2846 if(closestdist==-1||distance<closestdist){
2847 closestdist=distance;
2849 blah = player[i].coords;
2854 XYZ headspurtdirection;
2855 //int i = player[closest].skeleton.jointlabels[head];
2856 Joint& headjoint= player[closest].getJointFor(head);
2857 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2858 if(!player[closest].skeleton.free)
2859 flatvelocity2=player[closest].velocity;
2860 if(player[closest].skeleton.free)
2861 flatvelocity2=headjoint.velocity;
2862 if(!player[closest].skeleton.free)
2863 flatfacing2=DoRotation(DoRotation(DoRotation(headjoint.position,0,0,player[closest].tilt),player[closest].tilt2,0,0),0,player[closest].yaw,0)*player[closest].scale+player[closest].coords;
2864 if(player[closest].skeleton.free)
2865 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2866 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2867 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2868 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2869 headspurtdirection=headjoint.position-player[closest].getJointFor(neck).position;
2870 Normalise(&headspurtdirection);
2871 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2872 flatvelocity2+=headspurtdirection*8;
2873 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2875 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2877 emit_sound_at(splattersound, blah);
2878 emit_sound_at(breaksound2, blah, 100.);
2880 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2881 player[closest].RagDoll(0);
2882 player[closest].dead=2;
2883 player[closest].headless=1;
2884 player[closest].DoBloodBig(3,165);
2890 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2892 float closestdist=-1;
2894 XYZ flatfacing2,flatvelocity2;
2897 for(int i=1;i<numplayers;i++){
2898 distance=findDistancefast(&player[i].coords,&player[0].coords);
2900 if(closestdist==-1||distance<closestdist){
2901 closestdist=distance;
2903 blah=player[i].coords;
2908 emit_sound_at(splattersound, blah);
2910 emit_sound_at(breaksound2, blah);
2912 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2913 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2914 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2915 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].yaw,0)*player[closest].scale+player[closest].coords;
2916 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2917 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2918 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2919 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2920 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2921 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2922 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2925 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2926 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2927 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2928 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].yaw,0)*player[closest].scale+player[closest].coords;
2929 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2930 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2931 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2932 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2933 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2934 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2937 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2938 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2939 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2940 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].yaw,0)*player[closest].scale+player[closest].coords;
2941 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2942 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2943 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2944 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2945 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2946 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2949 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2950 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2951 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2952 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].yaw,0)*player[closest].scale+player[closest].coords;
2953 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2954 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2955 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2956 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2957 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2958 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2962 for(int j=0;j<numplayers; j++){
2964 if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
2965 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
2966 if(player[j].skeleton.free==2)
2967 player[j].skeleton.free=1;
2968 player[j].skeleton.longdead=0;
2969 player[j].RagDoll(0);
2970 for(int i=0;i<player[j].skeleton.num_joints; i++){
2971 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2972 if(findDistancefast(&temppos,&player[closest].coords)<25){
2973 flatvelocity2=temppos-player[closest].coords;
2974 Normalise(&flatvelocity2);
2975 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
2982 player[closest].DoDamage(10000);
2983 player[closest].RagDoll(0);
2984 player[closest].dead=2;
2985 player[closest].coords=20;
2986 player[closest].skeleton.free=2;
2993 if(Input::isKeyPressed(SDLK_f)){
2994 player[0].onfire=1-player[0].onfire;
2995 if(player[0].onfire){
2996 player[0].CatchFire();
2998 if(!player[0].onfire){
2999 emit_sound_at(fireendsound, player[0].coords);
3000 pause_sound(stream_firesound);
3004 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
3005 //if(!player[0].skeleton.free)player[0].damage+=500;
3006 player[0].RagDoll(0);
3007 //player[0].spurt=1;
3008 //player[0].DoDamage(1000);
3010 emit_sound_at(whooshsound, player[0].coords, 128.);
3013 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
3014 for(int i=0;i<objects.numobjects;i++){
3015 if(objects.type[i]==treeleavestype){
3016 objects.scale[i]*=.9;
3021 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3022 editorenabled=1-editorenabled;
3024 player[0].damagetolerance=100000;
3026 player[0].damagetolerance=200;
3028 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
3029 player[0].permanentdamage=0;
3030 player[0].superpermanentdamage=0;
3031 player[0].bloodloss=0;
3032 player[0].deathbleeding=0;
3036 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
3038 if(targetlevel>numchallengelevels-1)
3045 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
3047 float closestdist=-1;
3050 for(int i=1;i<numplayers;i++){
3051 distance=findDistancefast(&player[i].coords,&player[0].coords);
3052 if(closestdist==-1||distance<closestdist){
3053 closestdist=distance;
3057 if(closestdist>0&&closest>=0){
3058 //player[closest]=player[numplayers-1];
3059 //player[closest].skeleton=player[numplayers-1].skeleton;
3064 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
3066 float closestdist=-1;
3069 for(int i=1;i<max_objects;i++){
3070 distance=findDistancefast(&objects.position[i],&player[0].coords);
3071 if(closestdist==-1||distance<closestdist){
3072 closestdist=distance;
3076 if(closestdist>0&&closest>=0){
3077 objects.position[closest].y-=500;
3081 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3083 //if(drawmode>2)drawmode=0;
3084 if(objects.numobjects<max_objects-1){
3086 boxcoords.x=player[0].coords.x;
3087 boxcoords.z=player[0].coords.z;
3088 boxcoords.y=player[0].coords.y-3;
3089 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3090 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3091 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3092 float temprotat,temprotat2;
3093 temprotat=editoryaw;
3094 temprotat2=editorpitch;
3095 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3096 if(temprotat2<0)temprotat2=Random()%360;
3098 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3099 if(editortype==treetrunktype)
3100 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editoryaw-((int)editoryaw)%30,editorpitch,editorsize);
3104 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3105 if(numplayers<maxplayers-1){
3106 player[numplayers].scale=.2*5*player[0].scale;
3107 player[numplayers].creature=rabbittype;
3108 player[numplayers].howactive=editoractive;
3109 player[numplayers].skeleton.id=numplayers;
3110 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);
3112 //texsize=512*512*3/texdetail/texdetail;
3113 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3114 //player[numplayers].skeleton.skinText.resize(texsize);
3116 int k=abs(Random()%2)+1;
3118 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3119 player[numplayers].whichskin=0;
3122 LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3123 player[numplayers].whichskin=1;
3126 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3127 player[numplayers].whichskin=2;
3130 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
3131 player[numplayers].power=1;
3132 player[numplayers].speedmult=1;
3133 player[numplayers].currentanimation=bounceidleanim;
3134 player[numplayers].targetanimation=bounceidleanim;
3135 player[numplayers].currentframe=0;
3136 player[numplayers].targetframe=1;
3137 player[numplayers].target=0;
3138 player[numplayers].bled=0;
3139 player[numplayers].speed=1+(float)(Random()%100)/1000;
3141 player[numplayers].targetyaw=player[0].targetyaw;
3142 player[numplayers].yaw=player[0].yaw;
3144 player[numplayers].velocity=0;
3145 player[numplayers].coords=player[0].coords;
3146 player[numplayers].oldcoords=player[numplayers].coords;
3147 player[numplayers].realoldcoords=player[numplayers].coords;
3149 player[numplayers].id=numplayers;
3150 player[numplayers].skeleton.id=numplayers;
3151 player[numplayers].updatedelay=0;
3152 player[numplayers].normalsupdatedelay=0;
3154 player[numplayers].aitype=passivetype;
3156 if(player[0].creature==wolftype){
3157 headprop=player[0].proportionhead.x/1.1;
3158 bodyprop=player[0].proportionbody.x/1.1;
3159 armprop=player[0].proportionarms.x/1.1;
3160 legprop=player[0].proportionlegs.x/1.1;
3163 if(player[0].creature==rabbittype){
3164 headprop=player[0].proportionhead.x/1.2;
3165 bodyprop=player[0].proportionbody.x/1.05;
3166 armprop=player[0].proportionarms.x/1.00;
3167 legprop=player[0].proportionlegs.x/1.1;
3170 if(player[numplayers].creature==wolftype){
3171 player[numplayers].proportionhead=1.1*headprop;
3172 player[numplayers].proportionbody=1.1*bodyprop;
3173 player[numplayers].proportionarms=1.1*armprop;
3174 player[numplayers].proportionlegs=1.1*legprop;
3177 if(player[numplayers].creature==rabbittype){
3178 player[numplayers].proportionhead=1.2*headprop;
3179 player[numplayers].proportionbody=1.05*bodyprop;
3180 player[numplayers].proportionarms=1.00*armprop;
3181 player[numplayers].proportionlegs=1.1*legprop;
3182 player[numplayers].proportionlegs.y=1.05*legprop;
3185 player[numplayers].headless=0;
3186 player[numplayers].onfire=0;
3189 player[numplayers].proportionhead.z=0;
3190 player[numplayers].proportionbody.z=0;
3191 player[numplayers].proportionarms.z=0;
3192 player[numplayers].proportionlegs.z=0;
3195 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3197 player[numplayers].damagetolerance=200;
3199 player[numplayers].protectionhead=player[0].protectionhead;
3200 player[numplayers].protectionhigh=player[0].protectionhigh;
3201 player[numplayers].protectionlow=player[0].protectionlow;
3202 player[numplayers].armorhead=player[0].armorhead;
3203 player[numplayers].armorhigh=player[0].armorhigh;
3204 player[numplayers].armorlow=player[0].armorlow;
3205 player[numplayers].metalhead=player[0].metalhead;
3206 player[numplayers].metalhigh=player[0].metalhigh;
3207 player[numplayers].metallow=player[0].metallow;
3209 player[numplayers].immobile=player[0].immobile;
3211 player[numplayers].numclothes=player[0].numclothes;
3212 if(player[numplayers].numclothes)
3213 for(int i=0;i<player[numplayers].numclothes;i++){
3214 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3215 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3216 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3217 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3218 tintr=player[numplayers].clothestintr[i];
3219 tintg=player[numplayers].clothestintg[i];
3220 tintb=player[numplayers].clothestintb[i];
3221 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3223 if(player[numplayers].numclothes){
3224 player[numplayers].DoMipmaps();
3227 player[numplayers].power=player[0].power;
3228 player[numplayers].speedmult=player[0].speedmult;
3230 player[numplayers].damage=0;
3231 player[numplayers].permanentdamage=0;
3232 player[numplayers].superpermanentdamage=0;
3233 player[numplayers].deathbleeding=0;
3234 player[numplayers].bleeding=0;
3235 player[numplayers].numwaypoints=0;
3236 player[numplayers].waypoint=0;
3237 player[numplayers].jumppath=0;
3238 player[numplayers].weaponstuck=-1;
3239 player[numplayers].weaponactive=-1;
3240 player[numplayers].num_weapons=0;
3241 player[numplayers].bloodloss=0;
3242 player[numplayers].dead=0;
3244 player[numplayers].loaded=1;
3250 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3251 if(player[numplayers-1].numwaypoints<90){
3252 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3253 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3254 player[numplayers-1].numwaypoints++;
3258 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3259 if(numpathpoints<30){
3260 bool connected,alreadyconnected;
3263 for(int i=0;i<numpathpoints;i++){
3264 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3266 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3267 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3269 if(!alreadyconnected){
3270 numpathpointconnect[pathpointselected]++;
3272 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3278 pathpoint[numpathpoints-1]=player[0].coords;
3279 numpathpointconnect[numpathpoints-1]=0;
3280 if(numpathpoints>1&&pathpointselected!=-1){
3281 numpathpointconnect[pathpointselected]++;
3282 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3284 pathpointselected=numpathpoints-1;
3289 if(Input::isKeyPressed(SDLK_PERIOD)){
3290 pathpointselected++;
3291 if(pathpointselected>=numpathpoints)
3292 pathpointselected=-1;
3294 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3295 pathpointselected--;
3296 if(pathpointselected<=-2)
3297 pathpointselected=numpathpoints-1;
3299 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3300 if(pathpointselected!=-1){
3302 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3303 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3304 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3305 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3307 for(int i=0;i<numpathpoints;i++){
3308 for(int j=0;j<numpathpointconnect[i];j++){
3309 if(pathpointconnect[i][j]==pathpointselected){
3310 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3311 numpathpointconnect[i]--;
3313 if(pathpointconnect[i][j]==numpathpoints){
3314 pathpointconnect[i][j]=pathpointselected;
3318 pathpointselected=numpathpoints-1;
3322 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3324 if(editortype==treeleavestype||editortype==10)editortype--;
3325 if(editortype<0)editortype=firetype;
3328 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3330 if(editortype==treeleavestype||editortype==10)editortype++;
3331 if(editortype>firetype)editortype=0;
3334 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3335 editoryaw-=multiplier*100;
3336 if(editoryaw<-.01)editoryaw=-.01;
3339 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3340 editoryaw+=multiplier*100;
3343 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3344 editorsize+=multiplier;
3347 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3348 editorsize-=multiplier;
3349 if(editorsize<.1)editorsize=.1;
3353 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3354 mapradius-=multiplier*10;
3357 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3358 mapradius+=multiplier*10;
3360 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3361 editorpitch+=multiplier*100;
3364 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3365 editorpitch-=multiplier*100;
3366 if(editorpitch<-.01)editorpitch=-.01;
3368 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3370 float closestdist=-1;
3372 for(int i=0;i<objects.numobjects;i++){
3373 distance=findDistancefast(&objects.position[i],&player[0].coords);
3374 if(closestdist==-1||distance<closestdist){
3375 closestdist=distance;
3379 if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
3385 void doJumpReversals(){
3386 for(int k=0;k<numplayers;k++)
3387 for(int i=k;i<numplayers;i++){
3389 if( player[k].skeleton.free==0&&
3390 player[i].skeleton.oldfree==0&&
3391 (player[i].targetanimation==jumpupanim||
3392 player[k].targetanimation==jumpupanim)&&
3393 (player[i].aitype==playercontrolled||
3394 player[k].aitype==playercontrolled)&&
3395 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3396 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3397 if( findDistancefast(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3398 findDistancefastflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3399 //TODO: refactor two huge similar ifs
3400 if(player[i].targetanimation==jumpupanim&&
3401 player[k].targetanimation!=getupfrombackanim&&
3402 player[k].targetanimation!=getupfromfrontanim&&
3403 animation[player[k].targetanimation].height==middleheight&&
3404 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3405 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3406 player[k].aitype!=playercontrolled)){
3407 player[i].victim=&player[k];
3408 player[i].velocity=0;
3409 player[i].currentanimation=jumpreversedanim;
3410 player[i].targetanimation=jumpreversedanim;
3411 player[i].currentframe=0;
3412 player[i].targetframe=1;
3413 player[i].targettilt2=0;
3414 player[k].victim=&player[i];
3415 player[k].velocity=0;
3416 player[k].currentanimation=jumpreversalanim;
3417 player[k].targetanimation=jumpreversalanim;
3418 player[k].currentframe=0;
3419 player[k].targetframe=1;
3420 player[k].targettilt2=0;
3421 if(player[i].coords.y<player[k].coords.y+1){
3422 player[i].currentanimation=rabbitkickreversedanim;
3423 player[i].targetanimation=rabbitkickreversedanim;
3424 player[i].currentframe=1;
3425 player[i].targetframe=2;
3426 player[k].currentanimation=rabbitkickreversalanim;
3427 player[k].targetanimation=rabbitkickreversalanim;
3428 player[k].currentframe=1;
3429 player[k].targetframe=2;
3432 player[k].oldcoords=player[k].coords;
3433 player[i].coords=player[k].coords;
3434 player[k].targetyaw=player[i].targetyaw;
3435 player[k].yaw=player[i].targetyaw;
3436 if(player[k].aitype==attacktypecutoff)
3437 player[k].stunned=.5;
3439 if(player[k].targetanimation==jumpupanim&&
3440 player[i].targetanimation!=getupfrombackanim&&
3441 player[i].targetanimation!=getupfromfrontanim&&
3442 animation[player[i].targetanimation].height==middleheight&&
3443 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3444 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3445 player[i].aitype!=playercontrolled)){
3446 player[k].victim=&player[i];
3447 player[k].velocity=0;
3448 player[k].currentanimation=jumpreversedanim;
3449 player[k].targetanimation=jumpreversedanim;
3450 player[k].currentframe=0;
3451 player[k].targetframe=1;
3452 player[k].targettilt2=0;
3453 player[i].victim=&player[k];
3454 player[i].velocity=0;
3455 player[i].currentanimation=jumpreversalanim;
3456 player[i].targetanimation=jumpreversalanim;
3457 player[i].currentframe=0;
3458 player[i].targetframe=1;
3459 player[i].targettilt2=0;
3460 if(player[k].coords.y<player[i].coords.y+1){
3461 player[k].targetanimation=rabbitkickreversedanim;
3462 player[k].currentanimation=rabbitkickreversedanim;
3463 player[i].currentanimation=rabbitkickreversalanim;
3464 player[i].targetanimation=rabbitkickreversalanim;
3465 player[k].currentframe=1;
3466 player[k].targetframe=2;
3467 player[i].currentframe=1;
3468 player[i].targetframe=2;
3471 player[i].oldcoords=player[i].coords;
3472 player[k].coords=player[i].coords;
3473 player[i].targetyaw=player[k].targetyaw;
3474 player[i].yaw=player[k].targetyaw;
3475 if(player[i].aitype==attacktypecutoff)
3476 player[i].stunned=.5;
3483 void doAerialAcrobatics(){
3484 static XYZ facing,flatfacing;
3485 for(int k=0;k<numplayers;k++){
3486 player[k].turnspeed=500;
3488 if((player[k].isRun()&&
3489 ((player[k].targetyaw!=rabbitrunninganim&&
3490 player[k].targetyaw!=wolfrunninganim)||
3491 player[k].targetframe==4))||
3492 player[k].targetanimation==removeknifeanim||
3493 player[k].targetanimation==crouchremoveknifeanim||
3494 player[k].targetanimation==flipanim||
3495 player[k].targetanimation==fightsidestep||
3496 player[k].targetanimation==walkanim){
3497 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed);
3501 if(player[k].isStop()||
3502 player[k].isLanding()||
3503 player[k].targetanimation==staggerbackhighanim||
3504 (player[k].targetanimation==sneakanim&&player[k].currentanimation==sneakanim)||
3505 player[k].targetanimation==staggerbackhardanim||
3506 player[k].targetanimation==backhandspringanim||
3507 player[k].targetanimation==dodgebackanim||
3508 player[k].targetanimation==rollanim||
3509 (animation[player[k].targetanimation].attack&&
3510 player[k].targetanimation!=rabbitkickanim&&
3511 (player[k].targetanimation!=crouchstabanim||player[k].hasvictim)&&
3512 (player[k].targetanimation!=swordgroundstabanim||player[k].hasvictim))){
3513 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*2);
3516 if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
3517 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*4);
3520 /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3521 player[k].DoStuff();
3522 if(player[k].immobile&&k!=0)
3523 player[k].coords=player[k].realoldcoords;
3525 //if player's position has changed (?)
3526 if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0&&
3527 !player[k].skeleton.free&&
3528 player[k].targetanimation!=climbanim&&
3529 player[k].targetanimation!=hanganim){
3530 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3534 if(player[k].collide<-.3)
3535 player[k].collide=-.3;
3536 if(player[k].collide>1)
3537 player[k].collide=1;
3538 player[k].collide-=multiplier*30;
3541 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3543 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3544 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3545 if(objects.type[i]!=rocktype||
3546 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3547 objects.position[i].y>player[k].coords.y){
3548 lowpoint=player[k].coords;
3549 if(player[k].targetanimation!=jumpupanim&&
3550 player[k].targetanimation!=jumpdownanim&&
3551 !player[k].isFlip())
3555 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3556 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3557 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3558 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i])!=-1){
3559 flatfacing=lowpoint-player[k].coords;
3560 player[k].coords=lowpoint;
3561 player[k].coords.y-=1.3;
3562 player[k].collide=1;
3565 //TODO: refactor four similar blocks
3566 if(player[k].aitype==playercontrolled&&
3567 (player[k].targetanimation==jumpupanim||
3568 player[k].targetanimation==jumpdownanim||
3569 player[k].isFlip())&&
3570 !player[k].jumptogglekeydown&&
3571 player[k].jumpkeydown){
3572 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3573 XYZ tempcoords1=lowpoint;
3574 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3575 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3576 player[k].setAnimation(walljumpleftanim);
3577 emit_sound_at(movewhooshsound, player[k].coords);
3579 pause_sound(whooshsound);
3581 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3582 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3583 if(lowpointtarget.z<0)
3584 player[k].yaw=180-player[k].yaw;
3585 player[k].targetyaw=player[k].yaw;
3586 player[k].lowyaw=player[k].yaw;
3592 lowpoint=tempcoords1;
3593 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3594 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3595 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3596 player[k].setAnimation(walljumprightanim);
3597 emit_sound_at(movewhooshsound, player[k].coords);
3598 if(k==0)pause_sound(whooshsound);
3600 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3601 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3602 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3603 player[k].targetyaw=player[k].yaw;
3604 player[k].lowyaw=player[k].yaw;
3605 if(k==0)numwallflipped++;
3609 lowpoint=tempcoords1;
3610 lowpointtarget=lowpoint+player[k].facing*2;
3611 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3612 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3613 player[k].setAnimation(walljumpbackanim);
3614 emit_sound_at(movewhooshsound, player[k].coords);
3615 if(k==0)pause_sound(whooshsound);
3617 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3618 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3619 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3620 player[k].targetyaw=player[k].yaw;
3621 player[k].lowyaw=player[k].yaw;
3622 if(k==0)numwallflipped++;
3626 lowpoint=tempcoords1;
3627 lowpointtarget=lowpoint-player[k].facing*2;
3628 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3629 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3630 player[k].setAnimation(walljumpfrontanim);
3631 emit_sound_at(movewhooshsound, player[k].coords);
3632 if(k==0)pause_sound(whooshsound);
3634 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3635 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3636 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3638 player[k].targetyaw=player[k].yaw;
3639 player[k].lowyaw=player[k].yaw;
3640 if(k==0)numwallflipped++;
3648 else if(objects.type[i]==rocktype){
3649 lowpoint2=player[k].coords;
3650 lowpoint=player[k].coords;
3652 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.yaw[i])!=-1){
3653 player[k].coords=colpoint;
3654 player[k].collide=1;
3657 if(player[k].targetanimation==jumpdownanim||player[k].isFlip()){
3658 //flipped into a rock
3659 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)
3660 player[k].RagDoll(0);
3662 if(player[k].targetanimation==jumpupanim){
3663 player[k].jumppower=-4;
3664 player[k].targetanimation=player[k].getIdle();
3667 player[k].targetframe=0;
3668 player[k].onterrain=1;
3670 if(player[k].id==0){
3671 pause_sound(whooshsound);
3672 OPENAL_SetVolume(channels[whooshsound], 0);
3676 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3677 if(player[k].isFlip())
3678 player[k].jumppower=-4;
3679 player[k].targetanimation=player[k].getLanding();
3680 emit_sound_at(landsound, player[k].coords, 128.);
3682 envsound[numenvsounds]=player[k].coords;
3683 envsoundvol[numenvsounds]=16;
3684 envsoundlife[numenvsounds]=.4;
3694 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3695 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3696 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3697 lowpoint=player[k].coords;
3699 if(objects.type[i]!=rocktype)
3700 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.yaw[i],&objects.model[i])!=-1){
3701 if(player[k].targetanimation!=jumpupanim&&
3702 player[k].targetanimation!=jumpdownanim&&
3703 player[k].onterrain)
3704 player[k].avoidcollided=1;
3705 player[k].coords=lowpoint;
3706 player[k].coords.y-=1.35;
3707 player[k].collide=1;
3709 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3710 (player[k].currentanimation!=climbanim&&
3711 player[k].currentanimation!=hanganim&&
3712 !player[k].isWallJump()||
3713 player[k].targetanimation==jumpupanim||
3714 player[k].targetanimation==jumpdownanim)){
3715 lowpoint=player[k].coords;
3716 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.yaw[i]);
3717 lowpoint=player[k].coords;
3721 facing=DoRotation(facing,0,player[k].targetyaw+180,0);
3722 lowpointtarget=lowpoint+facing*1.4;
3723 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3725 lowpoint=player[k].coords;
3727 lowpointtarget=lowpoint+facing*1.4;
3729 lowpointtarget2=lowpointtarget;
3731 lowpointtarget3=lowpointtarget;
3733 lowpointtarget4=lowpointtarget;
3735 lowpointtarget5=lowpointtarget;
3737 lowpointtarget6=lowpointtarget;
3739 lowpointtarget7=lowpoint;
3741 lowpointtarget2.x+=.1;
3743 lowpointtarget3.z+=.1;
3745 lowpointtarget4.x-=.1;
3747 lowpointtarget5.z-=.1;
3749 lowpointtarget6.y+=45/13;
3750 lowpointtarget6+=facing*.6;
3751 lowpointtarget7.y+=90/13;
3752 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3753 if(objects.friction[i]>.5)
3755 if(whichhit!=-1&&player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)
3756 player[k].collided=1;
3757 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3758 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3759 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3760 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3761 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3762 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3763 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3764 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3765 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3766 &colpoint,&objects.position[i],&objects.yaw[i])!=-1)
3767 for(int j=0;j<45;j++){
3768 lowpoint=player[k].coords;
3769 lowpoint.y+=(float)j/13;
3770 lowpointtarget=lowpoint+facing*1.4;
3771 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3772 &colpoint2,&objects.position[i],&objects.yaw[i])==-1){
3773 if(j<=6||j<=25&&player[k].targetanimation==jumpdownanim)
3775 if(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim){
3776 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[k],0);
3777 lowpoint=player[k].coords;
3778 lowpoint.y+=(float)j/13;
3779 lowpointtarget=lowpoint+facing*1.3;
3780 flatfacing=player[k].coords;
3781 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[k],0)*.01;
3782 player[k].coords.y=lowpointtarget.y-.07;
3783 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3785 if(j>10||!player[k].isRun()){
3786 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
3788 pause_sound(whooshsound);
3790 emit_sound_at(jumpsound, player[k].coords, 128.);
3792 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3793 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3794 if(lowpointtarget.z<0)
3795 player[k].yaw=180-player[k].yaw;
3796 player[k].targetyaw=player[k].yaw;
3797 player[k].lowyaw=player[k].yaw;
3799 //player[k].velocity=lowpointtarget*.03;
3800 player[k].velocity=0;
3803 if(player[k].targetanimation==jumpupanim){
3804 player[k].targetanimation=climbanim;
3805 player[k].jumppower=0;
3806 player[k].jumpclimb=1;
3808 player[k].transspeed=6;
3810 player[k].targetframe=1;
3813 player[k].setAnimation(hanganim);
3814 player[k].jumppower=0;
3826 if(player[k].collide<=0){
3828 if(!player[k].onterrain&&
3829 player[k].targetanimation!=jumpupanim&&
3830 player[k].targetanimation!=jumpdownanim&&
3831 player[k].targetanimation!=climbanim&&
3832 player[k].targetanimation!=hanganim&&
3833 !player[k].isWallJump()&&
3834 !player[k].isFlip()){
3835 if(player[k].currentanimation!=climbanim&&
3836 player[k].currentanimation!=tempanim&&
3837 player[k].targetanimation!=backhandspringanim&&
3838 (player[k].targetanimation!=rollanim||
3839 player[k].targetframe<2||
3840 player[k].targetframe>6)){
3841 //stagger off ledge (?)
3842 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)
3843 player[k].RagDoll(0);
3844 player[k].setAnimation(jumpdownanim);
3847 emit_sound_at(whooshsound, player[k].coords, 128.);
3850 player[k].velocity.y+=gravity;
3854 player[k].realoldcoords=player[k].coords;
3859 static XYZ relative;
3860 static int randattack;
3861 static bool playerrealattackkeydown=0;
3863 if(!Input::isKeyDown(attackkey))
3866 player[0].attackkeydown=0;
3868 playerrealattackkeydown=0;
3870 playerrealattackkeydown=Input::isKeyDown(attackkey);
3871 if((player[0].parriedrecently<=0||
3872 player[0].weaponactive==-1)&&
3875 player[0].lastattack!=swordslashanim&&
3876 player[0].lastattack!=knifeslashstartanim&&
3877 player[0].lastattack!=staffhitanim&&
3878 player[0].lastattack!=staffspinhitanim)))
3879 player[0].attackkeydown=Input::isKeyDown(attackkey);
3880 if(Input::isKeyDown(attackkey)&&
3882 !player[0].backkeydown){
3883 for(int k=0;k<numplayers;k++){
3884 if((player[k].targetanimation==swordslashanim||
3885 player[k].targetanimation==staffhitanim||
3886 player[k].targetanimation==staffspinhitanim)&&
3887 player[0].currentanimation!=dodgebackanim&&
3888 !player[k].skeleton.free)
3889 player[k].Reverse();
3893 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3895 for(int k=0;k<numplayers;k++){
3896 if(indialogue!=-1)player[k].attackkeydown=0;
3897 if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
3898 if(player[k].aitype!=playercontrolled)
3899 player[k].victim=&player[0];
3900 //attack key pressed
3901 if(player[k].attackkeydown){
3903 if(player[k].backkeydown&&
3904 player[k].targetanimation!=backhandspringanim&&
3905 (player[k].isIdle()||
3906 player[k].isStop()||
3908 player[k].targetanimation==walkanim)){
3909 if(player[k].jumppower<=1){
3910 player[k].jumppower-=2;
3912 for(int i=0;i<numplayers;i++){
3914 if(player[i].targetanimation==swordslashanim||
3915 player[i].targetanimation==knifeslashstartanim||
3916 player[i].targetanimation==staffhitanim||
3917 player[i].targetanimation==staffspinhitanim)
3918 if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3919 player[k].setAnimation(dodgebackanim);
3920 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
3921 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3924 if(player[k].targetanimation!=dodgebackanim){
3925 if(k==0)numflipped++;
3926 player[k].setAnimation(backhandspringanim);
3927 player[k].targetyaw=-yaw+180;
3928 if(player[k].leftkeydown)
3929 player[k].targetyaw-=45;
3930 if(player[k].rightkeydown)
3931 player[k].targetyaw+=45;
3932 player[k].yaw=player[k].targetyaw;
3933 player[k].jumppower-=2;
3938 if(!animation[player[k].targetanimation].attack&&
3939 !player[k].backkeydown&&
3940 (player[k].isIdle()||
3942 player[k].targetanimation==walkanim||
3943 player[k].targetanimation==sneakanim||
3944 player[k].isCrouch())){
3945 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3946 //normal attacks (?)
3947 player[k].hasvictim=0;
3949 for(int i=0;i<numplayers;i++){
3950 if(i==k||!(k==0||i==0))continue;
3951 if(!player[k].hasvictim)
3952 if(animation[player[k].targetanimation].attack!=reversal){
3954 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
3956 !player[i].skeleton.free&&
3957 player[i].howactive<typedead1&&
3958 player[i].targetanimation!=jumpreversedanim&&
3959 player[i].targetanimation!=rabbitkickreversedanim&&
3960 player[i].targetanimation!=rabbitkickanim&&
3961 player[k].targetanimation!=rabbitkickanim&&
3962 player[i].targetanimation!=getupfrombackanim&&
3963 (player[i].targetanimation!=staggerbackhighanim&&
3964 (player[i].targetanimation!=staggerbackhardanim||
3965 animation[staggerbackhardanim].label[player[i].targetframe]==6))&&
3966 player[i].targetanimation!=jumpdownanim&&
3967 player[i].targetanimation!=jumpupanim&&
3968 player[i].targetanimation!=getupfromfrontanim){
3969 player[k].victim=&player[i];
3970 player[k].hasvictim=1;
3971 if(player[k].aitype==playercontrolled){ //human player
3973 if(distance<2.5*sq(player[k].scale*5)&&
3974 player[k].crouchkeydown&&
3975 animation[player[i].targetanimation].height!=lowheight)
3976 player[k].targetanimation=sweepanim;
3978 else if(distance<1.5*sq(player[k].scale*5)&&
3979 animation[player[i].targetanimation].height!=lowheight&&
3980 !player[k].forwardkeydown&&
3981 !player[k].leftkeydown&&
3982 !player[k].rightkeydown&&
3983 !player[k].crouchkeydown&&
3986 player[k].targetanimation=winduppunchanim;
3988 else if(distance<2.5*sq(player[k].scale*5)&&
3989 animation[player[i].targetanimation].height!=lowheight&&
3990 !player[k].forwardkeydown&&
3991 !player[k].leftkeydown&&
3992 !player[k].rightkeydown&&
3993 !player[k].crouchkeydown&&
3995 player[k].targetanimation=upunchanim;
3997 else if(distance<2.5*sq(player[k].scale*5)&&
3998 player[i].staggerdelay>0&&
3999 attackweapon==knife&&
4000 player[i].bloodloss>player[i].damagetolerance/2)
4001 player[k].targetanimation=knifefollowanim;
4003 else if(distance<2.5*sq(player[k].scale*5)&&
4004 animation[player[i].targetanimation].height!=lowheight&&
4005 !player[k].forwardkeydown&&
4006 !player[k].leftkeydown&&
4007 !player[k].rightkeydown&&
4008 !player[k].crouchkeydown&&
4009 attackweapon==knife&&
4010 player[k].weaponmissdelay<=0)
4011 player[k].targetanimation=knifeslashstartanim;
4013 else if(distance<4.5*sq(player[k].scale*5)&&
4014 animation[player[i].targetanimation].height!=lowheight&&
4015 !player[k].crouchkeydown&&
4016 attackweapon==sword&&
4017 player[k].weaponmissdelay<=0)
4018 player[k].targetanimation=swordslashanim;
4020 else if(distance<4.5*sq(player[k].scale*5)&&
4021 animation[player[i].targetanimation].height!=lowheight&&
4022 !player[k].crouchkeydown&&
4023 attackweapon==staff&&
4024 player[k].weaponmissdelay<=0&&
4025 !player[k].leftkeydown&&
4026 !player[k].rightkeydown&&
4027 !player[k].forwardkeydown)
4028 player[k].targetanimation=staffhitanim;
4030 else if(distance<4.5*sq(player[k].scale*5)&&
4031 animation[player[i].targetanimation].height!=lowheight&&
4032 !player[k].crouchkeydown&&
4033 attackweapon==staff&&
4034 player[k].weaponmissdelay<=0)
4035 player[k].targetanimation=staffspinhitanim;
4037 else if(distance<2.5*sq(player[k].scale*5)&&
4038 animation[player[i].targetanimation].height!=lowheight)
4039 player[k].targetanimation=spinkickanim;
4041 else if(distance<2.5*sq(player[k].scale*5)&&
4042 animation[player[i].targetanimation].height==lowheight&&
4043 animation[player[k].targetanimation].attack!=normalattack)
4044 player[k].targetanimation=lowkickanim;
4045 } else { //AI player
4046 if(distance<4.5*sq(player[k].scale*5)){
4047 randattack=abs(Random()%5);
4048 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
4050 if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)
4051 player[k].targetanimation=sweepanim;
4053 else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&
4055 player[k].targetanimation=upunchanim;
4057 else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)
4058 player[k].targetanimation=spinkickanim;
4060 else if(animation[player[i].targetanimation].height==lowheight)
4061 player[k].targetanimation=lowkickanim;
4065 if((tutoriallevel!=1||!attackweapon)&&
4066 distance<2.5*sq(player[k].scale*5)&&
4068 animation[player[i].targetanimation].height!=lowheight)
4069 player[k].targetanimation=sweepanim;
4071 else if(distance<2.5*sq(player[k].scale*5)&&
4072 attackweapon==knife&&
4073 player[k].weaponmissdelay<=0)
4074 player[k].targetanimation=knifeslashstartanim;
4076 else if(!(player[0].victim==&player[i]&&
4077 player[0].hasvictim&&
4078 player[0].targetanimation==swordslashanim)&&
4079 attackweapon==sword&&
4080 player[k].weaponmissdelay<=0)
4081 player[k].targetanimation=swordslashanim;
4083 else if(!(player[0].victim==&player[i]&&
4084 player[0].hasvictim&&
4085 player[0].targetanimation==swordslashanim)&&
4086 attackweapon==staff&&
4087 player[k].weaponmissdelay<=0&&
4089 player[k].targetanimation=staffhitanim;
4091 else if(!(player[0].victim==&player[i]&&
4092 player[0].hasvictim&&
4093 player[0].targetanimation==swordslashanim)&&
4094 attackweapon==staff&&
4095 player[k].weaponmissdelay<=0&&
4097 player[k].targetanimation=staffspinhitanim;
4099 else if((tutoriallevel!=1||!attackweapon)&&
4100 distance<2.5*sq(player[k].scale*5)&&
4102 animation[player[i].targetanimation].height!=lowheight)
4103 player[k].targetanimation=spinkickanim;
4105 else if(distance<2.5*sq(player[k].scale*5)&&
4106 animation[player[i].targetanimation].height==lowheight&&
4107 animation[player[k].targetanimation].attack!=normalattack)
4108 player[k].targetanimation=lowkickanim;
4112 //upunch becomes wolfslap
4113 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)
4114 player[k].targetanimation=wolfslapanim;
4117 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4118 player[i].howactive<typedead1&&
4119 distance<1.5*sq(player[k].scale*5)&&
4120 !player[i].skeleton.free&&
4121 player[i].targetanimation!=getupfrombackanim&&
4122 player[i].targetanimation!=getupfromfrontanim&&
4123 (player[i].stunned>0&&player[k].madskills||
4124 player[i].surprised>0||
4125 player[i].aitype==passivetype||
4126 attackweapon&&player[i].stunned>0)&&
4127 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4130 player[k].currentanimation=sneakattackanim;
4131 player[k].targetanimation=sneakattackanim;
4132 player[i].currentanimation=sneakattackedanim;
4133 player[i].targetanimation=sneakattackedanim;
4134 player[k].oldcoords=player[k].coords;
4135 player[k].coords=player[i].coords;
4138 if(attackweapon==knife){
4139 player[k].currentanimation=knifesneakattackanim;
4140 player[k].targetanimation=knifesneakattackanim;
4141 player[i].currentanimation=knifesneakattackedanim;
4142 player[i].targetanimation=knifesneakattackedanim;
4143 player[i].oldcoords=player[i].coords;
4144 player[i].coords=player[k].coords;
4147 if(attackweapon==sword){
4148 player[k].currentanimation=swordsneakattackanim;
4149 player[k].targetanimation=swordsneakattackanim;
4150 player[i].currentanimation=swordsneakattackedanim;
4151 player[i].targetanimation=swordsneakattackedanim;
4152 player[i].oldcoords=player[i].coords;
4153 player[i].coords=player[k].coords;
4155 if(attackweapon!=staff){
4156 player[k].victim=&player[i];
4157 player[k].hasvictim=1;
4158 player[i].targettilt2=0;
4159 player[i].targetframe=1;
4160 player[i].currentframe=0;
4162 player[i].velocity=0;
4163 player[k].targettilt2=player[i].targettilt2;
4164 player[k].currentframe=player[i].currentframe;
4165 player[k].targetframe=player[i].targetframe;
4166 player[k].target=player[i].target;
4167 player[k].velocity=0;
4168 player[k].targetyaw=player[i].yaw;
4169 player[k].yaw=player[i].yaw;
4170 player[i].targetyaw=player[i].yaw;
4173 if(animation[player[k].targetanimation].attack==normalattack&&
4174 player[k].victim==&player[i]&&
4175 (!player[i].skeleton.free)){
4177 player[k].targetframe=0;
4180 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
4181 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4182 player[k].lastattack3=player[k].lastattack2;
4183 player[k].lastattack2=player[k].lastattack;
4184 player[k].lastattack=player[k].targetanimation;
4186 if(player[k].targetanimation==knifefollowanim&&
4187 player[k].victim==&player[i]){
4189 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
4190 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4191 player[k].victim=&player[i];
4192 player[k].hasvictim=1;
4193 player[i].targetanimation=knifefollowedanim;
4194 player[i].currentanimation=knifefollowedanim;
4195 player[i].targettilt2=0;
4196 player[i].targettilt2=player[k].targettilt2;
4197 player[i].targetframe=1;
4198 player[i].currentframe=0;
4200 player[i].velocity=0;
4201 player[k].currentanimation=knifefollowanim;
4202 player[k].targetanimation=knifefollowanim;
4203 player[k].targettilt2=player[i].targettilt2;
4204 player[k].currentframe=player[i].currentframe;
4205 player[k].targetframe=player[i].targetframe;
4206 player[k].target=player[i].target;
4207 player[k].velocity=0;
4208 player[k].oldcoords=player[k].coords;
4209 player[i].coords=player[k].coords;
4210 player[i].targetyaw=player[k].targetyaw;
4211 player[i].yaw=player[k].targetyaw;
4212 player[k].yaw=player[k].targetyaw;
4213 player[i].yaw=player[k].targetyaw;
4217 const bool hasstaff=attackweapon==staff;
4218 if(k==0&&numplayers>1)
4219 for(int i=0;i<numplayers;i++){
4221 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4222 animation[player[k].targetanimation].attack==neutral){
4223 const float distance=findDistancefast(&player[k].coords,&player[i].coords);
4224 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4225 if(player[i].skeleton.free)
4226 if(distance<3.5*sq(player[k].scale*5)&&
4228 player[i].skeleton.longdead>1000||
4232 (player[i].skeleton.longdead>2000||
4233 player[i].damage>player[i].damagetolerance/8||
4234 player[i].bloodloss>player[i].damagetolerance/2)&&
4235 distance<1.5*sq(player[k].scale*5)))){
4236 player[k].victim=&player[i];
4237 player[k].hasvictim=1;
4238 if(attackweapon&&tutoriallevel!=1){
4240 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4241 player[k].targetanimation=crouchstabanim;
4243 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4244 player[k].targetanimation=swordgroundstabanim;
4246 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4247 player[k].targetanimation=staffgroundsmashanim;
4250 player[k].crouchkeydown&&
4251 player[k].targetanimation!=crouchstabanim&&
4254 player[i].skeleton.free&&
4255 player[i].skeleton.longdead>1000){
4256 player[k].targetanimation=killanim;
4257 //TODO: refactor this out, what does it do?
4258 for(int j=0;j<terrain.numdecals;j++){
4259 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4260 terrain.decalalivetime[j]<2)
4261 terrain.DeleteDecal(j);
4263 for(int l=0;l<objects.numobjects;l++){
4264 if(objects.model[l].type==decalstype)
4265 for(int j=0;j<objects.model[l].numdecals;j++){
4266 if((objects.model[l].decaltype[j]==blooddecal||
4267 objects.model[l].decaltype[j]==blooddecalslow)&&
4268 objects.model[l].decalalivetime[j]<2)
4269 objects.model[l].DeleteDecal(j);
4273 if(!player[i].dead||musictype!=2)
4275 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4276 player[k].staggerdelay<=0&&
4278 player[i].skeleton.longdead<300&&
4279 player[k].lastattack!=spinkickanim&&
4280 player[i].skeleton.free)&&
4281 (!player[i].dead||musictype!=stream_fighttheme)){
4282 player[k].targetanimation=dropkickanim;
4283 for(int j=0;j<terrain.numdecals;j++){
4284 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4285 terrain.decalalivetime[j]<2){
4286 terrain.DeleteDecal(j);
4289 for(int l=0;l<objects.numobjects;l++){
4290 if(objects.model[l].type==decalstype)
4291 for(int j=0;j<objects.model[l].numdecals;j++){
4292 if((objects.model[l].decaltype[j]==blooddecal||
4293 objects.model[l].decaltype[j]==blooddecalslow)&&
4294 objects.model[l].decalalivetime[j]<2){
4295 objects.model[l].DeleteDecal(j);
4301 if(animation[player[k].targetanimation].attack==normalattack&&
4302 player[k].victim==&player[i]&&
4303 (!player[i].skeleton.free||
4304 player[k].targetanimation==killanim||
4305 player[k].targetanimation==crouchstabanim||
4306 player[k].targetanimation==swordgroundstabanim||
4307 player[k].targetanimation==staffgroundsmashanim||
4308 player[k].targetanimation==dropkickanim)){
4310 player[k].targetframe=0;
4313 XYZ targetpoint=player[i].coords;
4314 if(player[k].targetanimation==crouchstabanim||
4315 player[k].targetanimation==swordgroundstabanim||
4316 player[k].targetanimation==staffgroundsmashanim){
4317 targetpoint+=(player[i].getJointFor(abdomen).position+
4318 player[i].getJointFor(neck).position)/2*
4321 player[k].targetyaw=roughDirectionTo(player[k].coords,targetpoint);
4322 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4324 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
4325 player[k].targetyaw+=(float)(abs(Random()%100)-50)/4;
4328 if(player[k].targetanimation==staffgroundsmashanim)
4329 player[k].targettilt2+=10;
4331 player[k].lastattack3=player[k].lastattack2;
4332 player[k].lastattack2=player[k].lastattack;
4333 player[k].lastattack=player[k].targetanimation;
4335 if(player[k].targetanimation==swordgroundstabanim){
4336 player[k].targetyaw+=30;
4341 if(!player[k].hasvictim){
4343 for(int i=0;i<numplayers;i++){
4344 if(i==k||!(i==0||k==0))continue;
4345 if(!player[i].skeleton.free){
4346 if(player[k].hasvictim){
4347 if(findDistancefast(&player[k].coords,&player[i].coords)<
4348 findDistancefast(&player[k].coords,&player[k].victim->coords))
4349 player[k].victim=&player[i];
4351 player[k].victim=&player[i];
4352 player[k].hasvictim=1;
4357 if(player[k].aitype==playercontrolled)
4359 if(player[k].attackkeydown&&
4361 player[k].wasRun()&&
4362 ((player[k].hasvictim&&
4363 findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4364 findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4365 !player[k].victim->skeleton.free&&
4366 player[k].victim->targetanimation!=getupfrombackanim&&
4367 player[k].victim->targetanimation!=getupfromfrontanim&&
4368 animation[player[k].victim->targetanimation].height!=lowheight&&
4369 player[k].aitype!=playercontrolled&& //wat???
4370 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4371 player[k].rabbitkickenabled)||
4372 player[k].jumpkeydown)){
4374 player[k].setAnimation(rabbitkickanim);
4377 if(animation[player[k].targetanimation].attack&&k==0){
4379 switch(attackweapon){
4380 case 0: numunarmedattack++; break;
4381 case knife: numknifeattack++; break;
4382 case sword: numswordattack++; break;
4383 case staff: numstaffattack++; break;
4392 void doPlayerCollisions(){
4393 static XYZ rotatetarget;
4394 static float collisionradius;
4396 for(int k=0;k<numplayers;k++)
4397 for(int i=k+1;i<numplayers;i++){
4398 //neither player is part of a reversal
4399 if((animation[player[i].targetanimation].attack!=reversed&&
4400 animation[player[i].targetanimation].attack!=reversal&&
4401 animation[player[k].targetanimation].attack!=reversed&&
4402 animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
4403 if((animation[player[i].currentanimation].attack!=reversed&&
4404 animation[player[i].currentanimation].attack!=reversal&&
4405 animation[player[k].currentanimation].attack!=reversed&&
4406 animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
4407 //neither is sleeping
4408 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4409 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4410 //in same patch, neither is climbing
4411 if(player[i].whichpatchx==player[k].whichpatchx&&
4412 player[i].whichpatchz==player[k].whichpatchz&&
4413 player[k].skeleton.oldfree==player[k].skeleton.free&&
4414 player[i].skeleton.oldfree==player[i].skeleton.free&&
4415 player[i].targetanimation!=climbanim&&
4416 player[i].targetanimation!=hanganim&&
4417 player[k].targetanimation!=climbanim&&
4418 player[k].targetanimation!=hanganim)
4419 //players are close (bounding box test)
4420 if(player[i].coords.y>player[k].coords.y-3)
4421 if(player[i].coords.y<player[k].coords.y+3)
4422 if(player[i].coords.x>player[k].coords.x-3)
4423 if(player[i].coords.x<player[k].coords.x+3)
4424 if(player[i].coords.z>player[k].coords.z-3)
4425 if(player[i].coords.z<player[k].coords.z+3){
4426 //spread fire from player to player
4427 if(findDistancefast(&player[i].coords,&player[k].coords)
4428 <3*sq((player[i].scale+player[k].scale)*2.5)){
4429 if(player[i].onfire||player[k].onfire){
4430 if(!player[i].onfire)player[i].CatchFire();
4431 if(!player[k].onfire)player[k].CatchFire();
4435 XYZ tempcoords1=player[i].coords;
4436 XYZ tempcoords2=player[k].coords;
4437 if(!player[i].skeleton.oldfree)
4438 tempcoords1.y+=player[i].getJointFor(abdomen).position.y*player[i].scale;
4439 if(!player[k].skeleton.oldfree)
4440 tempcoords2.y+=player[k].getJointFor(abdomen).position.y*player[k].scale;
4441 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4442 if(player[0].hasvictim)
4443 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4445 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4446 (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
4447 findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
4448 //jump down on a dead body
4451 if(player[0].targetanimation==jumpdownanim&&
4452 !player[0].skeleton.oldfree&&
4453 !player[0].skeleton.free&&
4454 player[l].skeleton.oldfree&&
4455 player[l].skeleton.free&&
4457 player[0].lastcollide<=0&&
4458 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4459 findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4460 player[0].coords.y=player[l].coords.y;
4461 player[l].velocity=player[0].velocity;
4462 player[l].skeleton.free=0;
4464 player[l].RagDoll(0);
4465 player[l].DoDamage(20);
4467 player[l].skeleton.longdead=0;
4468 player[0].lastcollide=1;
4472 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4473 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4474 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4475 rotatetarget=player[k].velocity-player[i].velocity;
4476 if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
4477 player[i].skeleton.free)&&
4478 (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
4479 player[k].skeleton.free))
4480 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4481 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4482 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4484 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
4485 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
4486 (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
4487 (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
4488 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4490 if( (i!=0||player[i].skeleton.free)&&
4491 (k!=0||player[k].skeleton.free)||
4492 (animation[player[i].targetanimation].height==highheight&&
4493 animation[player[k].targetanimation].height==highheight)){
4494 if(tutoriallevel!=1){
4495 emit_sound_at(heavyimpactsound, player[i].coords);
4498 player[i].RagDoll(0);
4499 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4500 award_bonus(0, aimbonus);
4502 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4503 player[k].RagDoll(0);
4504 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4505 award_bonus(0, aimbonus); // Huh, again?
4507 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4509 for(int j=0;j<player[i].skeleton.num_joints;j++){
4510 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4512 for(int j=0;j<player[k].skeleton.num_joints;j++){
4513 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4518 if( (animation[player[i].targetanimation].attack==neutral||
4519 animation[player[i].targetanimation].attack==normalattack)&&
4520 (animation[player[k].targetanimation].attack==neutral||
4521 animation[player[k].targetanimation].attack==normalattack)){
4523 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4524 if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4525 rotatetarget=player[k].coords-player[i].coords;
4526 Normalise(&rotatetarget);
4527 player[k].coords=(player[k].coords+player[i].coords)/2;
4528 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4529 *sq((player[i].scale+player[k].scale)*2.5);
4530 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4531 if(player[k].howactive==typeactive||hostile)
4532 if(player[k].isIdle()){
4533 if(player[k].howactive<typesleeping)
4534 player[k].setAnimation(player[k].getStop());
4535 else if(player[k].howactive==typesleeping)
4536 player[k].setAnimation(getupfromfrontanim);
4538 player[k].howactive=typeactive;
4540 if(player[i].howactive==typeactive||hostile)
4541 if(player[i].isIdle()){
4542 if(player[i].howactive<typesleeping)
4543 player[i].setAnimation(player[k].getStop());
4545 player[i].setAnimation(getupfromfrontanim);
4547 player[i].howactive=typeactive;
4550 //jump down on player
4552 if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
4553 !player[i].isCrouch()&&
4554 player[i].targetanimation!=rollanim&&
4555 !player[k].skeleton.oldfree&&!
4556 player[k].skeleton.free&&
4557 player[k].lastcollide<=0&&
4558 player[k].velocity.y<-10){
4559 player[i].velocity=player[k].velocity;
4560 player[k].velocity=player[k].velocity*-.5;
4561 player[k].velocity.y=player[i].velocity.y;
4562 player[i].DoDamage(20);
4563 player[i].RagDoll(0);
4564 player[k].lastcollide=1;
4565 award_bonus(k, AboveBonus);
4567 if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&
4568 !player[k].isCrouch()&&
4569 player[k].targetanimation!=rollanim&&
4570 !player[i].skeleton.oldfree&&
4571 !player[i].skeleton.free&&
4572 player[i].lastcollide<=0&&
4573 player[i].velocity.y<-10){
4574 player[k].velocity=player[i].velocity;
4575 player[i].velocity=player[i].velocity*-.3;
4576 player[i].velocity.y=player[k].velocity.y;
4577 player[k].DoDamage(20);
4578 player[k].RagDoll(0);
4579 player[i].lastcollide=1;
4580 award_bonus(i, AboveBonus);
4586 player[i].CheckKick();
4587 player[k].CheckKick();
4594 static bool connected;
4595 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4596 player[i].jumpclimb=0;
4597 //disable movement in editor
4599 player[i].stunned=1;
4602 if(findDistancefastflat(&player[0].coords,&player[i].coords)<30&&
4603 player[0].coords.y>player[i].coords.y+2&&
4604 !player[0].onterrain)
4608 if(player[i].aitype==pathfindtype){
4609 if(player[i].finalpathfindpoint==-1){
4610 float closestdistance;
4616 for(int j=0;j<numpathpoints;j++)
4617 if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4618 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
4620 player[i].finaltarget=pathpoint[j];
4622 player[i].finalpathfindpoint=closest;
4623 for(int j=0;j<numpathpoints;j++)
4624 for(int k=0;k<numpathpointconnect[j];k++){
4625 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4626 if(sq(tempdist)<closestdistance)
4627 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4628 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4629 closestdistance=sq(tempdist);
4631 player[i].finaltarget=colpoint;
4634 player[i].finalpathfindpoint=closest;
4637 if(player[i].targetpathfindpoint==-1){
4638 float closestdistance;
4644 if(player[i].lastpathfindpoint==-1){
4645 for(int j=0;j<numpathpoints;j++){
4646 if(j!=player[i].lastpathfindpoint)
4647 if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance)){
4648 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
4652 player[i].targetpathfindpoint=closest;
4653 for(int j=0;j<numpathpoints;j++)
4654 if(j!=player[i].lastpathfindpoint)
4655 for(int k=0;k<numpathpointconnect[j];k++){
4656 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4657 if(sq(tempdist)<closestdistance){
4658 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4659 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4660 closestdistance=sq(tempdist);
4665 player[i].targetpathfindpoint=closest;
4669 for(int j=0;j<numpathpoints;j++)
4670 if(j!=player[i].lastpathfindpoint&&
4671 j!=player[i].lastpathfindpoint2&&
4672 j!=player[i].lastpathfindpoint3&&
4673 j!=player[i].lastpathfindpoint4){
4675 if(numpathpointconnect[j])
4676 for(int k=0;k<numpathpointconnect[j];k++)
4677 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4680 if(numpathpointconnect[player[i].lastpathfindpoint])
4681 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4682 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4685 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4686 if(closest==-1||tempdist<closestdistance){
4687 closestdistance=tempdist;
4692 player[i].targetpathfindpoint=closest;
4695 player[i].losupdatedelay-=multiplier;
4697 player[i].targetyaw=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4698 player[i].lookyaw=player[i].targetyaw;
4700 //reached target point
4701 if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4702 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4703 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4704 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4705 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4706 if(player[i].lastpathfindpoint2==-1)
4707 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4708 if(player[i].lastpathfindpoint3==-1)
4709 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4710 if(player[i].lastpathfindpoint4==-1)
4711 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4712 player[i].targetpathfindpoint=-1;
4714 if( findDistancefastflat(&player[i].coords,&player[i].finalfinaltarget)<
4715 findDistancefastflat(&player[i].coords,&player[i].finaltarget)||
4716 findDistancefastflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4717 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4718 player[i].aitype=passivetype;
4721 player[i].forwardkeydown=1;
4722 player[i].leftkeydown=0;
4723 player[i].backkeydown=0;
4724 player[i].rightkeydown=0;
4725 player[i].crouchkeydown=0;
4726 player[i].attackkeydown=0;
4727 player[i].throwkeydown=0;
4729 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4730 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
4732 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4733 player[i].jumpkeydown=0;
4734 if((player[i].collided>.8&&player[i].jumppower>=5))
4735 player[i].jumpkeydown=1;
4737 if((tutoriallevel!=1||cananger)&&
4740 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4741 player[i].occluded<25){
4742 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4743 animation[player[0].targetanimation].height!=lowheight&&
4745 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4746 player[i].aitype=attacktypecutoff;
4747 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4748 animation[player[0].targetanimation].height==highheight&&
4750 player[i].aitype=attacktypecutoff;
4752 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4753 player[i].losupdatedelay=.2;
4754 for(int j=0;j<numplayers;j++)
4755 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4756 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4757 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4758 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4759 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4760 if(!player[j].isWallJump()&&-1==checkcollide(
4761 DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)
4762 *player[i].scale+player[i].coords,
4763 DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)
4764 *player[j].scale+player[j].coords)||
4765 (player[j].targetanimation==hanganim&&
4766 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4767 player[i].aitype=searchtype;
4768 player[i].lastchecktime=12;
4769 player[i].lastseen=player[j].coords;
4770 player[i].lastseentime=12;
4774 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4775 if(player[i].creature!=wolftype){
4776 player[i].stunned=.6;
4777 player[i].surprised=.6;
4781 if(player[i].aitype!=passivetype&&leveltime>.5)
4782 player[i].howactive=typeactive;
4784 if(player[i].aitype==passivetype){
4785 player[i].aiupdatedelay-=multiplier;
4786 player[i].losupdatedelay-=multiplier;
4787 player[i].lastseentime+=multiplier;
4788 player[i].pausetime-=multiplier;
4789 if(player[i].lastseentime>1)
4790 player[i].lastseentime=1;
4792 if(player[i].aiupdatedelay<0){
4793 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4794 player[i].targetyaw=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4795 player[i].lookyaw=player[i].targetyaw;
4796 player[i].aiupdatedelay=.05;
4798 if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4799 if(player[i].waypointtype[player[i].waypoint]==wppause)
4800 player[i].pausetime=4;
4801 player[i].waypoint++;
4802 if(player[i].waypoint>player[i].numwaypoints-1)
4803 player[i].waypoint=0;
4808 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4809 player[i].forwardkeydown=1;
4811 player[i].forwardkeydown=0;
4812 player[i].leftkeydown=0;
4813 player[i].backkeydown=0;
4814 player[i].rightkeydown=0;
4815 player[i].crouchkeydown=0;
4816 player[i].attackkeydown=0;
4817 player[i].throwkeydown=0;
4819 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4820 if(!player[i].avoidsomething)
4821 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
4823 XYZ leftpos,rightpos;
4824 float leftdist,rightdist;
4825 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4826 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4827 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
4828 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
4829 if(leftdist<rightdist)
4830 player[i].targetyaw+=90;
4832 player[i].targetyaw-=90;
4836 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
4837 player[i].jumpkeydown=0;
4838 if((player[i].collided>.8&&player[i].jumppower>=5))
4839 player[i].jumpkeydown=1;
4844 if(player[i].howactive<=typesleeping)
4845 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4846 for(int j=0;j<numenvsounds;j++){
4847 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4848 if(vol>0&&findDistancefast(&player[i].coords,&envsound[j])<
4849 2*(vol+vol*(player[i].creature==rabbittype)*3))
4850 player[i].aitype=attacktypecutoff;
4853 if(player[i].aitype!=passivetype){
4854 if(player[i].howactive==typesleeping)
4855 player[i].setAnimation(getupfromfrontanim);
4856 player[i].howactive=typeactive;
4860 if(player[i].howactive<typesleeping&&
4861 ((tutoriallevel!=1||cananger)&&hostile)&&
4863 findDistancefast(&player[i].coords,&player[0].coords)<400&&
4864 player[i].occluded<25){
4865 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&
4866 animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
4867 player[i].aitype=attacktypecutoff;
4868 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&
4869 animation[player[0].targetanimation].height==highheight&&!editorenabled)
4870 player[i].aitype=attacktypecutoff;
4873 if(player[i].creature==wolftype){
4875 for(int j=0;j<numplayers;j++){
4876 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4877 float smelldistance=50;
4878 if(j==0&&player[j].num_weapons>0){
4879 if(weapons[player[j].weaponids[0]].bloody)
4881 if(player[j].num_weapons==2)
4882 if(weapons[player[j].weaponids[1]].bloody)
4887 windsmell=windvector;
4888 Normalise(&windsmell);
4889 windsmell=windsmell*2+player[j].coords;
4890 if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4891 player[i].aitype=attacktypecutoff;
4896 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4897 player[i].losupdatedelay=.2;
4898 for(int j=0;j<numplayers;j++){
4899 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4900 if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
4901 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
4902 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4903 if((-1==checkcollide(
4904 DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
4905 player[i].scale+player[i].coords,
4906 DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)*
4907 player[j].scale+player[j].coords)&&
4908 !player[j].isWallJump())||
4909 (player[j].targetanimation==hanganim&&
4910 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4911 player[i].lastseentime-=.2;
4912 if(j==0&&animation[player[j].targetanimation].height==lowheight)
4913 player[i].lastseentime-=.4;
4915 player[i].lastseentime-=.6;
4917 if(player[i].lastseentime<=0){
4918 player[i].aitype=searchtype;
4919 player[i].lastchecktime=12;
4920 player[i].lastseen=player[j].coords;
4921 player[i].lastseentime=12;
4928 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4929 if(player[i].creature!=wolftype){
4930 player[i].stunned=.6;
4931 player[i].surprised=.6;
4933 if(player[i].creature==wolftype){
4934 player[i].stunned=.47;
4935 player[i].surprised=.47;
4943 if(player[i].aitype==searchtype){
4944 player[i].aiupdatedelay-=multiplier;
4945 player[i].losupdatedelay-=multiplier;
4946 if(!player[i].pause)
4947 player[i].lastseentime-=multiplier;
4948 player[i].lastchecktime-=multiplier;
4950 if(player[i].isRun()&&!player[i].onground){
4951 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4952 XYZ test2=player[i].coords+player[i].facing;
4954 XYZ test=player[i].coords+player[i].facing;
4956 j=checkcollide(test2,test,player[i].laststanding);
4958 j=checkcollide(test2,test);
4960 player[i].velocity=0;
4961 player[i].setAnimation(player[i].getStop());
4962 player[i].targetyaw+=180;
4963 player[i].stunned=.5;
4964 //player[i].aitype=passivetype;
4965 player[i].aitype=pathfindtype;
4966 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4967 player[i].finalpathfindpoint=-1;
4968 player[i].targetpathfindpoint=-1;
4969 player[i].lastpathfindpoint=-1;
4970 player[i].lastpathfindpoint2=-1;
4971 player[i].lastpathfindpoint3=-1;
4972 player[i].lastpathfindpoint4=-1;
4974 else player[i].laststanding=j;
4977 //check out last seen location
4978 if(player[i].aiupdatedelay<0){
4979 player[i].targetyaw=roughDirectionTo(player[i].coords,player[i].lastseen);
4980 player[i].lookyaw=player[i].targetyaw;
4981 player[i].aiupdatedelay=.05;
4982 player[i].forwardkeydown=1;
4984 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4985 player[i].forwardkeydown=0;
4986 player[i].aiupdatedelay=1;
4987 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4988 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4989 player[i].lastchecktime=3;
4992 player[i].leftkeydown=0;
4993 player[i].backkeydown=0;
4994 player[i].rightkeydown=0;
4995 player[i].crouchkeydown=0;
4996 player[i].attackkeydown=0;
4997 player[i].throwkeydown=0;
4999 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5000 if(!player[i].avoidsomething)player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5002 XYZ leftpos,rightpos;
5003 float leftdist,rightdist;
5004 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5005 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5006 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5007 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5008 if(leftdist<rightdist)player[i].targetyaw+=90;
5009 else player[i].targetyaw-=90;
5013 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5014 player[i].jumpkeydown=0;
5015 if((player[i].collided>.8&&player[i].jumppower>=5))
5016 player[i].jumpkeydown=1;
5018 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
5019 for(int k=0;k<numenvsounds;k++){
5020 if(findDistancefast(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
5021 player[i].aitype=attacktypecutoff;
5025 if(!player[0].dead&&
5026 player[i].losupdatedelay<0&&
5028 player[i].occluded<2&&
5029 ((tutoriallevel!=1||cananger)&&hostile)){
5030 player[i].losupdatedelay=.2;
5031 if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight){
5032 player[i].aitype=attacktypecutoff;
5033 player[i].lastseentime=1;
5035 if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
5036 //TODO: factor out canSeePlayer()
5037 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
5038 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5040 DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*
5041 player[i].scale+player[i].coords,
5042 DoRotation(player[0].getJointFor(head).position,0,player[0].yaw,0)*
5043 player[0].scale+player[0].coords)==-1)||
5044 (player[0].targetanimation==hanganim&&normaldotproduct(
5045 player[0].facing,player[i].coords-player[0].coords)<0)){
5046 /* //TODO: changed j to 0 on a whim, make sure this is correct
5047 (player[j].targetanimation==hanganim&&normaldotproduct(
5048 player[j].facing,player[i].coords-player[j].coords)<0)
5050 player[i].aitype=attacktypecutoff;
5051 player[i].lastseentime=1;
5055 if(player[i].lastseentime<0){
5056 //player[i].aitype=passivetype;
5058 player[i].aitype=pathfindtype;
5059 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5060 player[i].finalpathfindpoint=-1;
5061 player[i].targetpathfindpoint=-1;
5062 player[i].lastpathfindpoint=-1;
5063 player[i].lastpathfindpoint2=-1;
5064 player[i].lastpathfindpoint3=-1;
5065 player[i].lastpathfindpoint4=-1;
5069 if(player[i].aitype!=gethelptype)
5070 player[i].runninghowlong=0;
5072 //get help from buddies
5073 if(player[i].aitype==gethelptype) {
5074 player[i].runninghowlong+=multiplier;
5075 player[i].aiupdatedelay-=multiplier;
5077 if(player[i].aiupdatedelay<0||player[i].ally==0) {
5078 player[i].aiupdatedelay=.2;
5081 //TODO: factor out closest search somehow
5082 if(!player[i].ally) {
5084 float closestdist=-1;
5085 for(int k=0;k<numplayers;k++) {
5086 if(k!=i&&k!=0&&!player[k].dead&&
5087 player[k].howactive<typedead1&&
5088 !player[k].skeleton.free&&
5089 player[k].aitype==passivetype) {
5090 float distance=findDistancefast(&player[i].coords,&player[k].coords);
5091 if(closestdist==-1||distance<closestdist) {
5092 closestdist=distance;
5099 player[i].ally=closest;
5102 player[i].lastseen=player[0].coords;
5103 player[i].lastseentime=12;
5107 player[i].lastchecktime=12;
5109 XYZ facing=player[i].coords;
5110 XYZ flatfacing=player[player[i].ally].coords;
5111 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
5112 flatfacing.y+=player[player[i].ally].getJointFor(head).position.y*player[player[i].ally].scale;
5113 if(-1!=checkcollide(facing,flatfacing))
5114 player[i].lastseentime-=.1;
5116 //no available ally, run back to player
5117 if(player[i].ally<=0||
5118 player[player[i].ally].skeleton.free||
5119 player[player[i].ally].aitype!=passivetype||
5120 player[i].lastseentime<=0){
5121 player[i].aitype=searchtype;
5122 player[i].lastseentime=12;
5126 if(player[i].ally>0){
5127 player[i].targetyaw=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5128 player[i].lookyaw=player[i].targetyaw;
5129 player[i].aiupdatedelay=.05;
5130 player[i].forwardkeydown=1;
5132 if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
5133 player[i].aitype=searchtype;
5134 player[i].lastseentime=12;
5135 player[player[i].ally].aitype=searchtype;
5136 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5137 player[player[i].ally].lastseen=player[i].lastseen;
5138 player[player[i].ally].lastseentime=player[i].lastseentime;
5139 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5143 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5144 if(!player[i].avoidsomething)
5145 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5147 XYZ leftpos,rightpos;
5148 float leftdist,rightdist;
5149 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5150 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5151 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5152 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5153 if(leftdist<rightdist)
5154 player[i].targetyaw+=90;
5156 player[i].targetyaw-=90;
5161 player[i].leftkeydown=0;
5162 player[i].backkeydown=0;
5163 player[i].rightkeydown=0;
5164 player[i].crouchkeydown=0;
5165 player[i].attackkeydown=0;
5167 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5168 player[i].jumpkeydown=0;
5169 if(player[i].collided>.8&&player[i].jumppower>=5)
5170 player[i].jumpkeydown=1;
5173 //retreiving a weapon on the ground
5174 if(player[i].aitype==getweapontype){
5175 player[i].aiupdatedelay-=multiplier;
5176 player[i].lastchecktime-=multiplier;
5178 if(player[i].aiupdatedelay<0){
5179 player[i].aiupdatedelay=.2;
5182 if(player[i].ally<0){
5184 float closestdist=-1;
5185 for(int k=0;k<weapons.size();k++)
5186 if(weapons[k].owner==-1){
5187 float distance=findDistancefast(&player[i].coords,&weapons[k].position);
5188 if(closestdist==-1||distance<closestdist){
5189 closestdist=distance;
5195 player[i].ally=closest;
5200 player[i].lastseentime=12;
5202 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5203 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5204 player[i].aitype=attacktypecutoff;
5205 player[i].lastseentime=1;
5208 if(player[i].ally>=0){
5209 if(weapons[player[i].ally].owner!=-1||
5210 findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){
5211 player[i].aitype=attacktypecutoff;
5212 player[i].lastseentime=1;
5214 //TODO: factor these out as moveToward()
5215 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5216 player[i].lookyaw=player[i].targetyaw;
5217 player[i].aiupdatedelay=.05;
5218 player[i].forwardkeydown=1;
5221 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5222 if(!player[i].avoidsomething)
5223 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5225 XYZ leftpos,rightpos;
5226 float leftdist,rightdist;
5227 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5228 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5229 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
5230 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
5231 if(leftdist<rightdist)
5232 player[i].targetyaw+=90;
5234 player[i].targetyaw-=90;
5239 player[i].leftkeydown=0;
5240 player[i].backkeydown=0;
5241 player[i].rightkeydown=0;
5242 player[i].attackkeydown=0;
5243 player[i].throwkeydown=1;
5244 player[i].crouchkeydown=0;
5245 if(player[i].targetanimation!=crouchremoveknifeanim&&
5246 player[i].targetanimation!=removeknifeanim)
5247 player[i].throwtogglekeydown=0;
5248 player[i].drawkeydown=0;
5250 if(player[i].collided<1||player[i].targetanimation!=jumpupanim)
5251 player[i].jumpkeydown=0;
5252 if((player[i].collided>.8&&player[i].jumppower>=5))
5253 player[i].jumpkeydown=1;
5256 if(player[i].aitype==attacktypecutoff){
5257 player[i].aiupdatedelay-=multiplier;
5258 //dodge or reverse rabbit kicks, knife throws, flips
5259 if(player[i].damage<player[i].damagetolerance*2/3)
5260 if((player[0].targetanimation==rabbitkickanim||
5261 player[0].targetanimation==knifethrowanim||
5262 (player[0].isFlip()&&
5263 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5264 !player[0].skeleton.free&&
5265 (player[i].aiupdatedelay<.1)){
5266 player[i].attackkeydown=0;
5267 if(player[i].isIdle())
5268 player[i].crouchkeydown=1;
5269 if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
5270 if(weapons[player[0].weaponids[0]].getType()==knife){
5271 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5272 if(abs(Random()%2==0))
5273 player[i].setAnimation(backhandspringanim);
5275 player[i].setAnimation(rollanim);
5276 player[i].targetyaw+=90*(abs(Random()%2)*2-1);
5277 player[i].wentforweapon=0;
5279 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim)
5280 player[i].setAnimation(flipanim);
5283 player[i].forwardkeydown=0;
5284 player[i].aiupdatedelay=.02;
5286 //get confused by flips
5287 if(player[0].isFlip()&&
5288 !player[0].skeleton.free&&
5289 player[0].targetanimation!=walljumprightkickanim&&
5290 player[0].targetanimation!=walljumpleftkickanim){
5291 if(findDistancefast(&player[0].coords,&player[i].coords)<25)
5292 if((1-player[i].damage/player[i].damagetolerance)>.5)
5293 player[i].stunned=1;
5295 //go for weapon on the ground
5296 if(player[i].wentforweapon<3)
5297 for(int k=0;k<weapons.size();k++)
5298 if(player[i].creature!=wolftype)
5299 if(player[i].num_weapons==0&&
5300 weapons[k].owner==-1&&
5301 weapons[i].velocity.x==0&&
5302 weapons[i].velocity.z==0&&
5303 weapons[i].velocity.y==0){
5304 if(findDistancefast(&player[i].coords,&weapons[k].position)<16) {
5305 player[i].wentforweapon++;
5306 player[i].lastchecktime=6;
5307 player[i].aitype=getweapontype;
5311 //dodge/reverse walljump kicks
5312 if(player[i].damage<player[i].damagetolerance/2)
5313 if(animation[player[i].targetanimation].height!=highheight)
5314 if(player[i].damage<player[i].damagetolerance*.5&&
5315 ((player[0].targetanimation==walljumprightkickanim||
5316 player[0].targetanimation==walljumpleftkickanim)&&
5317 ((player[i].aiupdatedelay<.15&&
5319 (player[i].aiupdatedelay<.08&&
5321 player[i].crouchkeydown=1;
5323 //walked off a ledge (?)
5324 if(player[i].isRun()&&!player[i].onground)
5325 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5326 XYZ test2=player[i].coords+player[i].facing;
5328 XYZ test=player[i].coords+player[i].facing;
5330 j=checkcollide(test2,test,player[i].laststanding);
5332 j=checkcollide(test2,test);
5334 player[i].velocity=0;
5335 player[i].setAnimation(player[i].getStop());
5336 player[i].targetyaw+=180;
5337 player[i].stunned=.5;
5338 player[i].aitype=pathfindtype;
5339 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5340 player[i].finalpathfindpoint=-1;
5341 player[i].targetpathfindpoint=-1;
5342 player[i].lastpathfindpoint=-1;
5343 player[i].lastpathfindpoint2=-1;
5344 player[i].lastpathfindpoint3=-1;
5345 player[i].lastpathfindpoint4=-1;
5347 player[i].laststanding=j;
5349 //lose sight of player in the air (?)
5350 if(player[0].coords.y>player[i].coords.y+5&&
5351 animation[player[0].targetanimation].height!=highheight&&
5352 !player[0].onterrain){
5353 player[i].aitype=pathfindtype;
5354 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5355 player[i].finalpathfindpoint=-1;
5356 player[i].targetpathfindpoint=-1;
5357 player[i].lastpathfindpoint=-1;
5358 player[i].lastpathfindpoint2=-1;
5359 player[i].lastpathfindpoint3=-1;
5360 player[i].lastpathfindpoint4=-1;
5362 //it's time to think (?)
5363 if(player[i].aiupdatedelay<0&&
5364 !animation[player[i].targetanimation].attack&&
5365 player[i].targetanimation!=staggerbackhighanim&&
5366 player[i].targetanimation!=staggerbackhardanim&&
5367 player[i].targetanimation!=backhandspringanim&&
5368 player[i].targetanimation!=dodgebackanim){
5370 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5371 player[i].drawkeydown=Random()%2;
5373 player[i].drawkeydown=0;
5374 player[i].rabbitkickenabled=Random()%2;
5376 XYZ rotatetarget=player[0].coords+player[0].velocity;
5377 XYZ targetpoint=player[0].coords;
5378 if(findDistancefast(&player[0].coords,&player[i].coords)<
5379 findDistancefast(&rotatetarget,&player[i].coords))
5380 targetpoint+=player[0].velocity*
5381 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5382 player[i].targetyaw=roughDirectionTo(player[i].coords,targetpoint);
5383 player[i].lookyaw=player[i].targetyaw;
5384 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5386 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5387 player[i].forwardkeydown=1;
5388 else if((findDistancefast(&player[i].coords,&player[0].coords)>16||
5389 findDistancefast(&player[i].coords,&player[0].coords)<9)&&
5390 player[0].weaponactive!=-1)
5391 player[i].forwardkeydown=1;
5392 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5393 player[i].forwardkeydown=1;
5395 player[i].forwardkeydown=0;
5396 //chill out around the corpse
5398 player[i].forwardkeydown=0;
5400 player[i].forwardkeydown=1;
5401 if(Random()%100==0){
5402 player[i].aitype=pathfindtype;
5403 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5404 player[i].finalpathfindpoint=-1;
5405 player[i].targetpathfindpoint=-1;
5406 player[i].lastpathfindpoint=-1;
5407 player[i].lastpathfindpoint2=-1;
5408 player[i].lastpathfindpoint3=-1;
5409 player[i].lastpathfindpoint4=-1;
5412 player[i].leftkeydown=0;
5413 player[i].backkeydown=0;
5414 player[i].rightkeydown=0;
5415 player[i].crouchkeydown=0;
5416 player[i].throwkeydown=0;
5418 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5419 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5421 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5422 player[i].attackkeydown=1;
5424 player[i].attackkeydown=0;
5425 if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)
5426 player[i].attackkeydown=0;
5429 if(player[i].aitype!=playercontrolled&&
5430 (player[i].isIdle()||
5431 player[i].isCrouch()||
5432 player[i].isRun())){
5434 for(int j=0;j<numplayers;j++)
5435 if(j!=i&&!player[j].skeleton.free&&
5436 player[j].hasvictim&&
5437 (tutoriallevel==1&&reversaltrain||
5438 Random()%2==0&&difficulty==2||
5439 Random()%4==0&&difficulty==1||
5440 Random()%8==0&&difficulty==0||
5441 player[j].lastattack2==player[j].targetanimation&&
5442 player[j].lastattack3==player[j].targetanimation&&
5443 (Random()%2==0||difficulty==2)||
5444 (player[i].isIdle()||player[i].isRun())&&
5445 player[j].weaponactive!=-1||
5446 player[j].targetanimation==swordslashanim&&
5447 player[i].weaponactive!=-1||
5448 player[j].targetanimation==staffhitanim||
5449 player[j].targetanimation==staffspinhitanim))
5450 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&&
5451 player[j].victim==&player[i]&&
5452 (player[j].targetanimation==sweepanim||
5453 player[j].targetanimation==spinkickanim||
5454 player[j].targetanimation==staffhitanim||
5455 player[j].targetanimation==staffspinhitanim||
5456 player[j].targetanimation==winduppunchanim||
5457 player[j].targetanimation==upunchanim||
5458 player[j].targetanimation==wolfslapanim||
5459 player[j].targetanimation==knifeslashstartanim||
5460 player[j].targetanimation==swordslashanim&&
5461 (findDistancefast(&player[j].coords,&player[i].coords)<2||
5462 player[i].weaponactive!=-1))){
5469 player[target].Reverse();
5472 if(player[i].collided<1)
5473 player[i].jumpkeydown=0;
5474 if(player[i].collided>.8&&player[i].jumppower>=5||
5475 findDistancefast(&player[i].coords,&player[0].coords)>400&&
5476 player[i].onterrain&&
5477 player[i].creature==rabbittype)
5478 player[i].jumpkeydown=1;
5479 //TODO: why are we controlling the human?
5480 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5481 player[0].jumpkeydown=0;
5482 if(player[0].targetanimation==jumpdownanim&&
5483 findDistancefast(&player[0].coords,&player[i].coords)<40)
5484 player[i].crouchkeydown=1;
5485 if(player[i].jumpkeydown)
5486 player[i].attackkeydown=0;
5488 if(tutoriallevel==1)
5490 player[i].attackkeydown=0;
5493 XYZ facing=player[i].coords;
5494 XYZ flatfacing=player[0].coords;
5495 facing.y+=player[i].getJointFor(head).position.y*player[i].scale;
5496 flatfacing.y+=player[0].getJointFor(head).position.y*player[0].scale;
5497 if(player[i].occluded>=2)
5498 if(-1!=checkcollide(facing,flatfacing)){
5499 if(!player[i].pause)
5500 player[i].lastseentime-=.2;
5501 if(player[i].lastseentime<=0&&
5502 (player[i].creature!=wolftype||
5503 player[i].weaponstuck==-1)){
5504 player[i].aitype=searchtype;
5505 player[i].lastchecktime=12;
5506 player[i].lastseen=player[0].coords;
5507 player[i].lastseentime=12;
5510 player[i].lastseentime=1;
5513 if(animation[player[0].targetanimation].height==highheight&&
5514 (player[i].aitype==attacktypecutoff||
5515 player[i].aitype==searchtype))
5516 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5517 XYZ test=player[0].coords;
5519 if(-1==checkcollide(player[0].coords,test))
5520 player[i].stunned=1;
5523 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5524 player[i].stunned>0||
5525 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5527 player[i].lastseentime=1;
5528 player[i].targetyaw=player[i].yaw;
5529 player[i].forwardkeydown=0;
5530 player[i].leftkeydown=0;
5531 player[i].backkeydown=0;
5532 player[i].rightkeydown=0;
5533 player[i].jumpkeydown=0;
5534 player[i].attackkeydown=0;
5535 player[i].crouchkeydown=0;
5536 player[i].throwkeydown=0;
5544 XYZ flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
5547 if(player[i].aitype==attacktypecutoff){
5548 player[i].targetheadyaw=180-roughDirectionTo(player[i].coords,player[0].coords);
5549 player[i].targetheadpitch=pitchTo(player[i].coords,player[0].coords);
5550 }else if(player[i].howactive>=typesleeping){
5551 player[i].targetheadyaw=player[i].targetyaw;
5552 player[i].targetheadpitch=0;
5554 if(player[i].interestdelay<=0){
5555 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5556 player[i].headtarget=player[i].coords;
5557 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5558 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5559 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5560 player[i].headtarget+=player[i].facing*1.5;
5562 player[i].targetheadyaw=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5563 player[i].targetheadpitch=pitchTo(player[i].coords,player[i].headtarget);
5570 void updateSettingsMenu(){
5572 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)
5573 sprintf (sbuf, "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
5575 sprintf (sbuf, "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
5576 Menu::setText(0,sbuf);
5577 if(newdetail==0) Menu::setText(1,"Detail: Low");
5578 if(newdetail==1) Menu::setText(1,"Detail: Medium");
5579 if(newdetail==2) Menu::setText(1,"Detail: High");
5580 if(bloodtoggle==0) Menu::setText(2,"Blood: Off");
5581 if(bloodtoggle==1) Menu::setText(2,"Blood: On, low detail");
5582 if(bloodtoggle==2) Menu::setText(2,"Blood: On, high detail (slower)");
5583 if(difficulty==0) Menu::setText(3,"Difficulty: Easier");
5584 if(difficulty==1) Menu::setText(3,"Difficulty: Difficult");
5585 if(difficulty==2) Menu::setText(3,"Difficulty: Insane");
5586 Menu::setText(4,ismotionblur?"Blur Effects: Enabled (less compatible)":"Blur Effects: Disabled (more compatible)");
5587 Menu::setText(5,decals?"Decals: Enabled (slower)":"Decals: Disabled");
5588 Menu::setText(6,musictoggle?"Music: Enabled":"Music: Disabled");
5589 Menu::setText(9,invertmouse?"Invert mouse: Yes":"Invert mouse: No");
5590 sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity*5));
5591 Menu::setText(10,sbuf);
5592 sprintf (sbuf, "Volume: %d%%", (int)(volume*100));
5593 Menu::setText(11,sbuf);
5594 Menu::setText(13,showdamagebar?"Damage Bar: On":"Damage Bar: Off");
5595 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)
5596 sprintf (sbuf, "Back");
5598 sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)");
5599 Menu::setText(8,sbuf);
5602 void updateStereoConfigMenu(){
5604 sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode));
5605 Menu::setText(0,sbuf);
5606 sprintf(sbuf, "Stereo separation: %.3f", stereoseparation);
5607 Menu::setText(1,sbuf);
5608 sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
5609 Menu::setText(2,sbuf);
5612 void updateControlsMenu(){
5613 Menu::setText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey)));
5614 Menu::setText(1,(string)"Back: " +(keyselect==1?"_":Input::keyToChar(backkey)));
5615 Menu::setText(2,(string)"Left: " +(keyselect==2?"_":Input::keyToChar(leftkey)));
5616 Menu::setText(3,(string)"Right: " +(keyselect==3?"_":Input::keyToChar(rightkey)));
5617 Menu::setText(4,(string)"Crouch: " +(keyselect==4?"_":Input::keyToChar(crouchkey)));
5618 Menu::setText(5,(string)"Jump: " +(keyselect==5?"_":Input::keyToChar(jumpkey)));
5619 Menu::setText(6,(string)"Draw: " +(keyselect==6?"_":Input::keyToChar(drawkey)));
5620 Menu::setText(7,(string)"Throw: " +(keyselect==7?"_":Input::keyToChar(throwkey)));
5621 Menu::setText(8,(string)"Attack: " +(keyselect==8?"_":Input::keyToChar(attackkey)));
5623 Menu::setText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey)));
5627 Values of mainmenu :
5629 2 Menu pause (resume/end game)
5631 4 Controls configuration menu
5632 5 Main game menu (choose level or challenge)
5633 6 Deleting user menu
5634 7 User managment menu (select/add)
5635 8 Choose difficulty menu
5636 9 Challenge level selection menu
5637 10 End of the campaign congratulation (is that really a menu?)
5638 11 Same that 9 ??? => unused
5639 18 stereo configuration
5642 void Game::LoadMenu(){
5647 Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128);
5648 Menu::addButtonImage(1,Mainmenuitems[mainmenu==1?1:5],18,480-152-32,128,32);
5649 Menu::addButtonImage(2,Mainmenuitems[2],18,480-228-32,112,32);
5650 Menu::addButtonImage(3,Mainmenuitems[mainmenu==1?3:6],18,480-306-32,mainmenu==1?68:132,32);
5653 Menu::addButton( 0,"",10+20,440);
5654 Menu::addButton( 1,"",10+60,405);
5655 Menu::addButton( 2,"",10+70,370);
5656 Menu::addButton( 3,"",10+20-1000,335-1000);
5657 Menu::addButton( 4,"",10 ,335);
5658 Menu::addButton( 5,"",10+60,300);
5659 Menu::addButton( 6,"",10+70,265);
5660 Menu::addButton( 9,"",10 ,230);
5661 Menu::addButton(10,"",20 ,195);
5662 Menu::addButton(11,"",10+60,160);
5663 Menu::addButton(13,"",30 ,125);
5664 Menu::addButton( 7,"-Configure Controls-",10+15, 90);
5665 Menu::addButton(12,"-Configure Stereo -",10+15, 55);
5666 Menu::addButton(8,"Back",10,10);
5667 updateSettingsMenu();
5670 Menu::addButton(0,"",10 ,400);
5671 Menu::addButton(1,"",10+40,360);
5672 Menu::addButton(2,"",10+40,320);
5673 Menu::addButton(3,"",10+30,280);
5674 Menu::addButton(4,"",10+20,240);
5675 Menu::addButton(5,"",10+40,200);
5676 Menu::addButton(6,"",10+40,160);
5677 Menu::addButton(7,"",10+30,120);
5678 Menu::addButton(8,"",10+20,80);
5680 Menu::addButton(9,"",10+10,40);
5681 Menu::addButton(debugmode?10:9,"Back",10,10);
5682 updateControlsMenu();
5686 Menu::addLabel(-1,accountactive->getName(),5,400);
5687 Menu::addButton(1,"Tutorial",5,300);
5688 Menu::addButton(2,"Challenge",5,240);
5689 Menu::addButton(3,"Delete User",400,10);
5690 Menu::addButton(4,"Main Menu",5,10);
5691 Menu::addButton(5,"Change User",5,180);
5692 Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),200,420);
5695 //with (2,-5) offset from old code
5696 Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400);
5698 int numlevels = accountactive->getCampaignChoicesMade();
5699 numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1;
5700 for(int i=0;i<numlevels;i++){
5701 XYZ midpoint=campaignlevels[i].getCenter();
5702 float itemsize=campaignlevels[i].getWidth();
5703 const bool active=i>=accountactive->getCampaignChoicesMade();
5708 XYZ start=campaignlevels[i-1].getCenter();
5709 Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0);
5711 Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture,
5712 midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0);
5715 Menu::addMapLabel(-2,campaignlevels[i].description,
5716 campaignlevels[i].getStartX()+10,
5717 campaignlevels[i].getStartY()-4);
5722 Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400);
5723 Menu::addButton(1,"Yes",10,360);
5724 Menu::addButton(2,"No",10,320);
5727 if(Account::getNbAccounts()<8)
5728 Menu::addButton(0,"New User",10,400);
5730 Menu::addLabel(0,"No More Users",10,400);
5731 Menu::addLabel(-2,"",20,400);
5732 Menu::addButton(Account::getNbAccounts()+1,"Back",10,10);
5733 for(int i=0;i<Account::getNbAccounts();i++)
5734 Menu::addButton(i+1,Account::get(i)->getName(),10,340-20*(i+1));
5737 Menu::addButton(0,"Easier",10,400);
5738 Menu::addButton(1,"Difficult",10,360);
5739 Menu::addButton(2,"Insane",10,320);
5742 for(int i=0;i<numchallengelevels;i++){
5745 sprintf (temp, "Level %d",i+1);
5746 for(int j=strlen(temp);j<17;j++)
5749 sprintf (temp, "%d",(int)accountactive->getHighScore(i));
5750 for(int j=strlen(temp);j<(32-17);j++)
5753 sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60));
5754 if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0");
5756 sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60);
5759 Menu::addButton(i,name,10,400-i*25,i>accountactive->getProgress()?0.5:1,0,0);
5762 Menu::addButton(-1," High Score Best Time",10,440);
5763 Menu::addButton(numchallengelevels,"Back",10,10);
5766 Menu::addLabel(0,"Congratulations!",220,330);
5767 Menu::addLabel(1,"You have avenged your family and",140,300);
5768 Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270);
5769 Menu::addButton(3,"Back",10,10);
5771 sprintf(sbuf,"Your score: %d",(int)accountactive->getCampaignScore());
5772 Menu::addLabel(4,sbuf,190,200);
5773 sprintf(sbuf,"Highest score: %d",(int)accountactive->getCampaignHighScore());
5774 Menu::addLabel(5,sbuf,190,180);
5777 Menu::addButton(0,"",70,400);
5778 Menu::addButton(1,"",10,360);
5779 Menu::addButton(2,"",40,320);
5780 Menu::addButton(3,"Back",10,10);
5781 updateStereoConfigMenu();
5788 selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight);
5790 // some specific case where we do something even if the left mouse button is not pressed.
5791 if((mainmenu==5) && (endgame==2)) {
5792 accountactive->endGame();
5797 if(mainmenu==18 && Input::isKeyPressed(MOUSEBUTTON2) && selected==1){
5798 stereoseparation-=0.001;
5799 updateStereoConfigMenu();
5802 static int oldmainmenu=mainmenu;
5806 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5812 if(gameon) { //resume
5814 pause_sound(stream_menutheme);
5815 resume_stream(leveltheme);
5817 fireSound(firestartsound);
5819 mainmenu=(accountactive?5:7);
5827 if(newdetail>2) newdetail=detail;
5828 if(newdetail<0) newdetail=detail;
5829 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5830 if(newscreenwidth<0) newscreenwidth=screenwidth;
5831 if(newscreenheight>3000) newscreenheight=screenheight;
5832 if(newscreenheight<0) newscreenheight=screenheight;
5837 if(gameon){ //end game
5842 pause_sound(stream_menutheme);
5849 bool isCustomResolution,found;
5852 extern SDL_Rect **resolutions;
5853 isCustomResolution = true;
5855 for(int i = 0; (!found) && (resolutions[i]); i++) {
5856 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5857 isCustomResolution = false;
5859 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5861 if(resolutions[i] != NULL) {
5862 newscreenwidth = (int) resolutions[i]->w;
5863 newscreenheight = (int) resolutions[i]->h;
5864 } else if(isCustomResolution){
5865 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5866 newscreenwidth = (int) resolutions[0]->w;
5867 newscreenheight = (int) resolutions[0]->h;
5869 newscreenwidth = screenwidth;
5870 newscreenheight = screenheight;
5873 newscreenwidth = (int) resolutions[0]->w;
5874 newscreenheight = (int) resolutions[0]->h;
5881 newscreenwidth = (int) resolutions[0]->w;
5882 newscreenheight = (int) resolutions[0]->h;
5887 if(newdetail>2) newdetail=0;
5891 if(bloodtoggle>2) bloodtoggle=0;
5895 if(difficulty>2) difficulty=0;
5898 ismotionblur = !ismotionblur;
5904 musictoggle = !musictoggle;
5906 emit_stream_np(stream_menutheme);
5908 pause_sound(leveltheme);
5909 pause_sound(stream_fighttheme);
5910 pause_sound(stream_menutheme);
5912 for(int i=0;i<4;i++){
5913 oldmusicvolume[i]=0;
5927 mainmenu=gameon?2:1;
5930 invertmouse = !invertmouse;
5933 usermousesensitivity+=.2;
5934 if(usermousesensitivity>2)
5935 usermousesensitivity=.2;
5941 OPENAL_SetSFXMasterVolume((int)(volume*255));
5945 newstereomode = stereomode;
5950 showdamagebar = !showdamagebar;
5953 updateSettingsMenu();
5958 if(selected<(debugmode?10:9) && keyselect==-1)
5962 if(selected==(debugmode?10:9)){
5967 updateControlsMenu();
5972 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5982 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5983 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5986 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5990 pause_sound(stream_menutheme);
6007 pause_sound(stream_menutheme);
6016 mainmenu=(gameon?2:1);
6022 vector<string> campaigns = ListCampaigns();
6023 vector<string>::iterator c;
6024 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
6025 if(!campaigns.empty())
6026 accountactive->setCurrentCampaign(campaigns.front());
6029 if(c==campaigns.end())
6030 c=campaigns.begin();
6031 accountactive->setCurrentCampaign(*c);
6041 accountactive = Account::destroy(accountactive);
6043 } else if(selected==2) {
6050 if(selected==0 && Account::getNbAccounts()<8){
6052 } else if (selected < Account::getNbAccounts()+1) {
6055 accountactive=Account::get(selected-1);
6056 } else if (selected == Account::getNbAccounts()+1) {
6062 for(int j=0;j<255;j++){
6063 displaytext[0][j]=0;
6074 accountactive->setDifficulty(selected);
6078 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
6086 targetlevel=selected;
6091 Loadlevel(selected);
6096 pause_sound(stream_menutheme);
6098 if(selected==numchallengelevels){
6113 stereoseparation+=0.001;
6117 newstereomode = (StereoMode)(newstereomode + 1);
6118 while(!CanInitStereo(newstereomode)){
6119 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
6120 newstereomode = (StereoMode)(newstereomode + 1);
6121 if(newstereomode >= stereoCount)
6122 newstereomode = stereoNone;
6124 } else if(selected==2) {
6125 stereoreverse = !stereoreverse;
6126 } else if(selected==3) {
6130 stereomode = newstereomode;
6131 InitStereo(stereomode);
6134 updateStereoConfigMenu();
6139 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
6146 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
6149 inputText(displaytext[0],&displayselected,&displaychars[0]);
6150 if(!waiting) { // the input as finished
6151 if(displaychars[0]){ // with enter
6152 accountactive = Account::add(string(displaytext[0]));
6158 fireSound(firestartsound);
6160 for(int i=0;i<255;i++){
6161 displaytext[0][i]=0;
6171 displayblinkdelay-=multiplier;
6172 if(displayblinkdelay<=0){
6173 displayblinkdelay=.3;
6174 displayblink=1-displayblink;
6179 Menu::setText(0,displaytext[0],20,400,-1,-1);
6180 Menu::setText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1);
6183 if(oldmainmenu!=mainmenu)
6185 oldmainmenu=mainmenu;
6190 static XYZ facing,flatfacing;
6193 for(int i=0;i<15;i++){
6194 displaytime[i]+=multiplier;
6197 keyboardfrozen=false;
6200 if(Input::isKeyPressed(SDLK_F6)){
6201 if(Input::isKeyDown(SDLK_LSHIFT))
6204 stereoreverse=false;
6207 printf("Stereo reversed\n");
6209 printf("Stereo unreversed\n");
6212 if(Input::isKeyDown(SDLK_F7)){
6213 if(Input::isKeyDown(SDLK_LSHIFT))
6214 stereoseparation -= 0.001;
6216 stereoseparation -= 0.010;
6217 printf("Stereo decreased increased to %f\n", stereoseparation);
6220 if(Input::isKeyDown(SDLK_F8)){
6221 if(Input::isKeyDown(SDLK_LSHIFT))
6222 stereoseparation += 0.001;
6224 stereoseparation += 0.010;
6225 printf("Stereo separation increased to %f\n", stereoseparation);
6229 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
6230 if(tutorialstage!=51)
6231 tutorialstagetime=tutorialmaxtime;
6232 emit_sound_np(consolefailsound, 128.);
6236 Values of mainmenu :
6238 2 Menu pause (resume/end game)
6240 4 Controls configuration menu
6241 5 Main game menu (choose level or challenge)
6242 6 Deleting user menu
6243 7 User managment menu (select/add)
6244 8 Choose difficulty menu
6245 9 Challenge level selection menu
6246 10 End of the campaign congratulation (is that really a menu?)
6247 11 Same that 9 ??? => unused
6248 18 stereo configuration
6253 if(mainmenu&&endgame==1)
6255 //go to level select after completing a campaign level
6256 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
6263 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6264 emit_stream_np(stream_menutheme);
6265 pause_sound(leveltheme);
6269 //escape key pressed
6270 if(Input::isKeyPressed(SDLK_ESCAPE)&&
6271 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
6273 if(mainmenu==0&&!winfreeze)
6275 else if(mainmenu==1||mainmenu==2){
6276 mainmenu=0; //unpause
6279 if(musictoggle&&(mainmenu==1||mainmenu==2)){
6280 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6281 emit_stream_np(stream_menutheme);
6282 pause_sound(leveltheme);
6284 //on resume, play level music
6286 pause_sound(stream_menutheme);
6287 resume_stream(leveltheme);
6289 //finished with settings menu
6294 if(mainmenu>=3&&mainmenu!=8){
6301 mainmenu=gameon?2:1; break;
6304 case 6: case 7: case 9: case 10:
6315 if(hostile==1)hostiletime+=multiplier;
6317 if(!winfreeze)leveltime+=multiplier;
6320 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6323 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6327 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6331 inputText(displaytext[0],&displayselected,&displaychars[0]);
6333 if(displaychars[0]){
6334 for(int j=0;j<255;j++)
6335 displaytext[0][j]=0;
6342 displayblinkdelay-=multiplier;
6343 if(displayblinkdelay<=0){
6344 displayblinkdelay=.3;
6345 displayblink=1-displayblink;
6349 keyboardfrozen=true;
6351 if(Input::isKeyPressed(consolekey)&&debugmode) {
6354 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6363 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
6364 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6366 if(consolechars[0]>0) {
6367 consoletext[0][consolechars[0]]='\0';
6368 cmd_dispatch(consoletext[0]);
6369 for(int k=14;k>=1;k--) {
6370 for(int j=0;j<255;j++)
6371 consoletext[k][j]=consoletext[k-1][j];
6372 consolechars[k]=consolechars[k-1];
6374 for(int j=0;j<255;j++)
6375 consoletext[0][j]=0;
6381 consoleblinkdelay-=multiplier;
6382 if(consoleblinkdelay<=0) {
6383 consoleblinkdelay=.3;
6384 consoleblink=1-consoleblink;
6390 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6397 static int oldwinfreeze;
6398 if(winfreeze&&!oldwinfreeze){
6399 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6400 emit_sound_np(consolesuccesssound);
6403 oldwinfreeze=winfreeze;
6407 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6410 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6414 } else if(winfreeze) {
6422 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6425 static float talkdelay = 0;
6429 talkdelay-=multiplier;
6431 if(talkdelay<=0&&indialogue==-1&&animation[player[0].targetanimation].height!=highheight)
6432 for(int i=0;i<numdialogues;i++){
6433 int realdialoguetype;
6435 if(dialoguetype[i]>49){
6436 realdialoguetype=dialoguetype[i]-50;
6439 else if(dialoguetype[i]>39){
6440 realdialoguetype=dialoguetype[i]-40;
6443 else if(dialoguetype[i]>29){
6444 realdialoguetype=dialoguetype[i]-30;
6447 else if(dialoguetype[i]>19){
6448 realdialoguetype=dialoguetype[i]-20;
6451 else if(dialoguetype[i]>9){
6452 realdialoguetype=dialoguetype[i]-10;
6456 realdialoguetype=dialoguetype[i];
6459 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6460 realdialoguetype<numplayers&&
6461 realdialoguetype>0&&
6462 (dialoguegonethrough[i]==0||!special)&&
6463 (special||Input::isKeyPressed(attackkey))){
6464 if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||
6465 player[realdialoguetype].howactive>=typedead1||
6466 dialoguetype[i]>40&&dialoguetype[i]<50){
6468 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6469 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6470 player[participantfocus[whichdialogue][j]].yaw=participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
6471 player[participantfocus[whichdialogue][j]].targetyaw=participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
6472 player[participantfocus[whichdialogue][j]].velocity=0;
6473 player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
6474 player[participantfocus[whichdialogue][j]].targetframe=0;
6479 dialoguegonethrough[i]++;
6480 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6481 playdialogueboxsound();
6487 windvar+=multiplier;
6488 smoketex+=multiplier;
6489 tutorialstagetime+=multiplier;
6492 static float hotspotvisual[40];
6496 for(int i=0;i<numhotspots;i++)
6497 hotspotvisual[i]-=multiplier/320;
6499 for(int i=0;i<numhotspots;i++){
6500 //if(hotspottype[i]<=10)
6501 while(hotspotvisual[i]<0){
6503 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6504 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6505 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6506 hotspotsprite+=hotspot[i];
6507 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6508 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6512 for(int i=0;i<numhotspots;i++){
6513 if(hotspottype[i]<=10&&hotspottype[i]>0){
6514 hotspot[i]=player[hotspottype[i]].coords;
6525 if(tutoriallevel!=1){
6528 bonus!=spinecrusher&&
6529 bonus!=tracheotomy&&
6532 emit_sound_np(consolesuccesssound);
6534 } else if(bonustime==0){
6535 emit_sound_np(fireendsound);
6538 if(bonus!=solidhit&&
6540 bonus!=threexcombo&&
6545 bonusnum[bonus]+=0.15;
6548 bonusvalue/=bonusnum[bonus];
6549 bonustotal+=bonusvalue;
6551 bonustime+=multiplier;
6554 if(environment==snowyenvironment){
6555 precipdelay-=multiplier;
6556 while(precipdelay<0){
6560 XYZ footvel,footpoint;
6563 footpoint=viewer+viewerfacing*6;
6564 footpoint.y+=((float)abs(Random()%1200))/100-6;
6565 footpoint.x+=((float)abs(Random()%1200))/100-6;
6566 footpoint.z+=((float)abs(Random()%1200))/100-6;
6567 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6572 doAerialAcrobatics();
6575 static XYZ oldviewer;
6579 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6580 player[0].leftkeydown=Input::isKeyDown(leftkey);
6581 player[0].backkeydown=Input::isKeyDown(backkey);
6582 player[0].rightkeydown=Input::isKeyDown(rightkey);
6583 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6584 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6585 player[0].drawkeydown=Input::isKeyDown(drawkey);
6586 player[0].throwkeydown=Input::isKeyDown(throwkey);
6590 player[0].forwardkeydown=0;
6591 player[0].leftkeydown=0;
6592 player[0].backkeydown=0;
6593 player[0].rightkeydown=0;
6594 player[0].jumpkeydown=0;
6595 player[0].crouchkeydown=0;
6596 player[0].drawkeydown=0;
6597 player[0].throwkeydown=0;
6600 if(!player[0].jumpkeydown)
6601 player[0].jumpclimb=0;
6610 facing=DoRotation(facing,-pitch,0,0);
6611 facing=DoRotation(facing,0,0-yaw,0);
6616 flatfacing=DoRotation(flatfacing,0,-yaw,0);
6618 if(Input::isKeyDown(forwardkey))
6619 viewer+=facing*multiplier*4;
6620 if(Input::isKeyDown(backkey))
6621 viewer-=facing*multiplier*4;
6622 if(Input::isKeyDown(leftkey))
6623 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6624 if(Input::isKeyDown(rightkey))
6625 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6626 if(Input::isKeyDown(jumpkey))
6627 viewer.y+=multiplier*4;
6628 if(Input::isKeyDown(crouchkey))
6629 viewer.y-=multiplier*4;
6630 if( Input::isKeyPressed(SDLK_1)||
6631 Input::isKeyPressed(SDLK_2)||
6632 Input::isKeyPressed(SDLK_3)||
6633 Input::isKeyPressed(SDLK_4)||
6634 Input::isKeyPressed(SDLK_5)||
6635 Input::isKeyPressed(SDLK_6)||
6636 Input::isKeyPressed(SDLK_7)||
6637 Input::isKeyPressed(SDLK_8)||
6638 Input::isKeyPressed(SDLK_9)||
6639 Input::isKeyPressed(SDLK_0)||
6640 Input::isKeyPressed(SDLK_MINUS)){
6642 if(Input::isKeyPressed(SDLK_1))whichend=1;
6643 if(Input::isKeyPressed(SDLK_2))whichend=2;
6644 if(Input::isKeyPressed(SDLK_3))whichend=3;
6645 if(Input::isKeyPressed(SDLK_4))whichend=4;
6646 if(Input::isKeyPressed(SDLK_5))whichend=5;
6647 if(Input::isKeyPressed(SDLK_6))whichend=6;
6648 if(Input::isKeyPressed(SDLK_7))whichend=7;
6649 if(Input::isKeyPressed(SDLK_8))whichend=8;
6650 if(Input::isKeyPressed(SDLK_9))whichend=9;
6651 if(Input::isKeyPressed(SDLK_0))whichend=0;
6652 if(Input::isKeyPressed(SDLK_MINUS))
6655 participantfocus[whichdialogue][indialogue]=whichend;
6656 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6657 participantyaw[whichdialogue][whichend]=player[whichend].yaw;
6660 participantfocus[whichdialogue][indialogue]=-1;
6662 if(player[participantfocus[whichdialogue][indialogue]].dead){
6667 dialoguecamera[whichdialogue][indialogue]=viewer;
6668 dialoguecamerayaw[whichdialogue][indialogue]=yaw;
6669 dialoguecamerapitch[whichdialogue][indialogue]=pitch;
6671 if(indialogue<numdialogueboxes[whichdialogue]){
6672 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6673 playdialogueboxsound();
6677 for(int j=0;j<numplayers;j++){
6678 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6681 //TODO: should these be KeyDown or KeyPressed?
6682 if( Input::isKeyDown(SDLK_KP1)||
6683 Input::isKeyDown(SDLK_KP2)||
6684 Input::isKeyDown(SDLK_KP3)||
6685 Input::isKeyDown(SDLK_KP4)||
6686 Input::isKeyDown(SDLK_KP5)||
6687 Input::isKeyDown(SDLK_KP6)||
6688 Input::isKeyDown(SDLK_KP7)||
6689 Input::isKeyDown(SDLK_KP8)||
6690 Input::isKeyDown(SDLK_KP9)||
6691 Input::isKeyDown(SDLK_KP0)){
6693 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6694 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6695 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6696 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6697 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6698 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6699 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6700 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6701 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6702 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6703 participantfacing[whichdialogue][indialogue][whichend]=facing;
6705 if(indialogue>=numdialogueboxes[whichdialogue]){
6712 pause_sound(whooshsound);
6713 viewer=dialoguecamera[whichdialogue][indialogue];
6714 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6715 yaw=dialoguecamerayaw[whichdialogue][indialogue];
6716 pitch=dialoguecamerapitch[whichdialogue][indialogue];
6717 if(dialoguetime>0.5)
6718 if( Input::isKeyPressed(SDLK_1)||
6719 Input::isKeyPressed(SDLK_2)||
6720 Input::isKeyPressed(SDLK_3)||
6721 Input::isKeyPressed(SDLK_4)||
6722 Input::isKeyPressed(SDLK_5)||
6723 Input::isKeyPressed(SDLK_6)||
6724 Input::isKeyPressed(SDLK_7)||
6725 Input::isKeyPressed(SDLK_8)||
6726 Input::isKeyPressed(SDLK_9)||
6727 Input::isKeyPressed(SDLK_0)||
6728 Input::isKeyPressed(SDLK_MINUS)||
6729 Input::isKeyPressed(attackkey)){
6731 if(indialogue<numdialogueboxes[whichdialogue]){
6732 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6733 playdialogueboxsound();
6734 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6735 hotspot[numhotspots]=player[0].coords;
6736 hotspotsize[numhotspots]=10;
6737 hotspottype[numhotspots]=-1;
6741 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6745 if(player[participantfocus[whichdialogue][indialogue]].dead){
6753 if(indialogue>=numdialogueboxes[whichdialogue]){
6757 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6760 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6763 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6765 for(int i=1;i<numplayers;i++){
6766 player[i].aitype = attacktypecutoff;
6773 if(!player[0].jumpkeydown){
6774 player[0].jumptogglekeydown=0;
6776 if(player[0].jumpkeydown&&
6777 player[0].targetanimation!=jumpupanim&&
6778 player[0].targetanimation!=jumpdownanim&&
6779 !player[0].isFlip())
6780 player[0].jumptogglekeydown=1;
6783 dialoguetime+=multiplier;
6784 hawkyaw+=multiplier*25;
6786 realhawkcoords.x=25;
6787 realhawkcoords=DoRotation(realhawkcoords,0,hawkyaw,0)+hawkcoords;
6788 hawkcalldelay-=multiplier/2;
6790 if(hawkcalldelay<=0){
6791 emit_sound_at(hawksound, realhawkcoords);
6793 hawkcalldelay=16+abs(Random()%8);
6800 doPlayerCollisions();
6804 for(int k=0;k<numplayers;k++)
6805 if(k!=0&&player[k].immobile)
6806 player[k].coords=player[k].realoldcoords;
6808 for(int k=0;k<numplayers;k++){
6809 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6810 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6811 player[k].DoDamage(1000);
6817 static bool respawnkeydown;
6820 (Input::isKeyDown(SDLK_z)&&
6821 Input::isKeyDown(SDLK_LMETA)&&
6823 (Input::isKeyDown(jumpkey)&&
6827 targetlevel=whichlevel;
6831 if(!Input::isKeyDown(jumpkey))
6833 if(Input::isKeyDown(jumpkey))
6839 static bool movekey;
6842 for(int i=0;i<numplayers;i++){
6843 static float oldtargetyaw;
6844 if(!player[i].skeleton.free){
6845 oldtargetyaw=player[i].targetyaw;
6846 if(i==0&&indialogue==-1){
6847 //TODO: refactor repetitive code
6848 if(!animation[player[0].targetanimation].attack&&
6849 player[0].targetanimation!=staggerbackhighanim&&
6850 player[0].targetanimation!=staggerbackhardanim&&
6851 player[0].targetanimation!=crouchremoveknifeanim&&
6852 player[0].targetanimation!=removeknifeanim&&
6853 player[0].targetanimation!=backhandspringanim&&
6854 player[0].targetanimation!=dodgebackanim&&
6855 player[0].targetanimation!=walljumprightkickanim&&
6856 player[0].targetanimation!=walljumpleftkickanim){
6858 player[0].targetyaw=0;
6860 player[0].targetyaw=-yaw+180;
6866 flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
6870 facing=DoRotation(facing,-pitch,0,0);
6871 facing=DoRotation(facing,0,0-yaw,0);
6874 player[0].lookyaw=-yaw;
6876 player[i].targetheadyaw=yaw;
6877 player[i].targetheadpitch=pitch;
6879 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6880 if(!animation[player[i].targetanimation].attack&&
6881 player[i].targetanimation!=staggerbackhighanim&&
6882 player[i].targetanimation!=staggerbackhardanim&&
6883 player[i].targetanimation!=crouchremoveknifeanim&&
6884 player[i].targetanimation!=removeknifeanim&&
6885 player[i].targetanimation!=backhandspringanim&&
6886 player[i].targetanimation!=dodgebackanim&&
6887 player[i].targetanimation!=walljumprightkickanim&&
6888 player[i].targetanimation!=walljumpleftkickanim){
6889 player[i].targetyaw=-player[i].lookyaw+180;
6895 flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
6897 facing=DoRotation(facing,-player[i].lookpitch,0,0);
6898 facing=DoRotation(facing,0,0-player[i].lookyaw,0);
6900 player[i].targetheadyaw=player[i].lookyaw;
6901 player[i].targetheadpitch=player[i].lookpitch;
6904 player[i].targetheadyaw=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6905 player[i].targetheadpitch=pitchOf(participantfacing[whichdialogue][indialogue][i]);
6911 player[i].avoidsomething=0;
6913 //avoid flaming things
6914 for(int j=0;j<objects.numobjects;j++)
6915 if(objects.onfire[j])
6916 if(findDistancefast(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6917 if( findDistancefast(&player[i].coords,&objects.position[j])<
6918 findDistancefast(&player[i].coords,&player[0].coords)){
6919 player[i].collided=0;
6920 player[i].avoidcollided=1;
6921 if(player[i].avoidsomething==0||
6922 findDistancefast(&player[i].coords,&objects.position[j])<
6923 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6924 player[i].avoidwhere=objects.position[j];
6925 player[i].avoidsomething=1;
6929 //avoid flaming players
6930 for(int j=0;j<numplayers;j++)
6931 if(player[j].onfire)
6932 if(findDistancefast(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6933 if( findDistancefast(&player[i].coords,&player[j].coords)<
6934 findDistancefast(&player[i].coords,&player[0].coords)){
6935 player[i].collided=0;
6936 player[i].avoidcollided=1;
6937 if(player[i].avoidsomething==0||
6938 findDistancefast(&player[i].coords,&player[j].coords)<
6939 findDistancefast(&player[i].coords,&player[i].avoidwhere)){
6940 player[i].avoidwhere=player[j].coords;
6941 player[i].avoidsomething=1;
6945 if(player[i].collided>.8)
6946 player[i].avoidcollided=0;
6950 if(animation[player[i].targetanimation].attack==reversed){
6951 //player[i].targetyaw=player[i].yaw;
6952 player[i].forwardkeydown=0;
6953 player[i].leftkeydown=0;
6954 player[i].backkeydown=0;
6955 player[i].rightkeydown=0;
6956 player[i].jumpkeydown=0;
6957 player[i].attackkeydown=0;
6958 //player[i].crouchkeydown=0;
6959 player[i].throwkeydown=0;
6963 player[i].forwardkeydown=0;
6964 player[i].leftkeydown=0;
6965 player[i].backkeydown=0;
6966 player[i].rightkeydown=0;
6967 player[i].jumpkeydown=0;
6968 player[i].crouchkeydown=0;
6969 player[i].drawkeydown=0;
6970 player[i].throwkeydown=0;
6973 if(player[i].collided<-.3)
6974 player[i].collided=-.3;
6975 if(player[i].collided>1)
6976 player[i].collided=1;
6977 player[i].collided-=multiplier*4;
6978 player[i].whichdirectiondelay-=multiplier;
6979 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6980 player[i].avoidcollided=-.3;
6981 player[i].whichdirection=abs(Random()%2);
6982 player[i].whichdirectiondelay=.4;
6984 if(player[i].avoidcollided>1)
6985 player[i].avoidcollided=1;
6986 player[i].avoidcollided-=multiplier/4;
6987 if(!player[i].skeleton.free){
6988 player[i].stunned-=multiplier;
6989 player[i].surprised-=multiplier;
6991 if(i!=0&&player[i].surprised<=0&&
6992 player[i].aitype==attacktypecutoff&&
6994 !player[i].skeleton.free&&
6995 animation[player[i].targetanimation].attack==neutral)
6998 if(!player[i].throwkeydown)
6999 player[i].throwtogglekeydown=0;
7002 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
7003 if(player[i].weaponactive==-1&&
7004 player[i].num_weapons<2&&
7005 (player[i].isIdle()||
7006 player[i].isCrouch()||
7007 player[i].targetanimation==sneakanim||
7008 player[i].targetanimation==rollanim||
7009 player[i].targetanimation==backhandspringanim||
7010 player[i].isFlip()||
7011 player[i].isFlip()||
7012 player[i].aitype!=playercontrolled)){
7013 for(int j=0;j<weapons.size();j++){
7014 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
7015 player[i].aitype==playercontrolled)&&
7016 weapons[j].owner==-1&&
7017 player[i].weaponactive==-1)
7018 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2){
7019 if(findDistancefast(&player[i].coords,&weapons[j].position)<2){
7020 if(player[i].isCrouch()||
7021 player[i].targetanimation==sneakanim||
7023 player[i].isIdle()||
7024 player[i].aitype!=playercontrolled){
7025 player[i].throwtogglekeydown=1;
7026 player[i].setAnimation(crouchremoveknifeanim);
7027 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[j].position);
7028 player[i].hasvictim=0;
7030 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7031 player[i].throwtogglekeydown=1;
7032 player[i].hasvictim=0;
7034 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
7035 player[i].aitype==playercontrolled)&&
7036 weapons[j].owner==-1||
7038 weapons[j].owner==player[i].victim->id)
7039 if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
7040 if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){
7041 if(weapons[j].getType()!=staff)
7042 emit_sound_at(knifedrawsound, player[i].coords, 128.);
7044 player[i].weaponactive=0;
7045 weapons[j].owner=player[i].id;
7046 if(player[i].num_weapons>0)
7047 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7048 player[i].num_weapons++;
7049 player[i].weaponids[0]=j;
7052 }else if((player[i].isIdle()||
7053 player[i].isFlip()||
7054 player[i].aitype!=playercontrolled)&&
7055 findDistancefast(&player[i].coords,&weapons[j].position)<5&&
7056 player[i].coords.y<weapons[j].position.y){
7057 if(!player[i].isFlip()){
7058 player[i].throwtogglekeydown=1;
7059 player[i].setAnimation(removeknifeanim);
7060 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[j].position);
7062 if(player[i].isFlip()){
7063 player[i].throwtogglekeydown=1;
7064 player[i].hasvictim=0;
7066 for(int k=0;k<weapons.size();k++){
7067 if(player[i].weaponactive==-1)
7068 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
7069 player[i].aitype==playercontrolled)&&
7070 weapons[k].owner==-1||
7072 weapons[k].owner==player[i].victim->id)
7073 if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&&
7074 player[i].weaponactive==-1){
7075 if(weapons[k].getType()!=staff)
7076 emit_sound_at(knifedrawsound, player[i].coords, 128.);
7078 player[i].weaponactive=0;
7079 weapons[k].owner=player[i].id;
7080 if(player[i].num_weapons>0)
7081 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7082 player[i].num_weapons++;
7083 player[i].weaponids[0]=k;
7090 if(player[i].isCrouch()||
7091 player[i].targetanimation==sneakanim||
7093 player[i].isIdle()||player[i].targetanimation==rollanim||
7094 player[i].targetanimation==backhandspringanim){
7096 for(int j=0;j<numplayers;j++){
7097 if(player[i].weaponactive==-1)
7099 if(player[j].num_weapons&&
7100 player[j].skeleton.free&&
7101 findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
7102 (((player[j].skeleton.forward.y<0&&
7103 player[j].weaponstuckwhere==0)||
7104 (player[j].skeleton.forward.y>0&&
7105 player[j].weaponstuckwhere==1))||
7106 player[j].weaponstuck==-1||
7107 player[j].num_weapons>1)){
7108 if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
7109 player[i].throwtogglekeydown=1;
7110 player[i].victim=&player[j];
7111 player[i].hasvictim=1;
7112 player[i].setAnimation(crouchremoveknifeanim);
7113 player[i].targetyaw=roughDirectionTo(player[i].coords,player[j].coords);
7115 if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
7116 player[i].throwtogglekeydown=1;
7117 player[i].victim=&player[j];
7118 player[i].hasvictim=1;
7119 int k = player[j].weaponids[0];
7120 if(player[i].hasvictim){
7123 if(player[i].victim->weaponstuck!=-1){
7124 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7129 if(weapons[k].getType()!=staff)
7130 emit_sound_at(knifedrawsound, player[i].coords, 128.);
7133 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
7135 player[i].weaponactive=0;
7136 if(weapons[k].owner!=-1){
7137 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
7138 else player[i].victim->num_weapons=1;
7140 player[i].victim->skeleton.longdead=0;
7141 player[i].victim->skeleton.free=1;
7142 player[i].victim->skeleton.broken=0;
7144 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
7145 player[i].victim->skeleton.joints[l].velchange=0;
7146 player[i].victim->skeleton.joints[l].locked=0;
7152 Normalise(&relative);
7153 XYZ footvel,footpoint;
7155 footpoint=weapons[k].position;
7156 if(player[i].victim->weaponstuck!=-1){
7157 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7158 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
7159 weapons[k].bloody=2;
7160 weapons[k].blooddrip=5;
7161 player[i].victim->weaponstuck=-1;
7162 player[i].victim->bloodloss+=2000;
7163 player[i].victim->DoDamage(2000);
7166 if(player[i].victim->num_weapons>0){
7167 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
7168 if(player[i].victim->weaponids[0]==k)
7169 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
7172 player[i].victim->weaponactive=-1;
7174 player[i].victim->getJointFor(abdomen).velocity+=relative*6;
7175 player[i].victim->getJointFor(neck).velocity+=relative*6;
7176 player[i].victim->getJointFor(rightshoulder).velocity+=relative*6;
7177 player[i].victim->getJointFor(leftshoulder).velocity+=relative*6;
7180 if(player[i].num_weapons>0){
7181 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7183 player[i].num_weapons++;
7184 player[i].weaponids[0]=k;
7191 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7192 if(weapons[player[i].weaponids[0]].getType()==knife){
7193 if(player[i].isIdle()||
7195 player[i].isCrouch()||
7196 player[i].targetanimation==sneakanim||
7199 for(int j=0;j<numplayers;j++){
7201 if(tutoriallevel!=1||tutorialstage==49)
7203 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
7204 findDistancefast(&player[i].coords,&player[j].coords)<100&&
7205 findDistancefast(&player[i].coords,&player[j].coords)>1.5&&
7206 !player[j].skeleton.free&&
7207 -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*player[i].scale+player[i].coords)){
7208 if(!player[i].isFlip()){
7209 player[i].throwtogglekeydown=1;
7210 player[i].victim=&player[j];
7211 player[i].setAnimation(knifethrowanim);
7212 player[i].targetyaw=roughDirectionTo(player[i].coords,player[j].coords);
7213 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
7215 if(player[i].isFlip()){
7216 if(player[i].weaponactive!=-1){
7217 player[i].throwtogglekeydown=1;
7218 player[i].victim=&player[j];
7220 weapons[player[i].weaponids[0]].owner=-1;
7221 aim=player[i].victim->coords+DoRotation(player[i].victim->getJointFor(abdomen).position,0,player[i].victim->yaw,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].yaw,0)*player[i].scale);
7224 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
7226 weapons[player[i].weaponids[0]].velocity=aim*50;
7227 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
7228 weapons[player[i].weaponids[0]].missed=0;
7229 weapons[player[i].weaponids[0]].freetime=0;
7230 weapons[player[i].weaponids[0]].firstfree=1;
7231 weapons[player[i].weaponids[0]].physics=0;
7232 player[i].num_weapons--;
7233 if(player[i].num_weapons){
7234 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7236 player[i].weaponactive=-1;
7243 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7244 if(player[i].isCrouch()||player[i].targetanimation==sneakanim){
7245 player[i].throwtogglekeydown=1;
7246 weapons[player[i].weaponids[0]].owner=-1;
7247 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
7248 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
7249 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
7250 weapons[player[i].weaponids[0]].missed=1;
7251 weapons[player[i].weaponids[0]].freetime=0;
7252 weapons[player[i].weaponids[0]].firstfree=1;
7253 weapons[player[i].weaponids[0]].physics=1;
7254 player[i].num_weapons--;
7255 if(player[i].num_weapons){
7256 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7257 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7260 player[i].weaponactive=-1;
7261 for(int j=0;j<numplayers;j++){
7262 player[j].wentforweapon=0;
7270 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
7271 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
7272 player[i].num_weapons==2&&
7273 player[i].weaponactive==-1&&
7274 player[i].isIdle()||
7276 player[i].weaponactive!=-1&&
7279 if(player[i].weaponactive!=-1)
7280 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
7282 if(isgood&&player[i].creature!=wolftype){
7283 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7284 player[i].setAnimation(drawrightanim);
7285 player[i].drawtogglekeydown=1;
7287 if((player[i].isIdle()||
7288 (player[i].aitype!=playercontrolled&&
7289 player[0].weaponactive!=-1&&
7290 player[i].isRun()))&&
7291 player[i].num_weapons&&
7292 weapons[player[i].weaponids[0]].getType()==sword){
7293 player[i].setAnimation(drawleftanim);
7294 player[i].drawtogglekeydown=1;
7296 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7297 player[i].setAnimation(crouchdrawrightanim);
7298 player[i].drawtogglekeydown=1;
7305 if(player[i].weaponactive!=-1) {
7306 if (player[i].isCrouch()&&
7307 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
7309 player[i].onterrain&&
7310 player[i].num_weapons&&
7311 player[i].attackkeydown&&
7312 musictype!=stream_fighttheme) {
7313 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
7314 player[i].setAnimation(crouchstabanim);
7315 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
7316 player[i].setAnimation(swordgroundstabanim);
7317 player[i].hasvictim=0;
7321 if(!player[i].drawkeydown)
7322 player[i].drawtogglekeydown=0;
7329 absflatfacing=DoRotation(absflatfacing,0,-yaw,0);
7331 absflatfacing=flatfacing;
7334 player[i].forwardkeydown=0;
7335 player[i].leftkeydown=0;
7336 player[i].backkeydown=0;
7337 player[i].rightkeydown=0;
7338 player[i].jumpkeydown=0;
7339 player[i].crouchkeydown=0;
7340 player[i].drawkeydown=0;
7341 player[i].throwkeydown=0;
7345 if(!animation[player[i].targetanimation].attack&&
7346 player[i].targetanimation!=staggerbackhighanim&&
7347 player[i].targetanimation!=staggerbackhardanim&&
7348 player[i].targetanimation!=backhandspringanim&&
7349 player[i].targetanimation!=dodgebackanim){
7350 if(!player[i].forwardkeydown)
7351 player[i].forwardstogglekeydown=0;
7352 if(player[i].crouchkeydown){
7356 player[i].superruntoggle=1;
7358 for(int j=0;j<numplayers;j++)
7359 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7360 if(findDistancefast(&player[j].coords,&player[i].coords)<16)
7361 player[i].superruntoggle=0;
7365 for(int j=0;j<numplayers;j++){
7366 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7367 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7368 player[j].victim==&player[i]&&
7369 (player[j].targetanimation==sweepanim||
7370 player[j].targetanimation==upunchanim||
7371 player[j].targetanimation==wolfslapanim||
7372 ((player[j].targetanimation==swordslashanim||
7373 player[j].targetanimation==knifeslashstartanim||
7374 player[j].targetanimation==staffhitanim||
7375 player[j].targetanimation==staffspinhitanim)&&
7376 findDistancefast(&player[j].coords,&player[i].coords)<2))){
7385 player[target].Reverse();
7386 player[i].lowreversaldelay=.5;
7388 if(player[i].isIdle()){
7389 player[i].setAnimation(player[i].getCrouch());
7390 player[i].transspeed=10;
7392 if(player[i].isRun()||
7393 (player[i].isStop()&&
7394 (player[i].leftkeydown||
7395 player[i].rightkeydown||
7396 player[i].forwardkeydown||
7397 player[i].backkeydown))){
7398 player[i].setAnimation(rollanim);
7399 player[i].transspeed=20;
7402 if(!player[i].crouchkeydown){
7404 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
7406 if(player[i].isCrouch()){
7408 for(int j=0;j<numplayers;j++){
7410 !player[j].skeleton.free&&
7412 player[i].highreversaldelay<=0){
7413 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7414 player[j].victim==&player[i]&&
7415 (player[j].targetanimation==spinkickanim)&&
7416 player[i].isCrouch()){
7425 player[target].Reverse();
7426 player[i].highreversaldelay=.5;
7428 if(player[i].isCrouch()){
7429 if(!player[i].wasCrouch()){
7430 player[i].currentanimation=player[i].getCrouch();
7431 player[i].currentframe=0;
7433 player[i].setAnimation(player[i].getIdle());
7434 player[i].transspeed=10;
7437 if(player[i].targetanimation==sneakanim){
7438 player[i].setAnimation(player[i].getIdle());
7439 player[i].transspeed=10;
7442 if(player[i].forwardkeydown){
7443 if(player[i].isIdle()||
7444 (player[i].isStop()&&
7445 player[i].targetyaw==player[i].yaw)||
7446 (player[i].isLanding()&&
7447 player[i].targetframe>0&&
7448 !player[i].jumpkeydown)||
7449 (player[i].isLandhard()&&
7450 player[i].targetframe>0&&
7451 !player[i].jumpkeydown&&
7452 player[i].crouchkeydown)){
7453 if(player[i].aitype==passivetype)
7454 player[i].setAnimation(walkanim);
7456 player[i].setAnimation(player[i].getRun());
7458 if(player[i].isCrouch()){
7459 player[i].targetanimation=sneakanim;
7460 if(player[i].wasCrouch())
7462 player[i].targetframe=0;
7464 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7465 player[i].setAnimation(climbanim);
7466 player[i].targetframe=1;
7467 player[i].jumpclimb=1;
7469 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7470 player[i].velocity+=absflatfacing*5*multiplier;
7472 player[i].forwardstogglekeydown=1;
7475 if (player[i].rightkeydown){
7476 if(player[i].isIdle()||
7477 (player[i].isStop()&&
7478 player[i].targetyaw==player[i].yaw)||
7479 (player[i].isLanding()&&
7480 player[i].targetframe>0&&
7481 !player[i].jumpkeydown)||
7482 (player[i].isLandhard()&&
7483 player[i].targetframe>0&&
7484 !player[i].jumpkeydown&&
7485 player[i].crouchkeydown)){
7486 player[i].setAnimation(player[i].getRun());
7488 if(player[i].isCrouch()){
7489 player[i].targetanimation=sneakanim;
7490 if(player[i].wasCrouch())
7492 player[i].targetframe=0;
7494 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7495 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7497 player[i].targetyaw-=90;
7498 if(player[i].forwardkeydown)player[i].targetyaw+=45;
7499 if(player[i].backkeydown)player[i].targetyaw-=45;
7502 if ( player[i].leftkeydown){
7503 if(player[i].isIdle()||
7504 (player[i].isStop()&&
7505 player[i].targetyaw==player[i].yaw)||
7506 (player[i].isLanding()&&
7507 player[i].targetframe>0&&
7508 !player[i].jumpkeydown)||
7509 (player[i].isLandhard()&&
7510 player[i].targetframe>0&&
7511 !player[i].jumpkeydown&&
7512 player[i].crouchkeydown)){
7513 player[i].setAnimation(player[i].getRun());
7515 if(player[i].isCrouch()){
7516 player[i].targetanimation=sneakanim;
7517 if(player[i].wasCrouch())
7519 player[i].targetframe=0;
7521 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7522 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7524 player[i].targetyaw+=90;
7525 if(player[i].forwardkeydown)player[i].targetyaw-=45;
7526 if(player[i].backkeydown)player[i].targetyaw+=45;
7529 if(player[i].backkeydown){
7530 if(player[i].isIdle()||
7531 (player[i].isStop()&&
7532 player[i].targetyaw==player[i].yaw)||
7533 (player[i].isLanding()&&
7534 player[i].targetframe>0&&
7535 !player[i].jumpkeydown)||
7536 (player[i].isLandhard()&&
7537 player[i].targetframe>0&&
7538 !player[i].jumpkeydown&&
7539 player[i].crouchkeydown)){
7540 player[i].setAnimation(player[i].getRun());
7542 if(player[i].isCrouch()){
7543 player[i].targetanimation=sneakanim;
7544 if(player[i].wasCrouch())
7546 player[i].targetframe=0;
7548 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
7549 player[i].velocity-=absflatfacing*5*multiplier;
7551 if(player[i].targetanimation==hanganim){
7552 player[i].currentanimation=jumpdownanim;
7553 player[i].targetanimation=jumpdownanim;
7555 player[i].currentframe=0;
7556 player[i].targetframe=1;
7557 player[i].velocity=0;
7558 player[i].velocity.y+=gravity;
7559 player[i].coords.y-=1.4;
7560 player[i].grabdelay=1;
7562 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7563 player[i].targetyaw+=180;
7566 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7567 if((((player[i].isLanding()&&player[i].targetframe>=3)||
7569 player[i].targetanimation==walkanim||
7570 player[i].isCrouch()||
7571 player[i].targetanimation==sneakanim)&&
7572 player[i].jumppower>1)&&
7573 ((player[i].targetanimation!=rabbitrunninganim&&
7574 player[i].targetanimation!=wolfrunninganim)||i!=0)){
7575 player[i].jumpstart=0;
7576 player[i].setAnimation(jumpupanim);
7577 player[i].yaw=player[i].targetyaw;
7578 player[i].transspeed=20;
7579 player[i].FootLand(0,1);
7580 player[i].FootLand(1,1);
7584 flatfacing=DoRotation(facing,0,player[i].targetyaw+180,0);
7586 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7587 if(!movekey)player[i].velocity=0;
7592 for(int j=0;j<numplayers;j++){
7593 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7594 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&
7595 player[j].victim==&player[i]&&
7596 (player[j].targetanimation==sweepanim)){
7597 if(target>=0)target=-1;
7602 if(target>=0)player[i].velocity.y=1;
7603 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7604 player[i].velocity.y=7;
7605 player[i].crouchtogglekeydown=1;
7607 else player[i].velocity.y=5;
7609 if(mousejump&&i==0&&debugmode){
7610 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7611 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7614 player[i].coords.y+=.2;
7615 player[i].jumppower-=1;
7618 emit_sound_at(whooshsound, player[i].coords, 128.);
7620 emit_sound_at(jumpsound, player[i].coords, 128.);
7622 if((player[i].isIdle())&&player[i].jumppower>1){
7623 player[i].setAnimation(player[i].getLanding());
7624 player[i].targetframe=2;
7625 player[i].landhard=0;
7626 player[i].jumpstart=1;
7627 player[i].tempdeltav=deltav;
7629 if(player[i].targetanimation==jumpupanim&&
7633 player[i].aitype!=playercontrolled)){
7634 if(player[i].jumppower>multiplier*6){
7635 player[i].velocity.y+=multiplier*6;
7636 player[i].jumppower-=multiplier*6;
7638 if(player[i].jumppower<=multiplier*6){
7639 player[i].velocity.y+=player[i].jumppower;
7640 player[i].jumppower=0;
7643 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7647 if(player[i].isRun()||player[i].targetanimation==walkanim)
7648 player[i].setAnimation(player[i].getStop());
7649 if(player[i].targetanimation==sneakanim){
7650 player[i].targetanimation=player[i].getCrouch();
7651 if(player[i].currentanimation==sneakanim)
7653 player[i].targetframe=0;
7656 if(player[i].targetanimation==walkanim&&
7657 (player[i].aitype==attacktypecutoff||
7658 player[i].aitype==searchtype||
7659 (player[i].aitype==passivetype&&
7660 player[i].numwaypoints<=1)))
7661 player[i].setAnimation(player[i].getStop());
7662 if(player[i].isRun()&&(player[i].aitype==passivetype))
7663 player[i].setAnimation(player[i].getStop());
7666 if(player[i].targetanimation==rollanim)
7667 player[i].targetyaw=oldtargetyaw;
7671 for(int k=0;k<numplayers;k++){
7672 if(fabs(player[k].yaw-player[k].targetyaw)>180){
7673 if(player[k].yaw>player[k].targetyaw)
7679 //stop to turn in right direction
7680 if(fabs(player[k].yaw-player[k].targetyaw)>90&&(player[k].isRun()||player[k].targetanimation==walkanim))
7681 player[k].setAnimation(player[k].getStop());
7683 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim)
7684 player[k].targettilt=0;
7686 if(player[k].targetanimation!=jumpupanim&&
7687 player[k].targetanimation!=backhandspringanim&&
7688 player[k].targetanimation!=jumpdownanim&&
7689 !player[k].isFlip()){
7690 player[k].targettilt=0;
7691 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7692 player[k].jumppower=0;
7693 player[k].jumppower+=multiplier*7;
7694 if(player[k].isCrouch())
7695 player[k].jumppower+=multiplier*7;
7696 if(player[k].jumppower>5)
7697 player[k].jumppower=5;
7700 if(player[k].isRun())
7701 player[k].targettilt=(player[k].yaw-player[k].targetyaw)/4;
7703 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7704 player[k].grabdelay-=multiplier;
7708 for(int k=0;k<numplayers;k++){
7709 player[k].DoAnimations();
7710 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7711 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7717 for(int j=numenvsounds-1;j>=0;j--){
7718 envsoundlife[j]-=multiplier;
7719 if(envsoundlife[j]<0){
7721 envsoundlife[j]=envsoundlife[numenvsounds];
7722 envsound[j]=envsound[numenvsounds];
7726 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7728 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7730 if(tutoriallevel==1){
7747 if(tutorialstage>=51)
7748 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7749 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7750 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7752 emit_stream_np(stream_menutheme);
7761 if(tutorialstage<51)
7762 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
7763 emit_sound_at(fireendsound, player[0].coords);
7765 player[0].coords=(oldtemp+oldtemp2)/2;
7769 if(tutorialstage>=14&&tutorialstage<50)
7770 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
7771 emit_sound_at(fireendsound, player[1].coords);
7773 for(int i=0;i<player[1].skeleton.num_joints;i++){
7775 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7776 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7777 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].yaw,0)*player[1].scale+player[1].coords;
7778 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7779 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7783 player[1].coords=(oldtemp+oldtemp2)/2;
7784 for(int i=0;i<player[1].skeleton.num_joints;i++){
7785 player[1].skeleton.joints[i].velocity=0;
7787 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7788 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7789 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].yaw,0)*player[1].scale+player[1].coords;
7790 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7791 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7799 static float gLoc[3];
7803 static float vel[3];
7804 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7805 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7806 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7808 //Set orientation with forward and up vectors
7809 static XYZ upvector;
7813 upvector=DoRotation(upvector,-pitch+90,0,0);
7814 upvector=DoRotation(upvector,0,0-yaw,0);
7819 facing=DoRotation(facing,-pitch,0,0);
7820 facing=DoRotation(facing,0,0-yaw,0);
7823 static float ori[6];
7827 ori[3] = -upvector.x;
7828 ori[4] = upvector.y;
7829 ori[5] = -upvector.z;
7831 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7838 if(Input::isKeyPressed(SDLK_F1))
7842 void Game::TickOnce(){
7846 if(directing||indialogue==-1) {
7859 void Game::TickOnceAfter(){
7860 static XYZ colviewer;
7861 static XYZ coltarget;
7865 static float changedelay;
7866 static bool alldead;
7867 static float unseendelay;
7868 static float cameraspeed;
7871 static int oldmusictype=musictype;
7873 if(environment==snowyenvironment)
7874 leveltheme=stream_snowtheme;
7875 if(environment==grassyenvironment)
7876 leveltheme=stream_grasstheme;
7877 if(environment==desertenvironment)
7878 leveltheme=stream_deserttheme;
7882 musictype=leveltheme;
7883 for(int i=0;i<numplayers;i++){
7884 if((player[i].aitype==attacktypecutoff||
7885 player[i].aitype==getweapontype||
7886 player[i].aitype==gethelptype||
7887 player[i].aitype==searchtype)&&
7888 !player[i].dead/*&&player[i].surprised<=0*/&&
7889 (player[i].targetanimation!=sneakattackedanim&&
7890 player[i].targetanimation!=knifesneakattackedanim&&
7891 player[i].targetanimation!=swordsneakattackedanim)){
7892 musictype=stream_fighttheme;
7897 musictype=stream_menutheme;
7900 if(musictype==stream_fighttheme)
7903 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7904 unseendelay-=multiplier;
7906 musictype=stream_fighttheme;
7911 musictype=stream_menutheme;
7919 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7920 emit_sound_np(alarmsound);
7921 musicselected=musictype;
7923 if(musicselected==leveltheme)
7924 musicvolume[0]+=multiplier*450;
7926 musicvolume[0]-=multiplier*450;
7927 if(musicselected==stream_fighttheme)
7928 musicvolume[1]+=multiplier*450;
7930 musicvolume[1]-=multiplier*450;
7931 if(musicselected==stream_menutheme)
7932 musicvolume[2]+=multiplier*450;
7934 musicvolume[2]-=multiplier*450;
7936 for(int i=0;i<3;i++){
7937 if(musicvolume[i]<0)
7939 if(musicvolume[i]>512)
7943 if(musicvolume[2]>128&&!loading&&!mainmenu)
7947 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7948 emit_stream_np(leveltheme, musicvolume[0]);
7949 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7950 emit_stream_np(stream_fighttheme, musicvolume[1]);
7951 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7952 emit_stream_np(stream_menutheme, musicvolume[2]);
7953 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7954 pause_sound(leveltheme);
7955 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7956 pause_sound(stream_fighttheme);
7957 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7958 pause_sound(stream_menutheme);
7960 if(musicvolume[0]!=oldmusicvolume[0])
7961 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7962 if(musicvolume[1]!=oldmusicvolume[1])
7963 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7964 if(musicvolume[2]!=oldmusicvolume[2])
7965 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7967 for(int i=0;i<3;i++)
7968 oldmusicvolume[i]=musicvolume[i];
7970 pause_sound(leveltheme);
7971 pause_sound(stream_fighttheme);
7972 pause_sound(stream_menutheme);
7974 for(int i=0;i<4;i++){
7975 oldmusicvolume[i]=0;
7981 for(int i=0;i<numhotspots;i++){
7982 if(hotspottype[i]>10&&hotspottype[i]<20){
7983 if(player[hotspottype[i]-10].dead==0)
7985 else if(killhotspot==2)
7994 for(int i=0;i<numhotspots;i++)
7995 if(hotspottype[i]==-1)
7996 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
8000 for(int i=1;i<numplayers;i++)
8001 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
8003 if(numalarmed>maxalarmed)
8004 maxalarmed=numalarmed;
8006 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
8007 if(player[0].dead&&changedelay<=0){
8009 targetlevel=whichlevel;
8012 for(int i=1;i<numplayers;i++) {
8013 if(!player[i].dead&&player[i].howactive<typedead1) {
8020 if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
8022 targetlevel=whichlevel+1;
8023 if(targetlevel>numchallengelevels-1)targetlevel=0;
8025 if(winhotspot||windialogue) {
8027 targetlevel=whichlevel+1;
8028 if(targetlevel>numchallengelevels-1)targetlevel=0;
8034 targetlevel=whichlevel+1;
8035 if(targetlevel>numchallengelevels-1)targetlevel=0;
8038 if(changedelay>0&&!player[0].dead&&!won) {
8039 //high scores, awards, win
8041 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
8044 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
8060 if(!editorenabled&&gameon&&!mainmenu) {
8061 if(changedelay!=-999)
8062 changedelay-=multiplier/7;
8064 targetlevel=whichlevel;
8065 if(loading==2&&!campaign){
8068 fireSound(firestartsound);
8070 if(!player[0].dead&&targetlevel!=whichlevel)
8071 startbonustotal=bonustotal;
8073 Loadlevel(whichlevel);
8075 Loadlevel(targetlevel);
8081 if(loading==2&&targetlevel==whichlevel){
8085 fireSound(firestartsound);
8087 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
8093 if(changedelay<=-999&&
8097 (alldead&&maptype==mapkilleveryone)||
8101 if((player[0].dead||
8102 (alldead&&maptype==mapkilleveryone)||
8107 if(whichlevel!=-2&&!loading&&!player[0].dead) {
8117 // campaignchoosenext determines what to do when the level is complete:
8118 // 0 = load next level
8119 // 1 = go back to level select screen
8120 // 2 = stealthload next level
8121 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
8122 if(campaignlevels[actuallevel].nextlevel.empty())
8124 } else if(mainmenu==0&&winfreeze) {
8125 stealthloading = (campaignlevels[actuallevel].choosenext==2);
8127 if(!stealthloading){
8128 fireSound(firestartsound);
8143 actuallevel=campaignlevels[actuallevel].nextlevel.front();
8146 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
8150 pause_sound(stream_menutheme);
8161 oldmusictype=musictype;
8167 facing=DoRotation(facing,-pitch,0,0);
8168 facing=DoRotation(facing,0,0-yaw,0);
8169 viewerfacing=facing;
8172 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;
8173 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;
8175 if(player[0].skeleton.free){
8176 for(int i=0;i<player[0].skeleton.num_joints;i++){
8177 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
8178 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
8182 if(player[0].skeleton.free!=2/*&&!autocam*/){
8184 if(findLengthfast(&player[0].velocity)>400){
8185 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8187 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8188 coltarget=target-cameraloc;
8189 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8191 Normalise(&coltarget);
8192 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8193 else cameraloc=cameraloc+coltarget*multiplier*8;
8195 if(editorenabled)cameraloc=target;
8196 cameradist+=multiplier*5;
8197 if(cameradist>2.3)cameradist=2.3;
8198 viewer=cameraloc-facing*cameradist;
8200 coltarget=cameraloc;
8201 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8202 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8203 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8204 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8206 coltarget=cameraloc;
8207 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.yaw[i])!=-1)viewer=col;
8209 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8210 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8211 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8213 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.yaw[i])!=-1){
8217 cameradist=findDistance(&viewer,&target);
8218 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8219 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8220 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8224 //what did autocam do?
8225 if(player[0].skeleton.free!=2&&autocam){
8227 if(findLengthfast(&player[0].velocity)>400){
8228 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8230 if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
8231 cameradist+=multiplier*5;
8232 if(cameradist>3.3)cameradist=3.3;
8233 coltarget=target-cameraloc;
8234 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8235 else if(findLengthfast(&coltarget)>1)
8237 Normalise(&coltarget);
8238 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8239 else cameraloc=cameraloc+coltarget*multiplier*8;
8241 if(editorenabled)cameraloc=target;
8244 coltarget=cameraloc;
8245 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8246 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8247 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8248 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8250 coltarget=cameraloc;
8251 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.yaw[i])!=-1)viewer=col;
8253 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8254 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8255 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8257 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.yaw[i])!=-1){
8261 cameradist=findDistance(&viewer,&target);
8262 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8263 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8264 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8268 if(camerashake>.8)camerashake=.8;
8269 //if(woozy>10)woozy=10;
8270 //woozy+=multiplier;
8272 if(player[0].dead)camerashake=0;
8273 if(player[0].dead)woozy=0;
8274 camerashake-=multiplier*2;
8275 blackout-=multiplier*2;
8276 //if(player[0].isCrouch())woozy-=multiplier*8;
8277 if(camerashake<0)camerashake=0;
8278 if(blackout<0)blackout=0;
8279 //if(woozy<0)woozy=0;
8281 viewer.x+=(float)(Random()%100)*.0005*camerashake;
8282 viewer.y+=(float)(Random()%100)*.0005*camerashake;
8283 viewer.z+=(float)(Random()%100)*.0005*camerashake;