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 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Furdarko.jpg",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 findClosestPlayer(){
614 float closestdist = std::numeric_limits<float>::max();
616 for(int i=1; i<numplayers; i++){
617 float distance = distsq(&player[i].coords, &player[0].coords);
618 if(distance < closestdist){
619 closestdist = distance;
626 static int findClosestObject(){
628 float closestdist = std::numeric_limits<float>::max();
630 for(int i=0; i<objects.numobjects; i++){
631 float distance = distsq(&objects.position[i], &player[0].coords);
632 if(distance < closestdist){
633 closestdist = distance;
640 static void ch_sizenear(const char *args)
642 int closest = findClosestPlayer();
644 player[closest].scale = atof(args) * .2;
647 static void set_proportion(int pnum, const char *args)
649 float headprop,bodyprop,armprop,legprop;
651 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
653 if(player[pnum].creature==wolftype){
654 player[pnum].proportionhead=1.1*headprop;
655 player[pnum].proportionbody=1.1*bodyprop;
656 player[pnum].proportionarms=1.1*armprop;
657 player[pnum].proportionlegs=1.1*legprop;
658 } else if(player[pnum].creature==rabbittype){
659 player[pnum].proportionhead=1.2*headprop;
660 player[pnum].proportionbody=1.05*bodyprop;
661 player[pnum].proportionarms=1.00*armprop;
662 player[pnum].proportionlegs=1.1*legprop;
663 player[pnum].proportionlegs.y=1.05*legprop;
667 static void ch_proportion(const char *args)
669 set_proportion(0, args);
672 static void ch_proportionnear(const char *args)
674 int closest = findClosestPlayer();
676 set_proportion(closest, args);
679 static void set_protection(int pnum, const char *args)
681 float head, high, low;
682 sscanf(args, "%f%f%f", &head, &high, &low);
684 player[pnum].protectionhead = head;
685 player[pnum].protectionhigh = high;
686 player[pnum].protectionlow = low;
689 static void ch_protection(const char *args)
691 set_protection(0, args);
694 static void ch_protectionnear(const char *args)
696 int closest = findClosestPlayer();
698 set_protection(closest, args);
701 static void set_armor(int pnum, const char *args)
703 float head, high, low;
704 sscanf(args, "%f%f%f", &head, &high, &low);
706 player[pnum].armorhead = head;
707 player[pnum].armorhigh = high;
708 player[pnum].armorlow = low;
711 static void ch_armor(const char *args)
716 static void ch_armornear(const char *args)
718 int closest = findClosestPlayer();
720 set_armor(closest, args);
723 static void ch_protectionreset(const char *args)
725 set_protection(0, "1 1 1");
726 set_armor(0, "1 1 1");
729 static void set_metal(int pnum, const char *args)
731 float head, high, low;
732 sscanf(args, "%f%f%f", &head, &high, &low);
734 player[pnum].metalhead = head;
735 player[pnum].metalhigh = high;
736 player[pnum].metallow = low;
739 static void ch_metal(const char *args)
744 static void set_noclothes(int pnum, const char *args)
746 player[pnum].numclothes = 0;
747 player[pnum].skeleton.drawmodel.textureptr.load(
748 creatureskin[player[pnum].creature][player[pnum].whichskin],1,
749 &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
752 static void ch_noclothes(const char *args)
754 set_noclothes(0, args);
757 static void ch_noclothesnear(const char *args)
759 int closest = findClosestPlayer();
761 set_noclothes(closest, args);
765 static void set_clothes(int pnum, const char *args)
768 snprintf(buf, 63, ":Data:Textures:%s.png", args);
770 if (!AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
773 player[pnum].DoMipmaps();
774 strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
775 player[pnum].clothestintr[player[pnum].numclothes]=tintr;
776 player[pnum].clothestintg[player[pnum].numclothes]=tintg;
777 player[pnum].clothestintb[player[pnum].numclothes]=tintb;
778 player[pnum].numclothes++;
781 static void ch_clothes(const char *args)
783 set_clothes(0, args);
786 static void ch_clothesnear(const char *args)
788 int closest = findClosestPlayer();
790 set_clothes(closest, args);
793 static void ch_belt(const char *args)
795 player[0].skeleton.clothes = !player[0].skeleton.clothes;
799 static void ch_cellophane(const char *args)
801 cellophane = !cellophane;
802 float mul = cellophane ? 0 : 1;
804 for (int i = 0; i < numplayers; i++) {
805 player[i].proportionhead.z = player[i].proportionhead.x * mul;
806 player[i].proportionbody.z = player[i].proportionbody.x * mul;
807 player[i].proportionarms.z = player[i].proportionarms.x * mul;
808 player[i].proportionlegs.z = player[i].proportionlegs.x * mul;
812 static void ch_funnybunny(const char *args)
814 player[0].skeleton.id=0;
815 player[0].skeleton.Load(":Data:Skeleton:Basic Figure",":Data:Skeleton:Basic Figurelow",
816 ":Data:Skeleton:Rabbitbelt",":Data:Models:Body.solid",
817 ":Data:Models:Body2.solid",":Data:Models:Body3.solid",
818 ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
819 ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
820 ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
821 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
822 player[0].creature=rabbittype;
824 player[0].headless=0;
825 player[0].damagetolerance=200;
826 set_proportion(0, "1 1 1 1");
829 static void ch_wolfie(const char *args)
831 player[0].skeleton.id=0;
832 player[0].skeleton.Load(":Data:Skeleton:Basic Figure Wolf",":Data:Skeleton:Basic Figure Wolf Low",
833 ":Data:Skeleton:Rabbitbelt",":Data:Models:Wolf.solid",
834 ":Data:Models:Wolf2.solid",":Data:Models:Wolf3.solid",
835 ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
836 ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
837 ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
838 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
839 player[0].creature=wolftype;
840 player[0].damagetolerance=300;
841 set_proportion(0, "1 1 1 1");
844 static void ch_wolfieisgod(const char *args)
849 static void ch_wolf(const char *args)
851 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
854 static void ch_snowwolf(const char *args)
856 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:SnowWolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
859 static void ch_darkwolf(const char *args)
861 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:DarkWolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
864 static void ch_lizardwolf(const char *args)
866 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Lizardwolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
869 static void ch_white(const char *args)
871 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
874 static void ch_brown(const char *args)
876 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
879 static void ch_black(const char *args)
881 player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur2.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
884 static void ch_sizemin(const char *args)
886 for (int i = 1; i < numplayers; i++)
887 if (player[i].scale < 0.8 * 0.2)
888 player[i].scale = 0.8 * 0.2;
891 static void ch_tutorial(const char *args)
893 tutoriallevel = atoi(args);
896 static void ch_hostile(const char *args)
898 hostile = atoi(args);
901 static void ch_indemo(const char *args)
904 hotspot[numhotspots]=player[0].coords;
905 hotspotsize[numhotspots]=0;
906 hotspottype[numhotspots]=-111;
907 strcpy(hotspottext[numhotspots],"mapname");
911 static void ch_notindemo(const char *args)
917 static void ch_type(const char *args)
919 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
920 for (int i = 0; i < n; i++)
921 if (stripfx(args, editortypenames[i])) {
927 static void ch_path(const char *args)
929 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
930 for (int i = 0; i < n; i++)
931 if (stripfx(args, pathtypenames[i])) {
937 static void ch_hs(const char *args)
939 hotspot[numhotspots]=player[0].coords;
943 sscanf(args, "%f%d %n", &size, &type, &shift);
945 hotspotsize[numhotspots] = size;
946 hotspottype[numhotspots] = type;
948 strcpy(hotspottext[numhotspots], args + shift);
949 strcat(hotspottext[numhotspots], "\n");
954 static void ch_dialogue(const char *args)
957 char buf1[32], buf2[64];
959 sscanf(args, "%d %31s", &dlg, buf1);
960 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
962 dialoguetype[numdialogues] = dlg;
964 memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues]));
965 memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues]));
967 ifstream ipstream(ConvertFileName(buf2));
968 ipstream.ignore(256,':');
969 ipstream >> numdialogueboxes[numdialogues];
970 for(int i=0;i<numdialogueboxes[numdialogues];i++){
971 ipstream.ignore(256,':');
972 ipstream.ignore(256,':');
973 ipstream.ignore(256,' ');
974 ipstream >> dialogueboxlocation[numdialogues][i];
975 ipstream.ignore(256,':');
976 ipstream >> dialogueboxcolor[numdialogues][i][0];
977 ipstream >> dialogueboxcolor[numdialogues][i][1];
978 ipstream >> dialogueboxcolor[numdialogues][i][2];
979 ipstream.ignore(256,':');
980 ipstream.getline(dialoguename[numdialogues][i],64);
981 ipstream.ignore(256,':');
982 ipstream.ignore(256,' ');
983 ipstream.getline(dialoguetext[numdialogues][i],128);
984 for(int j=0;j<128;j++){
985 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
987 ipstream.ignore(256,':');
988 ipstream >> dialogueboxsound[numdialogues][i];
991 for(int i=0;i<numdialogueboxes[numdialogues];i++){
992 for(int j=0;j<numplayers;j++){
993 participantfacing[numdialogues][i][j]=player[j].facing;
1000 whichdialogue=numdialogues;
1005 static void ch_fixdialogue(const char *args)
1007 char buf1[32], buf2[64];
1010 sscanf(args, "%d %31s", &whichdi, buf1);
1011 snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1);
1013 memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi]));
1014 memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi]));
1016 ifstream ipstream(ConvertFileName(buf2));
1017 ipstream.ignore(256,':');
1018 ipstream >> numdialogueboxes[whichdi];
1019 for(int i=0;i<numdialogueboxes[whichdi];i++){
1020 ipstream.ignore(256,':');
1021 ipstream.ignore(256,':');
1022 ipstream.ignore(256,' ');
1023 ipstream >> dialogueboxlocation[whichdi][i];
1024 ipstream.ignore(256,':');
1025 ipstream >> dialogueboxcolor[whichdi][i][0];
1026 ipstream >> dialogueboxcolor[whichdi][i][1];
1027 ipstream >> dialogueboxcolor[whichdi][i][2];
1028 ipstream.ignore(256,':');
1029 ipstream.getline(dialoguename[whichdi][i],64);
1030 ipstream.ignore(256,':');
1031 ipstream.ignore(256,' ');
1032 ipstream.getline(dialoguetext[whichdi][i],128);
1033 for(int j=0;j<128;j++){
1034 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
1036 ipstream.ignore(256,':');
1037 ipstream >> dialogueboxsound[whichdi][i];
1043 static void ch_fixtype(const char *args)
1046 sscanf(args, "%d", &dlg);
1047 dialoguetype[0] = dlg;
1050 static void ch_fixrotation(const char *args)
1052 participantyaw[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].yaw;
1055 static void ch_ddialogue(const char *args)
1061 static void ch_dhs(const char *args)
1067 static void ch_immobile(const char *args)
1069 player[0].immobile = 1;
1072 static void ch_allimmobile(const char *args)
1074 for (int i = 1; i < numplayers; i++)
1075 player[i].immobile = 1;
1078 static void ch_mobile(const char *args)
1080 player[0].immobile = 0;
1083 static void ch_default(const char *args)
1085 player[0].armorhead=1;
1086 player[0].armorhigh=1;
1087 player[0].armorlow=1;
1088 player[0].protectionhead=1;
1089 player[0].protectionhigh=1;
1090 player[0].protectionlow=1;
1091 player[0].metalhead=1;
1092 player[0].metalhigh=1;
1093 player[0].metallow=1;
1095 player[0].speedmult=1;
1098 if(player[0].creature==wolftype){
1099 player[0].proportionhead=1.1;
1100 player[0].proportionbody=1.1;
1101 player[0].proportionarms=1.1;
1102 player[0].proportionlegs=1.1;
1103 } else if(player[0].creature==rabbittype){
1104 player[0].proportionhead=1.2;
1105 player[0].proportionbody=1.05;
1106 player[0].proportionarms=1.00;
1107 player[0].proportionlegs=1.1;
1108 player[0].proportionlegs.y=1.05;
1111 player[0].numclothes=0;
1112 player[0].skeleton.drawmodel.textureptr.load(
1113 creatureskin[player[0].creature][player[0].whichskin],1,
1114 &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
1116 editoractive=typeactive;
1117 player[0].immobile=0;
1120 static void ch_play(const char *args)
1123 sscanf(args, "%d", &dlg);
1124 whichdialogue = dlg;
1126 if (whichdialogue >= numdialogues)
1129 for(int i=0;i<numdialogueboxes[whichdialogue];i++){
1130 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
1131 player[participantfocus[whichdialogue][i]].yaw=participantyaw[whichdialogue][participantfocus[whichdialogue][i]];
1132 player[participantfocus[whichdialogue][i]].targetyaw=participantyaw[whichdialogue][participantfocus[whichdialogue][i]];
1133 player[participantfocus[whichdialogue][i]].velocity=0;
1134 player[participantfocus[whichdialogue][i]].animTarget=player[participantfocus[whichdialogue][i]].getIdle();
1135 player[participantfocus[whichdialogue][i]].frameTarget=0;
1141 playdialogueboxsound();
1144 static void ch_mapkilleveryone(const char *args)
1146 maptype = mapkilleveryone;
1149 static void ch_mapkillmost(const char *args)
1151 maptype = mapkillmost;
1154 static void ch_mapkillsomeone(const char *args)
1156 maptype = mapkillsomeone;
1159 static void ch_mapgosomewhere(const char *args)
1161 maptype = mapgosomewhere;
1164 static void ch_viewdistance(const char *args)
1166 viewdistance = atof(args)*100;
1169 static void ch_fadestart(const char *args)
1171 fadestart = atof(args);
1174 static void ch_slomo(const char *args)
1176 slomospeed = atof(args);
1181 static void ch_slofreq(const char *args)
1183 slomofreq = atof(args);
1186 static void ch_skytint(const char *args)
1188 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
1190 skyboxlightr=skyboxr;
1191 skyboxlightg=skyboxg;
1192 skyboxlightb=skyboxb;
1196 terrain.DoShadows();
1197 objects.DoShadows();
1200 static void ch_skylight(const char *args)
1202 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1206 terrain.DoShadows();
1207 objects.DoShadows();
1210 static void ch_skybox(const char *args)
1212 skyboxtexture = !skyboxtexture;
1216 terrain.DoShadows();
1217 objects.DoShadows();
1220 static void cmd_dispatch(const string cmd)
1222 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
1224 for (i = 0; i < n_cmds; i++)
1225 if (cmd.substr(0,cmd.find(' '))==string(cmd_names[i]))
1227 cout << "|" << cmd.substr(cmd.find(' ')+1) << "|" << endl;
1228 cmd_handlers[i](cmd.substr(cmd.find(' ')+1).c_str());
1231 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
1234 /********************> Tick() <*****/
1235 extern bool save_image(const char * fname);
1236 void Screenshot (void)
1239 time_t t = time(NULL);
1240 struct tm *tme = localtime(&t);
1241 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);
1244 mkdir("Screenshots");
1246 mkdir("Screenshots", S_IRWXU);
1252 void Game::SetUpLighting(){
1253 if(environment==snowyenvironment)
1254 light.setColors(.65,.65,.7,.4,.4,.44);
1255 if(environment==desertenvironment)
1256 light.setColors(.95,.95,.95,.4,.35,.3);
1257 if(environment==grassyenvironment)
1258 light.setColors(.95,.95,1,.4,.4,.44);
1260 light.setColors(1,1,1,.4,.4,.4);
1262 average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
1263 light.color[0]*=(skyboxlightr+average)/2;
1264 light.color[1]*=(skyboxlightg+average)/2;
1265 light.color[2]*=(skyboxlightb+average)/2;
1266 light.ambient[0]*=(skyboxlightr+average)/2;
1267 light.ambient[1]*=(skyboxlightg+average)/2;
1268 light.ambient[2]*=(skyboxlightb+average)/2;
1271 int findPathDist(int start,int end){
1272 int smallestcount,count,connected;
1273 int last,last2,last3,last4;
1277 for(int i=0;i<50;i++){
1283 while(last!=end&&count<30){
1285 for(int j=0;j<numpathpoints;j++){
1286 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
1289 if(numpathpointconnect[j])
1290 for(int k=0;k<numpathpointconnect[j];k++){
1291 if(pathpointconnect[j][k]==last)connected=1;
1294 if(numpathpointconnect[last])
1295 for(int k=0;k<numpathpointconnect[last];k++){
1296 if(pathpointconnect[last][k]==j)connected=1;
1299 if(closest==-1||Random()%2==0){
1310 if(count<smallestcount)smallestcount=count;
1312 return smallestcount;
1315 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
1316 static XYZ colpoint,colviewer,coltarget;
1317 static float minx,minz,maxx,maxz,miny,maxy;
1319 minx=min(startpoint.x,endpoint.x)-1;
1320 miny=min(startpoint.y,endpoint.y)-1;
1321 minz=min(startpoint.z,endpoint.z)-1;
1322 maxx=max(startpoint.x,endpoint.x)+1;
1323 maxy=max(startpoint.y,endpoint.y)+1;
1324 maxz=max(startpoint.z,endpoint.z)+1;
1326 for(int i=0;i<objects.numobjects;i++){
1327 if( objects.position[i].x>minx-objects.model[i].boundingsphereradius&&
1328 objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&
1329 objects.position[i].y>miny-objects.model[i].boundingsphereradius&&
1330 objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&
1331 objects.position[i].z>minz-objects.model[i].boundingsphereradius&&
1332 objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
1333 if( objects.type[i]!=treeleavestype&&
1334 objects.type[i]!=bushtype&&
1335 objects.type[i]!=firetype){
1336 colviewer=startpoint;
1338 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.yaw[i])!=-1)return i;
1343 //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1348 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
1349 static XYZ colpoint,colviewer,coltarget;
1350 static float minx,minz,maxx,maxz,miny,maxy;
1351 static int i; //FIXME: see below
1353 minx=min(startpoint.x,endpoint.x)-1;
1354 miny=min(startpoint.y,endpoint.y)-1;
1355 minz=min(startpoint.z,endpoint.z)-1;
1356 maxx=max(startpoint.x,endpoint.x)+1;
1357 maxy=max(startpoint.y,endpoint.y)+1;
1358 maxz=max(startpoint.z,endpoint.z)+1;
1361 if( objects.position[what].x>minx-objects.model[what].boundingsphereradius&&
1362 objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&
1363 objects.position[what].y>miny-objects.model[what].boundingsphereradius&&
1364 objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&
1365 objects.position[what].z>minz-objects.model[what].boundingsphereradius&&
1366 objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
1367 if( objects.type[what]!=treeleavestype&&
1368 objects.type[what]!=bushtype&&
1369 objects.type[what]!=firetype){
1370 colviewer=startpoint;
1373 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.yaw[what])!=-1)return i;
1378 if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
1383 void Setenvironment(int which)
1387 LOG(" Setting environment...");
1389 float temptexdetail;
1392 pause_sound(stream_snowtheme);
1393 pause_sound(stream_grasstheme);
1394 pause_sound(stream_deserttheme);
1395 pause_sound(stream_wind);
1396 pause_sound(stream_desertambient);
1399 if(environment==snowyenvironment){
1403 emit_stream_np(stream_wind);
1405 objects.treetextureptr.load(":Data:Textures:snowtree.png",0,1);
1406 objects.bushtextureptr.load(":Data:Textures:bushsnow.png",0,1);
1407 objects.rocktextureptr.load(":Data:Textures:bouldersnow.jpg",1,0);
1408 objects.boxtextureptr.load(":Data:Textures:snowbox.jpg",1,0);
1410 footstepsound = footstepsn1;
1411 footstepsound2 = footstepsn2;
1412 footstepsound3 = footstepst1;
1413 footstepsound4 = footstepst2;
1415 terraintexture.load(":Data:Textures:snow.jpg",1,0);
1416 terraintexture2.load(":Data:Textures:rock.jpg",1,0);
1418 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
1423 temptexdetail=texdetail;
1424 if(texdetail>1)texdetail=4;
1425 skybox->load( ":Data:Textures:Skybox(snow):Front.jpg",
1426 ":Data:Textures:Skybox(snow):Left.jpg",
1427 ":Data:Textures:Skybox(snow):Back.jpg",
1428 ":Data:Textures:Skybox(snow):Right.jpg",
1429 ":Data:Textures:Skybox(snow):Up.jpg",
1430 ":Data:Textures:Skybox(snow):Down.jpg");
1435 texdetail=temptexdetail;
1436 } else if(environment==desertenvironment){
1439 objects.treetextureptr.load(":Data:Textures:deserttree.png",0,1);
1440 objects.bushtextureptr.load(":Data:Textures:bushdesert.png",0,1);
1441 objects.rocktextureptr.load(":Data:Textures:boulderdesert.jpg",1,0);
1442 objects.boxtextureptr.load(":Data:Textures:desertbox.jpg",1,0);
1446 emit_stream_np(stream_desertambient);
1448 footstepsound = footstepsn1;
1449 footstepsound2 = footstepsn2;
1450 footstepsound3 = footstepsn1;
1451 footstepsound4 = footstepsn2;
1453 terraintexture.load(":Data:Textures:sand.jpg",1,0);
1454 terraintexture2.load(":Data:Textures:sandslope.jpg",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 objects.treetextureptr.load(":Data:Textures:tree.png",0,1);
1477 objects.bushtextureptr.load(":Data:Textures:bush.png",0,1);
1478 objects.rocktextureptr.load(":Data:Textures:boulder.jpg",1,0);
1479 objects.boxtextureptr.load(":Data:Textures:grassbox.jpg",1,0);
1482 emit_stream_np(stream_wind, 100.);
1484 footstepsound = footstepgr1;
1485 footstepsound2 = footstepgr2;
1486 footstepsound3 = footstepst1;
1487 footstepsound4 = footstepst2;
1489 terraintexture.load(":Data:Textures:grassdirt.jpg",1,0);
1490 terraintexture2.load(":Data:Textures:mossrock.jpg",1,0);
1492 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1496 temptexdetail=texdetail;
1497 if(texdetail>1)texdetail=4;
1498 skybox->load( ":Data:Textures:Skybox(grass):Front.jpg",
1499 ":Data:Textures:Skybox(grass):Left.jpg",
1500 ":Data:Textures:Skybox(grass):Back.jpg",
1501 ":Data:Textures:Skybox(grass):Right.jpg",
1502 ":Data:Textures:Skybox(grass):Up.jpg",
1503 ":Data:Textures:Skybox(grass):Down.jpg");
1507 texdetail=temptexdetail;
1509 temptexdetail=texdetail;
1511 terrain.load(":Data:Textures:heightmap.png");
1513 texdetail=temptexdetail;
1516 void LoadCampaign() {
1519 ifstream ipstream(ConvertFileName((":Data:Campaigns:"+accountactive->getCurrentCampaign()+".txt").c_str()));
1520 ipstream.ignore(256,':');
1522 ipstream >> numlevels;
1523 campaignlevels.clear();
1524 for(int i=0;i<numlevels;i++) {
1527 campaignlevels.push_back(cl);
1531 ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
1533 Mainmenuitems[7].load((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),0,0);
1535 Mainmenuitems[7].load(":Data:Textures:World.png",0,0);
1538 if(accountactive->getCampaignChoicesMade()==0) {
1539 accountactive->setCampaignScore(0);
1540 accountactive->resetFasttime();
1544 vector<string> ListCampaigns() {
1545 DIR *campaigns = opendir(ConvertFileName(":Data:Campaigns"));
1546 struct dirent *campaign = NULL;
1548 perror("Problem while loading campaigns");
1549 cerr << "campaign folder was : " << ConvertFileName(":Data:Campaigns") << endl;
1552 vector<string> campaignNames;
1553 while ((campaign = readdir(campaigns)) != NULL) {
1554 string name(campaign->d_name);
1557 if(!name.compare(name.length()-4,4,".txt")) {
1558 campaignNames.push_back(name.substr(0,name.length()-4));
1561 closedir(campaigns);
1562 return campaignNames;
1565 void Loadlevel(int which) {
1571 Loadlevel("tutorial");
1572 } else if(which >= 0 && which <= 15) {
1574 snprintf(buf, 32, "map%d", which + 1); // challenges
1577 Loadlevel("mapsave");
1580 void Loadlevel(const char *name) {
1583 static const char *pfx = ":Data:Maps:";
1586 float headprop,legprop,armprop,bodyprop;
1590 LOG(std::string("Loading level...") + name);
1602 if(tutoriallevel!=-1)
1607 if(tutoriallevel==1)
1609 if(tutorialstage==0) {
1610 tutorialstagetime=0;
1614 pause_sound(whooshsound);
1615 pause_sound(stream_firesound);
1617 // Change the map filename into something that is os specific
1618 buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
1619 sprintf(buf, "%s%s", pfx, name);
1620 const char *FixedFN = ConvertFileName(buf);
1624 //~ char* buff=getcwd(NULL,0);
1625 //~ cout << buff << " " << FixedFN << endl;
1627 tfile=fopen( FixedFN, "rb" );
1629 pause_sound(stream_firesound);
1635 animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
1639 for(int i=0;i<20;i++)
1640 dialoguegonethrough[i]=0;
1649 difficulty=accountactive->getDifficulty();
1663 for(int i=0;i<100;i++)
1683 bonustotal=startbonustotal;
1688 emit_sound_np(consolesuccesssound);
1693 if(!stealthloading){
1694 terrain.numdecals=0;
1695 Sprite::deleteSprites();
1696 for(int i=0;i<objects.numobjects;i++)
1697 objects.model[i].numdecals=0;
1699 int j=objects.numobjects;
1700 for(int i=0;i<j;i++){
1701 objects.DeleteObject(0);
1706 for(int i=0;i<subdivision;i++)
1707 for(int j=0;j<subdivision;j++)
1708 terrain.patchobjectnum[i][j]=0;
1715 funpackf(tfile, "Bi", &mapvers);
1717 funpackf(tfile, "Bi", &indemo);
1721 funpackf(tfile, "Bi", &maptype);
1723 maptype=mapkilleveryone;
1725 funpackf(tfile, "Bi", &hostile);
1729 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1735 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1743 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1745 skyboxlightr=skyboxr;
1746 skyboxlightg=skyboxg;
1747 skyboxlightb=skyboxb;
1750 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);
1752 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1753 player[0].originalcoords=player[0].coords;
1754 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1755 for(int j=0;j<player[0].num_weapons;j++){
1756 player[0].weaponids[j]=weapons.size();
1758 funpackf(tfile, "Bi", &type);
1759 weapons.push_back(Weapon(type,0));
1765 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1766 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1767 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1768 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1770 funpackf(tfile, "Bi", &player[0].numclothes);
1773 funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1775 player[0].whichskin=0;
1776 player[0].creature=rabbittype;
1779 player[0].lastattack=-1;
1780 player[0].lastattack2=-1;
1781 player[0].lastattack3=-1;
1785 funpackf(tfile, "Bi", &numdialogues);
1786 for(int k=0;k<numdialogues;k++){
1787 funpackf(tfile, "Bi", &numdialogueboxes[k]);
1788 funpackf(tfile, "Bi", &dialoguetype[k]);
1789 for(int l=0;l<10;l++){
1790 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1791 funpackf(tfile, "Bf", &participantyaw[k][l]);
1793 for(int l=0;l<numdialogueboxes[k];l++){
1794 funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1795 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1796 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1797 funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1798 funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1800 funpackf(tfile, "Bi",&templength);
1801 if(templength>128||templength<=0)
1804 for(m=0;m<templength;m++){
1805 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1806 if(dialoguetext[k][l][m]=='\0')
1809 dialoguetext[k][l][m] = 0;
1811 funpackf(tfile, "Bi",&templength);
1812 if(templength>64||templength<=0)templength=64;
1813 for(m=0;m<templength;m++){
1814 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1815 if(dialoguename[k][l][m]=='\0')
1818 dialoguename[k][l][m] = 0;
1819 funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1820 funpackf(tfile, "Bi", &participantfocus[k][l]);
1821 funpackf(tfile, "Bi", &participantaction[k][l]);
1824 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1826 funpackf(tfile, "Bf Bf",&dialoguecamerayaw[k][l],&dialoguecamerapitch[k][l]);
1832 for(int k=0;k<player[0].numclothes;k++){
1833 funpackf(tfile, "Bi", &templength);
1834 for(int l=0;l<templength;l++)
1835 funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1836 player[0].clothes[k][templength]='\0';
1837 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1840 funpackf(tfile, "Bi", &environment);
1842 funpackf(tfile, "Bi", &objects.numobjects);
1843 for(int i=0;i<objects.numobjects;i++){
1844 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]);
1845 if(objects.type[i]==treeleavestype)
1846 objects.scale[i]=objects.scale[i-1];
1850 funpackf(tfile, "Bi", &numhotspots);
1851 for(int i=0;i<numhotspots;i++){
1852 funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1853 funpackf(tfile, "Bi", &templength);
1855 for(int l=0;l<templength;l++)
1856 funpackf(tfile, "Bb", &hotspottext[i][l]);
1857 hotspottext[i][templength]='\0';
1858 if(hotspottype[i]==-111)
1867 if(!stealthloading){
1869 for(int i=0;i<objects.numobjects;i++)
1870 objects.center+=objects.position[i];
1871 objects.center/=objects.numobjects;
1877 float maxdistance=0;
1879 //~ int whichclosest;
1880 for(int i=0;i<objects.numobjects;i++){
1881 tempdist=distsq(&objects.center,&objects.position[i]);
1882 if(tempdist>maxdistance){
1884 maxdistance=tempdist;
1887 objects.radius=fast_sqrt(maxdistance);
1892 //mapcenter=objects.center;
1893 //mapradius=objects.radius;
1895 funpackf(tfile, "Bi", &numplayers);
1896 int howmanyremoved=0;
1897 bool removeanother=0;
1898 if(numplayers>1&&numplayers<maxplayers){
1899 for(int i=1;i<numplayers;i++){
1904 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);
1906 funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1908 player[i-howmanyremoved].howactive=typeactive;
1910 funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1912 player[i-howmanyremoved].scale=-1;
1914 funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1916 player[i-howmanyremoved].immobile=0;
1918 funpackf(tfile, "Bf",&player[i-howmanyremoved].yaw);
1920 player[i-howmanyremoved].yaw=0;
1921 player[i-howmanyremoved].targetyaw=player[i-howmanyremoved].yaw;
1922 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1927 if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5){
1928 for(int j=0;j<player[i-howmanyremoved].num_weapons;j++){
1929 player[i-howmanyremoved].weaponids[j]=weapons.size();
1931 funpackf(tfile, "Bi", &type);
1932 weapons.push_back(Weapon(type,i));
1935 funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1936 //player[i-howmanyremoved].numwaypoints=10;
1937 for(int j=0;j<player[i-howmanyremoved].numwaypoints;j++){
1938 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1939 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1940 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1942 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1944 player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1947 funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1948 if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)
1949 player[i-howmanyremoved].waypoint=0;
1951 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1952 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1953 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1954 funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1957 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1964 if(player[i-howmanyremoved].creature==wolftype){
1965 player[i-howmanyremoved].proportionhead=1.1*headprop;
1966 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1967 player[i-howmanyremoved].proportionarms=1.1*armprop;
1968 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1971 if(player[i-howmanyremoved].creature==rabbittype){
1972 player[i-howmanyremoved].proportionhead=1.2*headprop;
1973 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1974 player[i-howmanyremoved].proportionarms=1.00*armprop;
1975 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1976 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1979 funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1980 if(player[i-howmanyremoved].numclothes){
1981 for(int k=0;k<player[i-howmanyremoved].numclothes;k++){
1983 funpackf(tfile, "Bi", &templength);
1984 for(int l=0;l<templength;l++)
1985 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1986 player[i-howmanyremoved].clothes[k][templength]='\0';
1987 funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1996 numplayers-=howmanyremoved;
1997 funpackf(tfile, "Bi", &numpathpoints);
1998 if(numpathpoints>30||numpathpoints<0)
2000 for(int j=0;j<numpathpoints;j++){
2001 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
2002 for(int k=0;k<numpathpointconnect[j];k++){
2003 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
2009 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
2012 if(environment!=oldenvironment)
2013 Setenvironment(environment);
2014 oldenvironment=environment;
2016 if(!stealthloading){
2017 int j=objects.numobjects;
2018 objects.numobjects=0;
2019 for(int i=0;i<j;i++){
2020 objects.MakeObject(objects.type[i],objects.position[i],objects.yaw[i],objects.pitch[i],objects.scale[i]);
2025 terrain.DoShadows();
2028 objects.DoShadows();
2035 if(numplayers>maxplayers-1)
2036 numplayers=maxplayers-1;
2037 for(int i=0;i<numplayers;i++){
2043 if(i==0||player[i].scale<0)
2045 player[i].skeleton.free=0;
2046 player[i].skeleton.id=i;
2048 player[i].creature=rabbittype;
2049 if(player[i].creature!=wolftype){
2050 player[i].skeleton.Load(
2051 (char *)":Data:Skeleton:Basic Figure",
2052 (char *)":Data:Skeleton:Basic Figurelow",
2053 (char *)":Data:Skeleton:Rabbitbelt",
2054 (char *)":Data:Models:Body.solid",
2055 (char *)":Data:Models:Body2.solid",
2056 (char *)":Data:Models:Body3.solid",
2057 (char *)":Data:Models:Body4.solid",
2058 (char *)":Data:Models:Body5.solid",
2059 (char *)":Data:Models:Body6.solid",
2060 (char *)":Data:Models:Body7.solid",
2061 (char *)":Data:Models:Bodylow.solid",
2062 (char *)":Data:Models:Belt.solid",0);
2064 if(player[i].creature!=wolftype){
2065 player[i].skeleton.Load(
2066 (char *)":Data:Skeleton:Basic Figure",
2067 (char *)":Data:Skeleton:Basic Figurelow",
2068 (char *)":Data:Skeleton:Rabbitbelt",
2069 (char *)":Data:Models:Body.solid",
2070 (char *)":Data:Models:Body2.solid",
2071 (char *)":Data:Models:Body3.solid",
2072 (char *)":Data:Models:Body4.solid",
2073 (char *)":Data:Models:Body5.solid",
2074 (char *)":Data:Models:Body6.solid",
2075 (char *)":Data:Models:Body7.solid",
2076 (char *)":Data:Models:Bodylow.solid",
2077 (char *)":Data:Models:Belt.solid",1);
2078 player[i].skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png",1,1);
2080 if(player[i].creature==wolftype){
2081 player[i].skeleton.Load(
2082 (char *)":Data:Skeleton:Basic Figure Wolf",
2083 (char *)":Data:Skeleton:Basic Figure Wolf Low",
2084 (char *)":Data:Skeleton:Rabbitbelt",
2085 (char *)":Data:Models:Wolf.solid",
2086 (char *)":Data:Models:Wolf2.solid",
2087 (char *)":Data:Models:Wolf3.solid",
2088 (char *)":Data:Models:Wolf4.solid",
2089 (char *)":Data:Models:Wolf5.solid",
2090 (char *)":Data:Models:Wolf6.solid",
2091 (char *)":Data:Models:Wolf7.solid",
2092 (char *)":Data:Models:Wolflow.solid",
2093 (char *)":Data:Models:Belt.solid",0);
2099 //~ texsize=512*512*3/texdetail/texdetail;
2101 player[i].skeleton.drawmodel.textureptr.load(creatureskin[player[i].creature][player[i].whichskin],1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
2103 if(player[i].numclothes){
2104 for(int j=0;j<player[i].numclothes;j++){
2105 tintr=player[i].clothestintr[j];
2106 tintg=player[i].clothestintg[j];
2107 tintb=player[i].clothestintb[j];
2108 AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
2110 player[i].DoMipmaps();
2113 player[i].animCurrent=bounceidleanim;
2114 player[i].animTarget=bounceidleanim;
2115 player[i].frameCurrent=0;
2116 player[i].frameTarget=1;
2118 player[i].speed=1+(float)(Random()%100)/1000;
2120 player[i].speed-=.2;
2122 player[i].speed-=.1;
2124 player[i].velocity=0;
2125 player[i].oldcoords=player[i].coords;
2126 player[i].realoldcoords=player[i].coords;
2129 player[i].skeleton.id=i;
2130 player[i].updatedelay=0;
2131 player[i].normalsupdatedelay=0;
2133 player[i].aitype=passivetype;
2134 player[i].madskills=0;
2137 player[i].proportionhead=1.2;
2138 player[i].proportionbody=1.05;
2139 player[i].proportionarms=1.00;
2140 player[i].proportionlegs=1.1;
2141 player[i].proportionlegs.y=1.05;
2143 player[i].headless=0;
2144 player[i].currentoffset=0;
2145 player[i].targetoffset=0;
2147 player[i].damagetolerance=200;
2149 if(player[i].creature==wolftype){
2150 if(i==0||player[i].scale<0)
2151 player[i].scale=.23;
2152 player[i].damagetolerance=300;
2158 player[i].proportionhead.z=0;
2159 player[i].proportionbody.z=0;
2160 player[i].proportionarms.z=0;
2161 player[i].proportionlegs.z=0;
2164 player[i].tempanimation.Load((char *)"Tempanim",0,0);
2166 player[i].headmorphness=0;
2167 player[i].targetheadmorphness=1;
2168 player[i].headmorphstart=0;
2169 player[i].headmorphend=0;
2171 player[i].pausetime=0;
2174 player[i].jumppower=5;
2176 player[i].permanentdamage=0;
2177 player[i].superpermanentdamage=0;
2179 player[i].forwardkeydown=0;
2180 player[i].leftkeydown=0;
2181 player[i].backkeydown=0;
2182 player[i].rightkeydown=0;
2183 player[i].jumpkeydown=0;
2184 player[i].crouchkeydown=0;
2185 player[i].throwkeydown=0;
2187 player[i].collided=-10;
2189 player[i].bloodloss=0;
2190 player[i].weaponactive=-1;
2191 player[i].weaponstuck=-1;
2192 player[i].bleeding=0;
2193 player[i].deathbleeding=0;
2194 player[i].stunned=0;
2195 player[i].hasvictim=0;
2196 player[i].wentforweapon=0;
2199 player[0].aitype=playercontrolled;
2200 player[0].weaponactive=-1;
2203 player[0].power=1/.9;
2206 player[0].power=1/.8;
2209 player[0].damagetolerance=250;
2211 player[0].damagetolerance=300;
2213 player[0].armorhead*=1.5;
2215 player[0].armorhigh*=1.5;
2217 player[0].armorlow*=1.5;
2218 cameraloc=player[0].coords;
2222 hawkcoords=player[0].coords;
2227 //~ for(int i=0;i<weapons.size();i++){
2230 LOG("Starting background music...");
2232 OPENAL_StopSound(OPENAL_ALL);
2233 if(environment==snowyenvironment){
2235 emit_stream_np(stream_wind);
2236 }else if(environment==desertenvironment){
2238 emit_stream_np(stream_desertambient);
2239 }else if(environment==grassyenvironment){
2241 emit_stream_np(stream_wind, 100.);
2243 oldmusicvolume[0]=0;
2244 oldmusicvolume[1]=0;
2245 oldmusicvolume[2]=0;
2246 oldmusicvolume[3]=0;
2259 if(tutorialstagetime>tutorialmaxtime){
2262 if(tutorialstage<=1){
2267 switch(tutorialstage){
2273 tutorialmaxtime=600;
2275 tutorialmaxtime=1000;
2277 tutorialmaxtime=600;
2279 tutorialmaxtime=600;
2281 tutorialmaxtime=600;
2283 tutorialmaxtime=600;
2285 tutorialmaxtime=600;
2289 tutorialmaxtime=1000;
2291 tutorialmaxtime=1000;
2306 player[1].coords=(temp+temp2)/2;
2308 emit_sound_at(fireendsound, player[1].coords);
2310 for(int i=0;i<player[1].skeleton.num_joints;i++){
2312 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2313 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2314 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;
2315 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2316 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2321 tutorialmaxtime=500;
2323 tutorialmaxtime=500;
2325 tutorialmaxtime=500;
2327 tutorialmaxtime=500;
2330 //tutorialmaxtime=500;
2332 tutorialmaxtime=500;
2334 tutorialmaxtime=500;
2341 tutorialmaxtime=500;
2343 tutorialmaxtime=500;
2345 tutorialmaxtime=500;
2347 tutorialmaxtime=500;
2354 player[1].aitype=attacktypecutoff;
2356 tutorialmaxtime=400;
2358 tutorialmaxtime=400;
2359 player[0].escapednum=0;
2364 player[1].aitype=passivetype;
2370 tutorialmaxtime=400;
2373 player[1].aitype=attacktypecutoff;
2375 tutorialmaxtime=400;
2377 tutorialmaxtime=400;
2382 player[1].aitype=passivetype;
2389 player[1].aitype=attacktypecutoff;
2394 player[1].aitype=passivetype;
2406 w.position=(temp+temp2)/2;
2407 w.tippoint=(temp+temp2)/2;
2417 weapons.push_back(w);
2420 tutorialmaxtime=300;
2422 tutorialmaxtime=300;
2426 tutorialmaxtime=300;
2429 player[0].weaponactive=-1;
2430 player[0].num_weapons=0;
2431 player[1].weaponactive=0;
2432 player[1].num_weapons=1;
2433 player[1].weaponids[0]=0;
2437 player[1].aitype=attacktypecutoff;
2439 tutorialmaxtime=300;
2442 player[0].weaponactive=-1;
2443 player[0].num_weapons=0;
2444 player[1].weaponactive=0;
2445 player[1].num_weapons=1;
2446 player[1].weaponids[0]=0;
2448 tutorialmaxtime=300;
2451 player[0].weaponactive=-1;
2452 player[0].num_weapons=0;
2453 player[1].weaponactive=0;
2454 player[1].num_weapons=1;
2455 player[1].weaponids[0]=0;
2457 weapons[0].setType(sword);
2459 tutorialmaxtime=300;
2473 w.position=(temp+temp2)/2;
2474 w.tippoint=(temp+temp2)/2;
2484 weapons.push_back(w);
2488 player[0].weaponactive=0;
2489 player[0].num_weapons=1;
2490 player[0].weaponids[0]=1;
2491 player[1].weaponactive=0;
2492 player[1].num_weapons=1;
2493 player[1].weaponids[0]=0;
2499 player[1].aitype=passivetype;
2505 player[0].weaponactive=0;
2506 player[0].num_weapons=1;
2507 player[0].weaponids[0]=1;
2508 player[1].weaponactive=0;
2509 player[1].num_weapons=1;
2510 player[1].weaponids[0]=0;
2512 if(player[0].weaponactive!=-1)
2513 weapons[player[0].weaponids[player[0].weaponactive]].setType(staff);
2515 weapons[0].setType(staff);
2519 player[1].aitype=passivetype;
2521 tutorialmaxtime=200;
2523 weapons[1].position=1000;
2524 weapons[1].tippoint=1000;
2526 weapons[0].setType(knife);
2529 player[1].weaponactive=-1;
2530 player[1].num_weapons=0;
2531 player[0].weaponactive=0;
2532 player[0].num_weapons=1;
2533 player[0].weaponids[0]=0;
2539 emit_sound_at(fireendsound, player[1].coords);
2541 for(int i=0;i<player[1].skeleton.num_joints;i++){
2543 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
2544 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
2545 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;
2546 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
2547 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
2551 player[1].num_weapons=0;
2552 player[1].weaponstuck=-1;
2553 player[1].weaponactive=-1;
2558 tutorialmaxtime=80000;
2559 break; default: break;
2561 if(tutorialstage<=51)tutorialstagetime=0;
2565 if(tutorialstagetime<tutorialmaxtime-3){
2566 switch(tutorialstage){
2567 case 3: if(deltah||deltav)tutorialsuccess+=multiplier;
2568 break; case 4: if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
2569 break; case 5: if(player[0].jumpkeydown)tutorialsuccess=1;
2570 break; case 6: if(player[0].isCrouch())tutorialsuccess=1;
2571 break; case 7: if(player[0].animTarget==rollanim)tutorialsuccess=1;
2572 break; case 8: if(player[0].animTarget==sneakanim)tutorialsuccess+=multiplier;
2573 break; case 9: if(player[0].animTarget==rabbitrunninganim||player[0].animTarget==wolfrunninganim)tutorialsuccess+=multiplier;
2574 break; case 11: if(player[0].isWallJump())tutorialsuccess=1;
2575 break; case 12: if(player[0].animTarget==flipanim)tutorialsuccess=1;
2576 break; case 15: if(player[0].animTarget==upunchanim||player[0].animTarget==winduppunchanim)tutorialsuccess=1;
2577 break; case 16: if(player[0].animTarget==winduppunchanim)tutorialsuccess=1;
2578 break; case 17: if(player[0].animTarget==spinkickanim)tutorialsuccess=1;
2579 break; case 18: if(player[0].animTarget==sweepanim)tutorialsuccess=1;
2580 break; case 19: if(player[0].animTarget==dropkickanim)tutorialsuccess=1;
2581 break; case 20: if(player[0].animTarget==rabbitkickanim)tutorialsuccess=1;
2582 break; case 21: if(bonus==cannon)tutorialsuccess=1;
2583 break; case 22: if(bonus==spinecrusher)tutorialsuccess=1;
2584 break; case 23: if(player[0].animTarget==walljumprightkickanim||player[0].animTarget==walljumpleftkickanim)tutorialsuccess=1;
2585 break; case 24: if(player[0].animTarget==rabbittacklinganim)tutorialsuccess=1;
2586 break; case 25: if(player[0].animTarget==backhandspringanim)tutorialsuccess=1;
2587 break; case 28: if(animation[player[0].animTarget].attack==reversed&&player[0].feint)tutorialsuccess=1;
2589 if(player[0].escapednum==2) {
2593 player[1].aitype=passivetype;
2595 break; case 33: if(animation[player[0].animTarget].attack==reversal)tutorialsuccess=1;
2596 break; case 34: if(animation[player[0].animTarget].attack==reversal)tutorialsuccess=1;
2598 if(animation[player[0].animTarget].attack==reversal){
2602 player[1].aitype=passivetype;
2604 break; case 40: if(player[0].num_weapons>0)tutorialsuccess=1;
2605 break; case 41: if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
2606 break; case 43: if(player[0].animTarget==knifeslashstartanim)tutorialsuccess=1;
2607 break; case 44: if(animation[player[0].animTarget].attack==reversal)tutorialsuccess=1;
2608 break; case 45: if(animation[player[0].animTarget].attack==reversal)tutorialsuccess=1;
2609 break; case 46: if(animation[player[0].animTarget].attack==reversal)tutorialsuccess=1;
2610 break; case 49: if(player[1].weaponstuck!=-1)tutorialsuccess=1;
2611 break; default: break;
2613 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
2616 if(tutorialstagetime==tutorialmaxtime-3){
2617 emit_sound_np(consolesuccesssound);
2620 if(tutorialsuccess>=1){
2621 if(tutorialstage==34||tutorialstage==35)
2622 tutorialstagetime=tutorialmaxtime-1;
2626 if(tutorialstage<14||tutorialstage>=50){
2627 player[1].coords.y=300;
2628 player[1].velocity=0;
2633 float headprop,bodyprop,armprop,legprop;
2635 if(Input::isKeyPressed(SDLK_h)){
2636 player[0].damagetolerance=200000;
2639 player[0].permanentdamage=0;
2640 player[0].superpermanentdamage=0;
2643 if(Input::isKeyPressed(SDLK_j)){
2647 Setenvironment(environment);
2650 if(Input::isKeyPressed(SDLK_c)){
2651 cameramode=1-cameramode;
2654 if(Input::isKeyPressed(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)){
2655 if(player[0].num_weapons>0){
2656 if(weapons[player[0].weaponids[0]].getType()==sword)
2657 weapons[player[0].weaponids[0]].setType(staff);
2658 else if(weapons[player[0].weaponids[0]].getType()==staff)
2659 weapons[player[0].weaponids[0]].setType(knife);
2661 weapons[player[0].weaponids[0]].setType(sword);
2665 if(Input::isKeyPressed(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)){
2666 int closest=findClosestPlayer();
2668 if(player[closest].num_weapons){
2669 if(weapons[player[closest].weaponids[0]].getType()==sword)
2670 weapons[player[closest].weaponids[0]].setType(staff);
2671 else if(weapons[player[closest].weaponids[0]].getType()==staff)
2672 weapons[player[closest].weaponids[0]].setType(knife);
2674 weapons[player[closest].weaponids[0]].setType(sword);
2676 if(!player[closest].num_weapons){
2677 player[closest].weaponids[0]=weapons.size();
2679 weapons.push_back(Weapon(knife,closest));
2681 player[closest].num_weapons=1;
2686 if(Input::isKeyDown(SDLK_u)){
2687 int closest=findClosestPlayer();
2689 player[closest].yaw+=multiplier*50;
2690 player[closest].targetyaw=player[closest].yaw;
2695 if(Input::isKeyPressed(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)){
2696 int closest=findClosestPlayer();
2697 if(Input::isKeyDown(SDLK_LCTRL))
2701 player[closest].whichskin++;
2702 if(player[closest].whichskin>9)
2703 player[closest].whichskin=0;
2704 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
2705 player[closest].whichskin=0;
2707 player[closest].skeleton.drawmodel.textureptr.load(creatureskin[player[closest].creature][player[closest].whichskin],1,
2708 &player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2711 if(player[closest].numclothes){
2712 for(int i=0;i<player[closest].numclothes;i++){
2713 tintr=player[closest].clothestintr[i];
2714 tintg=player[closest].clothestintg[i];
2715 tintb=player[closest].clothestintb[i];
2716 AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
2718 player[closest].DoMipmaps();
2722 if(Input::isKeyPressed(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)){
2723 int closest=findClosestPlayer();
2725 if(player[closest].creature==wolftype){
2726 headprop=player[closest].proportionhead.x/1.1;
2727 bodyprop=player[closest].proportionbody.x/1.1;
2728 armprop=player[closest].proportionarms.x/1.1;
2729 legprop=player[closest].proportionlegs.x/1.1;
2732 if(player[closest].creature==rabbittype){
2733 headprop=player[closest].proportionhead.x/1.2;
2734 bodyprop=player[closest].proportionbody.x/1.05;
2735 armprop=player[closest].proportionarms.x/1.00;
2736 legprop=player[closest].proportionlegs.x/1.1;
2740 if(player[closest].creature==rabbittype){
2741 player[closest].skeleton.id=closest;
2742 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);
2743 player[closest].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
2744 player[closest].whichskin=0;
2745 player[closest].creature=wolftype;
2747 player[closest].proportionhead=1.1;
2748 player[closest].proportionbody=1.1;
2749 player[closest].proportionarms=1.1;
2750 player[closest].proportionlegs=1.1;
2751 player[closest].proportionlegs.y=1.1;
2752 player[closest].scale=.23*5*player[0].scale;
2754 player[closest].damagetolerance=300;
2758 player[closest].skeleton.id=closest;
2759 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);
2760 player[closest].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg",1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
2761 player[closest].whichskin=0;
2762 player[closest].creature=rabbittype;
2764 player[closest].proportionhead=1.2;
2765 player[closest].proportionbody=1.05;
2766 player[closest].proportionarms=1.00;
2767 player[closest].proportionlegs=1.1;
2768 player[closest].proportionlegs.y=1.05;
2769 player[closest].scale=.2*5*player[0].scale;
2771 player[closest].damagetolerance=200;
2774 if(player[closest].creature==wolftype){
2775 player[closest].proportionhead=1.1*headprop;
2776 player[closest].proportionbody=1.1*bodyprop;
2777 player[closest].proportionarms=1.1*armprop;
2778 player[closest].proportionlegs=1.1*legprop;
2781 if(player[closest].creature==rabbittype){
2782 player[closest].proportionhead=1.2*headprop;
2783 player[closest].proportionbody=1.05*bodyprop;
2784 player[closest].proportionarms=1.00*armprop;
2785 player[closest].proportionlegs=1.1*legprop;
2786 player[closest].proportionlegs.y=1.05*legprop;
2792 if(Input::isKeyPressed(SDLK_b)&&!Input::isKeyDown(SDLK_LSHIFT)){
2798 if(((Input::isKeyPressed(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))){
2800 float closestdist = std::numeric_limits<float>::max();
2802 for(int i=1; i<numplayers; i++){
2803 float distance = distsq(&player[i].coords, &player[0].coords);
2804 if(!player[i].headless)
2805 if(distance < closestdist){
2806 closestdist = distance;
2811 XYZ flatfacing2,flatvelocity2;
2813 if(closest!=-1 && distsq(&player[closest].coords, &player[0].coords)<144){
2814 blah = player[closest].coords;
2815 XYZ headspurtdirection;
2816 //int i = player[closest].skeleton.jointlabels[head];
2817 Joint& headjoint= player[closest].joint(head);
2818 for(int k=0;k<player[closest].skeleton.num_joints; k++){
2819 if(!player[closest].skeleton.free)
2820 flatvelocity2=player[closest].velocity;
2821 if(player[closest].skeleton.free)
2822 flatvelocity2=headjoint.velocity;
2823 if(!player[closest].skeleton.free)
2824 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;
2825 if(player[closest].skeleton.free)
2826 flatfacing2=headjoint.position*player[closest].scale+player[closest].coords;
2827 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2828 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2829 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2830 headspurtdirection=headjoint.position-player[closest].jointPos(neck);
2831 Normalise(&headspurtdirection);
2832 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
2833 flatvelocity2+=headspurtdirection*8;
2834 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
2836 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2838 emit_sound_at(splattersound, blah);
2839 emit_sound_at(breaksound2, blah, 100.);
2841 if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
2842 player[closest].RagDoll(0);
2843 player[closest].dead=2;
2844 player[closest].headless=1;
2845 player[closest].DoBloodBig(3,165);
2851 if(((Input::isKeyPressed(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))){
2852 int closest=findClosestPlayer();
2853 XYZ flatfacing2,flatvelocity2;
2855 if(closest>=0 && distsq(&player[closest].coords,&player[0].coords)<144){
2856 blah=player[closest].coords;
2857 emit_sound_at(splattersound, blah);
2858 emit_sound_at(breaksound2, blah);
2860 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2861 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2862 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2863 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;
2864 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2865 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2866 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2867 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2868 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2869 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
2870 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
2873 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2874 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2875 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2876 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;
2877 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2878 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2879 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2880 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2881 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
2882 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
2885 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2886 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2887 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2888 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;
2889 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2890 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2891 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2892 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2893 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2894 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2897 for(int i=0;i<player[closest].skeleton.num_joints; i++){
2898 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
2899 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
2900 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;
2901 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
2902 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
2903 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
2904 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
2905 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
2906 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
2910 for(int j=0;j<numplayers; j++){
2912 if(distsq(&player[j].coords,&player[closest].coords)<25){
2913 player[j].DoDamage((25-distsq(&player[j].coords,&player[closest].coords))*60);
2914 if(player[j].skeleton.free==2)
2915 player[j].skeleton.free=1;
2916 player[j].skeleton.longdead=0;
2917 player[j].RagDoll(0);
2918 for(int i=0;i<player[j].skeleton.num_joints; i++){
2919 temppos=player[j].skeleton.joints[i].position+player[j].coords;
2920 if(distsq(&temppos,&player[closest].coords)<25){
2921 flatvelocity2=temppos-player[closest].coords;
2922 Normalise(&flatvelocity2);
2923 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-distsq(&temppos,&player[closest].coords))*20);
2930 player[closest].DoDamage(10000);
2931 player[closest].RagDoll(0);
2932 player[closest].dead=2;
2933 player[closest].coords=20;
2934 player[closest].skeleton.free=2;
2941 if(Input::isKeyPressed(SDLK_f)){
2942 player[0].onfire=1-player[0].onfire;
2943 if(player[0].onfire){
2944 player[0].CatchFire();
2946 if(!player[0].onfire){
2947 emit_sound_at(fireendsound, player[0].coords);
2948 pause_sound(stream_firesound);
2952 if(Input::isKeyPressed(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)){
2953 //if(!player[0].skeleton.free)player[0].damage+=500;
2954 player[0].RagDoll(0);
2955 //player[0].spurt=1;
2956 //player[0].DoDamage(1000);
2958 emit_sound_at(whooshsound, player[0].coords, 128.);
2961 if(Input::isKeyPressed(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)){
2962 for(int i=0;i<objects.numobjects;i++){
2963 if(objects.type[i]==treeleavestype){
2964 objects.scale[i]*=.9;
2969 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
2970 editorenabled=1-editorenabled;
2972 player[0].damagetolerance=100000;
2974 player[0].damagetolerance=200;
2976 player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
2977 player[0].permanentdamage=0;
2978 player[0].superpermanentdamage=0;
2979 player[0].bloodloss=0;
2980 player[0].deathbleeding=0;
2984 if(whichlevel!=-2&&Input::isKeyPressed(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!editorenabled){
2986 if(targetlevel>numchallengelevels-1)
2993 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LSHIFT)){
2994 int closest=findClosestPlayer();
2996 //player[closest]=player[numplayers-1];
2997 //player[closest].skeleton=player[numplayers-1].skeleton;
3002 if(Input::isKeyPressed(SDLK_DELETE)&&Input::isKeyDown(SDLK_LCTRL)){
3003 int closest=findClosestObject();
3005 objects.position[closest].y-=500;
3008 if(Input::isKeyPressed(SDLK_m)&&Input::isKeyDown(SDLK_LSHIFT)){
3010 //if(drawmode>2)drawmode=0;
3011 if(objects.numobjects<max_objects-1){
3013 boxcoords.x=player[0].coords.x;
3014 boxcoords.z=player[0].coords.z;
3015 boxcoords.y=player[0].coords.y-3;
3016 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
3017 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
3018 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
3019 float temprotat,temprotat2;
3020 temprotat=editoryaw;
3021 temprotat2=editorpitch;
3022 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
3023 if(temprotat2<0)temprotat2=Random()%360;
3025 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
3026 if(editortype==treetrunktype)
3027 objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editoryaw-((int)editoryaw)%30,editorpitch,editorsize);
3031 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3032 if(numplayers<maxplayers-1){
3033 player[numplayers].scale=.2*5*player[0].scale;
3034 player[numplayers].creature=rabbittype;
3035 player[numplayers].howactive=editoractive;
3036 player[numplayers].skeleton.id=numplayers;
3037 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);
3039 //texsize=512*512*3/texdetail/texdetail;
3040 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
3041 //player[numplayers].skeleton.skinText.resize(texsize);
3043 int k=abs(Random()%2)+1;
3045 player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3046 player[numplayers].whichskin=0;
3049 player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3050 player[numplayers].whichskin=1;
3053 player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur2.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
3054 player[numplayers].whichskin=2;
3057 player[numplayers].skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png",1,1);
3058 player[numplayers].power=1;
3059 player[numplayers].speedmult=1;
3060 player[numplayers].animCurrent=bounceidleanim;
3061 player[numplayers].animTarget=bounceidleanim;
3062 player[numplayers].frameCurrent=0;
3063 player[numplayers].frameTarget=1;
3064 player[numplayers].target=0;
3065 player[numplayers].bled=0;
3066 player[numplayers].speed=1+(float)(Random()%100)/1000;
3068 player[numplayers].targetyaw=player[0].targetyaw;
3069 player[numplayers].yaw=player[0].yaw;
3071 player[numplayers].velocity=0;
3072 player[numplayers].coords=player[0].coords;
3073 player[numplayers].oldcoords=player[numplayers].coords;
3074 player[numplayers].realoldcoords=player[numplayers].coords;
3076 player[numplayers].id=numplayers;
3077 player[numplayers].skeleton.id=numplayers;
3078 player[numplayers].updatedelay=0;
3079 player[numplayers].normalsupdatedelay=0;
3081 player[numplayers].aitype=passivetype;
3083 if(player[0].creature==wolftype){
3084 headprop=player[0].proportionhead.x/1.1;
3085 bodyprop=player[0].proportionbody.x/1.1;
3086 armprop=player[0].proportionarms.x/1.1;
3087 legprop=player[0].proportionlegs.x/1.1;
3090 if(player[0].creature==rabbittype){
3091 headprop=player[0].proportionhead.x/1.2;
3092 bodyprop=player[0].proportionbody.x/1.05;
3093 armprop=player[0].proportionarms.x/1.00;
3094 legprop=player[0].proportionlegs.x/1.1;
3097 if(player[numplayers].creature==wolftype){
3098 player[numplayers].proportionhead=1.1*headprop;
3099 player[numplayers].proportionbody=1.1*bodyprop;
3100 player[numplayers].proportionarms=1.1*armprop;
3101 player[numplayers].proportionlegs=1.1*legprop;
3104 if(player[numplayers].creature==rabbittype){
3105 player[numplayers].proportionhead=1.2*headprop;
3106 player[numplayers].proportionbody=1.05*bodyprop;
3107 player[numplayers].proportionarms=1.00*armprop;
3108 player[numplayers].proportionlegs=1.1*legprop;
3109 player[numplayers].proportionlegs.y=1.05*legprop;
3112 player[numplayers].headless=0;
3113 player[numplayers].onfire=0;
3116 player[numplayers].proportionhead.z=0;
3117 player[numplayers].proportionbody.z=0;
3118 player[numplayers].proportionarms.z=0;
3119 player[numplayers].proportionlegs.z=0;
3122 player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
3124 player[numplayers].damagetolerance=200;
3126 player[numplayers].protectionhead=player[0].protectionhead;
3127 player[numplayers].protectionhigh=player[0].protectionhigh;
3128 player[numplayers].protectionlow=player[0].protectionlow;
3129 player[numplayers].armorhead=player[0].armorhead;
3130 player[numplayers].armorhigh=player[0].armorhigh;
3131 player[numplayers].armorlow=player[0].armorlow;
3132 player[numplayers].metalhead=player[0].metalhead;
3133 player[numplayers].metalhigh=player[0].metalhigh;
3134 player[numplayers].metallow=player[0].metallow;
3136 player[numplayers].immobile=player[0].immobile;
3138 player[numplayers].numclothes=player[0].numclothes;
3139 if(player[numplayers].numclothes)
3140 for(int i=0;i<player[numplayers].numclothes;i++){
3141 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
3142 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
3143 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
3144 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
3145 tintr=player[numplayers].clothestintr[i];
3146 tintg=player[numplayers].clothestintg[i];
3147 tintb=player[numplayers].clothestintb[i];
3148 AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
3150 if(player[numplayers].numclothes){
3151 player[numplayers].DoMipmaps();
3154 player[numplayers].power=player[0].power;
3155 player[numplayers].speedmult=player[0].speedmult;
3157 player[numplayers].damage=0;
3158 player[numplayers].permanentdamage=0;
3159 player[numplayers].superpermanentdamage=0;
3160 player[numplayers].deathbleeding=0;
3161 player[numplayers].bleeding=0;
3162 player[numplayers].numwaypoints=0;
3163 player[numplayers].waypoint=0;
3164 player[numplayers].jumppath=0;
3165 player[numplayers].weaponstuck=-1;
3166 player[numplayers].weaponactive=-1;
3167 player[numplayers].num_weapons=0;
3168 player[numplayers].bloodloss=0;
3169 player[numplayers].dead=0;
3171 player[numplayers].loaded=1;
3177 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LSHIFT)){
3178 if(player[numplayers-1].numwaypoints<90){
3179 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
3180 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
3181 player[numplayers-1].numwaypoints++;
3185 if(Input::isKeyPressed(SDLK_p)&&Input::isKeyDown(SDLK_LCTRL)){
3186 if(numpathpoints<30){
3187 bool connected,alreadyconnected;
3190 for(int i=0;i<numpathpoints;i++){
3191 if(distsq(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
3193 for(int j=0;j<numpathpointconnect[pathpointselected];j++){
3194 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
3196 if(!alreadyconnected){
3197 numpathpointconnect[pathpointselected]++;
3199 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
3205 pathpoint[numpathpoints-1]=player[0].coords;
3206 numpathpointconnect[numpathpoints-1]=0;
3207 if(numpathpoints>1&&pathpointselected!=-1){
3208 numpathpointconnect[pathpointselected]++;
3209 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
3211 pathpointselected=numpathpoints-1;
3216 if(Input::isKeyPressed(SDLK_PERIOD)){
3217 pathpointselected++;
3218 if(pathpointselected>=numpathpoints)
3219 pathpointselected=-1;
3221 if(Input::isKeyPressed(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)){
3222 pathpointselected--;
3223 if(pathpointselected<=-2)
3224 pathpointselected=numpathpoints-1;
3226 if(Input::isKeyPressed(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)){
3227 if(pathpointselected!=-1){
3229 pathpoint[pathpointselected]=pathpoint[numpathpoints];
3230 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
3231 for(int i=0;i<numpathpointconnect[pathpointselected];i++){
3232 pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
3234 for(int i=0;i<numpathpoints;i++){
3235 for(int j=0;j<numpathpointconnect[i];j++){
3236 if(pathpointconnect[i][j]==pathpointselected){
3237 pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
3238 numpathpointconnect[i]--;
3240 if(pathpointconnect[i][j]==numpathpoints){
3241 pathpointconnect[i][j]=pathpointselected;
3245 pathpointselected=numpathpoints-1;
3249 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3251 if(editortype==treeleavestype||editortype==10)editortype--;
3252 if(editortype<0)editortype=firetype;
3255 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3257 if(editortype==treeleavestype||editortype==10)editortype++;
3258 if(editortype>firetype)editortype=0;
3261 if(Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3262 editoryaw-=multiplier*100;
3263 if(editoryaw<-.01)editoryaw=-.01;
3266 if(Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
3267 editoryaw+=multiplier*100;
3270 if(Input::isKeyDown(SDLK_UP)&&!Input::isKeyDown(SDLK_LCTRL)){
3271 editorsize+=multiplier;
3274 if(Input::isKeyDown(SDLK_DOWN)&&!Input::isKeyDown(SDLK_LCTRL)){
3275 editorsize-=multiplier;
3276 if(editorsize<.1)editorsize=.1;
3280 if(Input::isKeyPressed(SDLK_LEFT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3281 mapradius-=multiplier*10;
3284 if(Input::isKeyPressed(SDLK_RIGHT)&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
3285 mapradius+=multiplier*10;
3287 if(Input::isKeyDown(SDLK_UP)&&Input::isKeyDown(SDLK_LCTRL)){
3288 editorpitch+=multiplier*100;
3291 if(Input::isKeyDown(SDLK_DOWN)&&Input::isKeyDown(SDLK_LCTRL)){
3292 editorpitch-=multiplier*100;
3293 if(editorpitch<-.01)editorpitch=-.01;
3295 if(Input::isKeyPressed(SDLK_DELETE)&&objects.numobjects&&Input::isKeyDown(SDLK_LSHIFT)){
3296 int closest=findClosestObject();
3298 objects.DeleteObject(closest);
3304 void doJumpReversals(){
3305 for(int k=0;k<numplayers;k++)
3306 for(int i=k;i<numplayers;i++){
3308 if( player[k].skeleton.free==0&&
3309 player[i].skeleton.oldfree==0&&
3310 (player[i].animTarget==jumpupanim||
3311 player[k].animTarget==jumpupanim)&&
3312 (player[i].aitype==playercontrolled||
3313 player[k].aitype==playercontrolled)&&
3314 (player[i].aitype==attacktypecutoff&&player[i].stunned<=0||
3315 player[k].aitype==attacktypecutoff&&player[k].stunned<=0)){
3316 if( distsq(&player[i].coords,&player[k].coords)<10*sq((player[i].scale+player[k].scale)*2.5)&&
3317 distsqflat(&player[i].coords,&player[k].coords)<2*sq((player[i].scale+player[k].scale)*2.5)){
3318 //TODO: refactor two huge similar ifs
3319 if(player[i].animTarget==jumpupanim&&
3320 player[k].animTarget!=getupfrombackanim&&
3321 player[k].animTarget!=getupfromfrontanim&&
3322 animation[player[k].animTarget].height==middleheight&&
3323 normaldotproduct(player[i].velocity,player[k].coords-player[i].coords)<0&&
3324 (player[k].aitype==playercontrolled&&player[k].attackkeydown||
3325 player[k].aitype!=playercontrolled)){
3326 player[i].victim=&player[k];
3327 player[i].velocity=0;
3328 player[i].animCurrent=jumpreversedanim;
3329 player[i].animTarget=jumpreversedanim;
3330 player[i].frameCurrent=0;
3331 player[i].frameTarget=1;
3332 player[i].targettilt2=0;
3333 player[k].victim=&player[i];
3334 player[k].velocity=0;
3335 player[k].animCurrent=jumpreversalanim;
3336 player[k].animTarget=jumpreversalanim;
3337 player[k].frameCurrent=0;
3338 player[k].frameTarget=1;
3339 player[k].targettilt2=0;
3340 if(player[i].coords.y<player[k].coords.y+1){
3341 player[i].animCurrent=rabbitkickreversedanim;
3342 player[i].animTarget=rabbitkickreversedanim;
3343 player[i].frameCurrent=1;
3344 player[i].frameTarget=2;
3345 player[k].animCurrent=rabbitkickreversalanim;
3346 player[k].animTarget=rabbitkickreversalanim;
3347 player[k].frameCurrent=1;
3348 player[k].frameTarget=2;
3351 player[k].oldcoords=player[k].coords;
3352 player[i].coords=player[k].coords;
3353 player[k].targetyaw=player[i].targetyaw;
3354 player[k].yaw=player[i].targetyaw;
3355 if(player[k].aitype==attacktypecutoff)
3356 player[k].stunned=.5;
3358 if(player[k].animTarget==jumpupanim&&
3359 player[i].animTarget!=getupfrombackanim&&
3360 player[i].animTarget!=getupfromfrontanim&&
3361 animation[player[i].animTarget].height==middleheight&&
3362 normaldotproduct(player[k].velocity,player[i].coords-player[k].coords)<0&&
3363 ((player[i].aitype==playercontrolled&&player[i].attackkeydown)||
3364 player[i].aitype!=playercontrolled)){
3365 player[k].victim=&player[i];
3366 player[k].velocity=0;
3367 player[k].animCurrent=jumpreversedanim;
3368 player[k].animTarget=jumpreversedanim;
3369 player[k].frameCurrent=0;
3370 player[k].frameTarget=1;
3371 player[k].targettilt2=0;
3372 player[i].victim=&player[k];
3373 player[i].velocity=0;
3374 player[i].animCurrent=jumpreversalanim;
3375 player[i].animTarget=jumpreversalanim;
3376 player[i].frameCurrent=0;
3377 player[i].frameTarget=1;
3378 player[i].targettilt2=0;
3379 if(player[k].coords.y<player[i].coords.y+1){
3380 player[k].animTarget=rabbitkickreversedanim;
3381 player[k].animCurrent=rabbitkickreversedanim;
3382 player[i].animCurrent=rabbitkickreversalanim;
3383 player[i].animTarget=rabbitkickreversalanim;
3384 player[k].frameCurrent=1;
3385 player[k].frameTarget=2;
3386 player[i].frameCurrent=1;
3387 player[i].frameTarget=2;
3390 player[i].oldcoords=player[i].coords;
3391 player[k].coords=player[i].coords;
3392 player[i].targetyaw=player[k].targetyaw;
3393 player[i].yaw=player[k].targetyaw;
3394 if(player[i].aitype==attacktypecutoff)
3395 player[i].stunned=.5;
3402 void doAerialAcrobatics(){
3403 static XYZ facing,flatfacing;
3404 for(int k=0;k<numplayers;k++){
3405 player[k].turnspeed=500;
3407 if((player[k].isRun()&&
3408 ((player[k].targetyaw!=rabbitrunninganim&&
3409 player[k].targetyaw!=wolfrunninganim)||
3410 player[k].frameTarget==4))||
3411 player[k].animTarget==removeknifeanim||
3412 player[k].animTarget==crouchremoveknifeanim||
3413 player[k].animTarget==flipanim||
3414 player[k].animTarget==fightsidestep||
3415 player[k].animTarget==walkanim){
3416 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed);
3420 if(player[k].isStop()||
3421 player[k].isLanding()||
3422 player[k].animTarget==staggerbackhighanim||
3423 (player[k].animTarget==sneakanim&&player[k].animCurrent==sneakanim)||
3424 player[k].animTarget==staggerbackhardanim||
3425 player[k].animTarget==backhandspringanim||
3426 player[k].animTarget==dodgebackanim||
3427 player[k].animTarget==rollanim||
3428 (animation[player[k].animTarget].attack&&
3429 player[k].animTarget!=rabbitkickanim&&
3430 (player[k].animTarget!=crouchstabanim||player[k].hasvictim)&&
3431 (player[k].animTarget!=swordgroundstabanim||player[k].hasvictim))){
3432 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*2);
3435 if(player[k].animTarget==sneakanim&&player[k].animCurrent!=sneakanim){
3436 player[k].yaw=stepTowardf(player[k].yaw, player[k].targetyaw, multiplier*player[k].turnspeed*4);
3439 /*if(player[k].aitype!=passivetype||(distsq(&player[k].coords,&viewer)<viewdistance*viewdistance))*/
3440 player[k].DoStuff();
3441 if(player[k].immobile&&k!=0)
3442 player[k].coords=player[k].realoldcoords;
3444 //if player's position has changed (?)
3445 if(distsq(&player[k].coords,&player[k].realoldcoords)>0&&
3446 !player[k].skeleton.free&&
3447 player[k].animTarget!=climbanim&&
3448 player[k].animTarget!=hanganim){
3449 XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
3453 if(player[k].collide<-.3)
3454 player[k].collide=-.3;
3455 if(player[k].collide>1)
3456 player[k].collide=1;
3457 player[k].collide-=multiplier*30;
3460 player[k].coords.y=max(player[k].coords.y, terrain.getHeight(player[k].coords.x,player[k].coords.z));
3462 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3463 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3464 if(objects.type[i]!=rocktype||
3465 objects.scale[i]>.5&&player[k].aitype==playercontrolled||
3466 objects.position[i].y>player[k].coords.y){
3467 lowpoint=player[k].coords;
3468 if(player[k].animTarget!=jumpupanim&&
3469 player[k].animTarget!=jumpdownanim&&
3470 !player[k].isFlip())
3474 if( player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)&&
3475 player[k].coords.y>terrain.getHeight(player[k].coords.x,player[k].coords.z)-.1)
3476 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
3477 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i])!=-1){
3478 flatfacing=lowpoint-player[k].coords;
3479 player[k].coords=lowpoint;
3480 player[k].coords.y-=1.3;
3481 player[k].collide=1;
3484 //TODO: refactor four similar blocks
3485 if(player[k].aitype==playercontrolled&&
3486 (player[k].animTarget==jumpupanim||
3487 player[k].animTarget==jumpdownanim||
3488 player[k].isFlip())&&
3489 !player[k].jumptogglekeydown&&
3490 player[k].jumpkeydown){
3491 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
3492 XYZ tempcoords1=lowpoint;
3493 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3494 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3495 player[k].setAnimation(walljumpleftanim);
3496 emit_sound_at(movewhooshsound, player[k].coords);
3498 pause_sound(whooshsound);
3500 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3501 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3502 if(lowpointtarget.z<0)
3503 player[k].yaw=180-player[k].yaw;
3504 player[k].targetyaw=player[k].yaw;
3505 player[k].lowyaw=player[k].yaw;
3511 lowpoint=tempcoords1;
3512 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
3513 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3514 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3515 player[k].setAnimation(walljumprightanim);
3516 emit_sound_at(movewhooshsound, player[k].coords);
3517 if(k==0)pause_sound(whooshsound);
3519 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3520 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3521 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3522 player[k].targetyaw=player[k].yaw;
3523 player[k].lowyaw=player[k].yaw;
3524 if(k==0)numwallflipped++;
3528 lowpoint=tempcoords1;
3529 lowpointtarget=lowpoint+player[k].facing*2;
3530 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3531 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3532 player[k].setAnimation(walljumpbackanim);
3533 emit_sound_at(movewhooshsound, player[k].coords);
3534 if(k==0)pause_sound(whooshsound);
3536 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3537 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3538 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3539 player[k].targetyaw=player[k].yaw;
3540 player[k].lowyaw=player[k].yaw;
3541 if(k==0)numwallflipped++;
3545 lowpoint=tempcoords1;
3546 lowpointtarget=lowpoint-player[k].facing*2;
3547 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3548 if(whichhit!=-1&&fabs(objects.model[i].facenormals[whichhit].y)<.3){
3549 player[k].setAnimation(walljumpfrontanim);
3550 emit_sound_at(movewhooshsound, player[k].coords);
3551 if(k==0)pause_sound(whooshsound);
3553 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3554 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3555 if(lowpointtarget.z<0)player[k].yaw=180-player[k].yaw;
3557 player[k].targetyaw=player[k].yaw;
3558 player[k].lowyaw=player[k].yaw;
3559 if(k==0)numwallflipped++;
3567 else if(objects.type[i]==rocktype){
3568 lowpoint2=player[k].coords;
3569 lowpoint=player[k].coords;
3571 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.yaw[i])!=-1){
3572 player[k].coords=colpoint;
3573 player[k].collide=1;
3576 if(player[k].animTarget==jumpdownanim||player[k].isFlip()){
3577 //flipped into a rock
3578 if(player[k].isFlip()&&animation[player[k].animTarget].label[player[k].frameTarget]==7)
3579 player[k].RagDoll(0);
3581 if(player[k].animTarget==jumpupanim){
3582 player[k].jumppower=-4;
3583 player[k].animTarget=player[k].getIdle();
3586 player[k].frameTarget=0;
3587 player[k].onterrain=1;
3589 if(player[k].id==0){
3590 pause_sound(whooshsound);
3591 OPENAL_SetVolume(channels[whooshsound], 0);
3595 if((player[k].animTarget==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
3596 if(player[k].isFlip())
3597 player[k].jumppower=-4;
3598 player[k].animTarget=player[k].getLanding();
3599 emit_sound_at(landsound, player[k].coords, 128.);
3601 envsound[numenvsounds]=player[k].coords;
3602 envsoundvol[numenvsounds]=16;
3603 envsoundlife[numenvsounds]=.4;
3613 if(tempcollide&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
3614 for(int l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
3615 int i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
3616 lowpoint=player[k].coords;
3618 if(objects.type[i]!=rocktype)
3619 if(player[k].SphereCheck(&lowpoint,1.33,&colpoint,&objects.position[i],&objects.yaw[i],&objects.model[i])!=-1){
3620 if(player[k].animTarget!=jumpupanim&&
3621 player[k].animTarget!=jumpdownanim&&
3622 player[k].onterrain)
3623 player[k].avoidcollided=1;
3624 player[k].coords=lowpoint;
3625 player[k].coords.y-=1.35;
3626 player[k].collide=1;
3628 if((player[k].grabdelay<=0||player[k].aitype!=playercontrolled)&&
3629 (player[k].animCurrent!=climbanim&&
3630 player[k].animCurrent!=hanganim&&
3631 !player[k].isWallJump()||
3632 player[k].animTarget==jumpupanim||
3633 player[k].animTarget==jumpdownanim)){
3634 lowpoint=player[k].coords;
3635 objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.yaw[i]);
3636 lowpoint=player[k].coords;
3640 facing=DoRotation(facing,0,player[k].targetyaw+180,0);
3641 lowpointtarget=lowpoint+facing*1.4;
3642 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3644 lowpoint=player[k].coords;
3646 lowpointtarget=lowpoint+facing*1.4;
3648 lowpointtarget2=lowpointtarget;
3650 lowpointtarget3=lowpointtarget;
3652 lowpointtarget4=lowpointtarget;
3654 lowpointtarget5=lowpointtarget;
3656 lowpointtarget6=lowpointtarget;
3658 lowpointtarget7=lowpoint;
3660 lowpointtarget2.x+=.1;
3662 lowpointtarget3.z+=.1;
3664 lowpointtarget4.x-=.1;
3666 lowpointtarget5.z-=.1;
3668 lowpointtarget6.y+=45/13;
3669 lowpointtarget6+=facing*.6;
3670 lowpointtarget7.y+=90/13;
3671 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.yaw[i]);
3672 if(objects.friction[i]>.5)
3674 if(whichhit!=-1&&player[k].animTarget!=jumpupanim&&player[k].animTarget!=jumpdownanim)
3675 player[k].collided=1;
3676 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
3677 if(checkcollide(lowpoint6,lowpointtarget6)==-1)
3678 if( objects.model[i].LineCheckPossible(&lowpoint2,&lowpointtarget2,
3679 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3680 objects.model[i].LineCheckPossible(&lowpoint3,&lowpointtarget3,
3681 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3682 objects.model[i].LineCheckPossible(&lowpoint4,&lowpointtarget4,
3683 &colpoint,&objects.position[i],&objects.yaw[i])!=-1&&
3684 objects.model[i].LineCheckPossible(&lowpoint5,&lowpointtarget5,
3685 &colpoint,&objects.position[i],&objects.yaw[i])!=-1)
3686 for(int j=0;j<45;j++){
3687 lowpoint=player[k].coords;
3688 lowpoint.y+=(float)j/13;
3689 lowpointtarget=lowpoint+facing*1.4;
3690 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,
3691 &colpoint2,&objects.position[i],&objects.yaw[i])==-1){
3692 if(j<=6||j<=25&&player[k].animTarget==jumpdownanim)
3694 if(player[k].animTarget==jumpupanim||player[k].animTarget==jumpdownanim){
3695 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[k],0);
3696 lowpoint=player[k].coords;
3697 lowpoint.y+=(float)j/13;
3698 lowpointtarget=lowpoint+facing*1.3;
3699 flatfacing=player[k].coords;
3700 player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[k],0)*.01;
3701 player[k].coords.y=lowpointtarget.y-.07;
3702 player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
3704 if(j>10||!player[k].isRun()){
3705 if(player[k].animTarget==jumpdownanim||player[k].animTarget==jumpupanim){
3707 pause_sound(whooshsound);
3709 emit_sound_at(jumpsound, player[k].coords, 128.);
3711 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.yaw[i],0);
3712 player[k].yaw=-asin(0-lowpointtarget.x)*180/M_PI;
3713 if(lowpointtarget.z<0)
3714 player[k].yaw=180-player[k].yaw;
3715 player[k].targetyaw=player[k].yaw;
3716 player[k].lowyaw=player[k].yaw;
3718 //player[k].velocity=lowpointtarget*.03;
3719 player[k].velocity=0;
3722 if(player[k].animTarget==jumpupanim){
3723 player[k].animTarget=climbanim;
3724 player[k].jumppower=0;
3725 player[k].jumpclimb=1;
3727 player[k].transspeed=6;
3729 player[k].frameTarget=1;
3732 player[k].setAnimation(hanganim);
3733 player[k].jumppower=0;
3745 if(player[k].collide<=0){
3747 if(!player[k].onterrain&&
3748 player[k].animTarget!=jumpupanim&&
3749 player[k].animTarget!=jumpdownanim&&
3750 player[k].animTarget!=climbanim&&
3751 player[k].animTarget!=hanganim&&
3752 !player[k].isWallJump()&&
3753 !player[k].isFlip()){
3754 if(player[k].animCurrent!=climbanim&&
3755 player[k].animCurrent!=tempanim&&
3756 player[k].animTarget!=backhandspringanim&&
3757 (player[k].animTarget!=rollanim||
3758 player[k].frameTarget<2||
3759 player[k].frameTarget>6)){
3760 //stagger off ledge (?)
3761 if(player[k].animTarget==staggerbackhighanim||player[k].animTarget==staggerbackhardanim)
3762 player[k].RagDoll(0);
3763 player[k].setAnimation(jumpdownanim);
3766 emit_sound_at(whooshsound, player[k].coords, 128.);
3769 player[k].velocity.y+=gravity;
3773 player[k].realoldcoords=player[k].coords;
3778 static XYZ relative;
3779 static int randattack;
3780 static bool playerrealattackkeydown=0;
3782 if(!Input::isKeyDown(attackkey))
3785 player[0].attackkeydown=0;
3787 playerrealattackkeydown=0;
3789 playerrealattackkeydown=Input::isKeyDown(attackkey);
3790 if((player[0].parriedrecently<=0||
3791 player[0].weaponactive==-1)&&
3794 player[0].lastattack!=swordslashanim&&
3795 player[0].lastattack!=knifeslashstartanim&&
3796 player[0].lastattack!=staffhitanim&&
3797 player[0].lastattack!=staffspinhitanim)))
3798 player[0].attackkeydown=Input::isKeyDown(attackkey);
3799 if(Input::isKeyDown(attackkey)&&
3801 !player[0].backkeydown){
3802 for(int k=0;k<numplayers;k++){
3803 if((player[k].animTarget==swordslashanim||
3804 player[k].animTarget==staffhitanim||
3805 player[k].animTarget==staffspinhitanim)&&
3806 player[0].animCurrent!=dodgebackanim&&
3807 !player[k].skeleton.free)
3808 player[k].Reverse();
3812 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
3814 for(int k=0;k<numplayers;k++){
3815 if(indialogue!=-1)player[k].attackkeydown=0;
3816 if(player[k].animTarget!=rabbitrunninganim&&player[k].animTarget!=wolfrunninganim){
3817 if(player[k].aitype!=playercontrolled)
3818 player[k].victim=&player[0];
3819 //attack key pressed
3820 if(player[k].attackkeydown){
3822 if(player[k].backkeydown&&
3823 player[k].animTarget!=backhandspringanim&&
3824 (player[k].isIdle()||
3825 player[k].isStop()||
3827 player[k].animTarget==walkanim)){
3828 if(player[k].jumppower<=1){
3829 player[k].jumppower-=2;
3831 for(int i=0;i<numplayers;i++){
3833 if(player[i].animTarget==swordslashanim||
3834 player[i].animTarget==knifeslashstartanim||
3835 player[i].animTarget==staffhitanim||
3836 player[i].animTarget==staffspinhitanim)
3837 if(distsq(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
3838 player[k].setAnimation(dodgebackanim);
3839 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
3840 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
3843 if(player[k].animTarget!=dodgebackanim){
3844 if(k==0)numflipped++;
3845 player[k].setAnimation(backhandspringanim);
3846 player[k].targetyaw=-yaw+180;
3847 if(player[k].leftkeydown)
3848 player[k].targetyaw-=45;
3849 if(player[k].rightkeydown)
3850 player[k].targetyaw+=45;
3851 player[k].yaw=player[k].targetyaw;
3852 player[k].jumppower-=2;
3857 if(!animation[player[k].animTarget].attack&&
3858 !player[k].backkeydown&&
3859 (player[k].isIdle()||
3861 player[k].animTarget==walkanim||
3862 player[k].animTarget==sneakanim||
3863 player[k].isCrouch())){
3864 const int attackweapon=player[k].weaponactive==-1?0:weapons[player[k].weaponids[player[k].weaponactive]].getType();
3865 //normal attacks (?)
3866 player[k].hasvictim=0;
3868 for(int i=0;i<numplayers;i++){
3869 if(i==k||!(k==0||i==0))continue;
3870 if(!player[k].hasvictim)
3871 if(animation[player[k].animTarget].attack!=reversal){
3873 const float distance=distsq(&player[k].coords,&player[i].coords);
3875 !player[i].skeleton.free&&
3876 player[i].howactive<typedead1&&
3877 player[i].animTarget!=jumpreversedanim&&
3878 player[i].animTarget!=rabbitkickreversedanim&&
3879 player[i].animTarget!=rabbitkickanim&&
3880 player[k].animTarget!=rabbitkickanim&&
3881 player[i].animTarget!=getupfrombackanim&&
3882 (player[i].animTarget!=staggerbackhighanim&&
3883 (player[i].animTarget!=staggerbackhardanim||
3884 animation[staggerbackhardanim].label[player[i].frameTarget]==6))&&
3885 player[i].animTarget!=jumpdownanim&&
3886 player[i].animTarget!=jumpupanim&&
3887 player[i].animTarget!=getupfromfrontanim){
3888 player[k].victim=&player[i];
3889 player[k].hasvictim=1;
3890 if(player[k].aitype==playercontrolled){ //human player
3892 if(distance<2.5*sq(player[k].scale*5)&&
3893 player[k].crouchkeydown&&
3894 animation[player[i].animTarget].height!=lowheight)
3895 player[k].animTarget=sweepanim;
3897 else if(distance<1.5*sq(player[k].scale*5)&&
3898 animation[player[i].animTarget].height!=lowheight&&
3899 !player[k].forwardkeydown&&
3900 !player[k].leftkeydown&&
3901 !player[k].rightkeydown&&
3902 !player[k].crouchkeydown&&
3905 player[k].animTarget=winduppunchanim;
3907 else if(distance<2.5*sq(player[k].scale*5)&&
3908 animation[player[i].animTarget].height!=lowheight&&
3909 !player[k].forwardkeydown&&
3910 !player[k].leftkeydown&&
3911 !player[k].rightkeydown&&
3912 !player[k].crouchkeydown&&
3914 player[k].animTarget=upunchanim;
3916 else if(distance<2.5*sq(player[k].scale*5)&&
3917 player[i].staggerdelay>0&&
3918 attackweapon==knife&&
3919 player[i].bloodloss>player[i].damagetolerance/2)
3920 player[k].animTarget=knifefollowanim;
3922 else if(distance<2.5*sq(player[k].scale*5)&&
3923 animation[player[i].animTarget].height!=lowheight&&
3924 !player[k].forwardkeydown&&
3925 !player[k].leftkeydown&&
3926 !player[k].rightkeydown&&
3927 !player[k].crouchkeydown&&
3928 attackweapon==knife&&
3929 player[k].weaponmissdelay<=0)
3930 player[k].animTarget=knifeslashstartanim;
3932 else if(distance<4.5*sq(player[k].scale*5)&&
3933 animation[player[i].animTarget].height!=lowheight&&
3934 !player[k].crouchkeydown&&
3935 attackweapon==sword&&
3936 player[k].weaponmissdelay<=0)
3937 player[k].animTarget=swordslashanim;
3939 else if(distance<4.5*sq(player[k].scale*5)&&
3940 animation[player[i].animTarget].height!=lowheight&&
3941 !player[k].crouchkeydown&&
3942 attackweapon==staff&&
3943 player[k].weaponmissdelay<=0&&
3944 !player[k].leftkeydown&&
3945 !player[k].rightkeydown&&
3946 !player[k].forwardkeydown)
3947 player[k].animTarget=staffhitanim;
3949 else if(distance<4.5*sq(player[k].scale*5)&&
3950 animation[player[i].animTarget].height!=lowheight&&
3951 !player[k].crouchkeydown&&
3952 attackweapon==staff&&
3953 player[k].weaponmissdelay<=0)
3954 player[k].animTarget=staffspinhitanim;
3956 else if(distance<2.5*sq(player[k].scale*5)&&
3957 animation[player[i].animTarget].height!=lowheight)
3958 player[k].animTarget=spinkickanim;
3960 else if(distance<2.5*sq(player[k].scale*5)&&
3961 animation[player[i].animTarget].height==lowheight&&
3962 animation[player[k].animTarget].attack!=normalattack)
3963 player[k].animTarget=lowkickanim;
3964 } else { //AI player
3965 if(distance<4.5*sq(player[k].scale*5)){
3966 randattack=abs(Random()%5);
3967 if(!attackweapon&&distance<2.5*sq(player[k].scale*5)){
3969 if(randattack==0&&animation[player[i].animTarget].height!=lowheight)
3970 player[k].animTarget=sweepanim;
3972 else if(randattack==1&&animation[player[i].animTarget].height!=lowheight&&
3974 player[k].animTarget=upunchanim;
3976 else if(randattack==2&&animation[player[i].animTarget].height!=lowheight)
3977 player[k].animTarget=spinkickanim;
3979 else if(animation[player[i].animTarget].height==lowheight)
3980 player[k].animTarget=lowkickanim;
3984 if((tutoriallevel!=1||!attackweapon)&&
3985 distance<2.5*sq(player[k].scale*5)&&
3987 animation[player[i].animTarget].height!=lowheight)
3988 player[k].animTarget=sweepanim;
3990 else if(distance<2.5*sq(player[k].scale*5)&&
3991 attackweapon==knife&&
3992 player[k].weaponmissdelay<=0)
3993 player[k].animTarget=knifeslashstartanim;
3995 else if(!(player[0].victim==&player[i]&&
3996 player[0].hasvictim&&
3997 player[0].animTarget==swordslashanim)&&
3998 attackweapon==sword&&
3999 player[k].weaponmissdelay<=0)
4000 player[k].animTarget=swordslashanim;
4002 else if(!(player[0].victim==&player[i]&&
4003 player[0].hasvictim&&
4004 player[0].animTarget==swordslashanim)&&
4005 attackweapon==staff&&
4006 player[k].weaponmissdelay<=0&&
4008 player[k].animTarget=staffhitanim;
4010 else if(!(player[0].victim==&player[i]&&
4011 player[0].hasvictim&&
4012 player[0].animTarget==swordslashanim)&&
4013 attackweapon==staff&&
4014 player[k].weaponmissdelay<=0&&
4016 player[k].animTarget=staffspinhitanim;
4018 else if((tutoriallevel!=1||!attackweapon)&&
4019 distance<2.5*sq(player[k].scale*5)&&
4021 animation[player[i].animTarget].height!=lowheight)
4022 player[k].animTarget=spinkickanim;
4024 else if(distance<2.5*sq(player[k].scale*5)&&
4025 animation[player[i].animTarget].height==lowheight&&
4026 animation[player[k].animTarget].attack!=normalattack)
4027 player[k].animTarget=lowkickanim;
4031 //upunch becomes wolfslap
4032 if(player[k].animTarget==upunchanim&&player[k].creature==wolftype)
4033 player[k].animTarget=wolfslapanim;
4036 if((k==0)&&(tutoriallevel!=1||tutorialstage==22)&&
4037 player[i].howactive<typedead1&&
4038 distance<1.5*sq(player[k].scale*5)&&
4039 !player[i].skeleton.free&&
4040 player[i].animTarget!=getupfrombackanim&&
4041 player[i].animTarget!=getupfromfrontanim&&
4042 (player[i].stunned>0&&player[k].madskills||
4043 player[i].surprised>0||
4044 player[i].aitype==passivetype||
4045 attackweapon&&player[i].stunned>0)&&
4046 normaldotproduct(player[i].facing,player[i].coords-player[k].coords)>0){
4049 player[k].animCurrent=sneakattackanim;
4050 player[k].animTarget=sneakattackanim;
4051 player[i].animCurrent=sneakattackedanim;
4052 player[i].animTarget=sneakattackedanim;
4053 player[k].oldcoords=player[k].coords;
4054 player[k].coords=player[i].coords;
4057 if(attackweapon==knife){
4058 player[k].animCurrent=knifesneakattackanim;
4059 player[k].animTarget=knifesneakattackanim;
4060 player[i].animCurrent=knifesneakattackedanim;
4061 player[i].animTarget=knifesneakattackedanim;
4062 player[i].oldcoords=player[i].coords;
4063 player[i].coords=player[k].coords;
4066 if(attackweapon==sword){
4067 player[k].animCurrent=swordsneakattackanim;
4068 player[k].animTarget=swordsneakattackanim;
4069 player[i].animCurrent=swordsneakattackedanim;
4070 player[i].animTarget=swordsneakattackedanim;
4071 player[i].oldcoords=player[i].coords;
4072 player[i].coords=player[k].coords;
4074 if(attackweapon!=staff){
4075 player[k].victim=&player[i];
4076 player[k].hasvictim=1;
4077 player[i].targettilt2=0;
4078 player[i].frameTarget=1;
4079 player[i].frameCurrent=0;
4081 player[i].velocity=0;
4082 player[k].targettilt2=player[i].targettilt2;
4083 player[k].frameCurrent=player[i].frameCurrent;
4084 player[k].frameTarget=player[i].frameTarget;
4085 player[k].target=player[i].target;
4086 player[k].velocity=0;
4087 player[k].targetyaw=player[i].yaw;
4088 player[k].yaw=player[i].yaw;
4089 player[i].targetyaw=player[i].yaw;
4092 if(animation[player[k].animTarget].attack==normalattack&&
4093 player[k].victim==&player[i]&&
4094 (!player[i].skeleton.free)){
4096 player[k].frameTarget=0;
4099 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
4100 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4101 player[k].lastattack3=player[k].lastattack2;
4102 player[k].lastattack2=player[k].lastattack;
4103 player[k].lastattack=player[k].animTarget;
4105 if(player[k].animTarget==knifefollowanim&&
4106 player[k].victim==&player[i]){
4108 player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords);
4109 player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
4110 player[k].victim=&player[i];
4111 player[k].hasvictim=1;
4112 player[i].animTarget=knifefollowedanim;
4113 player[i].animCurrent=knifefollowedanim;
4114 player[i].targettilt2=0;
4115 player[i].targettilt2=player[k].targettilt2;
4116 player[i].frameTarget=1;
4117 player[i].frameCurrent=0;
4119 player[i].velocity=0;
4120 player[k].animCurrent=knifefollowanim;
4121 player[k].animTarget=knifefollowanim;
4122 player[k].targettilt2=player[i].targettilt2;
4123 player[k].frameCurrent=player[i].frameCurrent;
4124 player[k].frameTarget=player[i].frameTarget;
4125 player[k].target=player[i].target;
4126 player[k].velocity=0;
4127 player[k].oldcoords=player[k].coords;
4128 player[i].coords=player[k].coords;
4129 player[i].targetyaw=player[k].targetyaw;
4130 player[i].yaw=player[k].targetyaw;
4131 player[k].yaw=player[k].targetyaw;
4132 player[i].yaw=player[k].targetyaw;
4136 const bool hasstaff=attackweapon==staff;
4137 if(k==0&&numplayers>1)
4138 for(int i=0;i<numplayers;i++){
4140 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
4141 animation[player[k].animTarget].attack==neutral){
4142 const float distance=distsq(&player[k].coords,&player[i].coords);
4143 if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
4144 if(player[i].skeleton.free)
4145 if(distance<3.5*sq(player[k].scale*5)&&
4147 player[i].skeleton.longdead>1000||
4151 (player[i].skeleton.longdead>2000||
4152 player[i].damage>player[i].damagetolerance/8||
4153 player[i].bloodloss>player[i].damagetolerance/2)&&
4154 distance<1.5*sq(player[k].scale*5)))){
4155 player[k].victim=&player[i];
4156 player[k].hasvictim=1;
4157 if(attackweapon&&tutoriallevel!=1){
4159 if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
4160 player[k].animTarget=crouchstabanim;
4162 if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
4163 player[k].animTarget=swordgroundstabanim;
4165 if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
4166 player[k].animTarget=staffgroundsmashanim;
4169 player[k].crouchkeydown&&
4170 player[k].animTarget!=crouchstabanim&&
4173 player[i].skeleton.free&&
4174 player[i].skeleton.longdead>1000){
4175 player[k].animTarget=killanim;
4176 //TODO: refactor this out, what does it do?
4177 for(int j=0;j<terrain.numdecals;j++){
4178 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4179 terrain.decalalivetime[j]<2)
4180 terrain.DeleteDecal(j);
4182 for(int l=0;l<objects.numobjects;l++){
4183 if(objects.model[l].type==decalstype)
4184 for(int j=0;j<objects.model[l].numdecals;j++){
4185 if((objects.model[l].decaltype[j]==blooddecal||
4186 objects.model[l].decaltype[j]==blooddecalslow)&&
4187 objects.model[l].decalalivetime[j]<2)
4188 objects.model[l].DeleteDecal(j);
4192 if(!player[i].dead||musictype!=2)
4194 (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
4195 player[k].staggerdelay<=0&&
4197 player[i].skeleton.longdead<300&&
4198 player[k].lastattack!=spinkickanim&&
4199 player[i].skeleton.free)&&
4200 (!player[i].dead||musictype!=stream_fighttheme)){
4201 player[k].animTarget=dropkickanim;
4202 for(int j=0;j<terrain.numdecals;j++){
4203 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
4204 terrain.decalalivetime[j]<2){
4205 terrain.DeleteDecal(j);
4208 for(int l=0;l<objects.numobjects;l++){
4209 if(objects.model[l].type==decalstype)
4210 for(int j=0;j<objects.model[l].numdecals;j++){
4211 if((objects.model[l].decaltype[j]==blooddecal||
4212 objects.model[l].decaltype[j]==blooddecalslow)&&
4213 objects.model[l].decalalivetime[j]<2){
4214 objects.model[l].DeleteDecal(j);
4220 if(animation[player[k].animTarget].attack==normalattack&&
4221 player[k].victim==&player[i]&&
4222 (!player[i].skeleton.free||
4223 player[k].animTarget==killanim||
4224 player[k].animTarget==crouchstabanim||
4225 player[k].animTarget==swordgroundstabanim||
4226 player[k].animTarget==staffgroundsmashanim||
4227 player[k].animTarget==dropkickanim)){
4229 player[k].frameTarget=0;
4232 XYZ targetpoint=player[i].coords;
4233 if(player[k].animTarget==crouchstabanim||
4234 player[k].animTarget==swordgroundstabanim||
4235 player[k].animTarget==staffgroundsmashanim){
4236 targetpoint+=(player[i].jointPos(abdomen)+
4237 player[i].jointPos(neck))/2*
4240 player[k].targetyaw=roughDirectionTo(player[k].coords,targetpoint);
4241 player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
4243 if(player[k].animTarget==crouchstabanim||player[k].animTarget==swordgroundstabanim){
4244 player[k].targetyaw+=(float)(abs(Random()%100)-50)/4;
4247 if(player[k].animTarget==staffgroundsmashanim)
4248 player[k].targettilt2+=10;
4250 player[k].lastattack3=player[k].lastattack2;
4251 player[k].lastattack2=player[k].lastattack;
4252 player[k].lastattack=player[k].animTarget;
4254 if(player[k].animTarget==swordgroundstabanim){
4255 player[k].targetyaw+=30;
4260 if(!player[k].hasvictim){
4262 for(int i=0;i<numplayers;i++){
4263 if(i==k||!(i==0||k==0))continue;
4264 if(!player[i].skeleton.free){
4265 if(player[k].hasvictim){
4266 if(distsq(&player[k].coords,&player[i].coords)<
4267 distsq(&player[k].coords,&player[k].victim->coords))
4268 player[k].victim=&player[i];
4270 player[k].victim=&player[i];
4271 player[k].hasvictim=1;
4276 if(player[k].aitype==playercontrolled)
4278 if(player[k].attackkeydown&&
4280 player[k].wasRun()&&
4281 ((player[k].hasvictim&&
4282 distsq(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
4283 distsq(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
4284 !player[k].victim->skeleton.free&&
4285 player[k].victim->animTarget!=getupfrombackanim&&
4286 player[k].victim->animTarget!=getupfromfrontanim&&
4287 animation[player[k].victim->animTarget].height!=lowheight&&
4288 player[k].aitype!=playercontrolled&& //wat???
4289 normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
4290 player[k].rabbitkickenabled)||
4291 player[k].jumpkeydown)){
4293 player[k].setAnimation(rabbitkickanim);
4296 if(animation[player[k].animTarget].attack&&k==0){
4298 switch(attackweapon){
4299 case 0: numunarmedattack++; break;
4300 case knife: numknifeattack++; break;
4301 case sword: numswordattack++; break;
4302 case staff: numstaffattack++; break;
4311 void doPlayerCollisions(){
4312 static XYZ rotatetarget;
4313 static float collisionradius;
4315 for(int k=0;k<numplayers;k++)
4316 for(int i=k+1;i<numplayers;i++){
4317 //neither player is part of a reversal
4318 if((animation[player[i].animTarget].attack!=reversed&&
4319 animation[player[i].animTarget].attack!=reversal&&
4320 animation[player[k].animTarget].attack!=reversed&&
4321 animation[player[k].animTarget].attack!=reversal)||(i!=0&&k!=0))
4322 if((animation[player[i].animCurrent].attack!=reversed&&
4323 animation[player[i].animCurrent].attack!=reversal&&
4324 animation[player[k].animCurrent].attack!=reversed&&
4325 animation[player[k].animCurrent].attack!=reversal)||(i!=0&&k!=0))
4326 //neither is sleeping
4327 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
4328 if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
4329 //in same patch, neither is climbing
4330 if(player[i].whichpatchx==player[k].whichpatchx&&
4331 player[i].whichpatchz==player[k].whichpatchz&&
4332 player[k].skeleton.oldfree==player[k].skeleton.free&&
4333 player[i].skeleton.oldfree==player[i].skeleton.free&&
4334 player[i].animTarget!=climbanim&&
4335 player[i].animTarget!=hanganim&&
4336 player[k].animTarget!=climbanim&&
4337 player[k].animTarget!=hanganim)
4338 //players are close (bounding box test)
4339 if(player[i].coords.y>player[k].coords.y-3)
4340 if(player[i].coords.y<player[k].coords.y+3)
4341 if(player[i].coords.x>player[k].coords.x-3)
4342 if(player[i].coords.x<player[k].coords.x+3)
4343 if(player[i].coords.z>player[k].coords.z-3)
4344 if(player[i].coords.z<player[k].coords.z+3){
4345 //spread fire from player to player
4346 if(distsq(&player[i].coords,&player[k].coords)
4347 <3*sq((player[i].scale+player[k].scale)*2.5)){
4348 if(player[i].onfire||player[k].onfire){
4349 if(!player[i].onfire)player[i].CatchFire();
4350 if(!player[k].onfire)player[k].CatchFire();
4354 XYZ tempcoords1=player[i].coords;
4355 XYZ tempcoords2=player[k].coords;
4356 if(!player[i].skeleton.oldfree)
4357 tempcoords1.y+=player[i].jointPos(abdomen).y*player[i].scale;
4358 if(!player[k].skeleton.oldfree)
4359 tempcoords2.y+=player[k].jointPos(abdomen).y*player[k].scale;
4360 collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
4361 if(player[0].hasvictim)
4362 if(player[0].animTarget==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
4364 if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
4365 (distsq(&tempcoords1,&tempcoords2)<collisionradius||
4366 distsq(&player[i].coords,&player[k].coords)<collisionradius)){
4367 //jump down on a dead body
4370 if(player[0].animTarget==jumpdownanim&&
4371 !player[0].skeleton.oldfree&&
4372 !player[0].skeleton.free&&
4373 player[l].skeleton.oldfree&&
4374 player[l].skeleton.free&&
4376 player[0].lastcollide<=0&&
4377 fabs(player[l].coords.y-player[0].coords.y)<.2&&
4378 distsq(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
4379 player[0].coords.y=player[l].coords.y;
4380 player[l].velocity=player[0].velocity;
4381 player[l].skeleton.free=0;
4383 player[l].RagDoll(0);
4384 player[l].DoDamage(20);
4386 player[l].skeleton.longdead=0;
4387 player[0].lastcollide=1;
4391 if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
4392 (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
4393 (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
4394 rotatetarget=player[k].velocity-player[i].velocity;
4395 if((player[i].animTarget!=getupfrombackanim&&player[i].animTarget!=getupfromfrontanim||
4396 player[i].skeleton.free)&&
4397 (player[k].animTarget!=getupfrombackanim&&player[k].animTarget!=getupfromfrontanim||
4398 player[k].skeleton.free))
4399 if((((k!=0&&findLengthfast(&rotatetarget)>150||
4400 k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
4401 normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
4403 k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].animCurrent].attack==neutral||
4404 /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].animCurrent].attack==neutral))||
4405 (player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim||player[i].isFlip())&&
4406 (player[k].animTarget==jumpupanim||player[k].animTarget==jumpdownanim||player[k].isFlip())&&
4407 k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
4409 if( (i!=0||player[i].skeleton.free)&&
4410 (k!=0||player[k].skeleton.free)||
4411 (animation[player[i].animTarget].height==highheight&&
4412 animation[player[k].animTarget].height==highheight)){
4413 if(tutoriallevel!=1){
4414 emit_sound_at(heavyimpactsound, player[i].coords);
4417 player[i].RagDoll(0);
4418 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
4419 award_bonus(0, aimbonus);
4421 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
4422 player[k].RagDoll(0);
4423 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
4424 award_bonus(0, aimbonus); // Huh, again?
4426 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
4428 for(int j=0;j<player[i].skeleton.num_joints;j++){
4429 player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
4431 for(int j=0;j<player[k].skeleton.num_joints;j++){
4432 player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
4437 if( (animation[player[i].animTarget].attack==neutral||
4438 animation[player[i].animTarget].attack==normalattack)&&
4439 (animation[player[k].animTarget].attack==neutral||
4440 animation[player[k].animTarget].attack==normalattack)){
4442 if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
4443 if(distsq(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
4444 rotatetarget=player[k].coords-player[i].coords;
4445 Normalise(&rotatetarget);
4446 player[k].coords=(player[k].coords+player[i].coords)/2;
4447 player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
4448 *sq((player[i].scale+player[k].scale)*2.5);
4449 player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
4450 if(player[k].howactive==typeactive||hostile)
4451 if(player[k].isIdle()){
4452 if(player[k].howactive<typesleeping)
4453 player[k].setAnimation(player[k].getStop());
4454 else if(player[k].howactive==typesleeping)
4455 player[k].setAnimation(getupfromfrontanim);
4457 player[k].howactive=typeactive;
4459 if(player[i].howactive==typeactive||hostile)
4460 if(player[i].isIdle()){
4461 if(player[i].howactive<typesleeping)
4462 player[i].setAnimation(player[k].getStop());
4464 player[i].setAnimation(getupfromfrontanim);
4466 player[i].howactive=typeactive;
4469 //jump down on player
4471 if(k==0&&i!=0&&player[k].animTarget==jumpdownanim&&
4472 !player[i].isCrouch()&&
4473 player[i].animTarget!=rollanim&&
4474 !player[k].skeleton.oldfree&&!
4475 player[k].skeleton.free&&
4476 player[k].lastcollide<=0&&
4477 player[k].velocity.y<-10){
4478 player[i].velocity=player[k].velocity;
4479 player[k].velocity=player[k].velocity*-.5;
4480 player[k].velocity.y=player[i].velocity.y;
4481 player[i].DoDamage(20);
4482 player[i].RagDoll(0);
4483 player[k].lastcollide=1;
4484 award_bonus(k, AboveBonus);
4486 if(i==0&&k!=0&&player[i].animTarget==jumpdownanim&&
4487 !player[k].isCrouch()&&
4488 player[k].animTarget!=rollanim&&
4489 !player[i].skeleton.oldfree&&
4490 !player[i].skeleton.free&&
4491 player[i].lastcollide<=0&&
4492 player[i].velocity.y<-10){
4493 player[k].velocity=player[i].velocity;
4494 player[i].velocity=player[i].velocity*-.3;
4495 player[i].velocity.y=player[k].velocity.y;
4496 player[k].DoDamage(20);
4497 player[k].RagDoll(0);
4498 player[i].lastcollide=1;
4499 award_bonus(i, AboveBonus);
4505 player[i].CheckKick();
4506 player[k].CheckKick();
4513 static bool connected;
4514 if(player[i].aitype!=playercontrolled&&indialogue==-1){
4515 player[i].jumpclimb=0;
4516 //disable movement in editor
4518 player[i].stunned=1;
4521 if(distsqflat(&player[0].coords,&player[i].coords)<30&&
4522 player[0].coords.y>player[i].coords.y+2&&
4523 !player[0].onterrain)
4527 if(player[i].aitype==pathfindtype){
4528 if(player[i].finalpathfindpoint==-1){
4529 float closestdistance;
4535 for(int j=0;j<numpathpoints;j++)
4536 if(closest==-1||distsq(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
4537 closestdistance=distsq(&player[i].finalfinaltarget,&pathpoint[j]);
4539 player[i].finaltarget=pathpoint[j];
4541 player[i].finalpathfindpoint=closest;
4542 for(int j=0;j<numpathpoints;j++)
4543 for(int k=0;k<numpathpointconnect[j];k++){
4544 DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4545 if(sq(tempdist)<closestdistance)
4546 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4547 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4548 closestdistance=sq(tempdist);
4550 player[i].finaltarget=colpoint;
4553 player[i].finalpathfindpoint=closest;
4556 if(player[i].targetpathfindpoint==-1){
4557 float closestdistance;
4563 if(player[i].lastpathfindpoint==-1){
4564 for(int j=0;j<numpathpoints;j++){
4565 if(j!=player[i].lastpathfindpoint)
4566 if(closest==-1||(distsq(&player[i].coords,&pathpoint[j])<closestdistance)){
4567 closestdistance=distsq(&player[i].coords,&pathpoint[j]);
4571 player[i].targetpathfindpoint=closest;
4572 for(int j=0;j<numpathpoints;j++)
4573 if(j!=player[i].lastpathfindpoint)
4574 for(int k=0;k<numpathpointconnect[j];k++){
4575 DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
4576 if(sq(tempdist)<closestdistance){
4577 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<
4578 findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
4579 closestdistance=sq(tempdist);
4584 player[i].targetpathfindpoint=closest;
4588 for(int j=0;j<numpathpoints;j++)
4589 if(j!=player[i].lastpathfindpoint&&
4590 j!=player[i].lastpathfindpoint2&&
4591 j!=player[i].lastpathfindpoint3&&
4592 j!=player[i].lastpathfindpoint4){
4594 if(numpathpointconnect[j])
4595 for(int k=0;k<numpathpointconnect[j];k++)
4596 if(pathpointconnect[j][k]==player[i].lastpathfindpoint)
4599 if(numpathpointconnect[player[i].lastpathfindpoint])
4600 for(int k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++)
4601 if(pathpointconnect[player[i].lastpathfindpoint][k]==j)
4604 tempdist=findPathDist(j,player[i].finalpathfindpoint);
4605 if(closest==-1||tempdist<closestdistance){
4606 closestdistance=tempdist;
4611 player[i].targetpathfindpoint=closest;
4614 player[i].losupdatedelay-=multiplier;
4616 player[i].targetyaw=roughDirectionTo(player[i].coords,pathpoint[player[i].targetpathfindpoint]);
4617 player[i].lookyaw=player[i].targetyaw;
4619 //reached target point
4620 if(distsqflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
4621 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4622 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4623 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4624 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
4625 if(player[i].lastpathfindpoint2==-1)
4626 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
4627 if(player[i].lastpathfindpoint3==-1)
4628 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
4629 if(player[i].lastpathfindpoint4==-1)
4630 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
4631 player[i].targetpathfindpoint=-1;
4633 if( distsqflat(&player[i].coords,&player[i].finalfinaltarget)<
4634 distsqflat(&player[i].coords,&player[i].finaltarget)||
4635 distsqflat(&player[i].coords,&player[i].finaltarget)<.6*sq(player[i].scale*5)||
4636 player[i].lastpathfindpoint==player[i].finalpathfindpoint) {
4637 player[i].aitype=passivetype;
4640 player[i].forwardkeydown=1;
4641 player[i].leftkeydown=0;
4642 player[i].backkeydown=0;
4643 player[i].rightkeydown=0;
4644 player[i].crouchkeydown=0;
4645 player[i].attackkeydown=0;
4646 player[i].throwkeydown=0;
4648 if(player[i].avoidcollided>.8 && !player[i].jumpkeydown && player[i].collided<.8)
4649 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
4651 if(player[i].collided<1||player[i].animTarget!=jumpupanim)
4652 player[i].jumpkeydown=0;
4653 if((player[i].collided>.8&&player[i].jumppower>=5))
4654 player[i].jumpkeydown=1;
4656 if((tutoriallevel!=1||cananger)&&
4659 distsq(&player[i].coords,&player[0].coords)<400&&
4660 player[i].occluded<25){
4661 if(distsq(&player[i].coords,&player[0].coords)<12&&
4662 animation[player[0].animTarget].height!=lowheight&&
4664 (player[0].coords.y<player[i].coords.y+5||player[0].onterrain))
4665 player[i].aitype=attacktypecutoff;
4666 if(distsq(&player[i].coords,&player[0].coords)<30&&
4667 animation[player[0].animTarget].height==highheight&&
4669 player[i].aitype=attacktypecutoff;
4671 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4672 player[i].losupdatedelay=.2;
4673 for(int j=0;j<numplayers;j++)
4674 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype)
4675 if(abs(Random()%2)||animation[player[j].animTarget].height!=lowheight||j!=0)
4676 if(distsq(&player[i].coords,&player[j].coords)<400)
4677 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4678 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
4679 if(!player[j].isWallJump()&&-1==checkcollide(
4680 DoRotation(player[i].jointPos(head),0,player[i].yaw,0)
4681 *player[i].scale+player[i].coords,
4682 DoRotation(player[j].jointPos(head),0,player[j].yaw,0)
4683 *player[j].scale+player[j].coords)||
4684 (player[j].animTarget==hanganim&&
4685 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4686 player[i].aitype=searchtype;
4687 player[i].lastchecktime=12;
4688 player[i].lastseen=player[j].coords;
4689 player[i].lastseentime=12;
4693 if(player[i].aitype==attacktypecutoff&&musictype!=2)
4694 if(player[i].creature!=wolftype){
4695 player[i].stunned=.6;
4696 player[i].surprised=.6;
4700 if(player[i].aitype!=passivetype&&leveltime>.5)
4701 player[i].howactive=typeactive;
4703 if(player[i].aitype==passivetype){
4704 player[i].aiupdatedelay-=multiplier;
4705 player[i].losupdatedelay-=multiplier;
4706 player[i].lastseentime+=multiplier;
4707 player[i].pausetime-=multiplier;
4708 if(player[i].lastseentime>1)
4709 player[i].lastseentime=1;
4711 if(player[i].aiupdatedelay<0){
4712 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
4713 player[i].targetyaw=roughDirectionTo(player[i].coords,player[i].waypoints[player[i].waypoint]);
4714 player[i].lookyaw=player[i].targetyaw;
4715 player[i].aiupdatedelay=.05;
4717 if(distsqflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
4718 if(player[i].waypointtype[player[i].waypoint]==wppause)
4719 player[i].pausetime=4;
4720 player[i].waypoint++;
4721 if(player[i].waypoint>player[i].numwaypoints-1)
4722 player[i].waypoint=0;
4727 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)
4728 player[i].forwardkeydown=1;
4730 player[i].forwardkeydown=0;
4731 player[i].leftkeydown=0;
4732 player[i].backkeydown=0;
4733 player[i].rightkeydown=0;
4734 player[i].crouchkeydown=0;
4735 player[i].attackkeydown=0;
4736 player[i].throwkeydown=0;
4738 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4739 if(!player[i].avoidsomething)
4740 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
4742 XYZ leftpos,rightpos;
4743 float leftdist,rightdist;
4744 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4745 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4746 leftdist = distsq(&leftpos, &player[i].avoidwhere);
4747 rightdist = distsq(&rightpos, &player[i].avoidwhere);
4748 if(leftdist<rightdist)
4749 player[i].targetyaw+=90;
4751 player[i].targetyaw-=90;
4755 if(player[i].collided<1||player[i].animTarget!=jumpupanim)
4756 player[i].jumpkeydown=0;
4757 if((player[i].collided>.8&&player[i].jumppower>=5))
4758 player[i].jumpkeydown=1;
4763 if(player[i].howactive<=typesleeping)
4764 if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
4765 for(int j=0;j<numenvsounds;j++){
4766 float vol=player[i].howactive==typesleeping?envsoundvol[j]-14:envsoundvol[j];
4767 if(vol>0&&distsq(&player[i].coords,&envsound[j])<
4768 2*(vol+vol*(player[i].creature==rabbittype)*3))
4769 player[i].aitype=attacktypecutoff;
4772 if(player[i].aitype!=passivetype){
4773 if(player[i].howactive==typesleeping)
4774 player[i].setAnimation(getupfromfrontanim);
4775 player[i].howactive=typeactive;
4779 if(player[i].howactive<typesleeping&&
4780 ((tutoriallevel!=1||cananger)&&hostile)&&
4782 distsq(&player[i].coords,&player[0].coords)<400&&
4783 player[i].occluded<25){
4784 if(distsq(&player[i].coords,&player[0].coords)<12&&
4785 animation[player[0].animTarget].height!=lowheight&&!editorenabled)
4786 player[i].aitype=attacktypecutoff;
4787 if(distsq(&player[i].coords,&player[0].coords)<30&&
4788 animation[player[0].animTarget].height==highheight&&!editorenabled)
4789 player[i].aitype=attacktypecutoff;
4792 if(player[i].creature==wolftype){
4794 for(int j=0;j<numplayers;j++){
4795 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
4796 float smelldistance=50;
4797 if(j==0&&player[j].num_weapons>0){
4798 if(weapons[player[j].weaponids[0]].bloody)
4800 if(player[j].num_weapons==2)
4801 if(weapons[player[j].weaponids[1]].bloody)
4806 windsmell=windvector;
4807 Normalise(&windsmell);
4808 windsmell=windsmell*2+player[j].coords;
4809 if(distsq(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
4810 player[i].aitype=attacktypecutoff;
4815 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
4816 player[i].losupdatedelay=.2;
4817 for(int j=0;j<numplayers;j++){
4818 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
4819 if(abs(Random()%2)||animation[player[j].animTarget].height!=lowheight||j!=0)
4820 if(distsq(&player[i].coords,&player[j].coords)<400)
4821 if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
4822 if((-1==checkcollide(
4823 DoRotation(player[i].jointPos(head),0,player[i].yaw,0)*
4824 player[i].scale+player[i].coords,
4825 DoRotation(player[j].jointPos(head),0,player[j].yaw,0)*
4826 player[j].scale+player[j].coords)&&
4827 !player[j].isWallJump())||
4828 (player[j].animTarget==hanganim&&
4829 normaldotproduct(player[j].facing,player[i].coords-player[j].coords)<0)){
4830 player[i].lastseentime-=.2;
4831 if(j==0&&animation[player[j].animTarget].height==lowheight)
4832 player[i].lastseentime-=.4;
4834 player[i].lastseentime-=.6;
4836 if(player[i].lastseentime<=0){
4837 player[i].aitype=searchtype;
4838 player[i].lastchecktime=12;
4839 player[i].lastseen=player[j].coords;
4840 player[i].lastseentime=12;
4847 if(player[i].aitype==attacktypecutoff&&musictype!=2){
4848 if(player[i].creature!=wolftype){
4849 player[i].stunned=.6;
4850 player[i].surprised=.6;
4852 if(player[i].creature==wolftype){
4853 player[i].stunned=.47;
4854 player[i].surprised=.47;
4862 if(player[i].aitype==searchtype){
4863 player[i].aiupdatedelay-=multiplier;
4864 player[i].losupdatedelay-=multiplier;
4865 if(!player[i].pause)
4866 player[i].lastseentime-=multiplier;
4867 player[i].lastchecktime-=multiplier;
4869 if(player[i].isRun()&&!player[i].onground){
4870 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
4871 XYZ test2=player[i].coords+player[i].facing;
4873 XYZ test=player[i].coords+player[i].facing;
4875 j=checkcollide(test2,test,player[i].laststanding);
4877 j=checkcollide(test2,test);
4879 player[i].velocity=0;
4880 player[i].setAnimation(player[i].getStop());
4881 player[i].targetyaw+=180;
4882 player[i].stunned=.5;
4883 //player[i].aitype=passivetype;
4884 player[i].aitype=pathfindtype;
4885 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4886 player[i].finalpathfindpoint=-1;
4887 player[i].targetpathfindpoint=-1;
4888 player[i].lastpathfindpoint=-1;
4889 player[i].lastpathfindpoint2=-1;
4890 player[i].lastpathfindpoint3=-1;
4891 player[i].lastpathfindpoint4=-1;
4893 else player[i].laststanding=j;
4896 //check out last seen location
4897 if(player[i].aiupdatedelay<0){
4898 player[i].targetyaw=roughDirectionTo(player[i].coords,player[i].lastseen);
4899 player[i].lookyaw=player[i].targetyaw;
4900 player[i].aiupdatedelay=.05;
4901 player[i].forwardkeydown=1;
4903 if(distsqflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){
4904 player[i].forwardkeydown=0;
4905 player[i].aiupdatedelay=1;
4906 player[i].lastseen.x+=(float(Random()%100)-50)/25;
4907 player[i].lastseen.z+=(float(Random()%100)-50)/25;
4908 player[i].lastchecktime=3;
4911 player[i].leftkeydown=0;
4912 player[i].backkeydown=0;
4913 player[i].rightkeydown=0;
4914 player[i].crouchkeydown=0;
4915 player[i].attackkeydown=0;
4916 player[i].throwkeydown=0;
4918 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
4919 if(!player[i].avoidsomething)player[i].targetyaw+=90*(player[i].whichdirection*2-1);
4921 XYZ leftpos,rightpos;
4922 float leftdist,rightdist;
4923 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
4924 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
4925 leftdist = distsq(&leftpos, &player[i].avoidwhere);
4926 rightdist = distsq(&rightpos, &player[i].avoidwhere);
4927 if(leftdist<rightdist)player[i].targetyaw+=90;
4928 else player[i].targetyaw-=90;
4932 if(player[i].collided<1||player[i].animTarget!=jumpupanim)
4933 player[i].jumpkeydown=0;
4934 if((player[i].collided>.8&&player[i].jumppower>=5))
4935 player[i].jumpkeydown=1;
4937 if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
4938 for(int k=0;k<numenvsounds;k++){
4939 if(distsq(&player[i].coords,&envsound[k])<2*(envsoundvol[k]+envsoundvol[k]*(player[i].creature==rabbittype)*3)){
4940 player[i].aitype=attacktypecutoff;
4944 if(!player[0].dead&&
4945 player[i].losupdatedelay<0&&
4947 player[i].occluded<2&&
4948 ((tutoriallevel!=1||cananger)&&hostile)){
4949 player[i].losupdatedelay=.2;
4950 if(distsq(&player[i].coords,&player[0].coords)<4&&animation[player[i].animTarget].height!=lowheight){
4951 player[i].aitype=attacktypecutoff;
4952 player[i].lastseentime=1;
4954 if(abs(Random()%2)||animation[player[i].animTarget].height!=lowheight)
4955 //TODO: factor out canSeePlayer()
4956 if(distsq(&player[i].coords,&player[0].coords)<400)
4957 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
4959 DoRotation(player[i].jointPos(head),0,player[i].yaw,0)*
4960 player[i].scale+player[i].coords,
4961 DoRotation(player[0].jointPos(head),0,player[0].yaw,0)*
4962 player[0].scale+player[0].coords)==-1)||
4963 (player[0].animTarget==hanganim&&normaldotproduct(
4964 player[0].facing,player[i].coords-player[0].coords)<0)){
4965 /* //TODO: changed j to 0 on a whim, make sure this is correct
4966 (player[j].animTarget==hanganim&&normaldotproduct(
4967 player[j].facing,player[i].coords-player[j].coords)<0)
4969 player[i].aitype=attacktypecutoff;
4970 player[i].lastseentime=1;
4974 if(player[i].lastseentime<0){
4975 //player[i].aitype=passivetype;
4977 player[i].aitype=pathfindtype;
4978 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
4979 player[i].finalpathfindpoint=-1;
4980 player[i].targetpathfindpoint=-1;
4981 player[i].lastpathfindpoint=-1;
4982 player[i].lastpathfindpoint2=-1;
4983 player[i].lastpathfindpoint3=-1;
4984 player[i].lastpathfindpoint4=-1;
4988 if(player[i].aitype!=gethelptype)
4989 player[i].runninghowlong=0;
4991 //get help from buddies
4992 if(player[i].aitype==gethelptype) {
4993 player[i].runninghowlong+=multiplier;
4994 player[i].aiupdatedelay-=multiplier;
4996 if(player[i].aiupdatedelay<0||player[i].ally==0) {
4997 player[i].aiupdatedelay=.2;
5000 //TODO: factor out closest search somehow
5001 if(!player[i].ally) {
5003 float closestdist=-1;
5004 for(int k=0;k<numplayers;k++) {
5005 if(k!=i&&k!=0&&!player[k].dead&&
5006 player[k].howactive<typedead1&&
5007 !player[k].skeleton.free&&
5008 player[k].aitype==passivetype) {
5009 float distance=distsq(&player[i].coords,&player[k].coords);
5010 if(closestdist==-1||distance<closestdist) {
5011 closestdist=distance;
5018 player[i].ally=closest;
5021 player[i].lastseen=player[0].coords;
5022 player[i].lastseentime=12;
5026 player[i].lastchecktime=12;
5028 XYZ facing=player[i].coords;
5029 XYZ flatfacing=player[player[i].ally].coords;
5030 facing.y+=player[i].jointPos(head).y*player[i].scale;
5031 flatfacing.y+=player[player[i].ally].jointPos(head).y*player[player[i].ally].scale;
5032 if(-1!=checkcollide(facing,flatfacing))
5033 player[i].lastseentime-=.1;
5035 //no available ally, run back to player
5036 if(player[i].ally<=0||
5037 player[player[i].ally].skeleton.free||
5038 player[player[i].ally].aitype!=passivetype||
5039 player[i].lastseentime<=0){
5040 player[i].aitype=searchtype;
5041 player[i].lastseentime=12;
5045 if(player[i].ally>0){
5046 player[i].targetyaw=roughDirectionTo(player[i].coords,player[player[i].ally].coords);
5047 player[i].lookyaw=player[i].targetyaw;
5048 player[i].aiupdatedelay=.05;
5049 player[i].forwardkeydown=1;
5051 if(distsqflat(&player[i].coords,&player[player[i].ally].coords)<3){
5052 player[i].aitype=searchtype;
5053 player[i].lastseentime=12;
5054 player[player[i].ally].aitype=searchtype;
5055 if(player[player[i].ally].lastseentime<player[i].lastseentime){
5056 player[player[i].ally].lastseen=player[i].lastseen;
5057 player[player[i].ally].lastseentime=player[i].lastseentime;
5058 player[player[i].ally].lastchecktime=player[i].lastchecktime;
5062 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5063 if(!player[i].avoidsomething)
5064 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5066 XYZ leftpos,rightpos;
5067 float leftdist,rightdist;
5068 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5069 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5070 leftdist = distsq(&leftpos, &player[i].avoidwhere);
5071 rightdist = distsq(&rightpos, &player[i].avoidwhere);
5072 if(leftdist<rightdist)
5073 player[i].targetyaw+=90;
5075 player[i].targetyaw-=90;
5080 player[i].leftkeydown=0;
5081 player[i].backkeydown=0;
5082 player[i].rightkeydown=0;
5083 player[i].crouchkeydown=0;
5084 player[i].attackkeydown=0;
5086 if(player[i].collided<1||player[i].animTarget!=jumpupanim)
5087 player[i].jumpkeydown=0;
5088 if(player[i].collided>.8&&player[i].jumppower>=5)
5089 player[i].jumpkeydown=1;
5092 //retreiving a weapon on the ground
5093 if(player[i].aitype==getweapontype){
5094 player[i].aiupdatedelay-=multiplier;
5095 player[i].lastchecktime-=multiplier;
5097 if(player[i].aiupdatedelay<0){
5098 player[i].aiupdatedelay=.2;
5101 if(player[i].ally<0){
5103 float closestdist=-1;
5104 for(int k=0;k<weapons.size();k++)
5105 if(weapons[k].owner==-1){
5106 float distance=distsq(&player[i].coords,&weapons[k].position);
5107 if(closestdist==-1||distance<closestdist){
5108 closestdist=distance;
5114 player[i].ally=closest;
5119 player[i].lastseentime=12;
5121 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
5122 if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
5123 player[i].aitype=attacktypecutoff;
5124 player[i].lastseentime=1;
5127 if(player[i].ally>=0){
5128 if(weapons[player[i].ally].owner!=-1||
5129 distsq(&player[i].coords,&weapons[player[i].ally].position)>16){
5130 player[i].aitype=attacktypecutoff;
5131 player[i].lastseentime=1;
5133 //TODO: factor these out as moveToward()
5134 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[player[i].ally].position);
5135 player[i].lookyaw=player[i].targetyaw;
5136 player[i].aiupdatedelay=.05;
5137 player[i].forwardkeydown=1;
5140 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
5141 if(!player[i].avoidsomething)
5142 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5144 XYZ leftpos,rightpos;
5145 float leftdist,rightdist;
5146 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
5147 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
5148 leftdist = distsq(&leftpos, &player[i].avoidwhere);
5149 rightdist = distsq(&rightpos, &player[i].avoidwhere);
5150 if(leftdist<rightdist)
5151 player[i].targetyaw+=90;
5153 player[i].targetyaw-=90;
5158 player[i].leftkeydown=0;
5159 player[i].backkeydown=0;
5160 player[i].rightkeydown=0;
5161 player[i].attackkeydown=0;
5162 player[i].throwkeydown=1;
5163 player[i].crouchkeydown=0;
5164 if(player[i].animTarget!=crouchremoveknifeanim&&
5165 player[i].animTarget!=removeknifeanim)
5166 player[i].throwtogglekeydown=0;
5167 player[i].drawkeydown=0;
5169 if(player[i].collided<1||player[i].animTarget!=jumpupanim)
5170 player[i].jumpkeydown=0;
5171 if((player[i].collided>.8&&player[i].jumppower>=5))
5172 player[i].jumpkeydown=1;
5175 if(player[i].aitype==attacktypecutoff){
5176 player[i].aiupdatedelay-=multiplier;
5177 //dodge or reverse rabbit kicks, knife throws, flips
5178 if(player[i].damage<player[i].damagetolerance*2/3)
5179 if((player[0].animTarget==rabbitkickanim||
5180 player[0].animTarget==knifethrowanim||
5181 (player[0].isFlip()&&
5182 normaldotproduct(player[0].facing,player[0].coords-player[i].coords)<0))&&
5183 !player[0].skeleton.free&&
5184 (player[i].aiupdatedelay<.1)){
5185 player[i].attackkeydown=0;
5186 if(player[i].isIdle())
5187 player[i].crouchkeydown=1;
5188 if(player[0].animTarget!=rabbitkickanim&&player[0].weaponactive!=-1){
5189 if(weapons[player[0].weaponids[0]].getType()==knife){
5190 if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
5191 if(abs(Random()%2==0))
5192 player[i].setAnimation(backhandspringanim);
5194 player[i].setAnimation(rollanim);
5195 player[i].targetyaw+=90*(abs(Random()%2)*2-1);
5196 player[i].wentforweapon=0;
5198 if(player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim)
5199 player[i].setAnimation(flipanim);
5202 player[i].forwardkeydown=0;
5203 player[i].aiupdatedelay=.02;
5205 //get confused by flips
5206 if(player[0].isFlip()&&
5207 !player[0].skeleton.free&&
5208 player[0].animTarget!=walljumprightkickanim&&
5209 player[0].animTarget!=walljumpleftkickanim){
5210 if(distsq(&player[0].coords,&player[i].coords)<25)
5211 if((1-player[i].damage/player[i].damagetolerance)>.5)
5212 player[i].stunned=1;
5214 //go for weapon on the ground
5215 if(player[i].wentforweapon<3)
5216 for(int k=0;k<weapons.size();k++)
5217 if(player[i].creature!=wolftype)
5218 if(player[i].num_weapons==0&&
5219 weapons[k].owner==-1&&
5220 weapons[i].velocity.x==0&&
5221 weapons[i].velocity.z==0&&
5222 weapons[i].velocity.y==0){
5223 if(distsq(&player[i].coords,&weapons[k].position)<16) {
5224 player[i].wentforweapon++;
5225 player[i].lastchecktime=6;
5226 player[i].aitype=getweapontype;
5230 //dodge/reverse walljump kicks
5231 if(player[i].damage<player[i].damagetolerance/2)
5232 if(animation[player[i].animTarget].height!=highheight)
5233 if(player[i].damage<player[i].damagetolerance*.5&&
5234 ((player[0].animTarget==walljumprightkickanim||
5235 player[0].animTarget==walljumpleftkickanim)&&
5236 ((player[i].aiupdatedelay<.15&&
5238 (player[i].aiupdatedelay<.08&&
5240 player[i].crouchkeydown=1;
5242 //walked off a ledge (?)
5243 if(player[i].isRun()&&!player[i].onground)
5244 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
5245 XYZ test2=player[i].coords+player[i].facing;
5247 XYZ test=player[i].coords+player[i].facing;
5249 j=checkcollide(test2,test,player[i].laststanding);
5251 j=checkcollide(test2,test);
5253 player[i].velocity=0;
5254 player[i].setAnimation(player[i].getStop());
5255 player[i].targetyaw+=180;
5256 player[i].stunned=.5;
5257 player[i].aitype=pathfindtype;
5258 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5259 player[i].finalpathfindpoint=-1;
5260 player[i].targetpathfindpoint=-1;
5261 player[i].lastpathfindpoint=-1;
5262 player[i].lastpathfindpoint2=-1;
5263 player[i].lastpathfindpoint3=-1;
5264 player[i].lastpathfindpoint4=-1;
5266 player[i].laststanding=j;
5268 //lose sight of player in the air (?)
5269 if(player[0].coords.y>player[i].coords.y+5&&
5270 animation[player[0].animTarget].height!=highheight&&
5271 !player[0].onterrain){
5272 player[i].aitype=pathfindtype;
5273 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5274 player[i].finalpathfindpoint=-1;
5275 player[i].targetpathfindpoint=-1;
5276 player[i].lastpathfindpoint=-1;
5277 player[i].lastpathfindpoint2=-1;
5278 player[i].lastpathfindpoint3=-1;
5279 player[i].lastpathfindpoint4=-1;
5281 //it's time to think (?)
5282 if(player[i].aiupdatedelay<0&&
5283 !animation[player[i].animTarget].attack&&
5284 player[i].animTarget!=staggerbackhighanim&&
5285 player[i].animTarget!=staggerbackhardanim&&
5286 player[i].animTarget!=backhandspringanim&&
5287 player[i].animTarget!=dodgebackanim){
5289 if(player[i].weaponactive==-1&&player[i].num_weapons>0)
5290 player[i].drawkeydown=Random()%2;
5292 player[i].drawkeydown=0;
5293 player[i].rabbitkickenabled=Random()%2;
5295 XYZ rotatetarget=player[0].coords+player[0].velocity;
5296 XYZ targetpoint=player[0].coords;
5297 if(distsq(&player[0].coords,&player[i].coords)<
5298 distsq(&rotatetarget,&player[i].coords))
5299 targetpoint+=player[0].velocity*
5300 findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity);
5301 player[i].targetyaw=roughDirectionTo(player[i].coords,targetpoint);
5302 player[i].lookyaw=player[i].targetyaw;
5303 player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000);
5305 if(distsq(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))
5306 player[i].forwardkeydown=1;
5307 else if((distsq(&player[i].coords,&player[0].coords)>16||
5308 distsq(&player[i].coords,&player[0].coords)<9)&&
5309 player[0].weaponactive!=-1)
5310 player[i].forwardkeydown=1;
5311 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))
5312 player[i].forwardkeydown=1;
5314 player[i].forwardkeydown=0;
5315 //chill out around the corpse
5317 player[i].forwardkeydown=0;
5319 player[i].forwardkeydown=1;
5320 if(Random()%100==0){
5321 player[i].aitype=pathfindtype;
5322 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
5323 player[i].finalpathfindpoint=-1;
5324 player[i].targetpathfindpoint=-1;
5325 player[i].lastpathfindpoint=-1;
5326 player[i].lastpathfindpoint2=-1;
5327 player[i].lastpathfindpoint3=-1;
5328 player[i].lastpathfindpoint4=-1;
5331 player[i].leftkeydown=0;
5332 player[i].backkeydown=0;
5333 player[i].rightkeydown=0;
5334 player[i].crouchkeydown=0;
5335 player[i].throwkeydown=0;
5337 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)
5338 player[i].targetyaw+=90*(player[i].whichdirection*2-1);
5340 if(Random()%2==0||player[i].weaponactive!=-1||player[i].creature==wolftype)
5341 player[i].attackkeydown=1;
5343 player[i].attackkeydown=0;
5344 if(player[i].isRun()&&Random()%6&&distsq(&player[i].coords,&player[0].coords)>7)
5345 player[i].attackkeydown=0;
5348 if(player[i].aitype!=playercontrolled&&
5349 (player[i].isIdle()||
5350 player[i].isCrouch()||
5351 player[i].isRun())){
5353 for(int j=0;j<numplayers;j++)
5354 if(j!=i&&!player[j].skeleton.free&&
5355 player[j].hasvictim&&
5356 (tutoriallevel==1&&reversaltrain||
5357 Random()%2==0&&difficulty==2||
5358 Random()%4==0&&difficulty==1||
5359 Random()%8==0&&difficulty==0||
5360 player[j].lastattack2==player[j].animTarget&&
5361 player[j].lastattack3==player[j].animTarget&&
5362 (Random()%2==0||difficulty==2)||
5363 (player[i].isIdle()||player[i].isRun())&&
5364 player[j].weaponactive!=-1||
5365 player[j].animTarget==swordslashanim&&
5366 player[i].weaponactive!=-1||
5367 player[j].animTarget==staffhitanim||
5368 player[j].animTarget==staffspinhitanim))
5369 if(distsq(&player[j].coords,&player[j].victim->coords)<4&&
5370 player[j].victim==&player[i]&&
5371 (player[j].animTarget==sweepanim||
5372 player[j].animTarget==spinkickanim||
5373 player[j].animTarget==staffhitanim||
5374 player[j].animTarget==staffspinhitanim||
5375 player[j].animTarget==winduppunchanim||
5376 player[j].animTarget==upunchanim||
5377 player[j].animTarget==wolfslapanim||
5378 player[j].animTarget==knifeslashstartanim||
5379 player[j].animTarget==swordslashanim&&
5380 (distsq(&player[j].coords,&player[i].coords)<2||
5381 player[i].weaponactive!=-1))){
5388 player[target].Reverse();
5391 if(player[i].collided<1)
5392 player[i].jumpkeydown=0;
5393 if(player[i].collided>.8&&player[i].jumppower>=5||
5394 distsq(&player[i].coords,&player[0].coords)>400&&
5395 player[i].onterrain&&
5396 player[i].creature==rabbittype)
5397 player[i].jumpkeydown=1;
5398 //TODO: why are we controlling the human?
5399 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
5400 player[0].jumpkeydown=0;
5401 if(player[0].animTarget==jumpdownanim&&
5402 distsq(&player[0].coords,&player[i].coords)<40)
5403 player[i].crouchkeydown=1;
5404 if(player[i].jumpkeydown)
5405 player[i].attackkeydown=0;
5407 if(tutoriallevel==1)
5409 player[i].attackkeydown=0;
5412 XYZ facing=player[i].coords;
5413 XYZ flatfacing=player[0].coords;
5414 facing.y+=player[i].jointPos(head).y*player[i].scale;
5415 flatfacing.y+=player[0].jointPos(head).y*player[0].scale;
5416 if(player[i].occluded>=2)
5417 if(-1!=checkcollide(facing,flatfacing)){
5418 if(!player[i].pause)
5419 player[i].lastseentime-=.2;
5420 if(player[i].lastseentime<=0&&
5421 (player[i].creature!=wolftype||
5422 player[i].weaponstuck==-1)){
5423 player[i].aitype=searchtype;
5424 player[i].lastchecktime=12;
5425 player[i].lastseen=player[0].coords;
5426 player[i].lastseentime=12;
5429 player[i].lastseentime=1;
5432 if(animation[player[0].animTarget].height==highheight&&
5433 (player[i].aitype==attacktypecutoff||
5434 player[i].aitype==searchtype))
5435 if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
5436 XYZ test=player[0].coords;
5438 if(-1==checkcollide(player[0].coords,test))
5439 player[i].stunned=1;
5442 if(player[i].aitype==passivetype&&!(player[i].numwaypoints>1)||
5443 player[i].stunned>0||
5444 player[i].pause&&player[i].damage>player[i].superpermanentdamage){
5446 player[i].lastseentime=1;
5447 player[i].targetyaw=player[i].yaw;
5448 player[i].forwardkeydown=0;
5449 player[i].leftkeydown=0;
5450 player[i].backkeydown=0;
5451 player[i].rightkeydown=0;
5452 player[i].jumpkeydown=0;
5453 player[i].attackkeydown=0;
5454 player[i].crouchkeydown=0;
5455 player[i].throwkeydown=0;
5463 XYZ flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
5466 if(player[i].aitype==attacktypecutoff){
5467 player[i].targetheadyaw=180-roughDirectionTo(player[i].coords,player[0].coords);
5468 player[i].targetheadpitch=pitchTo(player[i].coords,player[0].coords);
5469 }else if(player[i].howactive>=typesleeping){
5470 player[i].targetheadyaw=player[i].targetyaw;
5471 player[i].targetheadpitch=0;
5473 if(player[i].interestdelay<=0){
5474 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
5475 player[i].headtarget=player[i].coords;
5476 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
5477 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
5478 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
5479 player[i].headtarget+=player[i].facing*1.5;
5481 player[i].targetheadyaw=180-roughDirectionTo(player[i].coords,player[i].headtarget);
5482 player[i].targetheadpitch=pitchTo(player[i].coords,player[i].headtarget);
5489 void updateSettingsMenu(){
5491 if((float)newscreenwidth>(float)newscreenheight*1.61||(float)newscreenwidth<(float)newscreenheight*1.59)
5492 sprintf (sbuf, "Resolution: %d*%d",(int)newscreenwidth,(int)newscreenheight);
5494 sprintf (sbuf, "Resolution: %d*%d (widescreen)",(int)newscreenwidth,(int)newscreenheight);
5495 Menu::setText(0,sbuf);
5496 if(newdetail==0) Menu::setText(1,"Detail: Low");
5497 if(newdetail==1) Menu::setText(1,"Detail: Medium");
5498 if(newdetail==2) Menu::setText(1,"Detail: High");
5499 if(bloodtoggle==0) Menu::setText(2,"Blood: Off");
5500 if(bloodtoggle==1) Menu::setText(2,"Blood: On, low detail");
5501 if(bloodtoggle==2) Menu::setText(2,"Blood: On, high detail (slower)");
5502 if(difficulty==0) Menu::setText(3,"Difficulty: Easier");
5503 if(difficulty==1) Menu::setText(3,"Difficulty: Difficult");
5504 if(difficulty==2) Menu::setText(3,"Difficulty: Insane");
5505 Menu::setText(4,ismotionblur?"Blur Effects: Enabled (less compatible)":"Blur Effects: Disabled (more compatible)");
5506 Menu::setText(5,decals?"Decals: Enabled (slower)":"Decals: Disabled");
5507 Menu::setText(6,musictoggle?"Music: Enabled":"Music: Disabled");
5508 Menu::setText(9,invertmouse?"Invert mouse: Yes":"Invert mouse: No");
5509 sprintf (sbuf, "Mouse Speed: %d", (int)(usermousesensitivity*5));
5510 Menu::setText(10,sbuf);
5511 sprintf (sbuf, "Volume: %d%%", (int)(volume*100));
5512 Menu::setText(11,sbuf);
5513 Menu::setText(13,showdamagebar?"Damage Bar: On":"Damage Bar: Off");
5514 if(newdetail==detail&&newscreenheight==(int)screenheight&&newscreenwidth==(int)screenwidth)
5515 sprintf (sbuf, "Back");
5517 sprintf (sbuf, "Back (some changes take effect next time Lugaru is opened)");
5518 Menu::setText(8,sbuf);
5521 void updateStereoConfigMenu(){
5523 sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode));
5524 Menu::setText(0,sbuf);
5525 sprintf(sbuf, "Stereo separation: %.3f", stereoseparation);
5526 Menu::setText(1,sbuf);
5527 sprintf(sbuf, "Reverse stereo: %s", stereoreverse ? "Yes" : "No");
5528 Menu::setText(2,sbuf);
5531 void updateControlsMenu(){
5532 Menu::setText(0,(string)"Forwards: "+(keyselect==0?"_":Input::keyToChar(forwardkey)));
5533 Menu::setText(1,(string)"Back: " +(keyselect==1?"_":Input::keyToChar(backkey)));
5534 Menu::setText(2,(string)"Left: " +(keyselect==2?"_":Input::keyToChar(leftkey)));
5535 Menu::setText(3,(string)"Right: " +(keyselect==3?"_":Input::keyToChar(rightkey)));
5536 Menu::setText(4,(string)"Crouch: " +(keyselect==4?"_":Input::keyToChar(crouchkey)));
5537 Menu::setText(5,(string)"Jump: " +(keyselect==5?"_":Input::keyToChar(jumpkey)));
5538 Menu::setText(6,(string)"Draw: " +(keyselect==6?"_":Input::keyToChar(drawkey)));
5539 Menu::setText(7,(string)"Throw: " +(keyselect==7?"_":Input::keyToChar(throwkey)));
5540 Menu::setText(8,(string)"Attack: " +(keyselect==8?"_":Input::keyToChar(attackkey)));
5542 Menu::setText(9,(string)"Console: "+(keyselect==9?"_":Input::keyToChar(consolekey)));
5546 Values of mainmenu :
5548 2 Menu pause (resume/end game)
5550 4 Controls configuration menu
5551 5 Main game menu (choose level or challenge)
5552 6 Deleting user menu
5553 7 User managment menu (select/add)
5554 8 Choose difficulty menu
5555 9 Challenge level selection menu
5556 10 End of the campaign congratulation (is that really a menu?)
5557 11 Same that 9 ??? => unused
5558 18 stereo configuration
5561 void Game::LoadMenu(){
5566 Menu::addImage(0,Mainmenuitems[0],150,480-128,256,128);
5567 Menu::addButtonImage(1,Mainmenuitems[mainmenu==1?1:5],18,480-152-32,128,32);
5568 Menu::addButtonImage(2,Mainmenuitems[2],18,480-228-32,112,32);
5569 Menu::addButtonImage(3,Mainmenuitems[mainmenu==1?3:6],18,480-306-32,mainmenu==1?68:132,32);
5572 Menu::addButton( 0,"",10+20,440);
5573 Menu::addButton( 1,"",10+60,405);
5574 Menu::addButton( 2,"",10+70,370);
5575 Menu::addButton( 3,"",10+20-1000,335-1000);
5576 Menu::addButton( 4,"",10 ,335);
5577 Menu::addButton( 5,"",10+60,300);
5578 Menu::addButton( 6,"",10+70,265);
5579 Menu::addButton( 9,"",10 ,230);
5580 Menu::addButton(10,"",20 ,195);
5581 Menu::addButton(11,"",10+60,160);
5582 Menu::addButton(13,"",30 ,125);
5583 Menu::addButton( 7,"-Configure Controls-",10+15, 90);
5584 Menu::addButton(12,"-Configure Stereo -",10+15, 55);
5585 Menu::addButton(8,"Back",10,10);
5586 updateSettingsMenu();
5589 Menu::addButton(0,"",10 ,400);
5590 Menu::addButton(1,"",10+40,360);
5591 Menu::addButton(2,"",10+40,320);
5592 Menu::addButton(3,"",10+30,280);
5593 Menu::addButton(4,"",10+20,240);
5594 Menu::addButton(5,"",10+40,200);
5595 Menu::addButton(6,"",10+40,160);
5596 Menu::addButton(7,"",10+30,120);
5597 Menu::addButton(8,"",10+20,80);
5599 Menu::addButton(9,"",10+10,40);
5600 Menu::addButton(debugmode?10:9,"Back",10,10);
5601 updateControlsMenu();
5605 Menu::addLabel(-1,accountactive->getName(),5,400);
5606 Menu::addButton(1,"Tutorial",5,300);
5607 Menu::addButton(2,"Challenge",5,240);
5608 Menu::addButton(3,"Delete User",400,10);
5609 Menu::addButton(4,"Main Menu",5,10);
5610 Menu::addButton(5,"Change User",5,180);
5611 Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),200,420);
5614 //with (2,-5) offset from old code
5615 Menu::addImage(-1,Mainmenuitems[7],150+2,60-5,400,400);
5617 int numlevels = accountactive->getCampaignChoicesMade();
5618 numlevels += numlevels>0 ? campaignlevels[numlevels-1].nextlevel.size() : 1;
5619 for(int i=0;i<numlevels;i++){
5620 XYZ midpoint=campaignlevels[i].getCenter();
5621 float itemsize=campaignlevels[i].getWidth();
5622 const bool active=i>=accountactive->getCampaignChoicesMade();
5627 XYZ start=campaignlevels[i-1].getCenter();
5628 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);
5630 Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture,
5631 midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0);
5634 Menu::addMapLabel(-2,campaignlevels[i].description,
5635 campaignlevels[i].getStartX()+10,
5636 campaignlevels[i].getStartY()-4);
5641 Menu::addLabel(-1,"Are you sure you want to delete this user?",10,400);
5642 Menu::addButton(1,"Yes",10,360);
5643 Menu::addButton(2,"No",10,320);
5646 if(Account::getNbAccounts()<8)
5647 Menu::addButton(0,"New User",10,400);
5649 Menu::addLabel(0,"No More Users",10,400);
5650 Menu::addLabel(-2,"",20,400);
5651 Menu::addButton(Account::getNbAccounts()+1,"Back",10,10);
5652 for(int i=0;i<Account::getNbAccounts();i++)
5653 Menu::addButton(i+1,Account::get(i)->getName(),10,340-20*(i+1));
5656 Menu::addButton(0,"Easier",10,400);
5657 Menu::addButton(1,"Difficult",10,360);
5658 Menu::addButton(2,"Insane",10,320);
5661 for(int i=0;i<numchallengelevels;i++){
5664 sprintf (temp, "Level %d",i+1);
5665 for(int j=strlen(temp);j<17;j++)
5668 sprintf (temp, "%d",(int)accountactive->getHighScore(i));
5669 for(int j=strlen(temp);j<(32-17);j++)
5672 sprintf (temp, "%d:",(int)(((int)accountactive->getFastTime(i)-(int)(accountactive->getFastTime(i))%60)/60));
5673 if((int)(accountactive->getFastTime(i))%60<10)strcat(temp,"0");
5675 sprintf (temp, "%d",(int)(accountactive->getFastTime(i))%60);
5678 Menu::addButton(i,name,10,400-i*25,i>accountactive->getProgress()?0.5:1,0,0);
5681 Menu::addButton(-1," High Score Best Time",10,440);
5682 Menu::addButton(numchallengelevels,"Back",10,10);
5685 Menu::addLabel(0,"Congratulations!",220,330);
5686 Menu::addLabel(1,"You have avenged your family and",140,300);
5687 Menu::addLabel(2,"restored peace to the island of Lugaru.",110,270);
5688 Menu::addButton(3,"Back",10,10);
5690 sprintf(sbuf,"Your score: %d",(int)accountactive->getCampaignScore());
5691 Menu::addLabel(4,sbuf,190,200);
5692 sprintf(sbuf,"Highest score: %d",(int)accountactive->getCampaignHighScore());
5693 Menu::addLabel(5,sbuf,190,180);
5696 Menu::addButton(0,"",70,400);
5697 Menu::addButton(1,"",10,360);
5698 Menu::addButton(2,"",40,320);
5699 Menu::addButton(3,"Back",10,10);
5700 updateStereoConfigMenu();
5705 extern SDL_Rect **resolutions;
5709 selected=Menu::getSelected(mousecoordh*640/screenwidth,480-mousecoordv*480/screenheight);
5711 // some specific case where we do something even if the left mouse button is not pressed.
5712 if((mainmenu==5) && (endgame==2)) {
5713 accountactive->endGame();
5718 if(mainmenu==18 && Input::isKeyPressed(MOUSEBUTTON2) && selected==1){
5719 stereoseparation-=0.001;
5720 updateStereoConfigMenu();
5723 static int oldmainmenu=mainmenu;
5727 if(Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
5733 if(gameon) { //resume
5735 pause_sound(stream_menutheme);
5736 resume_stream(leveltheme);
5738 fireSound(firestartsound);
5740 mainmenu=(accountactive?5:7);
5748 if(newdetail>2) newdetail=detail;
5749 if(newdetail<0) newdetail=detail;
5750 if(newscreenwidth>3000) newscreenwidth=screenwidth;
5751 if(newscreenwidth<0) newscreenwidth=screenwidth;
5752 if(newscreenheight>3000) newscreenheight=screenheight;
5753 if(newscreenheight<0) newscreenheight=screenheight;
5758 if(gameon){ //end game
5763 pause_sound(stream_menutheme);
5770 bool isCustomResolution,found;
5773 isCustomResolution = true;
5775 for(int i = 0; (!found) && (resolutions[i]); i++) {
5776 if((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
5777 isCustomResolution = false;
5779 if((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
5781 if(resolutions[i] != NULL) {
5782 newscreenwidth = (int) resolutions[i]->w;
5783 newscreenheight = (int) resolutions[i]->h;
5784 } else if(isCustomResolution){
5785 if((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
5786 newscreenwidth = (int) resolutions[0]->w;
5787 newscreenheight = (int) resolutions[0]->h;
5789 newscreenwidth = screenwidth;
5790 newscreenheight = screenheight;
5793 newscreenwidth = (int) resolutions[0]->w;
5794 newscreenheight = (int) resolutions[0]->h;
5801 newscreenwidth = (int) resolutions[0]->w;
5802 newscreenheight = (int) resolutions[0]->h;
5807 if(newdetail>2) newdetail=0;
5811 if(bloodtoggle>2) bloodtoggle=0;
5815 if(difficulty>2) difficulty=0;
5818 ismotionblur = !ismotionblur;
5824 musictoggle = !musictoggle;
5826 emit_stream_np(stream_menutheme);
5828 pause_sound(leveltheme);
5829 pause_sound(stream_fighttheme);
5830 pause_sound(stream_menutheme);
5832 for(int i=0;i<4;i++){
5833 oldmusicvolume[i]=0;
5847 mainmenu=gameon?2:1;
5850 invertmouse = !invertmouse;
5853 usermousesensitivity+=.2;
5854 if(usermousesensitivity>2)
5855 usermousesensitivity=.2;
5861 OPENAL_SetSFXMasterVolume((int)(volume*255));
5865 newstereomode = stereomode;
5870 showdamagebar = !showdamagebar;
5873 updateSettingsMenu();
5878 if(selected<(debugmode?10:9) && keyselect==-1)
5882 if(selected==(debugmode?10:9)){
5887 updateControlsMenu();
5892 if((selected-NB_CAMPAIGN_MENU_ITEM >= accountactive->getCampaignChoicesMade())) {
5902 whichchoice=selected-NB_CAMPAIGN_MENU_ITEM-accountactive->getCampaignChoicesMade();
5903 actuallevel=(accountactive->getCampaignChoicesMade()>0?campaignlevels[accountactive->getCampaignChoicesMade()-1].nextlevel[whichchoice]:0);
5906 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
5910 pause_sound(stream_menutheme);
5927 pause_sound(stream_menutheme);
5936 mainmenu=(gameon?2:1);
5942 vector<string> campaigns = ListCampaigns();
5943 vector<string>::iterator c;
5944 if ((c = find(campaigns.begin(),campaigns.end(),accountactive->getCurrentCampaign()))==campaigns.end()) {
5945 if(!campaigns.empty())
5946 accountactive->setCurrentCampaign(campaigns.front());
5949 if(c==campaigns.end())
5950 c=campaigns.begin();
5951 accountactive->setCurrentCampaign(*c);
5961 accountactive = Account::destroy(accountactive);
5963 } else if(selected==2) {
5970 if(selected==0 && Account::getNbAccounts()<8){
5972 } else if (selected < Account::getNbAccounts()+1) {
5975 accountactive=Account::get(selected-1);
5976 } else if (selected == Account::getNbAccounts()+1) {
5982 for(int j=0;j<255;j++){
5983 displaytext[0][j]=0;
5994 accountactive->setDifficulty(selected);
5998 if(selected<numchallengelevels && selected<=accountactive->getProgress()){
6006 targetlevel=selected;
6011 Loadlevel(selected);
6016 pause_sound(stream_menutheme);
6018 if(selected==numchallengelevels){
6033 stereoseparation+=0.001;
6037 newstereomode = (StereoMode)(newstereomode + 1);
6038 while(!CanInitStereo(newstereomode)){
6039 printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
6040 newstereomode = (StereoMode)(newstereomode + 1);
6041 if(newstereomode >= stereoCount)
6042 newstereomode = stereoNone;
6044 } else if(selected==2) {
6045 stereoreverse = !stereoreverse;
6046 } else if(selected==3) {
6050 stereomode = newstereomode;
6051 InitStereo(stereomode);
6054 updateStereoConfigMenu();
6059 if(Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)){
6066 OPENAL_SetFrequency(channels[stream_menutheme], 22050);
6069 inputText(displaytext[0],&displayselected,&displaychars[0]);
6070 if(!waiting) { // the input as finished
6071 if(displaychars[0]){ // with enter
6072 accountactive = Account::add(string(displaytext[0]));
6078 fireSound(firestartsound);
6080 for(int i=0;i<255;i++){
6081 displaytext[0][i]=0;
6091 displayblinkdelay-=multiplier;
6092 if(displayblinkdelay<=0){
6093 displayblinkdelay=.3;
6094 displayblink=1-displayblink;
6099 Menu::setText(0,displaytext[0],20,400,-1,-1);
6100 Menu::setText(-2,displayblink?"_":"",20+displayselected*10,400,-1,-1);
6103 if(oldmainmenu!=mainmenu)
6105 oldmainmenu=mainmenu;
6110 static XYZ facing,flatfacing;
6113 for(int i=0;i<15;i++){
6114 displaytime[i]+=multiplier;
6117 keyboardfrozen=false;
6120 if(Input::isKeyPressed(SDLK_F6)){
6121 if(Input::isKeyDown(SDLK_LSHIFT))
6124 stereoreverse=false;
6127 printf("Stereo reversed\n");
6129 printf("Stereo unreversed\n");
6132 if(Input::isKeyDown(SDLK_F7)){
6133 if(Input::isKeyDown(SDLK_LSHIFT))
6134 stereoseparation -= 0.001;
6136 stereoseparation -= 0.010;
6137 printf("Stereo decreased increased to %f\n", stereoseparation);
6140 if(Input::isKeyDown(SDLK_F8)){
6141 if(Input::isKeyDown(SDLK_LSHIFT))
6142 stereoseparation += 0.001;
6144 stereoseparation += 0.010;
6145 printf("Stereo separation increased to %f\n", stereoseparation);
6149 if(Input::isKeyPressed(SDLK_TAB)&&tutoriallevel){
6150 if(tutorialstage!=51)
6151 tutorialstagetime=tutorialmaxtime;
6152 emit_sound_np(consolefailsound, 128.);
6156 Values of mainmenu :
6158 2 Menu pause (resume/end game)
6160 4 Controls configuration menu
6161 5 Main game menu (choose level or challenge)
6162 6 Deleting user menu
6163 7 User managment menu (select/add)
6164 8 Choose difficulty menu
6165 9 Challenge level selection menu
6166 10 End of the campaign congratulation (is that really a menu?)
6167 11 Same that 9 ??? => unused
6168 18 stereo configuration
6173 if(mainmenu&&endgame==1)
6175 //go to level select after completing a campaign level
6176 if(campaign&&winfreeze&&mainmenu==0&&campaignlevels[actuallevel].choosenext==1) {
6183 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6184 emit_stream_np(stream_menutheme);
6185 pause_sound(leveltheme);
6189 //escape key pressed
6190 if(Input::isKeyPressed(SDLK_ESCAPE)&&
6191 (gameon||mainmenu==0||(mainmenu>=3&&mainmenu!=8&&!(mainmenu==7&&entername)))) {
6193 if(mainmenu==0&&!winfreeze)
6195 else if(mainmenu==1||mainmenu==2){
6196 mainmenu=0; //unpause
6199 if(musictoggle&&(mainmenu==1||mainmenu==2)){
6200 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6201 emit_stream_np(stream_menutheme);
6202 pause_sound(leveltheme);
6204 //on resume, play level music
6206 pause_sound(stream_menutheme);
6207 resume_stream(leveltheme);
6209 //finished with settings menu
6214 if(mainmenu>=3&&mainmenu!=8){
6221 mainmenu=gameon?2:1; break;
6224 case 6: case 7: case 9: case 10:
6235 if(hostile==1)hostiletime+=multiplier;
6237 if(!winfreeze)leveltime+=multiplier;
6240 if(Input::isKeyPressed(SDLK_v)&&debugmode){
6243 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6247 if(Input::isKeyPressed(chatkey)&&!console&&!chatting&&debugmode)
6251 inputText(displaytext[0],&displayselected,&displaychars[0]);
6253 if(displaychars[0]){
6254 for(int j=0;j<255;j++)
6255 displaytext[0][j]=0;
6262 displayblinkdelay-=multiplier;
6263 if(displayblinkdelay<=0){
6264 displayblinkdelay=.3;
6265 displayblink=1-displayblink;
6269 keyboardfrozen=true;
6271 if(Input::isKeyPressed(consolekey)&&debugmode) {
6274 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6283 if(console&&!Input::isKeyDown(SDLK_LMETA)) {
6284 inputText(consoletext[0],&consoleselected,&consolechars[0]);
6286 if(consolechars[0]>0) {
6287 consoletext[0][consolechars[0]]='\0';
6288 cmd_dispatch(consoletext[0]);
6289 for(int k=14;k>=1;k--) {
6290 for(int j=0;j<255;j++)
6291 consoletext[k][j]=consoletext[k-1][j];
6292 consolechars[k]=consolechars[k-1];
6294 for(int j=0;j<255;j++)
6295 consoletext[0][j]=0;
6301 consoleblinkdelay-=multiplier;
6302 if(consoleblinkdelay<=0) {
6303 consoleblinkdelay=.3;
6304 consoleblink=1-consoleblink;
6310 if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
6317 static int oldwinfreeze;
6318 if(winfreeze&&!oldwinfreeze){
6319 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
6320 emit_sound_np(consolesuccesssound);
6323 oldwinfreeze=winfreeze;
6327 if((Input::isKeyPressed(jumpkey)||Input::isKeyPressed(SDLK_SPACE))&&!campaign)
6330 if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
6334 } else if(winfreeze) {
6342 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
6345 static float talkdelay = 0;
6349 talkdelay-=multiplier;
6351 if(talkdelay<=0&&indialogue==-1&&animation[player[0].animTarget].height!=highheight)
6352 for(int i=0;i<numdialogues;i++){
6353 int realdialoguetype;
6355 if(dialoguetype[i]>49){
6356 realdialoguetype=dialoguetype[i]-50;
6359 else if(dialoguetype[i]>39){
6360 realdialoguetype=dialoguetype[i]-40;
6363 else if(dialoguetype[i]>29){
6364 realdialoguetype=dialoguetype[i]-30;
6367 else if(dialoguetype[i]>19){
6368 realdialoguetype=dialoguetype[i]-20;
6371 else if(dialoguetype[i]>9){
6372 realdialoguetype=dialoguetype[i]-10;
6376 realdialoguetype=dialoguetype[i];
6379 if((!hostile||dialoguetype[i]>40&&dialoguetype[i]<50)&&
6380 realdialoguetype<numplayers&&
6381 realdialoguetype>0&&
6382 (dialoguegonethrough[i]==0||!special)&&
6383 (special||Input::isKeyPressed(attackkey))){
6384 if(distsq(&player[0].coords,&player[realdialoguetype].coords)<6||
6385 player[realdialoguetype].howactive>=typedead1||
6386 dialoguetype[i]>40&&dialoguetype[i]<50){
6388 for(int j=0;j<numdialogueboxes[whichdialogue];j++){
6389 player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
6390 player[participantfocus[whichdialogue][j]].yaw=participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
6391 player[participantfocus[whichdialogue][j]].targetyaw=participantyaw[whichdialogue][participantfocus[whichdialogue][j]];
6392 player[participantfocus[whichdialogue][j]].velocity=0;
6393 player[participantfocus[whichdialogue][j]].animTarget=player[participantfocus[whichdialogue][j]].getIdle();
6394 player[participantfocus[whichdialogue][j]].frameTarget=0;
6399 dialoguegonethrough[i]++;
6400 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6401 playdialogueboxsound();
6407 windvar+=multiplier;
6408 smoketex+=multiplier;
6409 tutorialstagetime+=multiplier;
6412 static float hotspotvisual[40];
6416 for(int i=0;i<numhotspots;i++)
6417 hotspotvisual[i]-=multiplier/320;
6419 for(int i=0;i<numhotspots;i++){
6420 //if(hotspottype[i]<=10)
6421 while(hotspotvisual[i]<0){
6423 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
6424 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
6425 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
6426 hotspotsprite+=hotspot[i];
6427 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
6428 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
6432 for(int i=0;i<numhotspots;i++){
6433 if(hotspottype[i]<=10&&hotspottype[i]>0){
6434 hotspot[i]=player[hotspottype[i]].coords;
6445 if(tutoriallevel!=1){
6448 bonus!=spinecrusher&&
6449 bonus!=tracheotomy&&
6452 emit_sound_np(consolesuccesssound);
6454 } else if(bonustime==0){
6455 emit_sound_np(fireendsound);
6458 if(bonus!=solidhit&&
6460 bonus!=threexcombo&&
6465 bonusnum[bonus]+=0.15;
6468 bonusvalue/=bonusnum[bonus];
6469 bonustotal+=bonusvalue;
6471 bonustime+=multiplier;
6474 if(environment==snowyenvironment){
6475 precipdelay-=multiplier;
6476 while(precipdelay<0){
6480 XYZ footvel,footpoint;
6483 footpoint=viewer+viewerfacing*6;
6484 footpoint.y+=((float)abs(Random()%1200))/100-6;
6485 footpoint.x+=((float)abs(Random()%1200))/100-6;
6486 footpoint.z+=((float)abs(Random()%1200))/100-6;
6487 Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6492 doAerialAcrobatics();
6495 static XYZ oldviewer;
6499 player[0].forwardkeydown=Input::isKeyDown(forwardkey);
6500 player[0].leftkeydown=Input::isKeyDown(leftkey);
6501 player[0].backkeydown=Input::isKeyDown(backkey);
6502 player[0].rightkeydown=Input::isKeyDown(rightkey);
6503 player[0].jumpkeydown=Input::isKeyDown(jumpkey);
6504 player[0].crouchkeydown=Input::isKeyDown(crouchkey);
6505 player[0].drawkeydown=Input::isKeyDown(drawkey);
6506 player[0].throwkeydown=Input::isKeyDown(throwkey);
6510 player[0].forwardkeydown=0;
6511 player[0].leftkeydown=0;
6512 player[0].backkeydown=0;
6513 player[0].rightkeydown=0;
6514 player[0].jumpkeydown=0;
6515 player[0].crouchkeydown=0;
6516 player[0].drawkeydown=0;
6517 player[0].throwkeydown=0;
6520 if(!player[0].jumpkeydown)
6521 player[0].jumpclimb=0;
6530 facing=DoRotation(facing,-pitch,0,0);
6531 facing=DoRotation(facing,0,0-yaw,0);
6536 flatfacing=DoRotation(flatfacing,0,-yaw,0);
6538 if(Input::isKeyDown(forwardkey))
6539 viewer+=facing*multiplier*4;
6540 if(Input::isKeyDown(backkey))
6541 viewer-=facing*multiplier*4;
6542 if(Input::isKeyDown(leftkey))
6543 viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6544 if(Input::isKeyDown(rightkey))
6545 viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6546 if(Input::isKeyDown(jumpkey))
6547 viewer.y+=multiplier*4;
6548 if(Input::isKeyDown(crouchkey))
6549 viewer.y-=multiplier*4;
6550 if( Input::isKeyPressed(SDLK_1)||
6551 Input::isKeyPressed(SDLK_2)||
6552 Input::isKeyPressed(SDLK_3)||
6553 Input::isKeyPressed(SDLK_4)||
6554 Input::isKeyPressed(SDLK_5)||
6555 Input::isKeyPressed(SDLK_6)||
6556 Input::isKeyPressed(SDLK_7)||
6557 Input::isKeyPressed(SDLK_8)||
6558 Input::isKeyPressed(SDLK_9)||
6559 Input::isKeyPressed(SDLK_0)||
6560 Input::isKeyPressed(SDLK_MINUS)){
6562 if(Input::isKeyPressed(SDLK_1))whichend=1;
6563 if(Input::isKeyPressed(SDLK_2))whichend=2;
6564 if(Input::isKeyPressed(SDLK_3))whichend=3;
6565 if(Input::isKeyPressed(SDLK_4))whichend=4;
6566 if(Input::isKeyPressed(SDLK_5))whichend=5;
6567 if(Input::isKeyPressed(SDLK_6))whichend=6;
6568 if(Input::isKeyPressed(SDLK_7))whichend=7;
6569 if(Input::isKeyPressed(SDLK_8))whichend=8;
6570 if(Input::isKeyPressed(SDLK_9))whichend=9;
6571 if(Input::isKeyPressed(SDLK_0))whichend=0;
6572 if(Input::isKeyPressed(SDLK_MINUS))
6575 participantfocus[whichdialogue][indialogue]=whichend;
6576 participantlocation[whichdialogue][whichend]=player[whichend].coords;
6577 participantyaw[whichdialogue][whichend]=player[whichend].yaw;
6580 participantfocus[whichdialogue][indialogue]=-1;
6582 if(player[participantfocus[whichdialogue][indialogue]].dead){
6587 dialoguecamera[whichdialogue][indialogue]=viewer;
6588 dialoguecamerayaw[whichdialogue][indialogue]=yaw;
6589 dialoguecamerapitch[whichdialogue][indialogue]=pitch;
6591 if(indialogue<numdialogueboxes[whichdialogue]){
6592 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6593 playdialogueboxsound();
6597 for(int j=0;j<numplayers;j++){
6598 participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6601 //TODO: should these be KeyDown or KeyPressed?
6602 if( Input::isKeyDown(SDLK_KP1)||
6603 Input::isKeyDown(SDLK_KP2)||
6604 Input::isKeyDown(SDLK_KP3)||
6605 Input::isKeyDown(SDLK_KP4)||
6606 Input::isKeyDown(SDLK_KP5)||
6607 Input::isKeyDown(SDLK_KP6)||
6608 Input::isKeyDown(SDLK_KP7)||
6609 Input::isKeyDown(SDLK_KP8)||
6610 Input::isKeyDown(SDLK_KP9)||
6611 Input::isKeyDown(SDLK_KP0)){
6613 if(Input::isKeyDown(SDLK_KP1))whichend=1;
6614 if(Input::isKeyDown(SDLK_KP2))whichend=2;
6615 if(Input::isKeyDown(SDLK_KP3))whichend=3;
6616 if(Input::isKeyDown(SDLK_KP4))whichend=4;
6617 if(Input::isKeyDown(SDLK_KP5))whichend=5;
6618 if(Input::isKeyDown(SDLK_KP6))whichend=6;
6619 if(Input::isKeyDown(SDLK_KP7))whichend=7;
6620 if(Input::isKeyDown(SDLK_KP8))whichend=8;
6621 if(Input::isKeyDown(SDLK_KP9))whichend=9;
6622 if(Input::isKeyDown(SDLK_KP0))whichend=0;
6623 participantfacing[whichdialogue][indialogue][whichend]=facing;
6625 if(indialogue>=numdialogueboxes[whichdialogue]){
6632 pause_sound(whooshsound);
6633 viewer=dialoguecamera[whichdialogue][indialogue];
6634 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.1);
6635 yaw=dialoguecamerayaw[whichdialogue][indialogue];
6636 pitch=dialoguecamerapitch[whichdialogue][indialogue];
6637 if(dialoguetime>0.5)
6638 if( Input::isKeyPressed(SDLK_1)||
6639 Input::isKeyPressed(SDLK_2)||
6640 Input::isKeyPressed(SDLK_3)||
6641 Input::isKeyPressed(SDLK_4)||
6642 Input::isKeyPressed(SDLK_5)||
6643 Input::isKeyPressed(SDLK_6)||
6644 Input::isKeyPressed(SDLK_7)||
6645 Input::isKeyPressed(SDLK_8)||
6646 Input::isKeyPressed(SDLK_9)||
6647 Input::isKeyPressed(SDLK_0)||
6648 Input::isKeyPressed(SDLK_MINUS)||
6649 Input::isKeyPressed(attackkey)){
6651 if(indialogue<numdialogueboxes[whichdialogue]){
6652 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6653 playdialogueboxsound();
6654 if(dialogueboxsound[whichdialogue][indialogue]==-5){
6655 hotspot[numhotspots]=player[0].coords;
6656 hotspotsize[numhotspots]=10;
6657 hotspottype[numhotspots]=-1;
6661 if(dialogueboxsound[whichdialogue][indialogue]==-6){
6665 if(player[participantfocus[whichdialogue][indialogue]].dead){
6673 if(indialogue>=numdialogueboxes[whichdialogue]){
6677 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6680 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6683 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6685 for(int i=1;i<numplayers;i++){
6686 player[i].aitype = attacktypecutoff;
6693 if(!player[0].jumpkeydown){
6694 player[0].jumptogglekeydown=0;
6696 if(player[0].jumpkeydown&&
6697 player[0].animTarget!=jumpupanim&&
6698 player[0].animTarget!=jumpdownanim&&
6699 !player[0].isFlip())
6700 player[0].jumptogglekeydown=1;
6703 dialoguetime+=multiplier;
6704 hawkyaw+=multiplier*25;
6706 realhawkcoords.x=25;
6707 realhawkcoords=DoRotation(realhawkcoords,0,hawkyaw,0)+hawkcoords;
6708 hawkcalldelay-=multiplier/2;
6710 if(hawkcalldelay<=0){
6711 emit_sound_at(hawksound, realhawkcoords);
6713 hawkcalldelay=16+abs(Random()%8);
6720 doPlayerCollisions();
6724 for(int k=0;k<numplayers;k++)
6725 if(k!=0&&player[k].immobile)
6726 player[k].coords=player[k].realoldcoords;
6728 for(int k=0;k<numplayers;k++){
6729 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6730 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
6731 player[k].DoDamage(1000);
6737 static bool respawnkeydown;
6740 (Input::isKeyDown(SDLK_z)&&
6741 Input::isKeyDown(SDLK_LMETA)&&
6743 (Input::isKeyDown(jumpkey)&&
6747 targetlevel=whichlevel;
6751 if(!Input::isKeyDown(jumpkey))
6753 if(Input::isKeyDown(jumpkey))
6759 static bool movekey;
6762 for(int i=0;i<numplayers;i++){
6763 static float oldtargetyaw;
6764 if(!player[i].skeleton.free){
6765 oldtargetyaw=player[i].targetyaw;
6766 if(i==0&&indialogue==-1){
6767 //TODO: refactor repetitive code
6768 if(!animation[player[0].animTarget].attack&&
6769 player[0].animTarget!=staggerbackhighanim&&
6770 player[0].animTarget!=staggerbackhardanim&&
6771 player[0].animTarget!=crouchremoveknifeanim&&
6772 player[0].animTarget!=removeknifeanim&&
6773 player[0].animTarget!=backhandspringanim&&
6774 player[0].animTarget!=dodgebackanim&&
6775 player[0].animTarget!=walljumprightkickanim&&
6776 player[0].animTarget!=walljumpleftkickanim){
6778 player[0].targetyaw=0;
6780 player[0].targetyaw=-yaw+180;
6786 flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
6790 facing=DoRotation(facing,-pitch,0,0);
6791 facing=DoRotation(facing,0,0-yaw,0);
6794 player[0].lookyaw=-yaw;
6796 player[i].targetheadyaw=yaw;
6797 player[i].targetheadpitch=pitch;
6799 if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
6800 if(!animation[player[i].animTarget].attack&&
6801 player[i].animTarget!=staggerbackhighanim&&
6802 player[i].animTarget!=staggerbackhardanim&&
6803 player[i].animTarget!=crouchremoveknifeanim&&
6804 player[i].animTarget!=removeknifeanim&&
6805 player[i].animTarget!=backhandspringanim&&
6806 player[i].animTarget!=dodgebackanim&&
6807 player[i].animTarget!=walljumprightkickanim&&
6808 player[i].animTarget!=walljumpleftkickanim){
6809 player[i].targetyaw=-player[i].lookyaw+180;
6815 flatfacing=DoRotation(facing,0,player[i].yaw+180,0);
6817 facing=DoRotation(facing,-player[i].lookpitch,0,0);
6818 facing=DoRotation(facing,0,0-player[i].lookyaw,0);
6820 player[i].targetheadyaw=player[i].lookyaw;
6821 player[i].targetheadpitch=player[i].lookpitch;
6824 player[i].targetheadyaw=180-roughDirection(participantfacing[whichdialogue][indialogue][i]);
6825 player[i].targetheadpitch=pitchOf(participantfacing[whichdialogue][indialogue][i]);
6831 player[i].avoidsomething=0;
6833 //avoid flaming things
6834 for(int j=0;j<objects.numobjects;j++)
6835 if(objects.onfire[j])
6836 if(distsq(&player[i].coords,&objects.position[j])<sq(objects.scale[j])*200)
6837 if( distsq(&player[i].coords,&objects.position[j])<
6838 distsq(&player[i].coords,&player[0].coords)){
6839 player[i].collided=0;
6840 player[i].avoidcollided=1;
6841 if(player[i].avoidsomething==0||
6842 distsq(&player[i].coords,&objects.position[j])<
6843 distsq(&player[i].coords,&player[i].avoidwhere)){
6844 player[i].avoidwhere=objects.position[j];
6845 player[i].avoidsomething=1;
6849 //avoid flaming players
6850 for(int j=0;j<numplayers;j++)
6851 if(player[j].onfire)
6852 if(distsq(&player[j].coords,&player[i].coords)<sq(0.3)*200)
6853 if( distsq(&player[i].coords,&player[j].coords)<
6854 distsq(&player[i].coords,&player[0].coords)){
6855 player[i].collided=0;
6856 player[i].avoidcollided=1;
6857 if(player[i].avoidsomething==0||
6858 distsq(&player[i].coords,&player[j].coords)<
6859 distsq(&player[i].coords,&player[i].avoidwhere)){
6860 player[i].avoidwhere=player[j].coords;
6861 player[i].avoidsomething=1;
6865 if(player[i].collided>.8)
6866 player[i].avoidcollided=0;
6870 if(animation[player[i].animTarget].attack==reversed){
6871 //player[i].targetyaw=player[i].yaw;
6872 player[i].forwardkeydown=0;
6873 player[i].leftkeydown=0;
6874 player[i].backkeydown=0;
6875 player[i].rightkeydown=0;
6876 player[i].jumpkeydown=0;
6877 player[i].attackkeydown=0;
6878 //player[i].crouchkeydown=0;
6879 player[i].throwkeydown=0;
6883 player[i].forwardkeydown=0;
6884 player[i].leftkeydown=0;
6885 player[i].backkeydown=0;
6886 player[i].rightkeydown=0;
6887 player[i].jumpkeydown=0;
6888 player[i].crouchkeydown=0;
6889 player[i].drawkeydown=0;
6890 player[i].throwkeydown=0;
6893 if(player[i].collided<-.3)
6894 player[i].collided=-.3;
6895 if(player[i].collided>1)
6896 player[i].collided=1;
6897 player[i].collided-=multiplier*4;
6898 player[i].whichdirectiondelay-=multiplier;
6899 if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
6900 player[i].avoidcollided=-.3;
6901 player[i].whichdirection=abs(Random()%2);
6902 player[i].whichdirectiondelay=.4;
6904 if(player[i].avoidcollided>1)
6905 player[i].avoidcollided=1;
6906 player[i].avoidcollided-=multiplier/4;
6907 if(!player[i].skeleton.free){
6908 player[i].stunned-=multiplier;
6909 player[i].surprised-=multiplier;
6911 if(i!=0&&player[i].surprised<=0&&
6912 player[i].aitype==attacktypecutoff&&
6914 !player[i].skeleton.free&&
6915 animation[player[i].animTarget].attack==neutral)
6918 if(!player[i].throwkeydown)
6919 player[i].throwtogglekeydown=0;
6922 if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
6923 if(player[i].weaponactive==-1&&
6924 player[i].num_weapons<2&&
6925 (player[i].isIdle()||
6926 player[i].isCrouch()||
6927 player[i].animTarget==sneakanim||
6928 player[i].animTarget==rollanim||
6929 player[i].animTarget==backhandspringanim||
6930 player[i].isFlip()||
6931 player[i].isFlip()||
6932 player[i].aitype!=playercontrolled)){
6933 for(int j=0;j<weapons.size();j++){
6934 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6935 player[i].aitype==playercontrolled)&&
6936 weapons[j].owner==-1&&
6937 player[i].weaponactive==-1)
6938 if(distsqflat(&player[i].coords,&weapons[j].position)<2){
6939 if(distsq(&player[i].coords,&weapons[j].position)<2){
6940 if(player[i].isCrouch()||
6941 player[i].animTarget==sneakanim||
6943 player[i].isIdle()||
6944 player[i].aitype!=playercontrolled){
6945 player[i].throwtogglekeydown=1;
6946 player[i].setAnimation(crouchremoveknifeanim);
6947 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[j].position);
6948 player[i].hasvictim=0;
6950 if(player[i].animTarget==rollanim||player[i].animTarget==backhandspringanim){
6951 player[i].throwtogglekeydown=1;
6952 player[i].hasvictim=0;
6954 if((weapons[j].velocity.x==0&&weapons[j].velocity.y==0&&weapons[j].velocity.z==0||
6955 player[i].aitype==playercontrolled)&&
6956 weapons[j].owner==-1||
6958 weapons[j].owner==player[i].victim->id)
6959 if(distsqflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1)
6960 if(distsq(&player[i].coords,&weapons[j].position)<1||player[i].victim){
6961 if(weapons[j].getType()!=staff)
6962 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6964 player[i].weaponactive=0;
6965 weapons[j].owner=player[i].id;
6966 if(player[i].num_weapons>0)
6967 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
6968 player[i].num_weapons++;
6969 player[i].weaponids[0]=j;
6972 }else if((player[i].isIdle()||
6973 player[i].isFlip()||
6974 player[i].aitype!=playercontrolled)&&
6975 distsq(&player[i].coords,&weapons[j].position)<5&&
6976 player[i].coords.y<weapons[j].position.y){
6977 if(!player[i].isFlip()){
6978 player[i].throwtogglekeydown=1;
6979 player[i].setAnimation(removeknifeanim);
6980 player[i].targetyaw=roughDirectionTo(player[i].coords,weapons[j].position);
6982 if(player[i].isFlip()){
6983 player[i].throwtogglekeydown=1;
6984 player[i].hasvictim=0;
6986 for(int k=0;k<weapons.size();k++){
6987 if(player[i].weaponactive==-1)
6988 if((weapons[k].velocity.x==0&&weapons[k].velocity.y==0&&weapons[k].velocity.z==0||
6989 player[i].aitype==playercontrolled)&&
6990 weapons[k].owner==-1||
6992 weapons[k].owner==player[i].victim->id)
6993 if(distsqflat(&player[i].coords,&weapons[k].position)<3&&
6994 player[i].weaponactive==-1){
6995 if(weapons[k].getType()!=staff)
6996 emit_sound_at(knifedrawsound, player[i].coords, 128.);
6998 player[i].weaponactive=0;
6999 weapons[k].owner=player[i].id;
7000 if(player[i].num_weapons>0)
7001 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7002 player[i].num_weapons++;
7003 player[i].weaponids[0]=k;
7010 if(player[i].isCrouch()||
7011 player[i].animTarget==sneakanim||
7013 player[i].isIdle()||player[i].animTarget==rollanim||
7014 player[i].animTarget==backhandspringanim){
7016 for(int j=0;j<numplayers;j++){
7017 if(player[i].weaponactive==-1)
7019 if(player[j].num_weapons&&
7020 player[j].skeleton.free&&
7021 distsq(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&&
7022 (((player[j].skeleton.forward.y<0&&
7023 player[j].weaponstuckwhere==0)||
7024 (player[j].skeleton.forward.y>0&&
7025 player[j].weaponstuckwhere==1))||
7026 player[j].weaponstuck==-1||
7027 player[j].num_weapons>1)){
7028 if(player[i].animTarget!=rollanim&&player[i].animTarget!=backhandspringanim){
7029 player[i].throwtogglekeydown=1;
7030 player[i].victim=&player[j];
7031 player[i].hasvictim=1;
7032 player[i].setAnimation(crouchremoveknifeanim);
7033 player[i].targetyaw=roughDirectionTo(player[i].coords,player[j].coords);
7035 if(player[i].animTarget==rollanim||player[i].animTarget==backhandspringanim){
7036 player[i].throwtogglekeydown=1;
7037 player[i].victim=&player[j];
7038 player[i].hasvictim=1;
7039 int k = player[j].weaponids[0];
7040 if(player[i].hasvictim){
7043 if(player[i].victim->weaponstuck!=-1){
7044 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7049 if(weapons[k].getType()!=staff)
7050 emit_sound_at(knifedrawsound, player[i].coords, 128.);
7053 emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
7055 player[i].weaponactive=0;
7056 if(weapons[k].owner!=-1){
7057 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
7058 else player[i].victim->num_weapons=1;
7060 player[i].victim->skeleton.longdead=0;
7061 player[i].victim->skeleton.free=1;
7062 player[i].victim->skeleton.broken=0;
7064 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
7065 player[i].victim->skeleton.joints[l].velchange=0;
7066 player[i].victim->skeleton.joints[l].locked=0;
7072 Normalise(&relative);
7073 XYZ footvel,footpoint;
7075 footpoint=weapons[k].position;
7076 if(player[i].victim->weaponstuck!=-1){
7077 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
7078 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
7079 weapons[k].bloody=2;
7080 weapons[k].blooddrip=5;
7081 player[i].victim->weaponstuck=-1;
7082 player[i].victim->bloodloss+=2000;
7083 player[i].victim->DoDamage(2000);
7086 if(player[i].victim->num_weapons>0){
7087 if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
7088 if(player[i].victim->weaponids[0]==k)
7089 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
7092 player[i].victim->weaponactive=-1;
7094 player[i].victim->jointVel(abdomen)+=relative*6;
7095 player[i].victim->jointVel(neck)+=relative*6;
7096 player[i].victim->jointVel(rightshoulder)+=relative*6;
7097 player[i].victim->jointVel(leftshoulder)+=relative*6;
7100 if(player[i].num_weapons>0){
7101 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
7103 player[i].num_weapons++;
7104 player[i].weaponids[0]=k;
7111 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7112 if(weapons[player[i].weaponids[0]].getType()==knife){
7113 if(player[i].isIdle()||
7115 player[i].isCrouch()||
7116 player[i].animTarget==sneakanim||
7119 for(int j=0;j<numplayers;j++){
7121 if(tutoriallevel!=1||tutorialstage==49)
7123 if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&&
7124 distsq(&player[i].coords,&player[j].coords)<100&&
7125 distsq(&player[i].coords,&player[j].coords)>1.5&&
7126 !player[j].skeleton.free&&
7127 -1==checkcollide(DoRotation(player[j].jointPos(head),0,player[j].yaw,0)*player[j].scale+player[j].coords,DoRotation(player[i].jointPos(head),0,player[i].yaw,0)*player[i].scale+player[i].coords)){
7128 if(!player[i].isFlip()){
7129 player[i].throwtogglekeydown=1;
7130 player[i].victim=&player[j];
7131 player[i].setAnimation(knifethrowanim);
7132 player[i].targetyaw=roughDirectionTo(player[i].coords,player[j].coords);
7133 player[i].targettilt2=pitchTo(player[i].coords,player[j].coords);
7135 if(player[i].isFlip()){
7136 if(player[i].weaponactive!=-1){
7137 player[i].throwtogglekeydown=1;
7138 player[i].victim=&player[j];
7140 weapons[player[i].weaponids[0]].owner=-1;
7141 aim=player[i].victim->coords+DoRotation(player[i].victim->jointPos(abdomen),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].jointPos(righthand),0,player[i].yaw,0)*player[i].scale);
7144 aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
7146 weapons[player[i].weaponids[0]].velocity=aim*50;
7147 weapons[player[i].weaponids[0]].tipvelocity=aim*50;
7148 weapons[player[i].weaponids[0]].missed=0;
7149 weapons[player[i].weaponids[0]].freetime=0;
7150 weapons[player[i].weaponids[0]].firstfree=1;
7151 weapons[player[i].weaponids[0]].physics=0;
7152 player[i].num_weapons--;
7153 if(player[i].num_weapons){
7154 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7156 player[i].weaponactive=-1;
7163 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
7164 if(player[i].isCrouch()||player[i].animTarget==sneakanim){
7165 player[i].throwtogglekeydown=1;
7166 weapons[player[i].weaponids[0]].owner=-1;
7167 weapons[player[i].weaponids[0]].velocity=player[i].velocity*.2;
7168 if(weapons[player[i].weaponids[0]].velocity.x==0)weapons[player[i].weaponids[0]].velocity.x=.1;
7169 weapons[player[i].weaponids[0]].tipvelocity=weapons[player[i].weaponids[0]].velocity;
7170 weapons[player[i].weaponids[0]].missed=1;
7171 weapons[player[i].weaponids[0]].freetime=0;
7172 weapons[player[i].weaponids[0]].firstfree=1;
7173 weapons[player[i].weaponids[0]].physics=1;
7174 player[i].num_weapons--;
7175 if(player[i].num_weapons){
7176 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
7177 if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
7180 player[i].weaponactive=-1;
7181 for(int j=0;j<numplayers;j++){
7182 player[j].wentforweapon=0;
7190 if(i==0||!player[0].dead||player[i].weaponactive!=-1) {
7191 if(player[i].drawkeydown&&!player[i].drawtogglekeydown||
7192 player[i].num_weapons==2&&
7193 player[i].weaponactive==-1&&
7194 player[i].isIdle()||
7196 player[i].weaponactive!=-1&&
7199 if(player[i].weaponactive!=-1)
7200 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==staff)
7202 if(isgood&&player[i].creature!=wolftype){
7203 if(player[i].isIdle()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7204 player[i].setAnimation(drawrightanim);
7205 player[i].drawtogglekeydown=1;
7207 if((player[i].isIdle()||
7208 (player[i].aitype!=playercontrolled&&
7209 player[0].weaponactive!=-1&&
7210 player[i].isRun()))&&
7211 player[i].num_weapons&&
7212 weapons[player[i].weaponids[0]].getType()==sword){
7213 player[i].setAnimation(drawleftanim);
7214 player[i].drawtogglekeydown=1;
7216 if(player[i].isCrouch()&&player[i].num_weapons&&weapons[player[i].weaponids[0]].getType()==knife){
7217 player[i].setAnimation(crouchdrawrightanim);
7218 player[i].drawtogglekeydown=1;
7225 if(player[i].weaponactive!=-1) {
7226 if (player[i].isCrouch()&&
7227 weapons[player[i].weaponids[player[i].weaponactive]].bloody&&
7229 player[i].onterrain&&
7230 player[i].num_weapons&&
7231 player[i].attackkeydown&&
7232 musictype!=stream_fighttheme) {
7233 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==knife)
7234 player[i].setAnimation(crouchstabanim);
7235 if(weapons[player[i].weaponids[player[i].weaponactive]].getType()==sword)
7236 player[i].setAnimation(swordgroundstabanim);
7237 player[i].hasvictim=0;
7241 if(!player[i].drawkeydown)
7242 player[i].drawtogglekeydown=0;
7249 absflatfacing=DoRotation(absflatfacing,0,-yaw,0);
7251 absflatfacing=flatfacing;
7254 player[i].forwardkeydown=0;
7255 player[i].leftkeydown=0;
7256 player[i].backkeydown=0;
7257 player[i].rightkeydown=0;
7258 player[i].jumpkeydown=0;
7259 player[i].crouchkeydown=0;
7260 player[i].drawkeydown=0;
7261 player[i].throwkeydown=0;
7265 if(!animation[player[i].animTarget].attack&&
7266 player[i].animTarget!=staggerbackhighanim&&
7267 player[i].animTarget!=staggerbackhardanim&&
7268 player[i].animTarget!=backhandspringanim&&
7269 player[i].animTarget!=dodgebackanim){
7270 if(!player[i].forwardkeydown)
7271 player[i].forwardstogglekeydown=0;
7272 if(player[i].crouchkeydown){
7276 player[i].superruntoggle=1;
7278 for(int j=0;j<numplayers;j++)
7279 if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype)
7280 if(distsq(&player[j].coords,&player[i].coords)<16)
7281 player[i].superruntoggle=0;
7285 for(int j=0;j<numplayers;j++){
7286 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
7287 if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
7288 player[j].victim==&player[i]&&
7289 (player[j].animTarget==sweepanim||
7290 player[j].animTarget==upunchanim||
7291 player[j].animTarget==wolfslapanim||
7292 ((player[j].animTarget==swordslashanim||
7293 player[j].animTarget==knifeslashstartanim||
7294 player[j].animTarget==staffhitanim||
7295 player[j].animTarget==staffspinhitanim)&&
7296 distsq(&player[j].coords,&player[i].coords)<2))){
7305 player[target].Reverse();
7306 player[i].lowreversaldelay=.5;
7308 if(player[i].isIdle()){
7309 player[i].setAnimation(player[i].getCrouch());
7310 player[i].transspeed=10;
7312 if(player[i].isRun()||
7313 (player[i].isStop()&&
7314 (player[i].leftkeydown||
7315 player[i].rightkeydown||
7316 player[i].forwardkeydown||
7317 player[i].backkeydown))){
7318 player[i].setAnimation(rollanim);
7319 player[i].transspeed=20;
7322 if(!player[i].crouchkeydown){
7324 if(!player[i].isRun()&&player[i].animTarget!=sneakanim&&i==0)player[i].superruntoggle=0;
7326 if(player[i].isCrouch()){
7328 for(int j=0;j<numplayers;j++){
7330 !player[j].skeleton.free&&
7332 player[i].highreversaldelay<=0){
7333 if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
7334 player[j].victim==&player[i]&&
7335 (player[j].animTarget==spinkickanim)&&
7336 player[i].isCrouch()){
7345 player[target].Reverse();
7346 player[i].highreversaldelay=.5;
7348 if(player[i].isCrouch()){
7349 if(!player[i].wasCrouch()){
7350 player[i].animCurrent=player[i].getCrouch();
7351 player[i].frameCurrent=0;
7353 player[i].setAnimation(player[i].getIdle());
7354 player[i].transspeed=10;
7357 if(player[i].animTarget==sneakanim){
7358 player[i].setAnimation(player[i].getIdle());
7359 player[i].transspeed=10;
7362 if(player[i].forwardkeydown){
7363 if(player[i].isIdle()||
7364 (player[i].isStop()&&
7365 player[i].targetyaw==player[i].yaw)||
7366 (player[i].isLanding()&&
7367 player[i].frameTarget>0&&
7368 !player[i].jumpkeydown)||
7369 (player[i].isLandhard()&&
7370 player[i].frameTarget>0&&
7371 !player[i].jumpkeydown&&
7372 player[i].crouchkeydown)){
7373 if(player[i].aitype==passivetype)
7374 player[i].setAnimation(walkanim);
7376 player[i].setAnimation(player[i].getRun());
7378 if(player[i].isCrouch()){
7379 player[i].animTarget=sneakanim;
7380 if(player[i].wasCrouch())
7382 player[i].frameTarget=0;
7384 if(player[i].animTarget==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
7385 player[i].setAnimation(climbanim);
7386 player[i].frameTarget=1;
7387 player[i].jumpclimb=1;
7389 if(player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim||player[i].isFlip()){
7390 player[i].velocity+=absflatfacing*5*multiplier;
7392 player[i].forwardstogglekeydown=1;
7395 if (player[i].rightkeydown){
7396 if(player[i].isIdle()||
7397 (player[i].isStop()&&
7398 player[i].targetyaw==player[i].yaw)||
7399 (player[i].isLanding()&&
7400 player[i].frameTarget>0&&
7401 !player[i].jumpkeydown)||
7402 (player[i].isLandhard()&&
7403 player[i].frameTarget>0&&
7404 !player[i].jumpkeydown&&
7405 player[i].crouchkeydown)){
7406 player[i].setAnimation(player[i].getRun());
7408 if(player[i].isCrouch()){
7409 player[i].animTarget=sneakanim;
7410 if(player[i].wasCrouch())
7412 player[i].frameTarget=0;
7414 if(player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim||player[i].isFlip()){
7415 player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7417 player[i].targetyaw-=90;
7418 if(player[i].forwardkeydown)player[i].targetyaw+=45;
7419 if(player[i].backkeydown)player[i].targetyaw-=45;
7422 if ( player[i].leftkeydown){
7423 if(player[i].isIdle()||
7424 (player[i].isStop()&&
7425 player[i].targetyaw==player[i].yaw)||
7426 (player[i].isLanding()&&
7427 player[i].frameTarget>0&&
7428 !player[i].jumpkeydown)||
7429 (player[i].isLandhard()&&
7430 player[i].frameTarget>0&&
7431 !player[i].jumpkeydown&&
7432 player[i].crouchkeydown)){
7433 player[i].setAnimation(player[i].getRun());
7435 if(player[i].isCrouch()){
7436 player[i].animTarget=sneakanim;
7437 if(player[i].wasCrouch())
7439 player[i].frameTarget=0;
7441 if(player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim||player[i].isFlip()){
7442 player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
7444 player[i].targetyaw+=90;
7445 if(player[i].forwardkeydown)player[i].targetyaw-=45;
7446 if(player[i].backkeydown)player[i].targetyaw+=45;
7449 if(player[i].backkeydown){
7450 if(player[i].isIdle()||
7451 (player[i].isStop()&&
7452 player[i].targetyaw==player[i].yaw)||
7453 (player[i].isLanding()&&
7454 player[i].frameTarget>0&&
7455 !player[i].jumpkeydown)||
7456 (player[i].isLandhard()&&
7457 player[i].frameTarget>0&&
7458 !player[i].jumpkeydown&&
7459 player[i].crouchkeydown)){
7460 player[i].setAnimation(player[i].getRun());
7462 if(player[i].isCrouch()){
7463 player[i].animTarget=sneakanim;
7464 if(player[i].wasCrouch())
7466 player[i].frameTarget=0;
7468 if(player[i].animTarget==jumpupanim||player[i].animTarget==jumpdownanim||player[i].isFlip()){
7469 player[i].velocity-=absflatfacing*5*multiplier;
7471 if(player[i].animTarget==hanganim){
7472 player[i].animCurrent=jumpdownanim;
7473 player[i].animTarget=jumpdownanim;
7475 player[i].frameCurrent=0;
7476 player[i].frameTarget=1;
7477 player[i].velocity=0;
7478 player[i].velocity.y+=gravity;
7479 player[i].coords.y-=1.4;
7480 player[i].grabdelay=1;
7482 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
7483 player[i].targetyaw+=180;
7486 if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
7487 if((((player[i].isLanding()&&player[i].frameTarget>=3)||
7489 player[i].animTarget==walkanim||
7490 player[i].isCrouch()||
7491 player[i].animTarget==sneakanim)&&
7492 player[i].jumppower>1)&&
7493 ((player[i].animTarget!=rabbitrunninganim&&
7494 player[i].animTarget!=wolfrunninganim)||i!=0)){
7495 player[i].jumpstart=0;
7496 player[i].setAnimation(jumpupanim);
7497 player[i].yaw=player[i].targetyaw;
7498 player[i].transspeed=20;
7499 player[i].FootLand(0,1);
7500 player[i].FootLand(1,1);
7504 flatfacing=DoRotation(facing,0,player[i].targetyaw+180,0);
7506 if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
7507 if(!movekey)player[i].velocity=0;
7512 for(int j=0;j<numplayers;j++){
7513 if(j!=i&&!player[j].skeleton.free&&player[j].victim){
7514 if(distsq(&player[j].coords,&player[j].victim->coords)<3&&
7515 player[j].victim==&player[i]&&
7516 (player[j].animTarget==sweepanim)){
7517 if(target>=0)target=-1;
7522 if(target>=0)player[i].velocity.y=1;
7523 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
7524 player[i].velocity.y=7;
7525 player[i].crouchtogglekeydown=1;
7527 else player[i].velocity.y=5;
7529 if(mousejump&&i==0&&debugmode){
7530 if(!player[i].isLanding())player[i].tempdeltav=deltav;
7531 if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
7534 player[i].coords.y+=.2;
7535 player[i].jumppower-=1;
7538 emit_sound_at(whooshsound, player[i].coords, 128.);
7540 emit_sound_at(jumpsound, player[i].coords, 128.);
7542 if((player[i].isIdle())&&player[i].jumppower>1){
7543 player[i].setAnimation(player[i].getLanding());
7544 player[i].frameTarget=2;
7545 player[i].landhard=0;
7546 player[i].jumpstart=1;
7547 player[i].tempdeltav=deltav;
7549 if(player[i].animTarget==jumpupanim&&
7553 player[i].aitype!=playercontrolled)){
7554 if(player[i].jumppower>multiplier*6){
7555 player[i].velocity.y+=multiplier*6;
7556 player[i].jumppower-=multiplier*6;
7558 if(player[i].jumppower<=multiplier*6){
7559 player[i].velocity.y+=player[i].jumppower;
7560 player[i].jumppower=0;
7563 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
7567 if(player[i].isRun()||player[i].animTarget==walkanim)
7568 player[i].setAnimation(player[i].getStop());
7569 if(player[i].animTarget==sneakanim){
7570 player[i].animTarget=player[i].getCrouch();
7571 if(player[i].animCurrent==sneakanim)
7573 player[i].frameTarget=0;
7576 if(player[i].animTarget==walkanim&&
7577 (player[i].aitype==attacktypecutoff||
7578 player[i].aitype==searchtype||
7579 (player[i].aitype==passivetype&&
7580 player[i].numwaypoints<=1)))
7581 player[i].setAnimation(player[i].getStop());
7582 if(player[i].isRun()&&(player[i].aitype==passivetype))
7583 player[i].setAnimation(player[i].getStop());
7586 if(player[i].animTarget==rollanim)
7587 player[i].targetyaw=oldtargetyaw;
7591 for(int k=0;k<numplayers;k++){
7592 if(fabs(player[k].yaw-player[k].targetyaw)>180){
7593 if(player[k].yaw>player[k].targetyaw)
7599 //stop to turn in right direction
7600 if(fabs(player[k].yaw-player[k].targetyaw)>90&&(player[k].isRun()||player[k].animTarget==walkanim))
7601 player[k].setAnimation(player[k].getStop());
7603 if(player[k].animTarget==backhandspringanim||player[k].animTarget==dodgebackanim)
7604 player[k].targettilt=0;
7606 if(player[k].animTarget!=jumpupanim&&
7607 player[k].animTarget!=backhandspringanim&&
7608 player[k].animTarget!=jumpdownanim&&
7609 !player[k].isFlip()){
7610 player[k].targettilt=0;
7611 if(player[k].jumppower<0&&!player[k].jumpkeydown)
7612 player[k].jumppower=0;
7613 player[k].jumppower+=multiplier*7;
7614 if(player[k].isCrouch())
7615 player[k].jumppower+=multiplier*7;
7616 if(player[k].jumppower>5)
7617 player[k].jumppower=5;
7620 if(player[k].isRun())
7621 player[k].targettilt=(player[k].yaw-player[k].targetyaw)/4;
7623 player[k].tilt=stepTowardf(player[k].tilt,player[k].targettilt,multiplier*150);
7624 player[k].grabdelay-=multiplier;
7628 for(int k=0;k<numplayers;k++){
7629 player[k].DoAnimations();
7630 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale);
7631 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale);
7637 for(int j=numenvsounds-1;j>=0;j--){
7638 envsoundlife[j]-=multiplier;
7639 if(envsoundlife[j]<0){
7641 envsoundlife[j]=envsoundlife[numenvsounds];
7642 envsound[j]=envsound[numenvsounds];
7646 OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
7648 OPENAL_SetFrequency(OPENAL_ALL, 22050);
7650 if(tutoriallevel==1){
7667 if(tutorialstage>=51)
7668 if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
7669 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
7670 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
7672 emit_stream_np(stream_menutheme);
7681 if(tutorialstage<51)
7682 if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){
7683 emit_sound_at(fireendsound, player[0].coords);
7685 player[0].coords=(oldtemp+oldtemp2)/2;
7689 if(tutorialstage>=14&&tutorialstage<50)
7690 if(distsq(&temp,&player[1].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[1].coords)<4){
7691 emit_sound_at(fireendsound, player[1].coords);
7693 for(int i=0;i<player[1].skeleton.num_joints;i++){
7695 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7696 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7697 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;
7698 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7699 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7703 player[1].coords=(oldtemp+oldtemp2)/2;
7704 for(int i=0;i<player[1].skeleton.num_joints;i++){
7705 player[1].skeleton.joints[i].velocity=0;
7707 if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
7708 if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
7709 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;
7710 if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
7711 Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
7719 static float gLoc[3];
7723 static float vel[3];
7724 vel[0]=(viewer.x-oldviewer.x)/multiplier;
7725 vel[1]=(viewer.y-oldviewer.y)/multiplier;
7726 vel[2]=(viewer.z-oldviewer.z)/multiplier;
7728 //Set orientation with forward and up vectors
7729 static XYZ upvector;
7733 upvector=DoRotation(upvector,-pitch+90,0,0);
7734 upvector=DoRotation(upvector,0,0-yaw,0);
7739 facing=DoRotation(facing,-pitch,0,0);
7740 facing=DoRotation(facing,0,0-yaw,0);
7743 static float ori[6];
7747 ori[3] = -upvector.x;
7748 ori[4] = upvector.y;
7749 ori[5] = -upvector.z;
7751 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
7758 if(Input::isKeyPressed(SDLK_F1))
7762 void Game::TickOnce(){
7766 if(directing||indialogue==-1) {
7779 void Game::TickOnceAfter(){
7780 static XYZ colviewer;
7781 static XYZ coltarget;
7785 static float changedelay;
7786 static bool alldead;
7787 static float unseendelay;
7788 static float cameraspeed;
7791 static int oldmusictype=musictype;
7793 if(environment==snowyenvironment)
7794 leveltheme=stream_snowtheme;
7795 if(environment==grassyenvironment)
7796 leveltheme=stream_grasstheme;
7797 if(environment==desertenvironment)
7798 leveltheme=stream_deserttheme;
7802 musictype=leveltheme;
7803 for(int i=0;i<numplayers;i++){
7804 if((player[i].aitype==attacktypecutoff||
7805 player[i].aitype==getweapontype||
7806 player[i].aitype==gethelptype||
7807 player[i].aitype==searchtype)&&
7808 !player[i].dead/*&&player[i].surprised<=0*/&&
7809 (player[i].animTarget!=sneakattackedanim&&
7810 player[i].animTarget!=knifesneakattackedanim&&
7811 player[i].animTarget!=swordsneakattackedanim)){
7812 musictype=stream_fighttheme;
7817 musictype=stream_menutheme;
7820 if(musictype==stream_fighttheme)
7823 if(oldmusictype==stream_fighttheme&&musictype!=stream_fighttheme){
7824 unseendelay-=multiplier;
7826 musictype=stream_fighttheme;
7831 musictype=stream_menutheme;
7839 if(musictype!=oldmusictype&&musictype==stream_fighttheme)
7840 emit_sound_np(alarmsound);
7841 musicselected=musictype;
7843 if(musicselected==leveltheme)
7844 musicvolume[0]+=multiplier*450;
7846 musicvolume[0]-=multiplier*450;
7847 if(musicselected==stream_fighttheme)
7848 musicvolume[1]+=multiplier*450;
7850 musicvolume[1]-=multiplier*450;
7851 if(musicselected==stream_menutheme)
7852 musicvolume[2]+=multiplier*450;
7854 musicvolume[2]-=multiplier*450;
7856 for(int i=0;i<3;i++){
7857 if(musicvolume[i]<0)
7859 if(musicvolume[i]>512)
7863 if(musicvolume[2]>128&&!loading&&!mainmenu)
7867 if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
7868 emit_stream_np(leveltheme, musicvolume[0]);
7869 if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
7870 emit_stream_np(stream_fighttheme, musicvolume[1]);
7871 if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
7872 emit_stream_np(stream_menutheme, musicvolume[2]);
7873 if(musicvolume[0]<=0&&oldmusicvolume[0]>0)
7874 pause_sound(leveltheme);
7875 if(musicvolume[1]<=0&&oldmusicvolume[1]>0)
7876 pause_sound(stream_fighttheme);
7877 if(musicvolume[2]<=0&&oldmusicvolume[2]>0)
7878 pause_sound(stream_menutheme);
7880 if(musicvolume[0]!=oldmusicvolume[0])
7881 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
7882 if(musicvolume[1]!=oldmusicvolume[1])
7883 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
7884 if(musicvolume[2]!=oldmusicvolume[2])
7885 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
7887 for(int i=0;i<3;i++)
7888 oldmusicvolume[i]=musicvolume[i];
7890 pause_sound(leveltheme);
7891 pause_sound(stream_fighttheme);
7892 pause_sound(stream_menutheme);
7894 for(int i=0;i<4;i++){
7895 oldmusicvolume[i]=0;
7901 for(int i=0;i<numhotspots;i++){
7902 if(hotspottype[i]>10&&hotspottype[i]<20){
7903 if(player[hotspottype[i]-10].dead==0)
7905 else if(killhotspot==2)
7914 for(int i=0;i<numhotspots;i++)
7915 if(hotspottype[i]==-1)
7916 if(distsq(&player[0].coords,&hotspot[i])<hotspotsize[i])
7920 for(int i=1;i<numplayers;i++)
7921 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)
7923 if(numalarmed>maxalarmed)
7924 maxalarmed=numalarmed;
7926 if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
7927 if(player[0].dead&&changedelay<=0){
7929 targetlevel=whichlevel;
7932 for(int i=1;i<numplayers;i++) {
7933 if(!player[i].dead&&player[i].howactive<typedead1) {
7940 if(alldead&&!player[0].dead&&maptype==mapkilleveryone) {
7942 targetlevel=whichlevel+1;
7943 if(targetlevel>numchallengelevels-1)targetlevel=0;
7945 if(winhotspot||windialogue) {
7947 targetlevel=whichlevel+1;
7948 if(targetlevel>numchallengelevels-1)targetlevel=0;
7954 targetlevel=whichlevel+1;
7955 if(targetlevel>numchallengelevels-1)targetlevel=0;
7958 if(changedelay>0&&!player[0].dead&&!won) {
7959 //high scores, awards, win
7961 accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
7964 accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
7980 if(!editorenabled&&gameon&&!mainmenu) {
7981 if(changedelay!=-999)
7982 changedelay-=multiplier/7;
7984 targetlevel=whichlevel;
7985 if(loading==2&&!campaign){
7988 fireSound(firestartsound);
7990 if(!player[0].dead&&targetlevel!=whichlevel)
7991 startbonustotal=bonustotal;
7993 Loadlevel(whichlevel);
7995 Loadlevel(targetlevel);
8001 if(loading==2&&targetlevel==whichlevel){
8005 fireSound(firestartsound);
8007 Loadlevel(campaignlevels[accountactive->getCampaignChoicesMade()].mapname.c_str());
8013 if(changedelay<=-999&&
8017 (alldead&&maptype==mapkilleveryone)||
8021 if((player[0].dead||
8022 (alldead&&maptype==mapkilleveryone)||
8027 if(whichlevel!=-2&&!loading&&!player[0].dead) {
8037 // campaignchoosenext determines what to do when the level is complete:
8038 // 0 = load next level
8039 // 1 = go back to level select screen
8040 // 2 = stealthload next level
8041 if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
8042 if(campaignlevels[actuallevel].nextlevel.empty())
8044 } else if(mainmenu==0&&winfreeze) {
8045 stealthloading = (campaignlevels[actuallevel].choosenext==2);
8047 if(!stealthloading){
8048 fireSound(firestartsound);
8063 actuallevel=campaignlevels[actuallevel].nextlevel.front();
8066 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
8070 pause_sound(stream_menutheme);
8081 oldmusictype=musictype;
8087 facing=DoRotation(facing,-pitch,0,0);
8088 facing=DoRotation(facing,0,0-yaw,0);
8089 viewerfacing=facing;
8092 if((animation[player[0].animTarget].attack!=3&&animation[player[0].animCurrent].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;
8093 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;
8095 if(player[0].skeleton.free){
8096 for(int i=0;i<player[0].skeleton.num_joints;i++){
8097 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
8098 target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
8102 if(player[0].skeleton.free!=2/*&&!autocam*/){
8104 if(findLengthfast(&player[0].velocity)>400){
8105 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8107 if(player[0].skeleton.free==0&&player[0].animTarget!=hanganim&&player[0].animTarget!=climbanim)target.y+=1.4;
8108 coltarget=target-cameraloc;
8109 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8111 Normalise(&coltarget);
8112 if(player[0].animTarget!=hanganim&&player[0].animTarget!=climbanim&&player[0].animCurrent!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8113 else cameraloc=cameraloc+coltarget*multiplier*8;
8115 if(editorenabled)cameraloc=target;
8116 cameradist+=multiplier*5;
8117 if(cameradist>2.3)cameradist=2.3;
8118 viewer=cameraloc-facing*cameradist;
8120 coltarget=cameraloc;
8121 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8122 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8123 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8124 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8126 coltarget=cameraloc;
8127 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.yaw[i])!=-1)viewer=col;
8129 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8130 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8131 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8133 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.yaw[i])!=-1){
8137 cameradist=findDistance(&viewer,&target);
8138 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8139 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8140 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8144 //what did autocam do?
8145 if(player[0].skeleton.free!=2&&autocam){
8147 if(findLengthfast(&player[0].velocity)>400){
8148 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
8150 if(player[0].skeleton.free==0&&player[0].animTarget!=hanganim&&player[0].animTarget!=climbanim)target.y+=1.4;
8151 cameradist+=multiplier*5;
8152 if(cameradist>3.3)cameradist=3.3;
8153 coltarget=target-cameraloc;
8154 if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
8155 else if(findLengthfast(&coltarget)>1)
8157 Normalise(&coltarget);
8158 if(player[0].animTarget!=hanganim&&player[0].animTarget!=climbanim&&player[0].animCurrent!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
8159 else cameraloc=cameraloc+coltarget*multiplier*8;
8161 if(editorenabled)cameraloc=target;
8164 coltarget=cameraloc;
8165 objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
8166 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8167 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8168 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8170 coltarget=cameraloc;
8171 if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.yaw[i])!=-1)viewer=col;
8173 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
8174 for(int j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
8175 int i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
8177 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.yaw[i])!=-1){
8181 cameradist=findDistance(&viewer,&target);
8182 viewer.y=max((double)viewer.y,terrain.getHeight(viewer.x,viewer.z)+.6);
8183 if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
8184 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
8188 if(camerashake>.8)camerashake=.8;
8189 //if(woozy>10)woozy=10;
8190 //woozy+=multiplier;
8192 if(player[0].dead)camerashake=0;
8193 if(player[0].dead)woozy=0;
8194 camerashake-=multiplier*2;
8195 blackout-=multiplier*2;
8196 //if(player[0].isCrouch())woozy-=multiplier*8;
8197 if(camerashake<0)camerashake=0;
8198 if(blackout<0)blackout=0;
8199 //if(woozy<0)woozy=0;
8201 viewer.x+=(float)(Random()%100)*.0005*camerashake;
8202 viewer.y+=(float)(Random()%100)*.0005*camerashake;
8203 viewer.z+=(float)(Random()%100)*.0005*camerashake;