2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 // Enable full math definitions
22 #define _USE_MATH_DEFINES
26 #include "Animation/Animation.hpp"
27 #include "Audio/openal_wrapper.hpp"
28 #include "Devtools/ConsoleCmds.hpp"
29 #include "Level/Awards.hpp"
30 #include "Level/Campaign.hpp"
31 #include "Level/Dialog.hpp"
32 #include "Level/Hotspot.hpp"
33 #include "Menu/Menu.hpp"
34 #include "Tutorial.hpp"
35 #include "User/Settings.hpp"
36 #include "Utils/Folders.hpp"
37 #include "Utils/Input.hpp"
41 #include <sys/types.h>
57 // Added more evilness needed for MSVC
59 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
60 #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
63 extern float multiplier;
65 extern int environment;
66 extern Terrain terrain;
67 extern float screenwidth, screenheight;
70 extern float texdetail;
72 extern float slomodelay;
73 extern bool floatjump;
76 extern float camerashake;
78 extern float blackout;
79 extern bool cellophane;
80 extern bool musictoggle;
81 extern int difficulty;
82 extern int bloodtoggle;
83 extern bool invertmouse;
85 extern float precipdelay;
86 extern XYZ viewerfacing;
87 extern bool ambientsound;
88 extern bool mousejump;
89 extern float viewdistance;
91 extern XYZ windvector;
95 extern int oldmainmenu;
96 extern bool visibleloading;
97 extern XYZ envsound[30];
98 extern float envsoundvol[30];
99 extern int numenvsounds;
100 extern float envsoundlife[30];
101 extern float usermousesensitivity;
102 extern bool ismotionblur;
103 extern bool showdamagebar; // (des)activate the damage bar
104 extern bool decalstoggle;
105 extern bool skyboxtexture;
106 extern float skyboxr;
107 extern float skyboxg;
108 extern float skyboxb;
109 extern float skyboxlightr;
110 extern float skyboxlightg;
111 extern float skyboxlightb;
112 extern float fadestart;
113 extern float slomospeed;
114 extern float slomofreq;
115 extern float smoketex;
116 extern bool againbonus;
117 extern bool reversaltrain;
118 extern bool canattack;
119 extern bool cananger;
120 extern float damagedealt;
122 extern int editoractive;
123 extern int editorpathtype;
125 extern float hostiletime;
127 extern bool gamestarted;
131 extern bool stillloading;
132 extern bool winfreeze;
134 extern bool campaign;
136 extern void toggleFullscreen();
140 bool winhotspot = false;
141 bool windialogue = false;
144 float cameradist = 0;
145 bool oldattackkey = 0;
147 float musicvolume[4] = {};
148 float oldmusicvolume[4] = {};
149 int musicselected = 0;
151 const char* rabbitskin[] = {
156 "Textures/Otter.jpg",
158 "Textures/Sable.jpg",
159 "Textures/Chocolate.jpg",
164 const char* wolfskin[] = {
166 "Textures/DarkWolf.jpg",
167 "Textures/SnowWolf.jpg"
170 const char** creatureskin[] = { rabbitskin, wolfskin };
172 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
173 STATIC_ASSERT(rabbittype == 0 && wolftype == 1)
177 // TODO: this is slightly incorrect
178 float roughDirection(XYZ vec)
181 float angle = -asin(-vec.x) * 180 / M_PI;
187 float roughDirectionTo(XYZ start, XYZ end)
189 return roughDirection(end - start);
191 inline float pitchOf(XYZ vec)
194 return -asin(vec.y) * 180 / M_PI;
196 float pitchTo(XYZ start, XYZ end)
198 return pitchOf(end - start);
204 inline float stepTowardf(float from, float to, float by)
206 if (fabs(from - to) < by) {
208 } else if (from > to) {
215 void Game::playdialoguescenesound()
218 temppos = Person::players.at(Dialog::currentScene().participantfocus)->coords;
219 temppos = temppos - viewer;
224 switch (Dialog::currentScene().sound) {
229 sound = consolefailsound;
232 sound = consolesuccesssound;
235 sound = firestartsound;
238 sound = fireendsound;
241 sound = rabbitchitter;
244 sound = rabbitchitter2;
247 sound = rabbitpainsound;
250 sound = rabbitpain1sound;
253 sound = rabbitattacksound;
256 sound = rabbitattack2sound;
259 sound = rabbitattack3sound;
262 sound = rabbitattack4sound;
286 sound = barkgrowlsound;
292 emit_sound_at(sound, temppos);
296 // ================================================================
298 int Game::findClosestPlayer()
301 float closestdist = std::numeric_limits<float>::max();
303 for (unsigned i = 1; i < Person::players.size(); i++) {
304 float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
305 if (distance < closestdist) {
306 closestdist = distance;
313 static int findClosestObject()
316 float closestdist = std::numeric_limits<float>::max();
318 for (unsigned int i = 0; i < Object::objects.size(); i++) {
319 float distance = distsq(&Object::objects[i]->position,
320 &Person::players[0]->coords);
321 if (distance < closestdist) {
322 closestdist = distance;
329 static void cmd_dispatch(const string cmd)
331 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
333 for (i = 0; i < n_cmds; i++) {
334 if (cmd.substr(0, cmd.find(' ')) == string(cmd_names[i])) {
335 cout << "|" << cmd.substr(cmd.find(' ') + 1) << "|" << endl;
336 cmd_handlers[i](cmd.substr(cmd.find(' ') + 1).c_str());
340 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
343 /********************> Tick() <*****/
344 extern bool save_screenshot(const char* fname);
345 void Screenshot(void)
348 time_t t = time(NULL);
349 struct tm* tme = localtime(&t);
350 sprintf(filename, "Screenshot-%04d%02d%02d-%02d%02d%02d.png",
351 tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
353 save_screenshot(filename);
356 void Game::SetUpLighting()
358 if (environment == snowyenvironment) {
359 light.setColors(.65, .65, .7, .4, .4, .44);
361 if (environment == desertenvironment) {
362 light.setColors(.95, .95, .95, .4, .35, .3);
364 if (environment == grassyenvironment) {
365 light.setColors(.95, .95, 1, .4, .4, .44);
367 if (!skyboxtexture) {
368 light.setColors(1, 1, 1, .4, .4, .4);
371 average = (skyboxlightr + skyboxlightg + skyboxlightb) / 3;
372 light.color[0] *= (skyboxlightr + average) / 2;
373 light.color[1] *= (skyboxlightg + average) / 2;
374 light.color[2] *= (skyboxlightb + average) / 2;
375 light.ambient[0] *= (skyboxlightr + average) / 2;
376 light.ambient[1] *= (skyboxlightg + average) / 2;
377 light.ambient[2] *= (skyboxlightb + average) / 2;
380 void Setenvironment(int which)
384 LOG(" Setting environment...");
389 pause_sound(stream_snowtheme);
390 pause_sound(stream_grasstheme);
391 pause_sound(stream_deserttheme);
392 pause_sound(stream_wind);
393 pause_sound(stream_desertambient);
395 if (environment == snowyenvironment) {
399 emit_stream_np(stream_wind);
402 Object::treetextureptr.load("Textures/SnowTree.png", 0);
403 Object::bushtextureptr.load("Textures/BushSnow.png", 0);
404 Object::rocktextureptr.load("Textures/BoulderSnow.jpg", 1);
405 Object::boxtextureptr.load("Textures/SnowBox.jpg", 1);
407 footstepsound = footstepsn1;
408 footstepsound2 = footstepsn2;
409 footstepsound3 = footstepst1;
410 footstepsound4 = footstepst2;
412 terraintexture.load("Textures/Snow.jpg", 1);
413 terraintexture2.load("Textures/Rock.jpg", 1);
415 temptexdetail = texdetail;
419 skybox->load("Textures/Skybox(snow)/Front.jpg",
420 "Textures/Skybox(snow)/Left.jpg",
421 "Textures/Skybox(snow)/Back.jpg",
422 "Textures/Skybox(snow)/Right.jpg",
423 "Textures/Skybox(snow)/Up.jpg",
424 "Textures/Skybox(snow)/Down.jpg");
426 texdetail = temptexdetail;
427 } else if (environment == desertenvironment) {
430 Object::treetextureptr.load("Textures/DesertTree.png", 0);
431 Object::bushtextureptr.load("Textures/BushDesert.png", 0);
432 Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1);
433 Object::boxtextureptr.load("Textures/DesertBox.jpg", 1);
436 emit_stream_np(stream_desertambient);
439 footstepsound = footstepsn1;
440 footstepsound2 = footstepsn2;
441 footstepsound3 = footstepsn1;
442 footstepsound4 = footstepsn2;
444 terraintexture.load("Textures/Sand.jpg", 1);
445 terraintexture2.load("Textures/SandSlope.jpg", 1);
447 temptexdetail = texdetail;
451 skybox->load("Textures/Skybox(sand)/Front.jpg",
452 "Textures/Skybox(sand)/Left.jpg",
453 "Textures/Skybox(sand)/Back.jpg",
454 "Textures/Skybox(sand)/Right.jpg",
455 "Textures/Skybox(sand)/Up.jpg",
456 "Textures/Skybox(sand)/Down.jpg");
458 texdetail = temptexdetail;
459 } else if (environment == grassyenvironment) {
462 Object::treetextureptr.load("Textures/Tree.png", 0);
463 Object::bushtextureptr.load("Textures/Bush.png", 0);
464 Object::rocktextureptr.load("Textures/Boulder.jpg", 1);
465 Object::boxtextureptr.load("Textures/GrassBox.jpg", 1);
468 emit_stream_np(stream_wind, 100.);
471 footstepsound = footstepgr1;
472 footstepsound2 = footstepgr2;
473 footstepsound3 = footstepst1;
474 footstepsound4 = footstepst2;
476 terraintexture.load("Textures/GrassDirt.jpg", 1);
477 terraintexture2.load("Textures/MossRock.jpg", 1);
479 temptexdetail = texdetail;
483 skybox->load("Textures/Skybox(grass)/Front.jpg",
484 "Textures/Skybox(grass)/Left.jpg",
485 "Textures/Skybox(grass)/Back.jpg",
486 "Textures/Skybox(grass)/Right.jpg",
487 "Textures/Skybox(grass)/Up.jpg",
488 "Textures/Skybox(grass)/Down.jpg");
490 texdetail = temptexdetail;
492 temptexdetail = texdetail;
494 terrain.load("Textures/HeightMap.png");
496 texdetail = temptexdetail;
499 bool Game::LoadLevel(int which)
505 return LoadLevel("tutorial", true);
506 } else if (which >= 0 && which <= 15) {
508 snprintf(buf, 32, "map%d", which + 1); // challenges
509 return LoadLevel(buf);
511 return LoadLevel("mapsave");
515 bool Game::LoadLevel(const std::string& name, bool tutorial)
517 const std::string level_path = Folders::getResourcePath("Maps/" + name);
518 if (!Folders::file_exists(level_path)) {
519 perror(std::string("LoadLevel: Could not open file '" + level_path).c_str());
523 int indemo; // FIXME this should be removed
529 LOG(std::string("Loading level...") + name);
532 visibleloading = true;
534 if (stealthloading) {
535 visibleloading = false;
544 Tutorial::active = tutorial;
546 if (Tutorial::active) {
549 if (Tutorial::stage == 0) {
550 Tutorial::stagetime = 0;
551 Tutorial::maxtime = 1;
553 pause_sound(whooshsound);
554 pause_sound(stream_firesound);
559 tfile = Folders::openMandatoryFile(level_path, "rb");
561 pause_sound(stream_firesound);
567 //~ Animation::animations[bounceidleanim].Load("Idle", middleheight, neutral);
569 Dialog::dialogs.clear();
571 Dialog::indialogue = -1;
577 if (Account::hasActive()) {
578 difficulty = Account::active().getDifficulty();
581 Hotspot::hotspots.clear();
582 Hotspot::current = -1;
593 for (unsigned char i = 0; i < 100; i++) {
603 numunarmedattack = 0;
614 bonustotal = startbonustotal;
619 emit_sound_np(consolesuccesssound);
624 if (!stealthloading) {
625 terrain.decals.clear();
626 Sprite::deleteSprites();
628 for (int i = 0; i < subdivision; i++) {
629 for (int j = 0; j < subdivision; j++) {
630 terrain.patchobjects[i][j].clear();
633 Game::LoadingScreen();
637 Person::players.resize(1);
639 funpackf(tfile, "Bi", &mapvers);
641 cerr << name << " has obsolete map version " << mapvers << endl;
644 funpackf(tfile, "Bi", &indemo);
649 funpackf(tfile, "Bi", &maptype);
651 maptype = mapkilleveryone;
654 funpackf(tfile, "Bi", &hostile);
659 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
665 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
673 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
675 skyboxlightr = skyboxr;
676 skyboxlightg = skyboxg;
677 skyboxlightb = skyboxb;
679 /* TODO - This should be done in an other way so that we can rebuild main player as well (so coords would need to be copied from old ones after rebuilding) */
680 if (stealthloading) {
681 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat, &lamefloat, &lamefloat, &lamefloat, &lamefloat, &Person::players[0]->num_weapons);
683 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &Person::players[0]->coords.x, &Person::players[0]->coords.y, &Person::players[0]->coords.z, &Person::players[0]->yaw, &Person::players[0]->targetyaw, &Person::players[0]->num_weapons);
685 if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) {
686 for (int j = 0; j < Person::players[0]->num_weapons; j++) {
687 Person::players[0]->weaponids[j] = weapons.size();
689 funpackf(tfile, "Bi", &type);
690 weapons.push_back(Weapon(type, 0));
694 Game::LoadingScreen();
696 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->armorhead, &Person::players[0]->armorhigh, &Person::players[0]->armorlow);
697 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->protectionhead, &Person::players[0]->protectionhigh, &Person::players[0]->protectionlow);
698 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->metalhead, &Person::players[0]->metalhigh, &Person::players[0]->metallow);
699 funpackf(tfile, "Bf Bf", &Person::players[0]->power, &Person::players[0]->speedmult);
701 funpackf(tfile, "Bi", &Person::players[0]->numclothes);
704 funpackf(tfile, "Bi Bi", &Person::players[0]->whichskin, &Person::players[0]->creature);
706 Person::players[0]->whichskin = 0;
707 Person::players[0]->creature = rabbittype;
710 Person::players[0]->lastattack = -1;
711 Person::players[0]->lastattack2 = -1;
712 Person::players[0]->lastattack3 = -1;
716 Dialog::loadDialogs(tfile);
719 for (int k = 0; k < Person::players[0]->numclothes; k++) {
720 funpackf(tfile, "Bi", &templength);
721 for (int l = 0; l < templength; l++) {
722 funpackf(tfile, "Bb", &Person::players[0]->clothes[k][l]);
724 Person::players[0]->clothes[k][templength] = '\0';
725 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->clothestintr[k], &Person::players[0]->clothestintg[k], &Person::players[0]->clothestintb[k]);
728 funpackf(tfile, "Bi", &environment);
730 if (environment != oldenvironment) {
731 Setenvironment(environment);
733 oldenvironment = environment;
735 Object::LoadObjectsFromFile(tfile, stealthloading);
739 funpackf(tfile, "Bi", &numhotspots);
740 if (numhotspots < 0) {
741 cerr << "Map " << name << " have an invalid number of hotspots" << endl;
744 Hotspot::hotspots.resize(numhotspots);
745 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
746 funpackf(tfile, "Bi Bf Bf Bf Bf", &Hotspot::hotspots[i].type, &Hotspot::hotspots[i].size, &Hotspot::hotspots[i].position.x, &Hotspot::hotspots[i].position.y, &Hotspot::hotspots[i].position.z);
747 funpackf(tfile, "Bi", &templength);
749 for (int l = 0; l < templength; l++) {
750 funpackf(tfile, "Bb", &Hotspot::hotspots[i].text[l]);
753 Hotspot::hotspots[i].text[templength] = '\0';
754 if (Hotspot::hotspots[i].type == -111) {
759 Hotspot::hotspots.clear();
762 Game::LoadingScreen();
764 if (!stealthloading) {
765 Object::ComputeCenter();
766 Object::ComputeRadius();
769 Game::LoadingScreen();
772 funpackf(tfile, "Bi", &numplayers);
773 if (numplayers > maxplayers) {
774 cout << "Warning: this level contains more players than allowed" << endl;
777 for (int i = 1; i < numplayers; i++) {
779 Person::players.push_back(shared_ptr<Person>(new Person(tfile, mapvers, j)));
781 } catch (InvalidPersonException e) {
782 cerr << "Invalid Person found in " << name << endl;
785 Game::LoadingScreen();
787 funpackf(tfile, "Bi", &numpathpoints);
788 if (numpathpoints > 30 || numpathpoints < 0) {
791 for (int j = 0; j < numpathpoints; j++) {
792 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x, &pathpoint[j].y, &pathpoint[j].z, &numpathpointconnect[j]);
793 for (int k = 0; k < numpathpointconnect[j]; k++) {
794 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
797 Game::LoadingScreen();
799 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x, &mapcenter.y, &mapcenter.z, &mapradius);
803 if (!stealthloading) {
804 Object::AddObjectsToTerrain();
806 Game::LoadingScreen();
808 Game::LoadingScreen();
813 for (unsigned i = 0; i < Person::players.size(); i++) {
814 Game::LoadingScreen();
816 Person::players[i]->burnt = 0;
817 Person::players[i]->bled = 0;
818 Person::players[i]->onfire = 0;
819 Person::players[i]->scale = .2;
821 Person::players[i]->creature = rabbittype;
824 Person::players[i]->skeleton.free = 0;
826 Person::players[i]->skeletonLoad();
828 Person::players[i]->addClothes();
831 Person::players[i]->animCurrent = bounceidleanim;
832 Person::players[i]->animTarget = bounceidleanim;
833 Person::players[i]->frameCurrent = 0;
834 Person::players[i]->frameTarget = 1;
835 Person::players[i]->target = 0;
837 Person::players[i]->speed = 1 + (float)(Random() % 100) / 1000;
838 if (difficulty == 0) {
839 Person::players[i]->speed -= .2;
841 if (difficulty == 1) {
842 Person::players[i]->speed -= .1;
846 Person::players[i]->velocity = 0;
847 Person::players[i]->oldcoords = Person::players[i]->coords;
848 Person::players[i]->realoldcoords = Person::players[i]->coords;
850 Person::players[i]->id = i;
851 Person::players[i]->updatedelay = 0;
852 Person::players[i]->normalsupdatedelay = 0;
854 Person::players[i]->proportionhead = 1.2;
855 Person::players[i]->proportionbody = 1.05;
856 Person::players[i]->proportionarms = 1.00;
857 Person::players[i]->proportionlegs = 1.1;
858 Person::players[i]->proportionlegs.y = 1.05;
859 Person::players[i]->headless = 0;
860 Person::players[i]->currentoffset = 0;
861 Person::players[i]->targetoffset = 0;
862 if (Person::players[i]->creature == wolftype) {
863 Person::players[i]->scale = .23;
864 Person::players[i]->damagetolerance = 300;
866 Person::players[i]->damagetolerance = 200;
870 Game::LoadingScreen();
873 Person::players[i]->proportionhead.z = 0;
874 Person::players[i]->proportionbody.z = 0;
875 Person::players[i]->proportionarms.z = 0;
876 Person::players[i]->proportionlegs.z = 0;
879 Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral);
882 Person::players[i]->headmorphness = 0;
883 Person::players[i]->targetheadmorphness = 1;
884 Person::players[i]->headmorphstart = 0;
885 Person::players[i]->headmorphend = 0;
887 Person::players[i]->pausetime = 0;
889 Person::players[i]->dead = 0;
890 Person::players[i]->jumppower = 5;
891 Person::players[i]->damage = 0;
892 Person::players[i]->permanentdamage = 0;
893 Person::players[i]->superpermanentdamage = 0;
895 Person::players[i]->forwardkeydown = 0;
896 Person::players[i]->leftkeydown = 0;
897 Person::players[i]->backkeydown = 0;
898 Person::players[i]->rightkeydown = 0;
899 Person::players[i]->jumpkeydown = 0;
900 Person::players[i]->crouchkeydown = 0;
901 Person::players[i]->throwkeydown = 0;
903 Person::players[i]->collided = -10;
904 Person::players[i]->loaded = 1;
905 Person::players[i]->bloodloss = 0;
906 Person::players[i]->weaponactive = -1;
907 Person::players[i]->weaponstuck = -1;
908 Person::players[i]->bleeding = 0;
909 Person::players[i]->deathbleeding = 0;
910 Person::players[i]->stunned = 0;
911 Person::players[i]->hasvictim = 0;
912 Person::players[i]->wentforweapon = 0;
916 Person::players[0]->aitype = playercontrolled;
918 if (difficulty == 1) {
919 Person::players[0]->power = 1 / .9;
920 Person::players[0]->damagetolerance = 250;
921 } else if (difficulty == 0) {
922 Person::players[0]->power = 1 / .8;
923 Person::players[0]->damagetolerance = 300;
924 Person::players[0]->armorhead *= 1.5;
925 Person::players[0]->armorhigh *= 1.5;
926 Person::players[0]->armorlow *= 1.5;
929 cameraloc = Person::players[0]->coords;
931 yaw = Person::players[0]->yaw;
933 hawkcoords = Person::players[0]->coords;
936 Game::LoadingScreen();
938 LOG("Starting background music...");
940 OPENAL_StopSound(OPENAL_ALL);
942 if (environment == snowyenvironment) {
943 emit_stream_np(stream_wind);
944 } else if (environment == desertenvironment) {
945 emit_stream_np(stream_desertambient);
946 } else if (environment == grassyenvironment) {
947 emit_stream_np(stream_wind, 100.);
950 oldmusicvolume[0] = 0;
951 oldmusicvolume[1] = 0;
952 oldmusicvolume[2] = 0;
953 oldmusicvolume[3] = 0;
957 visibleloading = false;
964 float headprop, bodyprop, armprop, legprop;
969 if (Input::isKeyDown(SDL_SCANCODE_LALT)) {
971 if (Input::isKeyPressed(SDL_SCANCODE_H)) {
972 Person::players[0]->damagetolerance = 200000;
973 Person::players[0]->damage = 0;
974 Person::players[0]->burnt = 0;
975 Person::players[0]->permanentdamage = 0;
976 Person::players[0]->superpermanentdamage = 0;
979 /* Change environment */
980 if (Input::isKeyPressed(SDL_SCANCODE_J)) {
982 if (environment > 2) {
985 Setenvironment(environment);
989 if (Input::isKeyPressed(SDL_SCANCODE_C)) {
990 cameramode = !cameramode;
993 /* Toggle Slow motion */
994 if (Input::isKeyPressed(SDL_SCANCODE_B)) {
1000 if (Input::isKeyPressed(SDL_SCANCODE_N)) {
1001 Person::players[0]->RagDoll(0);
1003 emit_sound_at(whooshsound, Person::players[0]->coords, 128.);
1006 /* Grow tree leaves?? */
1007 if (Input::isKeyPressed(SDL_SCANCODE_Y)) {
1008 for (auto& an_object : Object::objects) {
1009 if (an_object->type == treeleavestype) {
1010 an_object->scale *= .9;
1015 /* Change (or add) weapon */
1016 if (Input::isKeyPressed(SDL_SCANCODE_X)) {
1018 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1019 closest = findClosestPlayer();
1023 if (Person::players[closest]->num_weapons > 0) {
1024 if (weapons[Person::players[closest]->weaponids[0]].getType() == sword) {
1025 weapons[Person::players[closest]->weaponids[0]].setType(staff);
1026 } else if (weapons[Person::players[closest]->weaponids[0]].getType() == staff) {
1027 weapons[Person::players[closest]->weaponids[0]].setType(knife);
1029 weapons[Person::players[closest]->weaponids[0]].setType(sword);
1032 Person::players[closest]->weaponids[0] = weapons.size();
1034 weapons.push_back(Weapon(knife, closest));
1036 Person::players[closest]->num_weapons = 1;
1042 if (Input::isKeyDown(SDL_SCANCODE_U)) {
1044 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1045 closest = findClosestPlayer();
1049 Person::players[closest]->yaw += multiplier * 50;
1050 Person::players[closest]->targetyaw = Person::players[closest]->yaw;
1055 if (Input::isKeyPressed(SDL_SCANCODE_F)) {
1056 Person::players[0]->onfire = 1 - Person::players[0]->onfire;
1057 if (Person::players[0]->onfire) {
1058 Person::players[0]->CatchFire();
1060 if (!Person::players[0]->onfire) {
1061 emit_sound_at(fireendsound, Person::players[0]->coords);
1062 pause_sound(stream_firesound);
1067 if (Input::isKeyPressed(SDL_SCANCODE_O) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1069 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1070 closest = findClosestPlayer();
1074 Person::players[closest]->whichskin++;
1075 if (Person::players[closest]->whichskin > 9) {
1076 Person::players[closest]->whichskin = 0;
1078 if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) {
1079 Person::players[closest]->whichskin = 0;
1082 Person::players[closest]->skeleton.drawmodel.textureptr.load(creatureskin[Person::players[closest]->creature][Person::players[closest]->whichskin], 1,
1083 &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
1086 Person::players[closest]->addClothes();
1089 /* Change creature type */
1090 if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1092 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1093 closest = findClosestPlayer();
1097 if (Person::players[closest]->creature == wolftype) {
1098 headprop = Person::players[closest]->proportionhead.x / 1.1;
1099 bodyprop = Person::players[closest]->proportionbody.x / 1.1;
1100 armprop = Person::players[closest]->proportionarms.x / 1.1;
1101 legprop = Person::players[closest]->proportionlegs.x / 1.1;
1104 headprop = Person::players[closest]->proportionhead.x / 1.2;
1105 bodyprop = Person::players[closest]->proportionbody.x / 1.05;
1106 armprop = Person::players[closest]->proportionarms.x / 1.00;
1107 legprop = Person::players[closest]->proportionlegs.x / 1.1;
1110 if (Person::players[closest]->creature == rabbittype) {
1111 Person::players[closest]->creature = wolftype;
1112 Person::players[closest]->whichskin = 0;
1113 Person::players[closest]->skeletonLoad();
1115 Person::players[closest]->proportionhead = 1.1;
1116 Person::players[closest]->proportionbody = 1.1;
1117 Person::players[closest]->proportionarms = 1.1;
1118 Person::players[closest]->proportionlegs = 1.1;
1119 Person::players[closest]->proportionlegs.y = 1.1;
1120 Person::players[closest]->scale = .23 * 5 * Person::players[0]->scale;
1122 Person::players[closest]->damagetolerance = 300;
1124 Person::players[closest]->creature = rabbittype;
1125 Person::players[closest]->whichskin = 0;
1126 Person::players[closest]->skeletonLoad(true);
1128 Person::players[closest]->proportionhead = 1.2;
1129 Person::players[closest]->proportionbody = 1.05;
1130 Person::players[closest]->proportionarms = 1.00;
1131 Person::players[closest]->proportionlegs = 1.1;
1132 Person::players[closest]->proportionlegs.y = 1.05;
1133 Person::players[closest]->scale = .2 * 5 * Person::players[0]->scale;
1135 Person::players[closest]->damagetolerance = 200;
1138 if (Person::players[closest]->creature == wolftype) {
1139 Person::players[closest]->proportionhead = 1.1 * headprop;
1140 Person::players[closest]->proportionbody = 1.1 * bodyprop;
1141 Person::players[closest]->proportionarms = 1.1 * armprop;
1142 Person::players[closest]->proportionlegs = 1.1 * legprop;
1145 if (Person::players[closest]->creature == rabbittype) {
1146 Person::players[closest]->proportionhead = 1.2 * headprop;
1147 Person::players[closest]->proportionbody = 1.05 * bodyprop;
1148 Person::players[closest]->proportionarms = 1.00 * armprop;
1149 Person::players[closest]->proportionlegs = 1.1 * legprop;
1150 Person::players[closest]->proportionlegs.y = 1.05 * legprop;
1156 if (((Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
1158 float closestdist = std::numeric_limits<float>::max();
1160 for (unsigned i = 1; i < Person::players.size(); i++) {
1161 float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
1162 if (!Person::players[i]->headless) {
1163 if (distance < closestdist) {
1164 closestdist = distance;
1170 XYZ flatfacing2, flatvelocity2;
1172 if (closest != -1 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1173 blah = Person::players[closest]->coords;
1174 XYZ headspurtdirection;
1175 //int i = Person::players[closest]->skeleton.jointlabels[head];
1176 Joint& headjoint = Person::players[closest]->joint(head);
1177 for (unsigned k = 0; k < Person::players[closest]->skeleton.joints.size(); k++) {
1178 if (!Person::players[closest]->skeleton.free) {
1179 flatvelocity2 = Person::players[closest]->velocity;
1181 if (Person::players[closest]->skeleton.free) {
1182 flatvelocity2 = headjoint.velocity;
1184 if (!Person::players[closest]->skeleton.free) {
1185 flatfacing2 = DoRotation(DoRotation(DoRotation(headjoint.position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1187 if (Person::players[closest]->skeleton.free) {
1188 flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords;
1190 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1191 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1192 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1193 headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck);
1194 Normalise(&headspurtdirection);
1195 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, .6, 1);
1196 flatvelocity2 += headspurtdirection * 8;
1197 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 / 2, 1, 1, 1, .16, 1);
1199 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1201 emit_sound_at(splattersound, blah);
1202 emit_sound_at(breaksound2, blah, 100.);
1204 if (Person::players[closest]->skeleton.free == 2) {
1205 Person::players[closest]->skeleton.free = 0;
1207 Person::players[closest]->RagDoll(0);
1208 Person::players[closest]->dead = 2;
1209 Person::players[closest]->headless = 1;
1210 Person::players[closest]->DoBloodBig(3, 165);
1217 if (((Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
1218 int closest = findClosestPlayer();
1219 XYZ flatfacing2, flatvelocity2;
1221 if (closest >= 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1222 blah = Person::players[closest]->coords;
1223 emit_sound_at(splattersound, blah);
1224 emit_sound_at(breaksound2, blah);
1226 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1227 if (!Person::players[closest]->skeleton.free) {
1228 flatvelocity2 = Person::players[closest]->velocity;
1230 if (Person::players[closest]->skeleton.free) {
1231 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1233 if (!Person::players[closest]->skeleton.free) {
1234 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1236 if (Person::players[closest]->skeleton.free) {
1237 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1239 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1240 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1241 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1242 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1243 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .3, 1);
1244 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1247 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1248 if (!Person::players[closest]->skeleton.free) {
1249 flatvelocity2 = Person::players[closest]->velocity;
1251 if (Person::players[closest]->skeleton.free) {
1252 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1254 if (!Person::players[closest]->skeleton.free) {
1255 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1257 if (Person::players[closest]->skeleton.free) {
1258 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1260 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1261 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1262 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1263 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1264 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1267 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1268 if (!Person::players[closest]->skeleton.free) {
1269 flatvelocity2 = Person::players[closest]->velocity;
1271 if (Person::players[closest]->skeleton.free) {
1272 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1274 if (!Person::players[closest]->skeleton.free) {
1275 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1277 if (Person::players[closest]->skeleton.free) {
1278 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1280 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1281 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1282 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1283 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1284 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1287 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1288 if (!Person::players[closest]->skeleton.free) {
1289 flatvelocity2 = Person::players[closest]->velocity;
1291 if (Person::players[closest]->skeleton.free) {
1292 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1294 if (!Person::players[closest]->skeleton.free) {
1295 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1297 if (Person::players[closest]->skeleton.free) {
1298 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1300 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1301 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1302 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1303 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1304 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1308 for (unsigned j = 0; j < Person::players.size(); j++) {
1309 if (int(j) != closest) {
1310 if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) {
1311 Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60);
1312 if (Person::players[j]->skeleton.free == 2) {
1313 Person::players[j]->skeleton.free = 1;
1315 Person::players[j]->skeleton.longdead = 0;
1316 Person::players[j]->RagDoll(0);
1317 for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) {
1318 temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords;
1319 if (distsq(&temppos, &Person::players[closest]->coords) < 25) {
1320 flatvelocity2 = temppos - Person::players[closest]->coords;
1321 Normalise(&flatvelocity2);
1322 Person::players[j]->skeleton.joints[i].velocity += flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20);
1329 Person::players[closest]->DoDamage(10000);
1330 Person::players[closest]->RagDoll(0);
1331 Person::players[closest]->dead = 2;
1332 Person::players[closest]->coords = 20;
1333 Person::players[closest]->skeleton.free = 2;
1340 if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1341 editorenabled = !editorenabled;
1342 if (editorenabled) {
1343 Person::players[0]->damagetolerance = 100000;
1345 Person::players[0]->damagetolerance = 200;
1347 Person::players[0]->damage = 0; // these lines were in both if and else, but I think they would better fit in the if
1348 Person::players[0]->permanentdamage = 0;
1349 Person::players[0]->superpermanentdamage = 0;
1350 Person::players[0]->bloodloss = 0;
1351 Person::players[0]->deathbleeding = 0;
1356 if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) {
1358 if (targetlevel > numchallengelevels - 1) {
1365 if (editorenabled) {
1366 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1367 int closest = findClosestPlayer();
1369 Person::players.erase(Person::players.begin() + closest);
1373 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1374 int closest = findClosestObject();
1376 Object::objects[closest]->position.y -= 500;
1380 if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1381 if (Object::objects.size() < max_objects - 1) {
1383 scenecoords.x = Person::players[0]->coords.x;
1384 scenecoords.z = Person::players[0]->coords.z;
1385 scenecoords.y = Person::players[0]->coords.y - 3;
1386 if (editortype == bushtype) {
1387 scenecoords.y = Person::players[0]->coords.y - .5;
1389 if (editortype == firetype) {
1390 scenecoords.y = Person::players[0]->coords.y - .5;
1392 float temprotat, temprotat2;
1393 temprotat = editoryaw;
1394 temprotat2 = editorpitch;
1395 if (temprotat < 0 || editortype == bushtype) {
1396 temprotat = Random() % 360;
1398 if (temprotat2 < 0) {
1399 temprotat2 = Random() % 360;
1402 Object::MakeObject(editortype, scenecoords, (int)temprotat - ((int)temprotat) % 30, (int)temprotat2, editorsize);
1403 if (editortype == treetrunktype) {
1404 Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (temprotat2 < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize);
1409 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1410 Person::players.push_back(shared_ptr<Person>(new Person()));
1412 Person::players.back()->id = Person::players.size() - 1;
1414 Person::players.back()->scale = Person::players[0]->scale;
1415 Person::players.back()->creature = rabbittype;
1416 Person::players.back()->howactive = editoractive;
1418 int k = abs(Random() % 2) + 1;
1420 Person::players.back()->whichskin = 0;
1421 } else if (k == 1) {
1422 Person::players.back()->whichskin = 1;
1424 Person::players.back()->whichskin = 2;
1427 Person::players.back()->skeletonLoad(true);
1429 Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
1430 Person::players.back()->speed = 1 + (float)(Random() % 100) / 1000;
1432 Person::players.back()->targetyaw = Person::players[0]->targetyaw;
1433 Person::players.back()->yaw = Person::players[0]->yaw;
1435 Person::players.back()->coords = Person::players[0]->coords;
1436 Person::players.back()->oldcoords = Person::players.back()->coords;
1437 Person::players.back()->realoldcoords = Person::players.back()->coords;
1439 if (Person::players[0]->creature == wolftype) {
1440 headprop = Person::players[0]->proportionhead.x / 1.1;
1441 bodyprop = Person::players[0]->proportionbody.x / 1.1;
1442 armprop = Person::players[0]->proportionarms.x / 1.1;
1443 legprop = Person::players[0]->proportionlegs.x / 1.1;
1446 headprop = Person::players[0]->proportionhead.x / 1.2;
1447 bodyprop = Person::players[0]->proportionbody.x / 1.05;
1448 armprop = Person::players[0]->proportionarms.x / 1.00;
1449 legprop = Person::players[0]->proportionlegs.x / 1.1;
1452 if (Person::players.back()->creature == wolftype) {
1453 Person::players.back()->proportionhead = 1.1 * headprop;
1454 Person::players.back()->proportionbody = 1.1 * bodyprop;
1455 Person::players.back()->proportionarms = 1.1 * armprop;
1456 Person::players.back()->proportionlegs = 1.1 * legprop;
1459 if (Person::players.back()->creature == rabbittype) {
1460 Person::players.back()->proportionhead = 1.2 * headprop;
1461 Person::players.back()->proportionbody = 1.05 * bodyprop;
1462 Person::players.back()->proportionarms = 1.00 * armprop;
1463 Person::players.back()->proportionlegs = 1.1 * legprop;
1464 Person::players.back()->proportionlegs.y = 1.05 * legprop;
1468 Person::players.back()->proportionhead.z = 0;
1469 Person::players.back()->proportionbody.z = 0;
1470 Person::players.back()->proportionarms.z = 0;
1471 Person::players.back()->proportionlegs.z = 0;
1474 Person::players.back()->tempanimation = Animation("Tempanim", lowheight, neutral);
1476 Person::players.back()->damagetolerance = 200;
1478 Person::players.back()->protectionhead = Person::players[0]->protectionhead;
1479 Person::players.back()->protectionhigh = Person::players[0]->protectionhigh;
1480 Person::players.back()->protectionlow = Person::players[0]->protectionlow;
1481 Person::players.back()->armorhead = Person::players[0]->armorhead;
1482 Person::players.back()->armorhigh = Person::players[0]->armorhigh;
1483 Person::players.back()->armorlow = Person::players[0]->armorlow;
1484 Person::players.back()->metalhead = Person::players[0]->metalhead;
1485 Person::players.back()->metalhigh = Person::players[0]->metalhigh;
1486 Person::players.back()->metallow = Person::players[0]->metallow;
1488 Person::players.back()->immobile = Person::players[0]->immobile;
1490 Person::players.back()->numclothes = Person::players[0]->numclothes;
1491 for (int i = 0; i < Person::players.back()->numclothes; i++) {
1492 strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
1493 Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
1494 Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
1495 Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
1497 Person::players.back()->addClothes();
1499 Person::players.back()->power = Person::players[0]->power;
1500 Person::players.back()->speedmult = Person::players[0]->speedmult;
1502 Person::players.back()->loaded = true;
1505 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1506 if (Person::players.back()->numwaypoints < 90) {
1507 Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
1508 Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype;
1509 Person::players.back()->numwaypoints++;
1513 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1514 if (numpathpoints < 30) {
1515 bool connected, alreadyconnected;
1517 if (numpathpoints > 1) {
1518 for (int i = 0; i < numpathpoints; i++) {
1519 if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) {
1520 alreadyconnected = 0;
1521 for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) {
1522 if (pathpointconnect[pathpointselected][j] == i) {
1523 alreadyconnected = 1;
1526 if (!alreadyconnected) {
1527 numpathpointconnect[pathpointselected]++;
1529 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = i;
1536 pathpoint[numpathpoints - 1] = Person::players[0]->coords;
1537 numpathpointconnect[numpathpoints - 1] = 0;
1538 if (numpathpoints > 1 && pathpointselected != -1) {
1539 numpathpointconnect[pathpointselected]++;
1540 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = numpathpoints - 1;
1542 pathpointselected = numpathpoints - 1;
1547 if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) {
1548 pathpointselected++;
1549 if (pathpointselected >= numpathpoints) {
1550 pathpointselected = -1;
1554 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1555 pathpointselected--;
1556 if (pathpointselected <= -2) {
1557 pathpointselected = numpathpoints - 1;
1561 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1562 if (pathpointselected != -1) {
1564 pathpoint[pathpointselected] = pathpoint[numpathpoints];
1565 numpathpointconnect[pathpointselected] = numpathpointconnect[numpathpoints];
1566 for (int i = 0; i < numpathpointconnect[pathpointselected]; i++) {
1567 pathpointconnect[pathpointselected][i] = pathpointconnect[numpathpoints][i];
1569 for (int i = 0; i < numpathpoints; i++) {
1570 for (int j = 0; j < numpathpointconnect[i]; j++) {
1571 if (pathpointconnect[i][j] == pathpointselected) {
1572 pathpointconnect[i][j] = pathpointconnect[i][numpathpointconnect[i] - 1];
1573 numpathpointconnect[i]--;
1575 if (pathpointconnect[i][j] == numpathpoints) {
1576 pathpointconnect[i][j] = pathpointselected;
1580 pathpointselected = numpathpoints - 1;
1584 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1586 if (editortype == treeleavestype || editortype == 10) {
1589 if (editortype < 0) {
1590 editortype = firetype;
1594 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1596 if (editortype == treeleavestype || editortype == 10) {
1599 if (editortype > firetype) {
1604 if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1605 editoryaw -= multiplier * 100;
1606 if (editoryaw < -.01) {
1611 if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1612 editoryaw += multiplier * 100;
1615 if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1616 editorsize += multiplier;
1619 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1620 editorsize -= multiplier;
1621 if (editorsize < .1) {
1626 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1627 mapradius -= multiplier * 10;
1630 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1631 mapradius += multiplier * 10;
1634 if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1635 editorpitch += multiplier * 100;
1638 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1639 editorpitch -= multiplier * 100;
1640 if (editorpitch < -.01) {
1645 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Object::objects.size() && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1646 int closest = findClosestObject();
1648 Object::DeleteObject(closest);
1654 void doJumpReversals()
1656 for (unsigned k = 0; k < Person::players.size(); k++) {
1657 for (unsigned i = k + 1; i < Person::players.size(); i++) {
1658 if (Person::players[k]->skeleton.free == 0 &&
1659 Person::players[i]->skeleton.oldfree == 0 &&
1660 (Person::players[i]->animTarget == jumpupanim ||
1661 Person::players[k]->animTarget == jumpupanim) &&
1662 (Person::players[i]->aitype == playercontrolled ||
1663 Person::players[k]->aitype == playercontrolled) &&
1664 ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) ||
1665 (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) {
1666 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) &&
1667 distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
1668 //TODO: refactor two huge similar ifs
1669 if (Person::players[i]->animTarget == jumpupanim &&
1670 Person::players[k]->animTarget != getupfrombackanim &&
1671 Person::players[k]->animTarget != getupfromfrontanim &&
1672 Animation::animations[Person::players[k]->animTarget].height == middleheight &&
1673 normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 &&
1674 ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) ||
1675 Person::players[k]->aitype != playercontrolled)) {
1676 Person::players[i]->victim = Person::players[k];
1677 Person::players[i]->velocity = 0;
1678 Person::players[i]->animCurrent = jumpreversedanim;
1679 Person::players[i]->animTarget = jumpreversedanim;
1680 Person::players[i]->frameCurrent = 0;
1681 Person::players[i]->frameTarget = 1;
1682 Person::players[i]->targettilt2 = 0;
1683 Person::players[k]->victim = Person::players[i];
1684 Person::players[k]->velocity = 0;
1685 Person::players[k]->animCurrent = jumpreversalanim;
1686 Person::players[k]->animTarget = jumpreversalanim;
1687 Person::players[k]->frameCurrent = 0;
1688 Person::players[k]->frameTarget = 1;
1689 Person::players[k]->targettilt2 = 0;
1690 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 1) {
1691 Person::players[i]->animCurrent = rabbitkickreversedanim;
1692 Person::players[i]->animTarget = rabbitkickreversedanim;
1693 Person::players[i]->frameCurrent = 1;
1694 Person::players[i]->frameTarget = 2;
1695 Person::players[k]->animCurrent = rabbitkickreversalanim;
1696 Person::players[k]->animTarget = rabbitkickreversalanim;
1697 Person::players[k]->frameCurrent = 1;
1698 Person::players[k]->frameTarget = 2;
1700 Person::players[i]->target = 0;
1701 Person::players[k]->oldcoords = Person::players[k]->coords;
1702 Person::players[i]->coords = Person::players[k]->coords;
1703 Person::players[k]->targetyaw = Person::players[i]->targetyaw;
1704 Person::players[k]->yaw = Person::players[i]->targetyaw;
1705 if (Person::players[k]->aitype == attacktypecutoff) {
1706 Person::players[k]->stunned = .5;
1709 if (Person::players[k]->animTarget == jumpupanim &&
1710 Person::players[i]->animTarget != getupfrombackanim &&
1711 Person::players[i]->animTarget != getupfromfrontanim &&
1712 Animation::animations[Person::players[i]->animTarget].height == middleheight &&
1713 normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 &&
1714 ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) ||
1715 Person::players[i]->aitype != playercontrolled)) {
1716 Person::players[k]->victim = Person::players[i];
1717 Person::players[k]->velocity = 0;
1718 Person::players[k]->animCurrent = jumpreversedanim;
1719 Person::players[k]->animTarget = jumpreversedanim;
1720 Person::players[k]->frameCurrent = 0;
1721 Person::players[k]->frameTarget = 1;
1722 Person::players[k]->targettilt2 = 0;
1723 Person::players[i]->victim = Person::players[k];
1724 Person::players[i]->velocity = 0;
1725 Person::players[i]->animCurrent = jumpreversalanim;
1726 Person::players[i]->animTarget = jumpreversalanim;
1727 Person::players[i]->frameCurrent = 0;
1728 Person::players[i]->frameTarget = 1;
1729 Person::players[i]->targettilt2 = 0;
1730 if (Person::players[k]->coords.y < Person::players[i]->coords.y + 1) {
1731 Person::players[k]->animTarget = rabbitkickreversedanim;
1732 Person::players[k]->animCurrent = rabbitkickreversedanim;
1733 Person::players[i]->animCurrent = rabbitkickreversalanim;
1734 Person::players[i]->animTarget = rabbitkickreversalanim;
1735 Person::players[k]->frameCurrent = 1;
1736 Person::players[k]->frameTarget = 2;
1737 Person::players[i]->frameCurrent = 1;
1738 Person::players[i]->frameTarget = 2;
1740 Person::players[k]->target = 0;
1741 Person::players[i]->oldcoords = Person::players[i]->coords;
1742 Person::players[k]->coords = Person::players[i]->coords;
1743 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
1744 Person::players[i]->yaw = Person::players[k]->targetyaw;
1745 if (Person::players[i]->aitype == attacktypecutoff) {
1746 Person::players[i]->stunned = .5;
1755 void doAerialAcrobatics()
1757 static XYZ facing, flatfacing;
1758 for (unsigned k = 0; k < Person::players.size(); k++) {
1759 Person::players[k]->turnspeed = 500;
1761 if ((Person::players[k]->isRun() &&
1762 ((Person::players[k]->targetyaw != rabbitrunninganim &&
1763 Person::players[k]->targetyaw != wolfrunninganim) ||
1764 Person::players[k]->frameTarget == 4)) ||
1765 Person::players[k]->animTarget == removeknifeanim ||
1766 Person::players[k]->animTarget == crouchremoveknifeanim ||
1767 Person::players[k]->animTarget == flipanim ||
1768 Person::players[k]->animTarget == fightsidestep ||
1769 Person::players[k]->animTarget == walkanim) {
1770 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed);
1773 if (Person::players[k]->isStop() ||
1774 Person::players[k]->isLanding() ||
1775 Person::players[k]->animTarget == staggerbackhighanim ||
1776 (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) ||
1777 Person::players[k]->animTarget == staggerbackhardanim ||
1778 Person::players[k]->animTarget == backhandspringanim ||
1779 Person::players[k]->animTarget == dodgebackanim ||
1780 Person::players[k]->animTarget == rollanim ||
1781 (Animation::animations[Person::players[k]->animTarget].attack &&
1782 Person::players[k]->animTarget != rabbitkickanim &&
1783 (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) &&
1784 (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) {
1785 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 2);
1788 if (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent != sneakanim) {
1789 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 4);
1792 Person::players[k]->DoStuff();
1793 if (Person::players[k]->immobile && k != 0) {
1794 Person::players[k]->coords = Person::players[k]->realoldcoords;
1797 //if player's position has changed (?)
1798 if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 &&
1799 !Person::players[k]->skeleton.free &&
1800 Person::players[k]->animTarget != climbanim &&
1801 Person::players[k]->animTarget != hanganim) {
1802 XYZ lowpoint, lowpointtarget, lowpoint2, lowpointtarget2, lowpoint3, lowpointtarget3, lowpoint4, lowpointtarget4, lowpoint5, lowpointtarget5, lowpoint6, lowpointtarget6, lowpoint7, lowpointtarget7, colpoint, colpoint2;
1804 bool tempcollide = 0;
1806 if (Person::players[k]->collide < -.3) {
1807 Person::players[k]->collide = -.3;
1809 if (Person::players[k]->collide > 1) {
1810 Person::players[k]->collide = 1;
1812 Person::players[k]->collide -= multiplier * 30;
1815 Person::players[k]->coords.y = max(Person::players[k]->coords.y, terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z));
1817 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1818 unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1819 if (Object::objects[i]->type != rocktype ||
1820 Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled ||
1821 Object::objects[i]->position.y > Person::players[k]->coords.y) {
1822 lowpoint = Person::players[k]->coords;
1823 if (Person::players[k]->animTarget != jumpupanim &&
1824 Person::players[k]->animTarget != jumpdownanim &&
1825 !Person::players[k]->isFlip()) {
1830 if (Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) &&
1831 Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) {
1832 Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z);
1834 if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1835 flatfacing = lowpoint - Person::players[k]->coords;
1836 Person::players[k]->coords = lowpoint;
1837 Person::players[k]->coords.y -= 1.3;
1838 Person::players[k]->collide = 1;
1841 //TODO: refactor four similar blocks
1842 if (Person::players[k]->aitype == playercontrolled &&
1843 (Person::players[k]->animTarget == jumpupanim ||
1844 Person::players[k]->animTarget == jumpdownanim ||
1845 Person::players[k]->isFlip()) &&
1846 !Person::players[k]->jumptogglekeydown &&
1847 Person::players[k]->jumpkeydown) {
1848 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5;
1849 XYZ tempcoords1 = lowpoint;
1850 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1851 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1852 Person::players[k]->setTargetAnimation(walljumpleftanim);
1853 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1855 pause_sound(whooshsound);
1858 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1859 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1860 if (lowpointtarget.z < 0) {
1861 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1863 Person::players[k]->targetyaw = Person::players[k]->yaw;
1864 Person::players[k]->lowyaw = Person::players[k]->yaw;
1869 lowpoint = tempcoords1;
1870 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5;
1871 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1872 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1873 Person::players[k]->setTargetAnimation(walljumprightanim);
1874 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1876 pause_sound(whooshsound);
1879 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1880 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1881 if (lowpointtarget.z < 0) {
1882 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1884 Person::players[k]->targetyaw = Person::players[k]->yaw;
1885 Person::players[k]->lowyaw = Person::players[k]->yaw;
1890 lowpoint = tempcoords1;
1891 lowpointtarget = lowpoint + Person::players[k]->facing * 2;
1892 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1893 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1894 Person::players[k]->setTargetAnimation(walljumpbackanim);
1895 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1897 pause_sound(whooshsound);
1900 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1901 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1902 if (lowpointtarget.z < 0) {
1903 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1905 Person::players[k]->targetyaw = Person::players[k]->yaw;
1906 Person::players[k]->lowyaw = Person::players[k]->yaw;
1911 lowpoint = tempcoords1;
1912 lowpointtarget = lowpoint - Person::players[k]->facing * 2;
1913 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1914 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1915 Person::players[k]->setTargetAnimation(walljumpfrontanim);
1916 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1918 pause_sound(whooshsound);
1921 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1922 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1923 if (lowpointtarget.z < 0) {
1924 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1926 Person::players[k]->yaw += 180;
1927 Person::players[k]->targetyaw = Person::players[k]->yaw;
1928 Person::players[k]->lowyaw = Person::players[k]->yaw;
1938 } else if (Object::objects[i]->type == rocktype) {
1939 lowpoint2 = Person::players[k]->coords;
1940 lowpoint = Person::players[k]->coords;
1942 if (Object::objects[i]->model.LineCheck(&lowpoint, &lowpoint2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
1943 Person::players[k]->coords = colpoint;
1944 Person::players[k]->collide = 1;
1947 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) {
1948 //flipped into a rock
1949 if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) {
1950 Person::players[k]->RagDoll(0);
1953 if (Person::players[k]->animTarget == jumpupanim) {
1954 Person::players[k]->jumppower = -4;
1955 Person::players[k]->animTarget = Person::players[k]->getIdle();
1957 Person::players[k]->target = 0;
1958 Person::players[k]->frameTarget = 0;
1959 Person::players[k]->onterrain = 1;
1961 if (Person::players[k]->id == 0) {
1962 pause_sound(whooshsound);
1963 OPENAL_SetVolume(channels[whooshsound], 0);
1967 if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) {
1968 if (Person::players[k]->isFlip()) {
1969 Person::players[k]->jumppower = -4;
1971 Person::players[k]->animTarget = Person::players[k]->getLanding();
1972 emit_sound_at(landsound, Person::players[k]->coords, 128.);
1974 addEnvSound(Person::players[k]->coords);
1983 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1984 int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1985 lowpoint = Person::players[k]->coords;
1987 if (Object::objects[i]->type != rocktype) {
1988 if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1989 if (Person::players[k]->animTarget != jumpupanim &&
1990 Person::players[k]->animTarget != jumpdownanim &&
1991 Person::players[k]->onterrain) {
1992 Person::players[k]->avoidcollided = 1;
1994 Person::players[k]->coords = lowpoint;
1995 Person::players[k]->coords.y -= 1.35;
1996 Person::players[k]->collide = 1;
1998 if ((Person::players[k]->grabdelay <= 0 || Person::players[k]->aitype != playercontrolled) &&
1999 (Person::players[k]->animCurrent != climbanim &&
2000 Person::players[k]->animCurrent != hanganim &&
2001 !Person::players[k]->isWallJump() ||
2002 Person::players[k]->animTarget == jumpupanim ||
2003 Person::players[k]->animTarget == jumpdownanim)) {
2004 lowpoint = Person::players[k]->coords;
2005 Object::objects[i]->model.SphereCheckPossible(&lowpoint, 1.5, &Object::objects[i]->position, &Object::objects[i]->yaw);
2006 lowpoint = Person::players[k]->coords;
2010 facing = DoRotation(facing, 0, Person::players[k]->targetyaw + 180, 0);
2011 lowpointtarget = lowpoint + facing * 1.4;
2012 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
2013 if (whichhit != -1) {
2014 lowpoint = Person::players[k]->coords;
2016 lowpointtarget = lowpoint + facing * 1.4;
2017 lowpoint2 = lowpoint;
2018 lowpointtarget2 = lowpointtarget;
2019 lowpoint3 = lowpoint;
2020 lowpointtarget3 = lowpointtarget;
2021 lowpoint4 = lowpoint;
2022 lowpointtarget4 = lowpointtarget;
2023 lowpoint5 = lowpoint;
2024 lowpointtarget5 = lowpointtarget;
2025 lowpoint6 = lowpoint;
2026 lowpointtarget6 = lowpointtarget;
2027 lowpoint7 = lowpoint;
2028 lowpointtarget7 = lowpoint;
2030 lowpointtarget2.x += .1;
2032 lowpointtarget3.z += .1;
2034 lowpointtarget4.x -= .1;
2036 lowpointtarget5.z -= .1;
2037 lowpoint6.y += 45 / 13;
2038 lowpointtarget6.y += 45 / 13;
2039 lowpointtarget6 += facing * .6;
2040 lowpointtarget7.y += 90 / 13;
2041 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
2042 if (Object::objects[i]->friction > .5) {
2043 if (whichhit != -1) {
2044 if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) {
2045 Person::players[k]->collided = 1;
2047 if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) {
2048 if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) {
2049 if (Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2,
2050 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2051 Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3,
2052 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2053 Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4,
2054 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2055 Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5,
2056 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
2057 for (int j = 0; j < 45; j++) {
2058 lowpoint = Person::players[k]->coords;
2059 lowpoint.y += (float)j / 13;
2060 lowpointtarget = lowpoint + facing * 1.4;
2061 if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget,
2062 &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) {
2063 if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) {
2066 if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) {
2067 lowpoint = Person::players[k]->coords;
2068 lowpoint.y += (float)j / 13;
2069 lowpointtarget = lowpoint + facing * 1.3;
2070 flatfacing = Person::players[k]->coords;
2071 Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * .01;
2072 Person::players[k]->coords.y = lowpointtarget.y - .07;
2073 Person::players[k]->currentoffset = (flatfacing - Person::players[k]->coords) / Person::players[k]->scale;
2075 if (j > 10 || !Person::players[k]->isRun()) {
2076 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) {
2078 pause_sound(whooshsound);
2081 emit_sound_at(jumpsound, Person::players[k]->coords, 128.);
2083 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
2084 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
2085 if (lowpointtarget.z < 0) {
2086 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
2088 Person::players[k]->targetyaw = Person::players[k]->yaw;
2089 Person::players[k]->lowyaw = Person::players[k]->yaw;
2091 //Person::players[k]->velocity=lowpointtarget*.03;
2092 Person::players[k]->velocity = 0;
2095 if (Person::players[k]->animTarget == jumpupanim) {
2096 Person::players[k]->animTarget = climbanim;
2097 Person::players[k]->jumppower = 0;
2098 Person::players[k]->jumpclimb = 1;
2100 Person::players[k]->transspeed = 6;
2101 Person::players[k]->target = 0;
2102 Person::players[k]->frameTarget = 1;
2105 Person::players[k]->setTargetAnimation(hanganim);
2106 Person::players[k]->jumppower = 0;
2124 if (Person::players[k]->collide <= 0) {
2126 if (!Person::players[k]->onterrain &&
2127 Person::players[k]->animTarget != jumpupanim &&
2128 Person::players[k]->animTarget != jumpdownanim &&
2129 Person::players[k]->animTarget != climbanim &&
2130 Person::players[k]->animTarget != hanganim &&
2131 !Person::players[k]->isWallJump() &&
2132 !Person::players[k]->isFlip()) {
2133 if (Person::players[k]->animCurrent != climbanim &&
2134 Person::players[k]->animCurrent != tempanim &&
2135 Person::players[k]->animTarget != backhandspringanim &&
2136 (Person::players[k]->animTarget != rollanim ||
2137 Person::players[k]->frameTarget < 2 ||
2138 Person::players[k]->frameTarget > 6)) {
2139 //stagger off ledge (?)
2140 if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) {
2141 Person::players[k]->RagDoll(0);
2143 Person::players[k]->setTargetAnimation(jumpdownanim);
2146 emit_sound_at(whooshsound, Person::players[k]->coords, 128.);
2150 Person::players[k]->velocity.y += gravity;
2154 Person::players[k]->realoldcoords = Person::players[k]->coords;
2160 static int randattack;
2161 static bool playerrealattackkeydown = 0;
2163 if (!Input::isKeyDown(attackkey)) {
2167 Person::players[0]->attackkeydown = 0;
2170 playerrealattackkeydown = 0;
2172 if (!oldattackkey) {
2173 playerrealattackkeydown = Input::isKeyDown(attackkey);
2175 if ((Person::players[0]->parriedrecently <= 0 ||
2176 Person::players[0]->weaponactive == -1) &&
2179 Person::players[0]->lastattack != swordslashanim &&
2180 Person::players[0]->lastattack != knifeslashstartanim &&
2181 Person::players[0]->lastattack != staffhitanim &&
2182 Person::players[0]->lastattack != staffspinhitanim))) {
2183 Person::players[0]->attackkeydown = Input::isKeyDown(attackkey);
2185 if (Input::isKeyDown(attackkey) &&
2187 !Person::players[0]->backkeydown) {
2188 for (unsigned k = 0; k < Person::players.size(); k++) {
2189 if ((Person::players[k]->animTarget == swordslashanim ||
2190 Person::players[k]->animTarget == staffhitanim ||
2191 Person::players[k]->animTarget == staffspinhitanim) &&
2192 Person::players[0]->animCurrent != dodgebackanim &&
2193 !Person::players[k]->skeleton.free) {
2194 Person::players[k]->Reverse();
2199 if (!hostile || Dialog::inDialog()) {
2200 Person::players[0]->attackkeydown = 0;
2203 for (unsigned k = 0; k < Person::players.size(); k++) {
2204 if (Dialog::inDialog()) {
2205 Person::players[k]->attackkeydown = 0;
2207 if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) {
2208 if (Person::players[k]->aitype != playercontrolled) {
2209 Person::players[k]->victim = Person::players[0];
2211 //attack key pressed
2212 if (Person::players[k]->attackkeydown) {
2214 if (Person::players[k]->backkeydown &&
2215 Person::players[k]->animTarget != backhandspringanim &&
2216 (Person::players[k]->isIdle() ||
2217 Person::players[k]->isStop() ||
2218 Person::players[k]->isRun() ||
2219 Person::players[k]->animTarget == walkanim)) {
2220 if (Person::players[k]->jumppower <= 1) {
2221 Person::players[k]->jumppower -= 2;
2223 for (unsigned i = 0; i < Person::players.size(); i++) {
2227 if (Person::players[i]->animTarget == swordslashanim ||
2228 Person::players[i]->animTarget == knifeslashstartanim ||
2229 Person::players[i]->animTarget == staffhitanim ||
2230 Person::players[i]->animTarget == staffspinhitanim) {
2231 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) {
2232 Person::players[k]->setTargetAnimation(dodgebackanim);
2233 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2234 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2238 if (Person::players[k]->animTarget != dodgebackanim) {
2242 Person::players[k]->setTargetAnimation(backhandspringanim);
2243 Person::players[k]->targetyaw = -yaw + 180;
2244 if (Person::players[k]->leftkeydown) {
2245 Person::players[k]->targetyaw -= 45;
2247 if (Person::players[k]->rightkeydown) {
2248 Person::players[k]->targetyaw += 45;
2250 Person::players[k]->yaw = Person::players[k]->targetyaw;
2251 Person::players[k]->jumppower -= 2;
2256 if (!Animation::animations[Person::players[k]->animTarget].attack &&
2257 !Person::players[k]->backkeydown &&
2258 (Person::players[k]->isIdle() ||
2259 Person::players[k]->isRun() ||
2260 Person::players[k]->animTarget == walkanim ||
2261 Person::players[k]->animTarget == sneakanim ||
2262 Person::players[k]->isCrouch())) {
2263 const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType();
2264 //normal attacks (?)
2265 Person::players[k]->hasvictim = 0;
2266 if (Person::players.size() > 1) {
2267 for (unsigned i = 0; i < Person::players.size(); i++) {
2268 if (i == k || !(k == 0 || i == 0)) {
2271 if (!Person::players[k]->hasvictim) {
2272 if (Animation::animations[Person::players[k]->animTarget].attack != reversal) {
2274 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2275 if (distance < 4.5 &&
2276 !Person::players[i]->skeleton.free &&
2277 Person::players[i]->howactive < typedead1 &&
2278 Person::players[i]->animTarget != jumpreversedanim &&
2279 Person::players[i]->animTarget != rabbitkickreversedanim &&
2280 Person::players[i]->animTarget != rabbitkickanim &&
2281 Person::players[k]->animTarget != rabbitkickanim &&
2282 Person::players[i]->animTarget != getupfrombackanim &&
2283 (Person::players[i]->animTarget != staggerbackhighanim &&
2284 (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) &&
2285 Person::players[i]->animTarget != jumpdownanim &&
2286 Person::players[i]->animTarget != jumpupanim &&
2287 Person::players[i]->animTarget != getupfromfrontanim) {
2288 Person::players[k]->victim = Person::players[i];
2289 Person::players[k]->hasvictim = 1;
2290 if (Person::players[k]->aitype == playercontrolled) { //human player
2292 if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2293 Person::players[k]->crouchkeydown &&
2294 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2295 Person::players[k]->animTarget = sweepanim;
2297 } else if (distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2298 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2299 !Person::players[k]->forwardkeydown &&
2300 !Person::players[k]->leftkeydown &&
2301 !Person::players[k]->rightkeydown &&
2302 !Person::players[k]->crouchkeydown &&
2305 Person::players[k]->animTarget = winduppunchanim;
2307 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2308 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2309 !Person::players[k]->forwardkeydown &&
2310 !Person::players[k]->leftkeydown &&
2311 !Person::players[k]->rightkeydown &&
2312 !Person::players[k]->crouchkeydown &&
2314 Person::players[k]->animTarget = upunchanim;
2316 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2317 Person::players[i]->staggerdelay > 0 &&
2318 attackweapon == knife &&
2319 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) {
2320 Person::players[k]->animTarget = knifefollowanim;
2322 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2323 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2324 !Person::players[k]->forwardkeydown &&
2325 !Person::players[k]->leftkeydown &&
2326 !Person::players[k]->rightkeydown &&
2327 !Person::players[k]->crouchkeydown &&
2328 attackweapon == knife &&
2329 Person::players[k]->weaponmissdelay <= 0) {
2330 Person::players[k]->animTarget = knifeslashstartanim;
2332 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2333 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2334 !Person::players[k]->crouchkeydown &&
2335 attackweapon == sword &&
2336 Person::players[k]->weaponmissdelay <= 0) {
2337 Person::players[k]->animTarget = swordslashanim;
2339 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2340 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2341 !Person::players[k]->crouchkeydown &&
2342 attackweapon == staff &&
2343 Person::players[k]->weaponmissdelay <= 0 &&
2344 !Person::players[k]->leftkeydown &&
2345 !Person::players[k]->rightkeydown &&
2346 !Person::players[k]->forwardkeydown) {
2347 Person::players[k]->animTarget = staffhitanim;
2349 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2350 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2351 !Person::players[k]->crouchkeydown &&
2352 attackweapon == staff &&
2353 Person::players[k]->weaponmissdelay <= 0) {
2354 Person::players[k]->animTarget = staffspinhitanim;
2356 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2357 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2358 Person::players[k]->animTarget = spinkickanim;
2360 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2361 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2362 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2363 Person::players[k]->animTarget = lowkickanim;
2365 } else { //AI player
2366 if (distance < 4.5 * sq(Person::players[k]->scale * 5)) {
2367 randattack = abs(Random() % 5);
2368 if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) {
2370 if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2371 Person::players[k]->animTarget = sweepanim;
2373 } else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2375 Person::players[k]->animTarget = upunchanim;
2377 } else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2378 Person::players[k]->animTarget = spinkickanim;
2380 } else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) {
2381 Person::players[k]->animTarget = lowkickanim;
2386 if ((!Tutorial::active || !attackweapon) &&
2387 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2389 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2390 Person::players[k]->animTarget = sweepanim;
2392 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2393 attackweapon == knife &&
2394 Person::players[k]->weaponmissdelay <= 0) {
2395 Person::players[k]->animTarget = knifeslashstartanim;
2397 } else if (!(Person::players[0]->victim == Person::players[i] &&
2398 Person::players[0]->hasvictim &&
2399 Person::players[0]->animTarget == swordslashanim) &&
2400 attackweapon == sword &&
2401 Person::players[k]->weaponmissdelay <= 0) {
2402 Person::players[k]->animTarget = swordslashanim;
2404 } else if (!(Person::players[0]->victim == Person::players[i] &&
2405 Person::players[0]->hasvictim &&
2406 Person::players[0]->animTarget == swordslashanim) &&
2407 attackweapon == staff &&
2408 Person::players[k]->weaponmissdelay <= 0 &&
2410 Person::players[k]->animTarget = staffhitanim;
2412 } else if (!(Person::players[0]->victim == Person::players[i] &&
2413 Person::players[0]->hasvictim &&
2414 Person::players[0]->animTarget == swordslashanim) &&
2415 attackweapon == staff &&
2416 Person::players[k]->weaponmissdelay <= 0 &&
2418 Person::players[k]->animTarget = staffspinhitanim;
2420 } else if ((!Tutorial::active || !attackweapon) &&
2421 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2423 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2424 Person::players[k]->animTarget = spinkickanim;
2426 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2427 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2428 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2429 Person::players[k]->animTarget = lowkickanim;
2434 //upunch becomes wolfslap
2435 if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) {
2436 Person::players[k]->animTarget = wolfslapanim;
2440 if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) &&
2441 Person::players[i]->howactive < typedead1 &&
2442 distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2443 !Person::players[i]->skeleton.free &&
2444 Person::players[i]->animTarget != getupfrombackanim &&
2445 Person::players[i]->animTarget != getupfromfrontanim &&
2446 (Person::players[i]->surprised > 0 ||
2447 Person::players[i]->aitype == passivetype ||
2448 attackweapon && Person::players[i]->stunned > 0) &&
2449 normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) {
2451 if (!attackweapon) {
2452 Person::players[k]->animCurrent = sneakattackanim;
2453 Person::players[k]->animTarget = sneakattackanim;
2454 Person::players[i]->animCurrent = sneakattackedanim;
2455 Person::players[i]->animTarget = sneakattackedanim;
2456 Person::players[k]->oldcoords = Person::players[k]->coords;
2457 Person::players[k]->coords = Person::players[i]->coords;
2460 if (attackweapon == knife) {
2461 Person::players[k]->animCurrent = knifesneakattackanim;
2462 Person::players[k]->animTarget = knifesneakattackanim;
2463 Person::players[i]->animCurrent = knifesneakattackedanim;
2464 Person::players[i]->animTarget = knifesneakattackedanim;
2465 Person::players[i]->oldcoords = Person::players[i]->coords;
2466 Person::players[i]->coords = Person::players[k]->coords;
2469 if (attackweapon == sword) {
2470 Person::players[k]->animCurrent = swordsneakattackanim;
2471 Person::players[k]->animTarget = swordsneakattackanim;
2472 Person::players[i]->animCurrent = swordsneakattackedanim;
2473 Person::players[i]->animTarget = swordsneakattackedanim;
2474 Person::players[i]->oldcoords = Person::players[i]->coords;
2475 Person::players[i]->coords = Person::players[k]->coords;
2477 if (attackweapon != staff) {
2478 Person::players[k]->victim = Person::players[i];
2479 Person::players[k]->hasvictim = 1;
2480 Person::players[i]->targettilt2 = 0;
2481 Person::players[i]->frameTarget = 1;
2482 Person::players[i]->frameCurrent = 0;
2483 Person::players[i]->target = 0;
2484 Person::players[i]->velocity = 0;
2485 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2486 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2487 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2488 Person::players[k]->target = Person::players[i]->target;
2489 Person::players[k]->velocity = 0;
2490 Person::players[k]->targetyaw = Person::players[i]->yaw;
2491 Person::players[k]->yaw = Person::players[i]->yaw;
2492 Person::players[i]->targetyaw = Person::players[i]->yaw;
2495 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2496 Person::players[k]->victim == Person::players[i] &&
2497 (!Person::players[i]->skeleton.free)) {
2499 Person::players[k]->frameTarget = 0;
2500 Person::players[k]->target = 0;
2502 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2503 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2504 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2505 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2506 Person::players[k]->lastattack = Person::players[k]->animTarget;
2508 if (Person::players[k]->animTarget == knifefollowanim &&
2509 Person::players[k]->victim == Person::players[i]) {
2511 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2512 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2513 Person::players[k]->victim = Person::players[i];
2514 Person::players[k]->hasvictim = 1;
2515 Person::players[i]->animTarget = knifefollowedanim;
2516 Person::players[i]->animCurrent = knifefollowedanim;
2517 Person::players[i]->targettilt2 = 0;
2518 Person::players[i]->targettilt2 = Person::players[k]->targettilt2;
2519 Person::players[i]->frameTarget = 1;
2520 Person::players[i]->frameCurrent = 0;
2521 Person::players[i]->target = 0;
2522 Person::players[i]->velocity = 0;
2523 Person::players[k]->animCurrent = knifefollowanim;
2524 Person::players[k]->animTarget = knifefollowanim;
2525 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2526 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2527 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2528 Person::players[k]->target = Person::players[i]->target;
2529 Person::players[k]->velocity = 0;
2530 Person::players[k]->oldcoords = Person::players[k]->coords;
2531 Person::players[i]->coords = Person::players[k]->coords;
2532 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
2533 Person::players[i]->yaw = Person::players[k]->targetyaw;
2534 Person::players[k]->yaw = Person::players[k]->targetyaw;
2535 Person::players[i]->yaw = Person::players[k]->targetyaw;
2541 const bool hasstaff = attackweapon == staff;
2542 if (k == 0 && Person::players.size() > 1) {
2543 for (unsigned i = 0; i < Person::players.size(); i++) {
2547 if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) &&
2548 Animation::animations[Person::players[k]->animTarget].attack == neutral) {
2549 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2550 if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) {
2551 if (Person::players[i]->skeleton.free) {
2552 if (distance < 3.5 * sq(Person::players[k]->scale * 5) &&
2553 (Person::players[i]->dead ||
2554 Person::players[i]->skeleton.longdead > 1000 ||
2555 Person::players[k]->isRun() ||
2558 (Person::players[i]->skeleton.longdead > 2000 ||
2559 Person::players[i]->damage > Person::players[i]->damagetolerance / 8 ||
2560 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) &&
2561 distance < 1.5 * sq(Person::players[k]->scale * 5)))) {
2562 Person::players[k]->victim = Person::players[i];
2563 Person::players[k]->hasvictim = 1;
2564 if (attackweapon && !Tutorial::active) {
2566 if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) {
2567 Person::players[k]->animTarget = crouchstabanim;
2570 if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) {
2571 Person::players[k]->animTarget = swordgroundstabanim;
2574 if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) {
2575 Person::players[k]->animTarget = staffgroundsmashanim;
2578 if (distance < 2.5 &&
2579 Person::players[k]->crouchkeydown &&
2580 Person::players[k]->animTarget != crouchstabanim &&
2582 Person::players[i]->dead &&
2583 Person::players[i]->skeleton.free &&
2584 Person::players[i]->skeleton.longdead > 1000) {
2585 Person::players[k]->animTarget = killanim;
2586 terrain.deleteDeadDecals();
2587 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2588 if (Object::objects[l]->model.type == decalstype) {
2589 Object::objects[l]->model.deleteDeadDecals();
2593 if (!Person::players[i]->dead || musictype != 2) {
2594 if (distance < 3.5 &&
2595 (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) &&
2596 Person::players[k]->staggerdelay <= 0 &&
2597 (Person::players[i]->dead ||
2598 Person::players[i]->skeleton.longdead < 300 &&
2599 Person::players[k]->lastattack != spinkickanim &&
2600 Person::players[i]->skeleton.free) &&
2601 (!Person::players[i]->dead || musictype != stream_fighttheme)) {
2602 Person::players[k]->animTarget = dropkickanim;
2603 terrain.deleteDeadDecals();
2604 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2605 if (Object::objects[l]->model.type == decalstype) {
2606 Object::objects[l]->model.deleteDeadDecals();
2614 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2615 Person::players[k]->victim == Person::players[i] &&
2616 (!Person::players[i]->skeleton.free ||
2617 Person::players[k]->animTarget == killanim ||
2618 Person::players[k]->animTarget == crouchstabanim ||
2619 Person::players[k]->animTarget == swordgroundstabanim ||
2620 Person::players[k]->animTarget == staffgroundsmashanim ||
2621 Person::players[k]->animTarget == dropkickanim)) {
2623 Person::players[k]->frameTarget = 0;
2624 Person::players[k]->target = 0;
2626 XYZ targetpoint = Person::players[i]->coords;
2627 if (Person::players[k]->animTarget == crouchstabanim ||
2628 Person::players[k]->animTarget == swordgroundstabanim ||
2629 Person::players[k]->animTarget == staffgroundsmashanim) {
2630 targetpoint += (Person::players[i]->jointPos(abdomen) +
2631 Person::players[i]->jointPos(neck)) /
2633 Person::players[i]->scale;
2635 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, targetpoint);
2636 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, targetpoint);
2638 if (Person::players[k]->animTarget == crouchstabanim || Person::players[k]->animTarget == swordgroundstabanim) {
2639 Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4;
2642 if (Person::players[k]->animTarget == staffgroundsmashanim) {
2643 Person::players[k]->targettilt2 += 10;
2646 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2647 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2648 Person::players[k]->lastattack = Person::players[k]->animTarget;
2650 if (Person::players[k]->animTarget == swordgroundstabanim) {
2651 Person::players[k]->targetyaw += 30;
2657 if (!Person::players[k]->hasvictim) {
2659 for (unsigned i = 0; i < Person::players.size(); i++) {
2660 if (i == k || !(i == 0 || k == 0)) {
2663 if (!Person::players[i]->skeleton.free) {
2664 if (Person::players[k]->hasvictim) {
2665 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) <
2666 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) {
2667 Person::players[k]->victim = Person::players[i];
2670 Person::players[k]->victim = Person::players[i];
2671 Person::players[k]->hasvictim = 1;
2676 if (Person::players[k]->aitype == playercontrolled) {
2678 if (Person::players[k]->attackkeydown &&
2679 Person::players[k]->isRun() &&
2680 Person::players[k]->wasRun() &&
2681 ((Person::players[k]->hasvictim &&
2682 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) &&
2683 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) &&
2684 !Person::players[k]->victim->skeleton.free &&
2685 Person::players[k]->victim->animTarget != getupfrombackanim &&
2686 Person::players[k]->victim->animTarget != getupfromfrontanim &&
2687 Animation::animations[Person::players[k]->victim->animTarget].height != lowheight &&
2688 Person::players[k]->aitype != playercontrolled && //wat???
2689 normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 &&
2690 Person::players[k]->rabbitkickenabled) ||
2691 Person::players[k]->jumpkeydown)) {
2693 Person::players[k]->setTargetAnimation(rabbitkickanim);
2697 if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) {
2699 switch (attackweapon) {
2720 void doPlayerCollisions()
2722 static XYZ rotatetarget;
2723 static float collisionradius;
2724 if (Person::players.size() > 1) {
2725 for (unsigned k = 0; k < Person::players.size(); k++) {
2726 for (unsigned i = k + 1; i < Person::players.size(); i++) {
2727 //neither player is part of a reversal
2728 if ((Animation::animations[Person::players[i]->animTarget].attack != reversed &&
2729 Animation::animations[Person::players[i]->animTarget].attack != reversal &&
2730 Animation::animations[Person::players[k]->animTarget].attack != reversed &&
2731 Animation::animations[Person::players[k]->animTarget].attack != reversal) ||
2732 (i != 0 && k != 0)) {
2733 if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed &&
2734 Animation::animations[Person::players[i]->animCurrent].attack != reversal &&
2735 Animation::animations[Person::players[k]->animCurrent].attack != reversed &&
2736 Animation::animations[Person::players[k]->animCurrent].attack != reversal) ||
2737 (i != 0 && k != 0)) {
2738 //neither is sleeping
2739 if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) {
2740 if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) {
2741 //in same patch, neither is climbing
2742 if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx &&
2743 Person::players[i]->whichpatchz == Person::players[k]->whichpatchz &&
2744 Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free &&
2745 Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free &&
2746 Person::players[i]->animTarget != climbanim &&
2747 Person::players[i]->animTarget != hanganim &&
2748 Person::players[k]->animTarget != climbanim &&
2749 Person::players[k]->animTarget != hanganim) {
2750 //players are close (bounding box test)
2751 if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) {
2752 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) {
2753 if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) {
2754 if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) {
2755 if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) {
2756 if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) {
2757 //spread fire from player to player
2758 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2759 if (Person::players[i]->onfire || Person::players[k]->onfire) {
2760 if (!Person::players[i]->onfire) {
2761 Person::players[i]->CatchFire();
2763 if (!Person::players[k]->onfire) {
2764 Person::players[k]->CatchFire();
2769 XYZ tempcoords1 = Person::players[i]->coords;
2770 XYZ tempcoords2 = Person::players[k]->coords;
2771 if (!Person::players[i]->skeleton.oldfree) {
2772 tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale;
2774 if (!Person::players[k]->skeleton.oldfree) {
2775 tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale;
2777 collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2778 if (Person::players[0]->hasvictim) {
2779 if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) {
2780 collisionradius = 3;
2783 if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) &&
2784 (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
2785 distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) {
2786 //jump down on a dead body
2787 if (k == 0 || i == 0) {
2789 if (Person::players[0]->animTarget == jumpdownanim &&
2790 !Person::players[0]->skeleton.oldfree &&
2791 !Person::players[0]->skeleton.free &&
2792 Person::players[l]->skeleton.oldfree &&
2793 Person::players[l]->skeleton.free &&
2794 Person::players[l]->dead &&
2795 Person::players[0]->lastcollide <= 0 &&
2796 fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 &&
2797 distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) {
2798 Person::players[0]->coords.y = Person::players[l]->coords.y;
2799 Person::players[l]->velocity = Person::players[0]->velocity;
2800 Person::players[l]->skeleton.free = 0;
2801 Person::players[l]->yaw = 0;
2802 Person::players[l]->RagDoll(0);
2803 Person::players[l]->DoDamage(20);
2805 Person::players[l]->skeleton.longdead = 0;
2806 Person::players[0]->lastcollide = 1;
2810 if ((Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) ||
2811 (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) ||
2812 (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) {
2813 rotatetarget = Person::players[k]->velocity - Person::players[i]->velocity;
2814 if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim ||
2815 Person::players[i]->skeleton.free) &&
2816 (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim ||
2817 Person::players[k]->skeleton.free)) {
2818 if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
2819 k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) &&
2820 normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) &&
2822 k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral ||
2823 /*i!=0&&*/ Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) ||
2824 (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) &&
2825 (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) &&
2826 k == 0 && !Person::players[i]->skeleton.oldfree && !Person::players[k]->skeleton.oldfree) {
2828 if ((i != 0 || Person::players[i]->skeleton.free) &&
2829 (k != 0 || Person::players[k]->skeleton.free) ||
2830 (Animation::animations[Person::players[i]->animTarget].height == highheight &&
2831 Animation::animations[Person::players[k]->animTarget].height == highheight)) {
2832 if (!Tutorial::active) {
2833 emit_sound_at(heavyimpactsound, Person::players[i]->coords);
2836 Person::players[i]->RagDoll(0);
2837 if (Person::players[i]->damage > Person::players[i]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[i]->dead) {
2838 award_bonus(0, aimbonus);
2840 Person::players[i]->DoDamage(findLengthfast(&rotatetarget) / 4);
2841 Person::players[k]->RagDoll(0);
2842 if (Person::players[k]->damage > Person::players[k]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[k]->dead) {
2843 award_bonus(0, aimbonus); // Huh, again?
2845 Person::players[k]->DoDamage(findLengthfast(&rotatetarget) / 4);
2847 for (unsigned j = 0; j < Person::players[i]->skeleton.joints.size(); j++) {
2848 Person::players[i]->skeleton.joints[j].velocity = Person::players[i]->skeleton.joints[j].velocity / 5 + Person::players[k]->velocity;
2850 for (unsigned j = 0; j < Person::players[k]->skeleton.joints.size(); j++) {
2851 Person::players[k]->skeleton.joints[j].velocity = Person::players[k]->skeleton.joints[j].velocity / 5 + Person::players[i]->velocity;
2856 if ((Animation::animations[Person::players[i]->animTarget].attack == neutral ||
2857 Animation::animations[Person::players[i]->animTarget].attack == normalattack) &&
2858 (Animation::animations[Person::players[k]->animTarget].attack == neutral ||
2859 Animation::animations[Person::players[k]->animTarget].attack == normalattack)) {
2861 if (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0) {
2862 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < .5 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2863 rotatetarget = Person::players[k]->coords - Person::players[i]->coords;
2864 Normalise(&rotatetarget);
2865 Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2;
2866 Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2867 Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2868 if (Person::players[k]->howactive == typeactive || hostile) {
2869 if (Person::players[k]->isIdle()) {
2870 if (Person::players[k]->howactive < typesleeping) {
2871 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
2872 } else if (Person::players[k]->howactive == typesleeping) {
2873 Person::players[k]->setTargetAnimation(getupfromfrontanim);
2875 if (!editorenabled) {
2876 Person::players[k]->howactive = typeactive;
2880 if (Person::players[i]->howactive == typeactive || hostile) {
2881 if (Person::players[i]->isIdle()) {
2882 if (Person::players[i]->howactive < typesleeping) {
2883 Person::players[i]->setTargetAnimation(Person::players[k]->getStop());
2885 Person::players[i]->setTargetAnimation(getupfromfrontanim);
2887 if (!editorenabled) {
2888 Person::players[i]->howactive = typeactive;
2893 //jump down on player
2895 if (k == 0 && i != 0 && Person::players[k]->animTarget == jumpdownanim &&
2896 !Person::players[i]->isCrouch() &&
2897 Person::players[i]->animTarget != rollanim &&
2898 !Person::players[k]->skeleton.oldfree && !Person::players[k]->skeleton.free &&
2899 Person::players[k]->lastcollide <= 0 &&
2900 Person::players[k]->velocity.y < -10) {
2901 Person::players[i]->velocity = Person::players[k]->velocity;
2902 Person::players[k]->velocity = Person::players[k]->velocity * -.5;
2903 Person::players[k]->velocity.y = Person::players[i]->velocity.y;
2904 Person::players[i]->DoDamage(20);
2905 Person::players[i]->RagDoll(0);
2906 Person::players[k]->lastcollide = 1;
2907 award_bonus(k, AboveBonus);
2909 if (i == 0 && k != 0 && Person::players[i]->animTarget == jumpdownanim &&
2910 !Person::players[k]->isCrouch() &&
2911 Person::players[k]->animTarget != rollanim &&
2912 !Person::players[i]->skeleton.oldfree &&
2913 !Person::players[i]->skeleton.free &&
2914 Person::players[i]->lastcollide <= 0 &&
2915 Person::players[i]->velocity.y < -10) {
2916 Person::players[k]->velocity = Person::players[i]->velocity;
2917 Person::players[i]->velocity = Person::players[i]->velocity * -.3;
2918 Person::players[i]->velocity.y = Person::players[k]->velocity.y;
2919 Person::players[k]->DoDamage(20);
2920 Person::players[k]->RagDoll(0);
2921 Person::players[i]->lastcollide = 1;
2922 award_bonus(i, AboveBonus);
2928 Person::players[i]->CheckKick();
2929 Person::players[k]->CheckKick();
2949 static XYZ facing, flatfacing;
2954 if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
2955 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
2956 stereoreverse = true;
2958 stereoreverse = false;
2961 if (stereoreverse) {
2962 printf("Stereo reversed\n");
2964 printf("Stereo unreversed\n");
2968 if (Input::isKeyDown(SDL_SCANCODE_F7)) {
2969 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
2970 stereoseparation -= 0.001;
2972 stereoseparation -= 0.010;
2974 printf("Stereo decreased increased to %f\n", stereoseparation);
2977 if (Input::isKeyDown(SDL_SCANCODE_F8)) {
2978 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
2979 stereoseparation += 0.001;
2981 stereoseparation += 0.010;
2983 printf("Stereo separation increased to %f\n", stereoseparation);
2986 if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) {
2987 if (Tutorial::stage != 51) {
2988 Tutorial::stagetime = Tutorial::maxtime;
2990 emit_sound_np(consolefailsound, 128.);
2994 Values of mainmenu :
2996 2 Menu pause (resume/end game)
2998 4 Controls configuration menu
2999 5 Main game menu (choose level or challenge)
3000 6 Deleting user menu
3001 7 User managment menu (select/add)
3002 8 Choose difficulty menu
3003 9 Challenge level selection menu
3004 10 End of the campaign congratulation (is that really a menu?)
3005 11 Same that 9 ??? => unused
3006 18 stereo configuration
3011 if (mainmenu && endgame == 1) {
3014 //go to level select after completing a campaign level
3015 if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) {
3022 OPENAL_SetFrequency(OPENAL_ALL);
3023 emit_stream_np(stream_menutheme);
3024 pause_sound(leveltheme);
3028 //escape key pressed
3029 if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
3030 (gameon || mainmenu == 0)) {
3032 if (mainmenu == 0 && !winfreeze) {
3033 mainmenu = 2; //pause
3034 } else if (mainmenu == 1 || mainmenu == 2) {
3035 mainmenu = 0; //unpause
3038 if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
3039 OPENAL_SetFrequency(OPENAL_ALL);
3040 emit_stream_np(stream_menutheme);
3041 pause_sound(leveltheme);
3043 //on resume, play level music
3045 pause_sound(stream_menutheme);
3046 resume_stream(leveltheme);
3057 hostiletime += multiplier;
3062 leveltime += multiplier;
3066 if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V) && devtools) {
3069 OPENAL_SetFrequency(OPENAL_ALL);
3073 if (Input::isKeyPressed(consolekey) && devtools) {
3076 OPENAL_SetFrequency(OPENAL_ALL);
3086 if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) {
3087 inputText(consoletext[0], &consoleselected);
3089 if (!consoletext[0].empty()) {
3090 cmd_dispatch(consoletext[0]);
3091 for (int k = 14; k >= 1; k--) {
3092 consoletext[k] = consoletext[k - 1];
3094 consoletext[0].clear();
3095 consoleselected = 0;
3099 consoleblinkdelay -= multiplier;
3100 if (consoleblinkdelay <= 0) {
3101 consoleblinkdelay = .3;
3102 consoleblink = !consoleblink;
3106 static int oldwinfreeze;
3107 if (winfreeze && !oldwinfreeze) {
3108 OPENAL_SetFrequency(OPENAL_ALL);
3109 emit_sound_np(consolesuccesssound);
3111 if (winfreeze == 0) {
3112 oldwinfreeze = winfreeze;
3117 if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign) {
3122 if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) {
3126 } else if (winfreeze) {
3132 if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
3135 static float talkdelay = 0;
3137 if (Dialog::inDialog()) {
3140 talkdelay -= multiplier;
3142 if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) {
3143 for (unsigned i = 0; i < Dialog::dialogs.size(); i++) {
3144 Dialog::dialogs[i].tick(i);
3148 windvar += multiplier;
3149 smoketex += multiplier;
3150 Tutorial::stagetime += multiplier;
3153 static float hotspotvisual[40];
3154 if (Hotspot::hotspots.size()) {
3156 if (editorenabled) {
3157 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3158 hotspotvisual[i] -= multiplier / 320;
3162 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3163 while (hotspotvisual[i] < 0) {
3165 hotspotsprite.x = float(abs(Random() % 100000)) / 100000 * Hotspot::hotspots[i].size;
3166 hotspotsprite = DoRotation(hotspotsprite, 0, 0, Random() % 360);
3167 hotspotsprite = DoRotation(hotspotsprite, 0, Random() % 360, 0);
3168 hotspotsprite += Hotspot::hotspots[i].position;
3169 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite * 0, 1, 0.5, 0, 7, 0.4);
3170 hotspotvisual[i] += 0.1 / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size;
3174 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3175 if (Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type > 0) {
3176 Hotspot::hotspots[i].position = Person::players[Hotspot::hotspots[i].type]->coords;
3182 if (Tutorial::active) {
3183 Tutorial::Do(multiplier);
3187 if (!Tutorial::active) {
3188 if (bonustime == 0 &&
3189 bonus != solidhit &&
3190 bonus != spinecrusher &&
3191 bonus != tracheotomy &&
3192 bonus != backstab &&
3194 emit_sound_np(consolesuccesssound);
3196 } else if (bonustime == 0) {
3197 emit_sound_np(fireendsound);
3199 if (bonustime == 0) {
3200 if (bonus != solidhit &&
3201 bonus != twoxcombo &&
3202 bonus != threexcombo &&
3203 bonus != fourxcombo &&
3204 bonus != megacombo) {
3207 bonusnum[bonus] += 0.15;
3209 if (Tutorial::active) {
3212 if (bonusvalue > 0) {
3213 bonusvalue /= bonusnum[bonus];
3214 if (bonusvalue <= 0) {
3218 bonustotal += bonusvalue;
3220 bonustime += multiplier;
3223 if (environment == snowyenvironment) {
3224 precipdelay -= multiplier;
3225 while (precipdelay < 0) {
3230 XYZ footvel, footpoint;
3233 footpoint = viewer + viewerfacing * 6;
3234 footpoint.y += ((float)abs(Random() % 1200)) / 100 - 6;
3235 footpoint.x += ((float)abs(Random() % 1200)) / 100 - 6;
3236 footpoint.z += ((float)abs(Random() % 1200)) / 100 - 6;
3237 Sprite::MakeSprite(snowsprite, footpoint, footvel, 1, 1, 1, .1, 1);
3241 doAerialAcrobatics();
3243 static XYZ oldviewer;
3246 if (!Dialog::inDialog()) {
3247 Person::players[0]->forwardkeydown = Input::isKeyDown(forwardkey);
3248 Person::players[0]->leftkeydown = Input::isKeyDown(leftkey);
3249 Person::players[0]->backkeydown = Input::isKeyDown(backkey);
3250 Person::players[0]->rightkeydown = Input::isKeyDown(rightkey);
3251 Person::players[0]->jumpkeydown = Input::isKeyDown(jumpkey);
3252 Person::players[0]->crouchkeydown = Input::isKeyDown(crouchkey);
3253 Person::players[0]->drawkeydown = Input::isKeyDown(drawkey);
3254 Person::players[0]->throwkeydown = Input::isKeyDown(throwkey);
3256 Person::players[0]->forwardkeydown = 0;
3257 Person::players[0]->leftkeydown = 0;
3258 Person::players[0]->backkeydown = 0;
3259 Person::players[0]->rightkeydown = 0;
3260 Person::players[0]->jumpkeydown = 0;
3261 Person::players[0]->crouchkeydown = 0;
3262 Person::players[0]->drawkeydown = 0;
3263 Person::players[0]->throwkeydown = 0;
3266 if (!Person::players[0]->jumpkeydown) {
3267 Person::players[0]->jumpclimb = 0;
3270 if (Dialog::inDialog()) {
3272 if (Dialog::directing) {
3276 facing = DoRotation(facing, -pitch, 0, 0);
3277 facing = DoRotation(facing, 0, 0 - yaw, 0);
3282 flatfacing = DoRotation(flatfacing, 0, -yaw, 0);
3284 if (Input::isKeyDown(forwardkey)) {
3285 viewer += facing * multiplier * 4;
3287 if (Input::isKeyDown(backkey)) {
3288 viewer -= facing * multiplier * 4;
3290 if (Input::isKeyDown(leftkey)) {
3291 viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4;
3293 if (Input::isKeyDown(rightkey)) {
3294 viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4;
3296 if (Input::isKeyDown(jumpkey)) {
3297 viewer.y += multiplier * 4;
3299 if (Input::isKeyDown(crouchkey)) {
3300 viewer.y -= multiplier * 4;
3302 if (Input::isKeyPressed(SDL_SCANCODE_1) ||
3303 Input::isKeyPressed(SDL_SCANCODE_2) ||
3304 Input::isKeyPressed(SDL_SCANCODE_3) ||
3305 Input::isKeyPressed(SDL_SCANCODE_4) ||
3306 Input::isKeyPressed(SDL_SCANCODE_5) ||
3307 Input::isKeyPressed(SDL_SCANCODE_6) ||
3308 Input::isKeyPressed(SDL_SCANCODE_7) ||
3309 Input::isKeyPressed(SDL_SCANCODE_8) ||
3310 Input::isKeyPressed(SDL_SCANCODE_9) ||
3311 Input::isKeyPressed(SDL_SCANCODE_0) ||
3312 Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3314 if (Input::isKeyPressed(SDL_SCANCODE_1)) {
3317 if (Input::isKeyPressed(SDL_SCANCODE_2)) {
3320 if (Input::isKeyPressed(SDL_SCANCODE_3)) {
3323 if (Input::isKeyPressed(SDL_SCANCODE_4)) {
3326 if (Input::isKeyPressed(SDL_SCANCODE_5)) {
3329 if (Input::isKeyPressed(SDL_SCANCODE_6)) {
3332 if (Input::isKeyPressed(SDL_SCANCODE_7)) {
3335 if (Input::isKeyPressed(SDL_SCANCODE_8)) {
3338 if (Input::isKeyPressed(SDL_SCANCODE_9)) {
3341 if (Input::isKeyPressed(SDL_SCANCODE_0)) {
3344 if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3347 if (whichend != -1) {
3348 Dialog::currentScene().participantfocus = whichend;
3349 Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords;
3350 Dialog::currentDialog().participantyaw[whichend] = Person::players[whichend]->yaw;
3352 if (whichend == -1) {
3353 Dialog::currentScene().participantfocus = -1;
3355 /* FIXME: potentially accessing -1 in Person::players! */
3356 if (Person::players[Dialog::currentScene().participantfocus]->dead) {
3357 Dialog::indialogue = -1;
3358 Dialog::directing = false;
3361 Dialog::currentScene().camera = viewer;
3362 Dialog::currentScene().camerayaw = yaw;
3363 Dialog::currentScene().camerapitch = pitch;
3364 Dialog::indialogue++;
3365 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3366 if (Dialog::currentScene().sound != 0) {
3367 playdialoguescenesound();
3371 for (unsigned j = 0; j < Person::players.size(); j++) {
3372 Dialog::currentScene().participantfacing[j] = Dialog::currentDialog().scenes[Dialog::indialogue - 1].participantfacing[j];
3375 //TODO: should these be KeyDown or KeyPressed?
3376 if (Input::isKeyDown(SDL_SCANCODE_KP_1) ||
3377 Input::isKeyDown(SDL_SCANCODE_KP_2) ||
3378 Input::isKeyDown(SDL_SCANCODE_KP_3) ||
3379 Input::isKeyDown(SDL_SCANCODE_KP_4) ||
3380 Input::isKeyDown(SDL_SCANCODE_KP_5) ||
3381 Input::isKeyDown(SDL_SCANCODE_KP_6) ||
3382 Input::isKeyDown(SDL_SCANCODE_KP_7) ||
3383 Input::isKeyDown(SDL_SCANCODE_KP_8) ||
3384 Input::isKeyDown(SDL_SCANCODE_KP_9) ||
3385 Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3387 if (Input::isKeyDown(SDL_SCANCODE_KP_1)) {
3390 if (Input::isKeyDown(SDL_SCANCODE_KP_2)) {
3393 if (Input::isKeyDown(SDL_SCANCODE_KP_3)) {
3396 if (Input::isKeyDown(SDL_SCANCODE_KP_4)) {
3399 if (Input::isKeyDown(SDL_SCANCODE_KP_5)) {
3402 if (Input::isKeyDown(SDL_SCANCODE_KP_6)) {
3405 if (Input::isKeyDown(SDL_SCANCODE_KP_7)) {
3408 if (Input::isKeyDown(SDL_SCANCODE_KP_8)) {
3411 if (Input::isKeyDown(SDL_SCANCODE_KP_9)) {
3414 if (Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3417 Dialog::currentScene().participantfacing[whichend] = facing;
3419 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3420 Dialog::indialogue = -1;
3421 Dialog::directing = false;
3425 if (!Dialog::directing) {
3426 pause_sound(whooshsound);
3427 viewer = Dialog::currentScene().camera;
3428 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .1);
3429 yaw = Dialog::currentScene().camerayaw;
3430 pitch = Dialog::currentScene().camerapitch;
3431 if (Dialog::dialoguetime > 0.5) {
3432 if (Input::isKeyPressed(attackkey)) {
3433 Dialog::indialogue++;
3434 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3435 if (Dialog::currentScene().sound != 0) {
3436 playdialoguescenesound();
3437 if (Dialog::currentScene().sound == -5) {
3438 Hotspot::hotspots.emplace_back(Person::players[0]->coords, -1, 10);
3440 if (Dialog::currentScene().sound == -6) {
3444 if (Person::players.at(Dialog::currentScene().participantfocus)->dead) {
3445 Dialog::indialogue = -1;
3446 Dialog::directing = false;
3453 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3454 Dialog::indialogue = -1;
3455 Dialog::directing = false;
3457 if (Dialog::currentDialog().type > 19 && Dialog::currentDialog().type < 30) {
3460 if (Dialog::currentDialog().type > 29 && Dialog::currentDialog().type < 40) {
3463 if (Dialog::currentDialog().type > 49 && Dialog::currentDialog().type < 60) {
3465 for (unsigned i = 1; i < Person::players.size(); i++) {
3466 Person::players[i]->aitype = attacktypecutoff;
3473 if (!Person::players[0]->jumpkeydown) {
3474 Person::players[0]->jumptogglekeydown = 0;
3476 if (Person::players[0]->jumpkeydown &&
3477 Person::players[0]->animTarget != jumpupanim &&
3478 Person::players[0]->animTarget != jumpdownanim &&
3479 !Person::players[0]->isFlip()) {
3480 Person::players[0]->jumptogglekeydown = 1;
3483 Dialog::dialoguetime += multiplier;
3484 hawkyaw += multiplier * 25;
3486 realhawkcoords.x = 25;
3487 realhawkcoords = DoRotation(realhawkcoords, 0, hawkyaw, 0) + hawkcoords;
3488 hawkcalldelay -= multiplier / 2;
3490 if (hawkcalldelay <= 0) {
3491 emit_sound_at(hawksound, realhawkcoords);
3493 hawkcalldelay = 16 + abs(Random() % 8);
3500 doPlayerCollisions();
3504 for (unsigned k = 0; k < Person::players.size(); k++) {
3505 if (k != 0 && Person::players[k]->immobile) {
3506 Person::players[k]->coords = Person::players[k]->realoldcoords;
3510 for (unsigned k = 0; k < Person::players.size(); k++) {
3511 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3512 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3513 Person::players[k]->DoDamage(1000);
3519 static bool respawnkeydown;
3520 if (!editorenabled &&
3521 (whichlevel != -2 &&
3522 (Input::isKeyDown(SDL_SCANCODE_Z) &&
3523 Input::isKeyDown(SDL_SCANCODE_LGUI) &&
3525 (Input::isKeyDown(jumpkey) &&
3528 Person::players[0]->dead))) {
3529 targetlevel = whichlevel;
3533 respawnkeydown = Input::isKeyDown(jumpkey);
3535 static bool movekey;
3538 for (unsigned i = 0; i < Person::players.size(); i++) {
3539 static float oldtargetyaw;
3540 if (!Person::players[i]->skeleton.free) {
3541 oldtargetyaw = Person::players[i]->targetyaw;
3542 if (i == 0 && !Dialog::inDialog()) {
3543 //TODO: refactor repetitive code
3544 if (!Animation::animations[Person::players[0]->animTarget].attack &&
3545 Person::players[0]->animTarget != staggerbackhighanim &&
3546 Person::players[0]->animTarget != staggerbackhardanim &&
3547 Person::players[0]->animTarget != crouchremoveknifeanim &&
3548 Person::players[0]->animTarget != removeknifeanim &&
3549 Person::players[0]->animTarget != backhandspringanim &&
3550 Person::players[0]->animTarget != dodgebackanim &&
3551 Person::players[0]->animTarget != walljumprightkickanim &&
3552 Person::players[0]->animTarget != walljumpleftkickanim) {
3554 Person::players[0]->targetyaw = 0;
3556 Person::players[0]->targetyaw = -yaw + 180;
3563 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3565 facing = flatfacing;
3567 facing = DoRotation(facing, -pitch, 0, 0);
3568 facing = DoRotation(facing, 0, 0 - yaw, 0);
3571 Person::players[0]->lookyaw = -yaw;
3573 Person::players[i]->targetheadyaw = yaw;
3574 Person::players[i]->targetheadpitch = pitch;
3576 if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) {
3577 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3578 Person::players[i]->animTarget != staggerbackhighanim &&
3579 Person::players[i]->animTarget != staggerbackhardanim &&
3580 Person::players[i]->animTarget != crouchremoveknifeanim &&
3581 Person::players[i]->animTarget != removeknifeanim &&
3582 Person::players[i]->animTarget != backhandspringanim &&
3583 Person::players[i]->animTarget != dodgebackanim &&
3584 Person::players[i]->animTarget != walljumprightkickanim &&
3585 Person::players[i]->animTarget != walljumpleftkickanim) {
3586 Person::players[i]->targetyaw = -Person::players[i]->lookyaw + 180;
3592 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3594 facing = DoRotation(facing, -Person::players[i]->lookpitch, 0, 0);
3595 facing = DoRotation(facing, 0, 0 - Person::players[i]->lookyaw, 0);
3597 Person::players[i]->targetheadyaw = Person::players[i]->lookyaw;
3598 Person::players[i]->targetheadpitch = Person::players[i]->lookpitch;
3600 if (Dialog::inDialog()) {
3601 Person::players[i]->targetheadyaw = 180 - roughDirection(Dialog::currentScene().participantfacing[i]);
3602 Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]);
3605 if (leveltime < .5) {
3609 Person::players[i]->avoidsomething = 0;
3611 //avoid flaming things
3612 for (unsigned int j = 0; j < Object::objects.size(); j++) {
3613 if (Object::objects[j]->onfire) {
3614 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) {
3615 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3616 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3617 Person::players[i]->collided = 0;
3618 Person::players[i]->avoidcollided = 1;
3619 if (Person::players[i]->avoidsomething == 0 ||
3620 distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3621 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3622 Person::players[i]->avoidwhere = Object::objects[j]->position;
3623 Person::players[i]->avoidsomething = 1;
3630 //avoid flaming players
3631 for (unsigned j = 0; j < Person::players.size(); j++) {
3632 if (Person::players[j]->onfire) {
3633 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) {
3634 if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3635 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3636 Person::players[i]->collided = 0;
3637 Person::players[i]->avoidcollided = 1;
3638 if (Person::players[i]->avoidsomething == 0 ||
3639 distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3640 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3641 Person::players[i]->avoidwhere = Person::players[j]->coords;
3642 Person::players[i]->avoidsomething = 1;
3649 if (Person::players[i]->collided > .8) {
3650 Person::players[i]->avoidcollided = 0;
3653 Person::players[i]->doAI();
3655 if (Animation::animations[Person::players[i]->animTarget].attack == reversed) {
3656 //Person::players[i]->targetyaw=Person::players[i]->yaw;
3657 Person::players[i]->forwardkeydown = 0;
3658 Person::players[i]->leftkeydown = 0;
3659 Person::players[i]->backkeydown = 0;
3660 Person::players[i]->rightkeydown = 0;
3661 Person::players[i]->jumpkeydown = 0;
3662 Person::players[i]->attackkeydown = 0;
3663 //Person::players[i]->crouchkeydown=0;
3664 Person::players[i]->throwkeydown = 0;
3667 if (Dialog::inDialog()) {
3668 Person::players[i]->forwardkeydown = 0;
3669 Person::players[i]->leftkeydown = 0;
3670 Person::players[i]->backkeydown = 0;
3671 Person::players[i]->rightkeydown = 0;
3672 Person::players[i]->jumpkeydown = 0;
3673 Person::players[i]->crouchkeydown = 0;
3674 Person::players[i]->drawkeydown = 0;
3675 Person::players[i]->throwkeydown = 0;
3678 if (Person::players[i]->collided < -.3) {
3679 Person::players[i]->collided = -.3;
3681 if (Person::players[i]->collided > 1) {
3682 Person::players[i]->collided = 1;
3684 Person::players[i]->collided -= multiplier * 4;
3685 Person::players[i]->whichdirectiondelay -= multiplier;
3686 if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) {
3687 Person::players[i]->avoidcollided = -.3;
3688 Person::players[i]->whichdirection = abs(Random() % 2);
3689 Person::players[i]->whichdirectiondelay = .4;
3691 if (Person::players[i]->avoidcollided > 1) {
3692 Person::players[i]->avoidcollided = 1;
3694 Person::players[i]->avoidcollided -= multiplier / 4;
3695 if (!Person::players[i]->skeleton.free) {
3696 Person::players[i]->stunned -= multiplier;
3697 Person::players[i]->surprised -= multiplier;
3699 if (i != 0 && Person::players[i]->surprised <= 0 &&
3700 Person::players[i]->aitype == attacktypecutoff &&
3701 !Person::players[i]->dead &&
3702 !Person::players[i]->skeleton.free &&
3703 Animation::animations[Person::players[i]->animTarget].attack == neutral) {
3707 if (!Person::players[i]->throwkeydown) {
3708 Person::players[i]->throwtogglekeydown = 0;
3712 if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) {
3713 if (Person::players[i]->weaponactive == -1 &&
3714 Person::players[i]->num_weapons < 2 &&
3715 (Person::players[i]->isIdle() ||
3716 Person::players[i]->isCrouch() ||
3717 Person::players[i]->animTarget == sneakanim ||
3718 Person::players[i]->animTarget == rollanim ||
3719 Person::players[i]->animTarget == backhandspringanim ||
3720 Person::players[i]->isFlip() ||
3721 Person::players[i]->aitype != playercontrolled)) {
3722 for (unsigned j = 0; j < weapons.size(); j++) {
3723 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3724 Person::players[i]->aitype == playercontrolled) &&
3725 weapons[j].owner == -1 &&
3726 Person::players[i]->weaponactive == -1) {
3727 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) {
3728 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) {
3729 if (Person::players[i]->isCrouch() ||
3730 Person::players[i]->animTarget == sneakanim ||
3731 Person::players[i]->isRun() ||
3732 Person::players[i]->isIdle() ||
3733 Person::players[i]->aitype != playercontrolled) {
3734 Person::players[i]->throwtogglekeydown = 1;
3735 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3736 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3737 Person::players[i]->hasvictim = 0;
3739 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3740 Person::players[i]->throwtogglekeydown = 1;
3741 Person::players[i]->hasvictim = 0;
3743 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3744 Person::players[i]->aitype == playercontrolled) &&
3745 weapons[j].owner == -1 ||
3746 Person::players[i]->victim &&
3747 weapons[j].owner == int(Person::players[i]->victim->id)) {
3748 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) {
3749 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) {
3750 if (weapons[j].getType() != staff) {
3751 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3754 Person::players[i]->takeWeapon(j);
3759 } else if ((Person::players[i]->isIdle() ||
3760 Person::players[i]->isFlip() ||
3761 Person::players[i]->aitype != playercontrolled) &&
3762 distsq(&Person::players[i]->coords, &weapons[j].position) < 5 &&
3763 Person::players[i]->coords.y < weapons[j].position.y) {
3764 if (!Person::players[i]->isFlip()) {
3765 Person::players[i]->throwtogglekeydown = 1;
3766 Person::players[i]->setTargetAnimation(removeknifeanim);
3767 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3769 if (Person::players[i]->isFlip()) {
3770 Person::players[i]->throwtogglekeydown = 1;
3771 Person::players[i]->hasvictim = 0;
3773 for (unsigned k = 0; k < weapons.size(); k++) {
3774 if (Person::players[i]->weaponactive == -1) {
3775 if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 ||
3776 Person::players[i]->aitype == playercontrolled) &&
3777 weapons[k].owner == -1 ||
3778 Person::players[i]->victim &&
3779 weapons[k].owner == int(Person::players[i]->victim->id)) {
3780 if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 &&
3781 Person::players[i]->weaponactive == -1) {
3782 if (weapons[k].getType() != staff) {
3783 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3786 Person::players[i]->takeWeapon(k);
3796 if (Person::players[i]->isCrouch() ||
3797 Person::players[i]->animTarget == sneakanim ||
3798 Person::players[i]->isRun() ||
3799 Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim ||
3800 Person::players[i]->animTarget == backhandspringanim) {
3801 if (Person::players.size() > 1) {
3802 for (unsigned j = 0; j < Person::players.size(); j++) {
3803 if (Person::players[i]->weaponactive == -1) {
3805 if (Person::players[j]->num_weapons &&
3806 Person::players[j]->skeleton.free &&
3807 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ &&
3808 (((Person::players[j]->skeleton.forward.y < 0 &&
3809 Person::players[j]->weaponstuckwhere == 0) ||
3810 (Person::players[j]->skeleton.forward.y > 0 &&
3811 Person::players[j]->weaponstuckwhere == 1)) ||
3812 Person::players[j]->weaponstuck == -1 ||
3813 Person::players[j]->num_weapons > 1)) {
3814 if (Person::players[i]->animTarget != rollanim && Person::players[i]->animTarget != backhandspringanim) {
3815 Person::players[i]->throwtogglekeydown = 1;
3816 Person::players[i]->victim = Person::players[j];
3817 Person::players[i]->hasvictim = 1;
3818 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3819 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3821 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3822 Person::players[i]->throwtogglekeydown = 1;
3823 Person::players[i]->victim = Person::players[j];
3824 Person::players[i]->hasvictim = 1;
3825 int k = Person::players[j]->weaponids[0];
3826 if (Person::players[i]->hasvictim) {
3829 if (Person::players[i]->victim->weaponstuck != -1) {
3830 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3835 if (weapons[k].getType() != staff) {
3836 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3840 emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.);
3843 if (weapons[k].owner != -1) {
3844 if (Person::players[i]->victim->num_weapons == 1) {
3845 Person::players[i]->victim->num_weapons = 0;
3847 Person::players[i]->victim->num_weapons = 1;
3850 Person::players[i]->victim->skeleton.longdead = 0;
3851 Person::players[i]->victim->skeleton.free = 1;
3852 Person::players[i]->victim->skeleton.broken = 0;
3854 for (unsigned l = 0; l < Person::players[i]->victim->skeleton.joints.size(); l++) {
3855 Person::players[i]->victim->skeleton.joints[l].velchange = 0;
3856 Person::players[i]->victim->skeleton.joints[l].locked = 0;
3862 Normalise(&relative);
3863 XYZ footvel, footpoint;
3865 footpoint = weapons[k].position;
3866 if (Person::players[i]->victim->weaponstuck != -1) {
3867 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3869 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
3871 weapons[k].bloody = 2;
3872 weapons[k].blooddrip = 5;
3873 Person::players[i]->victim->weaponstuck = -1;
3874 Person::players[i]->victim->bloodloss += 2000;
3875 Person::players[i]->victim->DoDamage(2000);
3878 if (Person::players[i]->victim->num_weapons > 0) {
3879 if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) {
3880 Person::players[i]->victim->weaponstuck = 0;
3882 if (Person::players[i]->victim->weaponids[0] == k) {
3883 Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons];
3887 Person::players[i]->victim->weaponactive = -1;
3889 Person::players[i]->victim->jointVel(abdomen) += relative * 6;
3890 Person::players[i]->victim->jointVel(neck) += relative * 6;
3891 Person::players[i]->victim->jointVel(rightshoulder) += relative * 6;
3892 Person::players[i]->victim->jointVel(leftshoulder) += relative * 6;
3894 Person::players[i]->takeWeapon(k);
3904 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3905 if (weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3906 if (Person::players[i]->isIdle() ||
3907 Person::players[i]->isRun() ||
3908 Person::players[i]->isCrouch() ||
3909 Person::players[i]->animTarget == sneakanim ||
3910 Person::players[i]->isFlip()) {
3911 if (Person::players.size() > 1) {
3912 for (unsigned j = 0; j < Person::players.size(); j++) {
3914 if (!Tutorial::active || Tutorial::stage == 49) {
3916 if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 &&
3917 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 &&
3918 distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 &&
3919 !Person::players[j]->skeleton.free &&
3920 -1 == Object::checkcollide(DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords, DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0) * Person::players[i]->scale + Person::players[i]->coords)) {
3921 if (!Person::players[i]->isFlip()) {
3922 Person::players[i]->throwtogglekeydown = 1;
3923 Person::players[i]->victim = Person::players[j];
3924 Person::players[i]->setTargetAnimation(knifethrowanim);
3925 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3926 Person::players[i]->targettilt2 = pitchTo(Person::players[i]->coords, Person::players[j]->coords);
3928 if (Person::players[i]->isFlip()) {
3929 if (Person::players[i]->weaponactive != -1) {
3930 Person::players[i]->throwtogglekeydown = 1;
3931 Person::players[i]->victim = Person::players[j];
3933 aim = Person::players[i]->victim->coords + DoRotation(Person::players[i]->victim->jointPos(abdomen), 0, Person::players[i]->victim->yaw, 0) * Person::players[i]->victim->scale + Person::players[i]->victim->velocity * findDistance(&Person::players[i]->victim->coords, &Person::players[i]->coords) / 50 - (Person::players[i]->coords + DoRotation(Person::players[i]->jointPos(righthand), 0, Person::players[i]->yaw, 0) * Person::players[i]->scale);
3936 aim = DoRotation(aim, (float)abs(Random() % 30) - 15, (float)abs(Random() % 30) - 15, 0);
3938 weapons[Person::players[i]->weaponids[0]].thrown(aim * 50, false);
3939 Person::players[i]->num_weapons--;
3940 if (Person::players[i]->num_weapons) {
3941 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3943 Person::players[i]->weaponactive = -1;
3955 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3956 if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) {
3957 Person::players[i]->throwtogglekeydown = 1;
3958 XYZ tempVelocity = Person::players[i]->velocity * .2;
3959 if (tempVelocity.x == 0) {
3960 tempVelocity.x = .1;
3962 weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false);
3963 Person::players[i]->num_weapons--;
3964 if (Person::players[i]->num_weapons) {
3965 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3966 if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) {
3967 Person::players[i]->weaponstuck = 0;
3971 Person::players[i]->weaponactive = -1;
3972 for (unsigned j = 0; j < Person::players.size(); j++) {
3973 Person::players[j]->wentforweapon = 0;
3980 if (i == 0 || !Person::players[0]->dead || (Person::players[i]->weaponactive != -1)) {
3981 if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown ||
3982 (Person::players[i]->num_weapons == 2) &&
3983 (Person::players[i]->weaponactive == -1) &&
3984 Person::players[i]->isIdle() ||
3985 Person::players[0]->dead &&
3986 (Person::players[i]->weaponactive != -1) &&
3989 if (Person::players[i]->weaponactive != -1) {
3990 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) {
3994 if (isgood && Person::players[i]->creature != wolftype) {
3995 if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3996 Person::players[i]->setTargetAnimation(drawrightanim);
3997 Person::players[i]->drawtogglekeydown = 1;
3999 if ((Person::players[i]->isIdle() ||
4000 (Person::players[i]->aitype != playercontrolled &&
4001 Person::players[0]->weaponactive != -1 &&
4002 Person::players[i]->isRun())) &&
4003 Person::players[i]->num_weapons &&
4004 weapons[Person::players[i]->weaponids[0]].getType() == sword) {
4005 Person::players[i]->setTargetAnimation(drawleftanim);
4006 Person::players[i]->drawtogglekeydown = 1;
4008 if (Person::players[i]->isCrouch() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
4009 Person::players[i]->setTargetAnimation(crouchdrawrightanim);
4010 Person::players[i]->drawtogglekeydown = 1;
4017 if (Person::players[i]->weaponactive != -1) {
4018 if (Person::players[i]->isCrouch() &&
4019 weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody &&
4021 Person::players[i]->onterrain &&
4022 Person::players[i]->num_weapons &&
4023 Person::players[i]->attackkeydown &&
4024 musictype != stream_fighttheme) {
4025 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) {
4026 Person::players[i]->setTargetAnimation(crouchstabanim);
4028 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) {
4029 Person::players[i]->setTargetAnimation(swordgroundstabanim);
4031 Person::players[i]->hasvictim = 0;
4035 if (!Person::players[i]->drawkeydown) {
4036 Person::players[i]->drawtogglekeydown = 0;
4042 absflatfacing.z = -1;
4044 absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0);
4046 absflatfacing = flatfacing;
4049 if (Dialog::inDialog()) {
4050 Person::players[i]->forwardkeydown = 0;
4051 Person::players[i]->leftkeydown = 0;
4052 Person::players[i]->backkeydown = 0;
4053 Person::players[i]->rightkeydown = 0;
4054 Person::players[i]->jumpkeydown = 0;
4055 Person::players[i]->crouchkeydown = 0;
4056 Person::players[i]->drawkeydown = 0;
4057 Person::players[i]->throwkeydown = 0;
4061 if (!Animation::animations[Person::players[i]->animTarget].attack &&
4062 Person::players[i]->animTarget != staggerbackhighanim &&
4063 Person::players[i]->animTarget != staggerbackhardanim &&
4064 Person::players[i]->animTarget != backhandspringanim &&
4065 Person::players[i]->animTarget != dodgebackanim) {
4066 if (!Person::players[i]->forwardkeydown) {
4067 Person::players[i]->forwardstogglekeydown = 0;
4069 if (Person::players[i]->crouchkeydown) {
4073 Person::players[i]->superruntoggle = 1;
4074 if (Person::players.size() > 1) {
4075 for (unsigned j = 0; j < Person::players.size(); j++) {
4076 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) {
4077 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) {
4078 Person::players[i]->superruntoggle = 0;
4085 if (Person::players.size() > 1) {
4086 for (unsigned j = 0; j < Person::players.size(); j++) {
4087 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) {
4088 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4089 Person::players[j]->victim == Person::players[i] &&
4090 (Person::players[j]->animTarget == sweepanim ||
4091 Person::players[j]->animTarget == upunchanim ||
4092 Person::players[j]->animTarget == wolfslapanim ||
4093 ((Person::players[j]->animTarget == swordslashanim ||
4094 Person::players[j]->animTarget == knifeslashstartanim ||
4095 Person::players[j]->animTarget == staffhitanim ||
4096 Person::players[j]->animTarget == staffspinhitanim) &&
4097 distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) {
4108 Person::players[target]->Reverse();
4110 Person::players[i]->lowreversaldelay = .5;
4112 if (Person::players[i]->isIdle()) {
4113 Person::players[i]->setTargetAnimation(Person::players[i]->getCrouch());
4114 Person::players[i]->transspeed = 10;
4116 if (Person::players[i]->isRun() ||
4117 (Person::players[i]->isStop() &&
4118 (Person::players[i]->leftkeydown ||
4119 Person::players[i]->rightkeydown ||
4120 Person::players[i]->forwardkeydown ||
4121 Person::players[i]->backkeydown))) {
4122 Person::players[i]->setTargetAnimation(rollanim);
4123 Person::players[i]->transspeed = 20;
4126 if (!Person::players[i]->crouchkeydown) {
4128 if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) {
4129 Person::players[i]->superruntoggle = 0;
4132 if (Person::players[i]->isCrouch()) {
4133 if (Person::players.size() > 1) {
4134 for (unsigned j = 0; j < Person::players.size(); j++) {
4136 !Person::players[j]->skeleton.free &&
4137 Person::players[j]->victim &&
4138 Person::players[i]->highreversaldelay <= 0) {
4139 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4140 Person::players[j]->victim == Person::players[i] &&
4141 (Person::players[j]->animTarget == spinkickanim) &&
4142 Person::players[i]->isCrouch()) {
4153 Person::players[target]->Reverse();
4155 Person::players[i]->highreversaldelay = .5;
4157 if (Person::players[i]->isCrouch()) {
4158 if (!Person::players[i]->wasCrouch()) {
4159 Person::players[i]->animCurrent = Person::players[i]->getCrouch();
4160 Person::players[i]->frameCurrent = 0;
4162 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4163 Person::players[i]->transspeed = 10;
4166 if (Person::players[i]->animTarget == sneakanim) {
4167 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4168 Person::players[i]->transspeed = 10;
4171 if (Person::players[i]->forwardkeydown) {
4172 if (Person::players[i]->isIdle() ||
4173 (Person::players[i]->isStop() &&
4174 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4175 (Person::players[i]->isLanding() &&
4176 Person::players[i]->frameTarget > 0 &&
4177 !Person::players[i]->jumpkeydown) ||
4178 (Person::players[i]->isLandhard() &&
4179 Person::players[i]->frameTarget > 0 &&
4180 !Person::players[i]->jumpkeydown &&
4181 Person::players[i]->crouchkeydown)) {
4182 if (Person::players[i]->aitype == passivetype) {
4183 Person::players[i]->setTargetAnimation(walkanim);
4185 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4188 if (Person::players[i]->isCrouch()) {
4189 Person::players[i]->animTarget = sneakanim;
4190 if (Person::players[i]->wasCrouch()) {
4191 Person::players[i]->target = 0;
4193 Person::players[i]->frameTarget = 0;
4195 if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) {
4196 Person::players[i]->setTargetAnimation(climbanim);
4197 Person::players[i]->frameTarget = 1;
4198 Person::players[i]->jumpclimb = 1;
4200 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4201 Person::players[i]->velocity += absflatfacing * 5 * multiplier;
4203 Person::players[i]->forwardstogglekeydown = 1;
4206 if (Person::players[i]->rightkeydown) {
4207 if (Person::players[i]->isIdle() ||
4208 (Person::players[i]->isStop() &&
4209 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4210 (Person::players[i]->isLanding() &&
4211 Person::players[i]->frameTarget > 0 &&
4212 !Person::players[i]->jumpkeydown) ||
4213 (Person::players[i]->isLandhard() &&
4214 Person::players[i]->frameTarget > 0 &&
4215 !Person::players[i]->jumpkeydown &&
4216 Person::players[i]->crouchkeydown)) {
4217 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4219 if (Person::players[i]->isCrouch()) {
4220 Person::players[i]->animTarget = sneakanim;
4221 if (Person::players[i]->wasCrouch()) {
4222 Person::players[i]->target = 0;
4224 Person::players[i]->frameTarget = 0;
4226 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4227 Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4229 Person::players[i]->targetyaw -= 90;
4230 if (Person::players[i]->forwardkeydown) {
4231 Person::players[i]->targetyaw += 45;
4233 if (Person::players[i]->backkeydown) {
4234 Person::players[i]->targetyaw -= 45;
4238 if (Person::players[i]->leftkeydown) {
4239 if (Person::players[i]->isIdle() ||
4240 (Person::players[i]->isStop() &&
4241 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4242 (Person::players[i]->isLanding() &&
4243 Person::players[i]->frameTarget > 0 &&
4244 !Person::players[i]->jumpkeydown) ||
4245 (Person::players[i]->isLandhard() &&
4246 Person::players[i]->frameTarget > 0 &&
4247 !Person::players[i]->jumpkeydown &&
4248 Person::players[i]->crouchkeydown)) {
4249 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4251 if (Person::players[i]->isCrouch()) {
4252 Person::players[i]->animTarget = sneakanim;
4253 if (Person::players[i]->wasCrouch()) {
4254 Person::players[i]->target = 0;
4256 Person::players[i]->frameTarget = 0;
4258 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4259 Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4261 Person::players[i]->targetyaw += 90;
4262 if (Person::players[i]->forwardkeydown) {
4263 Person::players[i]->targetyaw -= 45;
4265 if (Person::players[i]->backkeydown) {
4266 Person::players[i]->targetyaw += 45;
4270 if (Person::players[i]->backkeydown) {
4271 if (Person::players[i]->isIdle() ||
4272 (Person::players[i]->isStop() &&
4273 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4274 (Person::players[i]->isLanding() &&
4275 Person::players[i]->frameTarget > 0 &&
4276 !Person::players[i]->jumpkeydown) ||
4277 (Person::players[i]->isLandhard() &&
4278 Person::players[i]->frameTarget > 0 &&
4279 !Person::players[i]->jumpkeydown &&
4280 Person::players[i]->crouchkeydown)) {
4281 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4283 if (Person::players[i]->isCrouch()) {
4284 Person::players[i]->animTarget = sneakanim;
4285 if (Person::players[i]->wasCrouch()) {
4286 Person::players[i]->target = 0;
4288 Person::players[i]->frameTarget = 0;
4290 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4291 Person::players[i]->velocity -= absflatfacing * 5 * multiplier;
4293 if (Person::players[i]->animTarget == hanganim) {
4294 Person::players[i]->animCurrent = jumpdownanim;
4295 Person::players[i]->animTarget = jumpdownanim;
4296 Person::players[i]->target = 0;
4297 Person::players[i]->frameCurrent = 0;
4298 Person::players[i]->frameTarget = 1;
4299 Person::players[i]->velocity = 0;
4300 Person::players[i]->velocity.y += gravity;
4301 Person::players[i]->coords.y -= 1.4;
4302 Person::players[i]->grabdelay = 1;
4304 if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) {
4305 Person::players[i]->targetyaw += 180;
4309 if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) {
4310 if ((((Person::players[i]->isLanding() && Person::players[i]->frameTarget >= 3) ||
4311 Person::players[i]->isRun() ||
4312 Person::players[i]->animTarget == walkanim ||
4313 Person::players[i]->isCrouch() ||
4314 Person::players[i]->animTarget == sneakanim) &&
4315 Person::players[i]->jumppower > 1) &&
4316 ((Person::players[i]->animTarget != rabbitrunninganim &&
4317 Person::players[i]->animTarget != wolfrunninganim) ||
4319 Person::players[i]->jumpstart = 0;
4320 Person::players[i]->setTargetAnimation(jumpupanim);
4321 Person::players[i]->yaw = Person::players[i]->targetyaw;
4322 Person::players[i]->transspeed = 20;
4323 Person::players[i]->FootLand(leftfoot, 1);
4324 Person::players[i]->FootLand(rightfoot, 1);
4328 flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0);
4331 Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale;
4334 Person::players[i]->velocity = 0;
4339 if (Person::players.size() > 1) {
4340 for (unsigned j = 0; j < Person::players.size(); j++) {
4341 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) {
4342 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4343 (Person::players[j]->victim == Person::players[i]) &&
4344 (Person::players[j]->animTarget == sweepanim)) {
4355 Person::players[i]->velocity.y = 1;
4356 } else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) {
4357 Person::players[i]->velocity.y = 7;
4358 Person::players[i]->crouchtogglekeydown = 1;
4360 Person::players[i]->velocity.y = 5;
4363 if (mousejump && i == 0 && devtools) {
4364 if (!Person::players[i]->isLanding()) {
4365 Person::players[i]->tempdeltav = deltav;
4367 if (Person::players[i]->tempdeltav < 0) {
4368 Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000;
4372 Person::players[i]->coords.y += .2;
4373 Person::players[i]->jumppower -= 1;
4376 emit_sound_at(whooshsound, Person::players[i]->coords, 128.);
4379 emit_sound_at(jumpsound, Person::players[i]->coords, 128.);
4381 if ((Person::players[i]->isIdle()) && Person::players[i]->jumppower > 1) {
4382 Person::players[i]->setTargetAnimation(Person::players[i]->getLanding());
4383 Person::players[i]->frameTarget = 2;
4384 Person::players[i]->landhard = 0;
4385 Person::players[i]->jumpstart = 1;
4386 Person::players[i]->tempdeltav = deltav;
4388 if (Person::players[i]->animTarget == jumpupanim &&
4392 Person::players[i]->aitype != playercontrolled)) {
4393 if (Person::players[i]->jumppower > multiplier * 6) {
4394 Person::players[i]->velocity.y += multiplier * 6;
4395 Person::players[i]->jumppower -= multiplier * 6;
4397 if (Person::players[i]->jumppower <= multiplier * 6) {
4398 Person::players[i]->velocity.y += Person::players[i]->jumppower;
4399 Person::players[i]->jumppower = 0;
4402 if (((floatjump || editorenabled) && devtools) && i == 0) {
4403 Person::players[i]->velocity.y += multiplier * 30;
4408 if (Person::players[i]->isRun() || Person::players[i]->animTarget == walkanim) {
4409 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4411 if (Person::players[i]->animTarget == sneakanim) {
4412 Person::players[i]->animTarget = Person::players[i]->getCrouch();
4413 if (Person::players[i]->animCurrent == sneakanim) {
4414 Person::players[i]->target = 0;
4416 Person::players[i]->frameTarget = 0;
4419 if (Person::players[i]->animTarget == walkanim &&
4420 (Person::players[i]->aitype == attacktypecutoff ||
4421 Person::players[i]->aitype == searchtype ||
4422 (Person::players[i]->aitype == passivetype &&
4423 Person::players[i]->numwaypoints <= 1))) {
4424 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4426 if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) {
4427 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4431 if (Person::players[i]->animTarget == rollanim) {
4432 Person::players[i]->targetyaw = oldtargetyaw;
4437 for (unsigned k = 0; k < Person::players.size(); k++) {
4438 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) {
4439 if (Person::players[k]->yaw > Person::players[k]->targetyaw) {
4440 Person::players[k]->yaw -= 360;
4442 Person::players[k]->yaw += 360;
4446 //stop to turn in right direction
4447 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) {
4448 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
4451 if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) {
4452 Person::players[k]->targettilt = 0;
4455 if (Person::players[k]->animTarget != jumpupanim &&
4456 Person::players[k]->animTarget != backhandspringanim &&
4457 Person::players[k]->animTarget != jumpdownanim &&
4458 !Person::players[k]->isFlip()) {
4459 Person::players[k]->targettilt = 0;
4460 if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) {
4461 Person::players[k]->jumppower = 0;
4463 Person::players[k]->jumppower += multiplier * 7;
4464 if (Person::players[k]->isCrouch()) {
4465 Person::players[k]->jumppower += multiplier * 7;
4467 if (Person::players[k]->jumppower > 5) {
4468 Person::players[k]->jumppower = 5;
4472 if (Person::players[k]->isRun()) {
4473 Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4;
4476 Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150);
4477 Person::players[k]->grabdelay -= multiplier;
4481 for (unsigned k = 0; k < Person::players.size(); k++) {
4482 Person::players[k]->DoAnimations();
4483 Person::players[k]->whichpatchx = Person::players[k]->coords.x / (terrain.size / subdivision * terrain.scale);
4484 Person::players[k]->whichpatchz = Person::players[k]->coords.z / (terrain.size / subdivision * terrain.scale);
4490 for (int j = numenvsounds - 1; j >= 0; j--) {
4491 envsoundlife[j] -= multiplier;
4492 if (envsoundlife[j] < 0) {
4494 envsoundlife[j] = envsoundlife[numenvsounds];
4495 envsound[j] = envsound[numenvsounds];
4498 OPENAL_SetFrequency(OPENAL_ALL, slomo);
4500 if (Tutorial::active) {
4501 Tutorial::DoStuff(multiplier);
4505 static float gLoc[3];
4509 static float vel[3];
4510 vel[0] = (viewer.x - oldviewer.x) / multiplier;
4511 vel[1] = (viewer.y - oldviewer.y) / multiplier;
4512 vel[2] = (viewer.z - oldviewer.z) / multiplier;
4514 //Set orientation with forward and up vectors
4515 static XYZ upvector;
4519 upvector = DoRotation(upvector, -pitch + 90, 0, 0);
4520 upvector = DoRotation(upvector, 0, 0 - yaw, 0);
4525 facing = DoRotation(facing, -pitch, 0, 0);
4526 facing = DoRotation(facing, 0, 0 - yaw, 0);
4528 static float ori[6];
4532 ori[3] = -upvector.x;
4533 ori[4] = upvector.y;
4534 ori[5] = -upvector.z;
4536 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
4543 if (Input::isKeyPressed(SDL_SCANCODE_F1)) {
4548 void Game::TickOnce()
4551 yaw += multiplier * 5;
4552 } else if (Dialog::directing || !Dialog::inDialog()) {
4555 pitch -= deltav * .7;
4557 pitch += deltav * .7;
4568 void Game::TickOnceAfter()
4570 static XYZ colviewer;
4571 static XYZ coltarget;
4575 static float changedelay;
4576 static bool alldead;
4577 static float unseendelay;
4578 static float cameraspeed;
4581 static int oldmusictype = musictype;
4583 if (environment == snowyenvironment) {
4584 leveltheme = stream_snowtheme;
4586 if (environment == grassyenvironment) {
4587 leveltheme = stream_grasstheme;
4589 if (environment == desertenvironment) {
4590 leveltheme = stream_deserttheme;
4595 musictype = leveltheme;
4596 for (unsigned i = 0; i < Person::players.size(); i++) {
4597 if ((Person::players[i]->aitype == attacktypecutoff ||
4598 Person::players[i]->aitype == getweapontype ||
4599 Person::players[i]->aitype == gethelptype ||
4600 Person::players[i]->aitype == searchtype) &&
4601 !Person::players[i]->dead &&
4602 (Person::players[i]->animTarget != sneakattackedanim &&
4603 Person::players[i]->animTarget != knifesneakattackedanim &&
4604 Person::players[i]->animTarget != swordsneakattackedanim)) {
4605 musictype = stream_fighttheme;
4609 if (Person::players[0]->dead) {
4610 musictype = stream_menutheme;
4613 if (musictype == stream_fighttheme) {
4617 if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) {
4618 unseendelay -= multiplier;
4619 if (unseendelay > 0) {
4620 musictype = stream_fighttheme;
4625 musictype = stream_menutheme;
4626 musicvolume[2] = 512;
4633 if (musictype != oldmusictype && musictype == stream_fighttheme) {
4634 emit_sound_np(alarmsound);
4637 musicselected = musictype;
4639 if (musicselected == leveltheme) {
4640 musicvolume[0] += multiplier * 450;
4642 musicvolume[0] -= multiplier * 450;
4644 if (musicselected == stream_fighttheme) {
4645 musicvolume[1] += multiplier * 450;
4647 musicvolume[1] -= multiplier * 450;
4649 if (musicselected == stream_menutheme) {
4650 musicvolume[2] += multiplier * 450;
4652 musicvolume[2] -= multiplier * 450;
4655 for (int i = 0; i < 3; i++) {
4656 if (musicvolume[i] < 0) {
4659 if (musicvolume[i] > 512) {
4660 musicvolume[i] = 512;
4664 if (musicvolume[2] > 128 && !loading && !mainmenu) {
4665 musicvolume[2] = 128;
4669 if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) {
4670 emit_stream_np(leveltheme, musicvolume[0]);
4672 if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) {
4673 emit_stream_np(stream_fighttheme, musicvolume[1]);
4675 if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) {
4676 emit_stream_np(stream_menutheme, musicvolume[2]);
4678 if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) {
4679 pause_sound(leveltheme);
4681 if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) {
4682 pause_sound(stream_fighttheme);
4684 if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) {
4685 pause_sound(stream_menutheme);
4688 if (musicvolume[0] != oldmusicvolume[0]) {
4689 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
4691 if (musicvolume[1] != oldmusicvolume[1]) {
4692 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
4694 if (musicvolume[2] != oldmusicvolume[2]) {
4695 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
4698 for (int i = 0; i < 3; i++) {
4699 oldmusicvolume[i] = musicvolume[i];
4702 pause_sound(leveltheme);
4703 pause_sound(stream_fighttheme);
4704 pause_sound(stream_menutheme);
4706 for (int i = 0; i < 4; i++) {
4707 oldmusicvolume[i] = 0;
4712 Hotspot::killhotspot = 2;
4713 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4714 if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) {
4715 if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) {
4716 Hotspot::killhotspot = 0;
4717 } else if (Hotspot::killhotspot == 2) {
4718 Hotspot::killhotspot = 1;
4722 if (Hotspot::killhotspot == 2) {
4723 Hotspot::killhotspot = 0;
4727 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4728 if (Hotspot::hotspots[i].type == -1) {
4729 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size) {
4736 for (unsigned i = 1; i < Person::players.size(); i++) {
4737 if (!Person::players[i]->dead && Person::players[i]->aitype == attacktypecutoff && Person::players[i]->surprised <= 0) {
4741 if (numalarmed > maxalarmed) {
4742 maxalarmed = numalarmed;
4745 if (changedelay <= 0 && !loading && !editorenabled && gameon && !Tutorial::active && changedelay != -999 && !won) {
4746 if (Person::players[0]->dead) {
4748 targetlevel = whichlevel;
4751 for (unsigned i = 1; i < Person::players.size(); i++) {
4752 if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1) {
4758 if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) {
4760 targetlevel = whichlevel + 1;
4761 if (targetlevel > numchallengelevels - 1) {
4765 if (winhotspot || windialogue) {
4767 targetlevel = whichlevel + 1;
4768 if (targetlevel > numchallengelevels - 1) {
4773 if (Hotspot::killhotspot) {
4775 targetlevel = whichlevel + 1;
4776 if (targetlevel > numchallengelevels - 1) {
4781 if (changedelay > 0 && !Person::players[0]->dead && !won) {
4782 //high scores, awards, win
4784 Account::active().winCampaignLevel(whichchoice, bonustotal, leveltime);
4787 wonleveltime = leveltime;
4788 Account::active().winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
4791 Account::saveFile(Folders::getUserSavePath());
4797 if (leveltime < 1) {
4802 Hotspot::killhotspot = 0;
4805 if (!editorenabled && gameon && !mainmenu) {
4806 if (changedelay != -999) {
4807 changedelay -= multiplier / 7;
4809 if (Person::players[0]->dead) {
4810 targetlevel = whichlevel;
4812 if (loading == 2 && !campaign) {
4815 fireSound(firestartsound);
4817 if (!Person::players[0]->dead && targetlevel != whichlevel) {
4818 startbonustotal = bonustotal;
4821 LoadLevel(targetlevel);
4826 if (loading == 2 && targetlevel == whichlevel) {
4830 fireSound(firestartsound);
4832 LoadLevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
4838 if (changedelay <= -999 &&
4841 (Person::players[0]->dead ||
4842 (alldead && maptype == mapkilleveryone) ||
4844 (Hotspot::killhotspot))) {
4847 if ((Person::players[0]->dead ||
4848 (alldead && maptype == mapkilleveryone) ||
4851 (Hotspot::killhotspot)) &&
4853 if (whichlevel != -2 && !loading && !Person::players[0]->dead) {
4857 if (Person::players[0]->dead) {
4864 // campaignchoosenext determines what to do when the level is complete:
4865 // 0 = load next level
4866 // 1 = go back to level select screen
4867 // 2 = stealthload next level
4868 if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) {
4869 if (campaignlevels[actuallevel].nextlevel.empty()) {
4872 } else if (mainmenu == 0 && winfreeze) {
4873 stealthloading = (campaignlevels[actuallevel].choosenext == 2);
4875 if (!stealthloading) {
4876 fireSound(firestartsound);
4881 startbonustotal = 0;
4888 if (!firstLoadDone) {
4892 actuallevel = campaignlevels[actuallevel].nextlevel.front();
4893 visibleloading = true;
4895 LoadLevel(campaignlevels[actuallevel].mapname.c_str());
4899 pause_sound(stream_menutheme);
4910 oldmusictype = musictype;
4916 facing = DoRotation(facing, -pitch, 0, 0);
4917 facing = DoRotation(facing, 0, 0 - yaw, 0);
4918 viewerfacing = facing;
4921 if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) {
4922 target = Person::players[0]->coords + Person::players[0]->currentoffset * (1 - Person::players[0]->target) * Person::players[0]->scale + Person::players[0]->targetoffset * Person::players[0]->target * Person::players[0]->scale - Person::players[0]->facing * .05;
4924 target = Person::players[0]->oldcoords + Person::players[0]->currentoffset * (1 - Person::players[0]->target) * Person::players[0]->scale + Person::players[0]->targetoffset * Person::players[0]->target * Person::players[0]->scale - Person::players[0]->facing * .05;
4927 if (Person::players[0]->skeleton.free) {
4928 for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
4929 if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) {
4930 target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y;
4935 if (Person::players[0]->skeleton.free != 2) {
4937 if (findLengthfast(&Person::players[0]->velocity) > 400) {
4938 cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96;
4940 if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) {
4943 coltarget = target - cameraloc;
4944 if (findLengthfast(&coltarget) < multiplier * multiplier * 400) {
4947 Normalise(&coltarget);
4948 if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) {
4949 cameraloc = cameraloc + coltarget * multiplier * cameraspeed;
4951 cameraloc = cameraloc + coltarget * multiplier * 8;
4954 if (editorenabled) {
4957 cameradist += multiplier * 5;
4958 if (cameradist > 2.3) {
4961 viewer = cameraloc - facing * cameradist;
4963 coltarget = cameraloc;
4964 Object::SphereCheckPossible(&colviewer, findDistance(&colviewer, &coltarget));
4965 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4966 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4968 coltarget = cameraloc;
4969 if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4973 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4974 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4976 if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4980 cameradist = findDistance(&viewer, &target);
4981 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .6);
4982 if (cameraloc.y < terrain.getHeight(cameraloc.x, cameraloc.z)) {
4983 cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z);
4986 if (camerashake > .8) {
4989 woozy += multiplier;
4990 if (Person::players[0]->dead) {
4993 if (Person::players[0]->dead) {
4996 camerashake -= multiplier * 2;
4997 blackout -= multiplier * 2;
4998 if (camerashake < 0) {
5005 viewer.x += (float)(Random() % 100) * .0005 * camerashake;
5006 viewer.y += (float)(Random() % 100) * .0005 * camerashake;
5007 viewer.z += (float)(Random() % 100) * .0005 * camerashake;