2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - 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 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
152 STATIC_ASSERT(rabbittype == 0 && wolftype == 1)
156 // TODO: this is slightly incorrect
157 float roughDirection(XYZ vec)
160 float angle = -asin(-vec.x) * 180 / M_PI;
166 float roughDirectionTo(XYZ start, XYZ end)
168 return roughDirection(end - start);
170 inline float pitchOf(XYZ vec)
173 return -asin(vec.y) * 180 / M_PI;
175 float pitchTo(XYZ start, XYZ end)
177 return pitchOf(end - start);
183 inline float stepTowardf(float from, float to, float by)
185 if (fabs(from - to) < by) {
187 } else if (from > to) {
194 void Game::playdialoguescenesound()
197 temppos = Person::players.at(Dialog::currentScene().participantfocus)->coords;
198 temppos = temppos - viewer;
203 switch (Dialog::currentScene().sound) {
208 sound = consolefailsound;
211 sound = consolesuccesssound;
214 sound = firestartsound;
217 sound = fireendsound;
220 sound = rabbitchitter;
223 sound = rabbitchitter2;
226 sound = rabbitpainsound;
229 sound = rabbitpain1sound;
232 sound = rabbitattacksound;
235 sound = rabbitattack2sound;
238 sound = rabbitattack3sound;
241 sound = rabbitattack4sound;
265 sound = barkgrowlsound;
271 emit_sound_at(sound, temppos);
275 // ================================================================
277 int Game::findClosestPlayer()
280 float closestdist = std::numeric_limits<float>::max();
282 for (unsigned int i = 1; i < Person::players.size(); i++) {
283 float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
284 if (distance < closestdist) {
285 closestdist = distance;
292 static int findClosestObject()
295 float closestdist = std::numeric_limits<float>::max();
297 for (unsigned int i = 0; i < Object::objects.size(); i++) {
298 float distance = distsq(&Object::objects[i]->position,
299 &Person::players[0]->coords);
300 if (distance < closestdist) {
301 closestdist = distance;
308 static void cmd_dispatch(const string cmd)
310 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
312 for (i = 0; i < n_cmds; i++) {
313 if (cmd.substr(0, cmd.find(' ')) == string(cmd_names[i])) {
314 cout << "|" << cmd.substr(cmd.find(' ') + 1) << "|" << endl;
315 cmd_handlers[i](cmd.substr(cmd.find(' ') + 1).c_str());
319 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
322 /********************> Tick() <*****/
323 extern bool save_screenshot(const char* fname);
324 void Screenshot(void)
327 time_t t = time(NULL);
328 struct tm* tme = localtime(&t);
329 sprintf(filename, "Screenshot-%04d%02d%02d-%02d%02d%02d.png",
330 tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
332 save_screenshot(filename);
335 void Game::SetUpLighting()
337 if (environment == snowyenvironment) {
338 light.setColors(.65, .65, .7, .4, .4, .44);
340 if (environment == desertenvironment) {
341 light.setColors(.95, .95, .95, .4, .35, .3);
343 if (environment == grassyenvironment) {
344 light.setColors(.95, .95, 1, .4, .4, .44);
346 if (!skyboxtexture) {
347 light.setColors(1, 1, 1, .4, .4, .4);
350 average = (skyboxlightr + skyboxlightg + skyboxlightb) / 3;
351 light.color[0] *= (skyboxlightr + average) / 2;
352 light.color[1] *= (skyboxlightg + average) / 2;
353 light.color[2] *= (skyboxlightb + average) / 2;
354 light.ambient[0] *= (skyboxlightr + average) / 2;
355 light.ambient[1] *= (skyboxlightg + average) / 2;
356 light.ambient[2] *= (skyboxlightb + average) / 2;
359 void Setenvironment(int which)
363 LOG(" Setting environment...");
368 pause_sound(stream_snowtheme);
369 pause_sound(stream_grasstheme);
370 pause_sound(stream_deserttheme);
371 pause_sound(stream_wind);
372 pause_sound(stream_desertambient);
374 if (environment == snowyenvironment) {
378 emit_stream_np(stream_wind);
381 Object::treetextureptr.load("Textures/SnowTree.png", 0);
382 Object::bushtextureptr.load("Textures/BushSnow.png", 0);
383 Object::rocktextureptr.load("Textures/BoulderSnow.jpg", 1);
384 Object::boxtextureptr.load("Textures/SnowBox.jpg", 1);
386 footstepsound = footstepsn1;
387 footstepsound2 = footstepsn2;
388 footstepsound3 = footstepst1;
389 footstepsound4 = footstepst2;
391 terraintexture.load("Textures/Snow.jpg", 1);
392 terraintexture2.load("Textures/Rock.jpg", 1);
394 temptexdetail = texdetail;
398 skybox->load("Textures/Skybox(snow)/Front.jpg",
399 "Textures/Skybox(snow)/Left.jpg",
400 "Textures/Skybox(snow)/Back.jpg",
401 "Textures/Skybox(snow)/Right.jpg",
402 "Textures/Skybox(snow)/Up.jpg",
403 "Textures/Skybox(snow)/Down.jpg");
405 texdetail = temptexdetail;
406 } else if (environment == desertenvironment) {
409 Object::treetextureptr.load("Textures/DesertTree.png", 0);
410 Object::bushtextureptr.load("Textures/BushDesert.png", 0);
411 Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1);
412 Object::boxtextureptr.load("Textures/DesertBox.jpg", 1);
415 emit_stream_np(stream_desertambient);
418 footstepsound = footstepsn1;
419 footstepsound2 = footstepsn2;
420 footstepsound3 = footstepsn1;
421 footstepsound4 = footstepsn2;
423 terraintexture.load("Textures/Sand.jpg", 1);
424 terraintexture2.load("Textures/SandSlope.jpg", 1);
426 temptexdetail = texdetail;
430 skybox->load("Textures/Skybox(sand)/Front.jpg",
431 "Textures/Skybox(sand)/Left.jpg",
432 "Textures/Skybox(sand)/Back.jpg",
433 "Textures/Skybox(sand)/Right.jpg",
434 "Textures/Skybox(sand)/Up.jpg",
435 "Textures/Skybox(sand)/Down.jpg");
437 texdetail = temptexdetail;
438 } else if (environment == grassyenvironment) {
441 Object::treetextureptr.load("Textures/Tree.png", 0);
442 Object::bushtextureptr.load("Textures/Bush.png", 0);
443 Object::rocktextureptr.load("Textures/Boulder.jpg", 1);
444 Object::boxtextureptr.load("Textures/GrassBox.jpg", 1);
447 emit_stream_np(stream_wind, 100.);
450 footstepsound = footstepgr1;
451 footstepsound2 = footstepgr2;
452 footstepsound3 = footstepst1;
453 footstepsound4 = footstepst2;
455 terraintexture.load("Textures/GrassDirt.jpg", 1);
456 terraintexture2.load("Textures/MossRock.jpg", 1);
458 temptexdetail = texdetail;
462 skybox->load("Textures/Skybox(grass)/Front.jpg",
463 "Textures/Skybox(grass)/Left.jpg",
464 "Textures/Skybox(grass)/Back.jpg",
465 "Textures/Skybox(grass)/Right.jpg",
466 "Textures/Skybox(grass)/Up.jpg",
467 "Textures/Skybox(grass)/Down.jpg");
469 texdetail = temptexdetail;
471 temptexdetail = texdetail;
473 terrain.load("Textures/HeightMap.png");
475 texdetail = temptexdetail;
478 bool Game::LoadLevel(int which)
484 return LoadLevel("tutorial", true);
485 } else if (which >= 0 && which <= 15) {
487 snprintf(buf, 32, "map%d", which + 1); // challenges
488 return LoadLevel(buf);
490 return LoadLevel("mapsave");
494 bool Game::LoadLevel(const std::string& name, bool tutorial)
496 const std::string level_path = Folders::getResourcePath("Maps/" + name);
497 if (!Folders::file_exists(level_path)) {
498 perror(std::string("LoadLevel: Could not open file '" + level_path).c_str());
502 int indemo; // FIXME this should be removed
508 LOG(std::string("Loading level...") + name);
511 visibleloading = true;
513 if (stealthloading) {
514 visibleloading = false;
523 Tutorial::active = tutorial;
525 if (Tutorial::active) {
528 if (Tutorial::stage == 0) {
529 Tutorial::stagetime = 0;
530 Tutorial::maxtime = 1;
532 pause_sound(whooshsound);
533 pause_sound(stream_firesound);
538 tfile = Folders::openMandatoryFile(level_path, "rb");
540 pause_sound(stream_firesound);
546 //~ Animation::animations[bounceidleanim].Load("Idle", middleheight, neutral);
548 Dialog::dialogs.clear();
550 Dialog::indialogue = -1;
556 if (Account::hasActive()) {
557 difficulty = Account::active().getDifficulty();
560 Hotspot::hotspots.clear();
561 Hotspot::current = -1;
572 for (unsigned char i = 0; i < 100; i++) {
582 numunarmedattack = 0;
593 bonustotal = startbonustotal;
598 emit_sound_np(consolesuccesssound);
603 if (!stealthloading) {
604 terrain.decals.clear();
605 Sprite::deleteSprites();
607 for (int i = 0; i < subdivision; i++) {
608 for (int j = 0; j < subdivision; j++) {
609 terrain.patchobjects[i][j].clear();
612 Game::LoadingScreen();
616 Person::players.resize(1);
618 funpackf(tfile, "Bi", &mapvers);
620 cerr << name << " has obsolete map version " << mapvers << endl;
623 funpackf(tfile, "Bi", &indemo);
628 funpackf(tfile, "Bi", &maptype);
630 maptype = mapkilleveryone;
633 funpackf(tfile, "Bi", &hostile);
638 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
644 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
652 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
654 skyboxlightr = skyboxr;
655 skyboxlightg = skyboxg;
656 skyboxlightb = skyboxb;
658 /* 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) */
659 if (stealthloading) {
660 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat, &lamefloat, &lamefloat, &lamefloat, &lamefloat, &Person::players[0]->num_weapons);
662 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);
664 if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) {
665 for (int j = 0; j < Person::players[0]->num_weapons; j++) {
666 Person::players[0]->weaponids[j] = weapons.size();
668 funpackf(tfile, "Bi", &type);
669 weapons.push_back(Weapon(type, 0));
673 Game::LoadingScreen();
675 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->armorhead, &Person::players[0]->armorhigh, &Person::players[0]->armorlow);
676 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->protectionhead, &Person::players[0]->protectionhigh, &Person::players[0]->protectionlow);
677 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->metalhead, &Person::players[0]->metalhigh, &Person::players[0]->metallow);
678 funpackf(tfile, "Bf Bf", &Person::players[0]->power, &Person::players[0]->speedmult);
680 funpackf(tfile, "Bi", &Person::players[0]->numclothes);
683 funpackf(tfile, "Bi Bi", &Person::players[0]->whichskin, &Person::players[0]->creature);
685 Person::players[0]->whichskin = 0;
686 Person::players[0]->creature = rabbittype;
689 Person::players[0]->lastattack = -1;
690 Person::players[0]->lastattack2 = -1;
691 Person::players[0]->lastattack3 = -1;
695 Dialog::loadDialogs(tfile);
698 for (int k = 0; k < Person::players[0]->numclothes; k++) {
699 funpackf(tfile, "Bi", &templength);
700 for (int l = 0; l < templength; l++) {
701 funpackf(tfile, "Bb", &Person::players[0]->clothes[k][l]);
703 Person::players[0]->clothes[k][templength] = '\0';
704 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->clothestintr[k], &Person::players[0]->clothestintg[k], &Person::players[0]->clothestintb[k]);
707 funpackf(tfile, "Bi", &environment);
709 if (environment != oldenvironment) {
710 Setenvironment(environment);
712 oldenvironment = environment;
714 Object::LoadObjectsFromFile(tfile, stealthloading);
718 funpackf(tfile, "Bi", &numhotspots);
719 if (numhotspots < 0) {
720 cerr << "Map " << name << " have an invalid number of hotspots" << endl;
723 Hotspot::hotspots.resize(numhotspots);
724 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
725 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);
726 funpackf(tfile, "Bi", &templength);
728 for (int l = 0; l < templength; l++) {
729 funpackf(tfile, "Bb", &Hotspot::hotspots[i].text[l]);
732 Hotspot::hotspots[i].text[templength] = '\0';
733 if (Hotspot::hotspots[i].type == -111) {
738 Hotspot::hotspots.clear();
741 Game::LoadingScreen();
743 if (!stealthloading) {
744 Object::ComputeCenter();
745 Object::ComputeRadius();
748 Game::LoadingScreen();
751 funpackf(tfile, "Bi", &numplayers);
752 if (numplayers > maxplayers) {
753 cout << "Warning: this level contains more players than allowed" << endl;
756 for (int i = 1; i < numplayers; i++) {
758 Person::players.push_back(shared_ptr<Person>(new Person(tfile, mapvers, j)));
760 } catch (InvalidPersonException e) {
761 cerr << "Invalid Person found in " << name << endl;
764 Game::LoadingScreen();
766 funpackf(tfile, "Bi", &numpathpoints);
767 if (numpathpoints > 30 || numpathpoints < 0) {
770 for (int j = 0; j < numpathpoints; j++) {
771 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x, &pathpoint[j].y, &pathpoint[j].z, &numpathpointconnect[j]);
772 for (int k = 0; k < numpathpointconnect[j]; k++) {
773 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
776 Game::LoadingScreen();
778 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x, &mapcenter.y, &mapcenter.z, &mapradius);
782 if (!stealthloading) {
783 Object::AddObjectsToTerrain();
785 Game::LoadingScreen();
787 Game::LoadingScreen();
792 for (unsigned i = 0; i < Person::players.size(); i++) {
793 Game::LoadingScreen();
795 Person::players[i]->burnt = 0;
796 Person::players[i]->bled = 0;
797 Person::players[i]->onfire = 0;
798 Person::players[i]->scale = .2;
800 Person::players[i]->creature = rabbittype;
803 Person::players[i]->skeleton.free = 0;
805 Person::players[i]->skeletonLoad();
807 Person::players[i]->addClothes();
810 Person::players[i]->animCurrent = bounceidleanim;
811 Person::players[i]->animTarget = bounceidleanim;
812 Person::players[i]->frameCurrent = 0;
813 Person::players[i]->frameTarget = 1;
814 Person::players[i]->target = 0;
816 Person::players[i]->speed = 1 + (float)(Random() % 100) / 1000;
817 if (difficulty == 0) {
818 Person::players[i]->speed -= .2;
820 if (difficulty == 1) {
821 Person::players[i]->speed -= .1;
825 Person::players[i]->velocity = 0;
826 Person::players[i]->oldcoords = Person::players[i]->coords;
827 Person::players[i]->realoldcoords = Person::players[i]->coords;
829 Person::players[i]->id = i;
830 Person::players[i]->updatedelay = 0;
831 Person::players[i]->normalsupdatedelay = 0;
833 Person::players[i]->setProportions(1, 1, 1, 1);
834 Person::players[i]->headless = 0;
835 Person::players[i]->currentoffset = 0;
836 Person::players[i]->targetoffset = 0;
837 if (Person::players[i]->creature == wolftype) {
838 Person::players[i]->scale = .23;
839 Person::players[i]->damagetolerance = 300;
841 Person::players[i]->damagetolerance = 200;
845 Game::LoadingScreen();
847 Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral);
850 Person::players[i]->headmorphness = 0;
851 Person::players[i]->targetheadmorphness = 1;
852 Person::players[i]->headmorphstart = 0;
853 Person::players[i]->headmorphend = 0;
855 Person::players[i]->pausetime = 0;
857 Person::players[i]->dead = 0;
858 Person::players[i]->jumppower = 5;
859 Person::players[i]->damage = 0;
860 Person::players[i]->permanentdamage = 0;
861 Person::players[i]->superpermanentdamage = 0;
863 Person::players[i]->forwardkeydown = 0;
864 Person::players[i]->leftkeydown = 0;
865 Person::players[i]->backkeydown = 0;
866 Person::players[i]->rightkeydown = 0;
867 Person::players[i]->jumpkeydown = 0;
868 Person::players[i]->crouchkeydown = 0;
869 Person::players[i]->throwkeydown = 0;
871 Person::players[i]->collided = -10;
872 Person::players[i]->loaded = 1;
873 Person::players[i]->bloodloss = 0;
874 Person::players[i]->weaponactive = -1;
875 Person::players[i]->weaponstuck = -1;
876 Person::players[i]->bleeding = 0;
877 Person::players[i]->deathbleeding = 0;
878 Person::players[i]->stunned = 0;
879 Person::players[i]->hasvictim = 0;
880 Person::players[i]->wentforweapon = 0;
884 Person::players[0]->aitype = playercontrolled;
886 if (difficulty == 1) {
887 Person::players[0]->power = 1 / .9;
888 Person::players[0]->damagetolerance = 250;
889 } else if (difficulty == 0) {
890 Person::players[0]->power = 1 / .8;
891 Person::players[0]->damagetolerance = 300;
892 Person::players[0]->armorhead *= 1.5;
893 Person::players[0]->armorhigh *= 1.5;
894 Person::players[0]->armorlow *= 1.5;
897 cameraloc = Person::players[0]->coords;
899 yaw = Person::players[0]->yaw;
901 hawkcoords = Person::players[0]->coords;
904 Game::LoadingScreen();
906 LOG("Starting background music...");
908 OPENAL_StopSound(OPENAL_ALL);
910 if (environment == snowyenvironment) {
911 emit_stream_np(stream_wind);
912 } else if (environment == desertenvironment) {
913 emit_stream_np(stream_desertambient);
914 } else if (environment == grassyenvironment) {
915 emit_stream_np(stream_wind, 100.);
918 oldmusicvolume[0] = 0;
919 oldmusicvolume[1] = 0;
920 oldmusicvolume[2] = 0;
921 oldmusicvolume[3] = 0;
925 visibleloading = false;
930 /* Process input events that impact settings, console, devtools, etc.
931 * Gameplay-related input processing is still done in Game::Tick() for now
932 * as it is tightly coupled to the game logic.
934 void Game::ProcessInput()
936 /* Pump SDL input events */
939 /* Menu handling (main menu, leave game) */
940 if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
941 (gameon || mainmenu == 0)) {
943 if (mainmenu == 0 && !winfreeze) {
944 mainmenu = 2; // Pause
945 } else if (mainmenu == 1 || mainmenu == 2) {
946 mainmenu = 0; // Unpause
949 if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
950 OPENAL_SetFrequency(OPENAL_ALL);
951 emit_stream_np(stream_menutheme);
952 pause_sound(leveltheme);
954 // On resume, play level music
956 pause_sound(stream_menutheme);
957 resume_stream(leveltheme);
962 if (!campaign && !mainmenu) {
963 if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE))) {
969 if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && gameon) {
973 } else if (winfreeze) {
980 /* Tutorial mode hotkeys */
981 if (Tutorial::active) {
982 // Skip current tutorial stage
983 if (Input::isKeyPressed(SDL_SCANCODE_TAB)) {
984 if (Tutorial::stage != 51) {
985 Tutorial::stagetime = Tutorial::maxtime;
987 emit_sound_np(consolefailsound, 128.);
992 if (Input::isKeyPressed(SDL_SCANCODE_F1)) {
996 /* Stereo video mode hotkeys */
997 if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
998 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
999 stereoreverse = true;
1000 printf("Stereo reversed\n");
1002 stereoreverse = false;
1003 printf("Stereo unreversed\n");
1007 if (Input::isKeyDown(SDL_SCANCODE_F7)) {
1008 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1009 stereoseparation -= 0.001;
1011 stereoseparation -= 0.010;
1013 printf("Stereo separation decreased to %f\n", stereoseparation);
1016 if (Input::isKeyDown(SDL_SCANCODE_F8)) {
1017 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1018 stereoseparation += 0.001;
1020 stereoseparation += 0.010;
1022 printf("Stereo separation increased to %f\n", stereoseparation);
1026 if (devtools && !mainmenu) {
1028 if (Input::isKeyPressed(consolekey)) {
1031 OPENAL_SetFrequency(OPENAL_ALL);
1038 /* Other devtools, disabled when the console is shown */
1045 void Game::ProcessDevInput()
1047 if (!devtools || mainmenu || console) {
1051 if (Input::isKeyDown(SDL_SCANCODE_LALT)) {
1053 if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1054 editorenabled = !editorenabled;
1055 if (editorenabled) {
1056 Person::players[0]->damagetolerance = 100000;
1057 Person::players[0]->damage = 0;
1058 Person::players[0]->permanentdamage = 0;
1059 Person::players[0]->superpermanentdamage = 0;
1060 Person::players[0]->burnt = 0;
1061 Person::players[0]->bloodloss = 0;
1062 Person::players[0]->deathbleeding = 0;
1064 Person::players[0]->damagetolerance = 200;
1068 /* Nullify damage and give 200000 health */
1069 if (Input::isKeyPressed(SDL_SCANCODE_H)) {
1070 Person::players[0]->damagetolerance = 200000;
1071 Person::players[0]->damage = 0;
1072 Person::players[0]->permanentdamage = 0;
1073 Person::players[0]->superpermanentdamage = 0;
1074 Person::players[0]->burnt = 0;
1075 Person::players[0]->bloodloss = 0;
1076 Person::players[0]->deathbleeding = 0;
1079 /* Change environment */
1080 if (Input::isKeyPressed(SDL_SCANCODE_J)) {
1082 if (environment > 2) {
1085 Setenvironment(environment);
1089 if (Input::isKeyPressed(SDL_SCANCODE_C)) {
1090 cameramode = !cameramode;
1094 if (Input::isKeyPressed(SDL_SCANCODE_V)) {
1097 OPENAL_SetFrequency(OPENAL_ALL);
1101 /* Toggle slow motion */
1102 if (Input::isKeyPressed(SDL_SCANCODE_B)) {
1108 if (Input::isKeyPressed(SDL_SCANCODE_N)) {
1109 Person::players[0]->RagDoll(0);
1110 emit_sound_at(whooshsound, Person::players[0]->coords, 128.);
1113 /* Shrink tree leaves?? */
1114 // FIXME: Can't see what this does in game.
1115 if (Input::isKeyPressed(SDL_SCANCODE_Y)) {
1116 for (auto& an_object : Object::objects) {
1117 if (an_object->type == treeleavestype) {
1118 an_object->scale *= .9;
1123 /* Change (or add) weapon */
1124 if (Input::isKeyPressed(SDL_SCANCODE_X)) {
1126 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1127 closest = findClosestPlayer();
1131 if (Person::players[closest]->num_weapons > 0) {
1133 switch (weapons[Person::players[closest]->weaponids[0]].getType()) {
1144 weapons[Person::players[closest]->weaponids[0]].setType(weapontype);
1146 Person::players[closest]->weaponids[0] = weapons.size();
1147 weapons.push_back(Weapon(knife, closest));
1148 Person::players[closest]->num_weapons = 1;
1153 /* Change yaw (rotate around Z axis) */
1154 if (Input::isKeyDown(SDL_SCANCODE_U)) {
1156 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1157 closest = findClosestPlayer();
1161 Person::players[closest]->yaw += multiplier * 50;
1162 Person::players[closest]->targetyaw = Person::players[closest]->yaw;
1167 if (Input::isKeyPressed(SDL_SCANCODE_F)) {
1169 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1170 closest = findClosestPlayer();
1174 Person::players[closest]->onfire = !Person::players[closest]->onfire;
1175 if (Person::players[closest]->onfire) {
1176 Person::players[closest]->CatchFire();
1178 emit_sound_at(fireendsound, Person::players[closest]->coords);
1179 pause_sound(stream_firesound);
1185 if (Input::isKeyPressed(SDL_SCANCODE_T) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1187 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1188 closest = findClosestPlayer();
1192 Person::players[closest]->whichskin++;
1193 if (Person::players[closest]->whichskin > 9) {
1194 Person::players[closest]->whichskin = 0;
1196 if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) {
1197 Person::players[closest]->whichskin = 0;
1200 Person::players[closest]->skeleton.drawmodel.textureptr.load(
1201 PersonType::types[Person::players[closest]->creature].skins[Person::players[closest]->whichskin], 1,
1202 &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
1205 Person::players[closest]->addClothes();
1208 /* Change creature type */
1209 if (Input::isKeyPressed(SDL_SCANCODE_T) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1211 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1212 closest = findClosestPlayer();
1216 person_type nextType = static_cast<person_type>((Person::players[closest]->creature + 1) % PersonType::types.size());
1217 Person::players[closest]->changeCreatureType(nextType);
1221 /* Explose nearby player's head */
1222 if (Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1223 int closest = findClosestPlayer();
1224 if (closest > 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1225 XYZ flatfacing2, flatvelocity2, flatvelocity2_orig;
1226 XYZ headspurtdirection;
1227 Joint& headjoint = Person::players[closest]->joint(head);
1229 if (!Person::players[closest]->skeleton.free) {
1230 flatvelocity2_orig = Person::players[closest]->velocity;
1231 flatfacing2 = DoRotation(
1233 DoRotation(headjoint.position, 0, 0, Person::players[closest]->tilt),
1234 Person::players[closest]->tilt2, 0, 0),
1235 0, Person::players[closest]->yaw, 0) *
1236 Person::players[closest]->scale +
1237 Person::players[closest]->coords;
1239 flatvelocity2_orig = headjoint.velocity;
1240 flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords;
1243 headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck);
1244 Normalise(&headspurtdirection);
1246 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1247 flatvelocity2 = flatvelocity2_orig;
1248 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1249 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1250 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1251 printf("Test: %f\n", flatvelocity2.x);
1252 printf("Test orig: %f\n", flatvelocity2_orig.x);
1253 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, .6, 1);
1254 flatvelocity2 += headspurtdirection * 8;
1255 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 / 2, 1, 1, 1, .16, 1);
1257 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1259 emit_sound_at(splattersound, Person::players[closest]->coords);
1260 emit_sound_at(breaksound2, Person::players[closest]->coords, 100.);
1262 if (Person::players[closest]->skeleton.free == 2) {
1263 Person::players[closest]->skeleton.free = 0;
1265 Person::players[closest]->RagDoll(0);
1266 Person::players[closest]->dead = 2;
1267 Person::players[closest]->headless = 1;
1268 Person::players[closest]->DoBloodBig(3, 165);
1274 /* Explode nearby player */
1275 if (Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1276 int closest = findClosestPlayer();
1277 if (closest >= 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1278 XYZ flatfacing2, flatvelocity2, flatvelocity2_orig;
1280 emit_sound_at(splattersound, Person::players[closest]->coords);
1281 emit_sound_at(breaksound2, Person::players[closest]->coords);
1283 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1284 if (!Person::players[closest]->skeleton.free) {
1285 flatvelocity2_orig = Person::players[closest]->velocity;
1286 flatfacing2 = DoRotation(
1288 DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt),
1289 Person::players[closest]->tilt2, 0, 0),
1290 0, Person::players[closest]->yaw, 0) *
1291 Person::players[closest]->scale +
1292 Person::players[closest]->coords;
1294 flatvelocity2_orig = Person::players[closest]->skeleton.joints[i].velocity;
1295 flatfacing2 = Person::players[closest]->skeleton.joints[i].position *
1296 Person::players[closest]->scale +
1297 Person::players[closest]->coords;
1301 flatvelocity2 = flatvelocity2_orig;
1302 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1303 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1304 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1305 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1306 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .3, 1);
1307 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1310 flatvelocity2 = flatvelocity2_orig;
1311 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1312 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1313 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1314 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1315 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1318 flatvelocity2 = flatvelocity2_orig;
1319 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1320 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1321 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1322 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1323 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1326 flatvelocity2 = flatvelocity2_orig;
1327 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1328 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1329 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1330 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1331 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1335 for (unsigned j = 0; j < Person::players.size(); j++) {
1336 if (int(j) == closest) {
1339 if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) {
1340 Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60);
1341 if (Person::players[j]->skeleton.free == 2) {
1342 Person::players[j]->skeleton.free = 1;
1344 Person::players[j]->skeleton.longdead = 0;
1345 Person::players[j]->RagDoll(0);
1346 for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) {
1347 temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords;
1348 if (distsq(&temppos, &Person::players[closest]->coords) < 25) {
1349 flatvelocity2 = temppos - Person::players[closest]->coords;
1350 Normalise(&flatvelocity2);
1351 Person::players[j]->skeleton.joints[i].velocity +=
1352 flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20);
1358 Person::players[closest]->DoDamage(10000);
1359 Person::players[closest]->RagDoll(0);
1360 Person::players[closest]->dead = 2;
1361 Person::players[closest]->coords = 20;
1362 Person::players[closest]->skeleton.free = 2;
1369 /* Skip level (only for challenges) */
1370 // FIXME: Allow skipping levels in campaigns too
1371 if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) {
1373 if (targetlevel > numchallengelevels - 1) {
1380 /* Editor mode keys */
1381 if (editorenabled) {
1382 /* Closest player deletion */
1383 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1384 int closest = findClosestPlayer();
1386 Person::players.erase(Person::players.begin() + closest);
1390 /* Closest object deletion */
1391 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1392 int closest = findClosestObject();
1394 Object::DeleteObject(closest);
1399 if (Input::isKeyPressed(SDL_SCANCODE_O)) {
1400 if (Object::objects.size() < max_objects - 1) {
1401 XYZ scenecoords = Person::players[0]->coords;
1403 if (editortype == bushtype || editortype == firetype) {
1404 scenecoords.y -= 3.5;
1409 float tmpyaw, tmppitch;
1411 tmppitch = editorpitch;
1412 if (tmpyaw < 0 || editortype == bushtype) {
1413 tmpyaw = Random() % 360;
1416 tmppitch = Random() % 360;
1419 Object::MakeObject(editortype, scenecoords, (int)tmpyaw - ((int)tmpyaw) % 30, (int)tmppitch, editorsize);
1420 if (editortype == treetrunktype) {
1421 Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (tmppitch < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize);
1427 if (Input::isKeyPressed(SDL_SCANCODE_P) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1428 Person::players.push_back(shared_ptr<Person>(new Person()));
1430 Person::players.back()->id = Person::players.size() - 1;
1432 Person::players.back()->scale = Person::players[0]->scale;
1433 Person::players.back()->creature = rabbittype;
1434 Person::players.back()->howactive = editoractive;
1435 Person::players.back()->whichskin = (int)(abs(Random() % 3));
1437 Person::players.back()->skeletonLoad(true);
1439 Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
1440 Person::players.back()->speed = 1 + (float)(Random() % 100) / 1000;
1442 Person::players.back()->targetyaw = Person::players[0]->targetyaw;
1443 Person::players.back()->yaw = Person::players[0]->yaw;
1445 Person::players.back()->coords = Person::players[0]->coords;
1446 Person::players.back()->oldcoords = Person::players.back()->coords;
1447 Person::players.back()->realoldcoords = Person::players.back()->coords;
1449 Person::players.back()->setProportions(1, 1, 1, 1);
1451 Person::players.back()->tempanimation = Animation("Tempanim", lowheight, neutral);
1453 Person::players.back()->damagetolerance = 200;
1455 Person::players.back()->protectionhead = Person::players[0]->protectionhead;
1456 Person::players.back()->protectionhigh = Person::players[0]->protectionhigh;
1457 Person::players.back()->protectionlow = Person::players[0]->protectionlow;
1458 Person::players.back()->armorhead = Person::players[0]->armorhead;
1459 Person::players.back()->armorhigh = Person::players[0]->armorhigh;
1460 Person::players.back()->armorlow = Person::players[0]->armorlow;
1461 Person::players.back()->metalhead = Person::players[0]->metalhead;
1462 Person::players.back()->metalhigh = Person::players[0]->metalhigh;
1463 Person::players.back()->metallow = Person::players[0]->metallow;
1465 Person::players.back()->immobile = Person::players[0]->immobile;
1467 Person::players.back()->numclothes = Person::players[0]->numclothes;
1468 for (int i = 0; i < Person::players.back()->numclothes; i++) {
1469 strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
1470 Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
1471 Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
1472 Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
1474 Person::players.back()->addClothes();
1476 Person::players.back()->power = Person::players[0]->power;
1477 Person::players.back()->speedmult = Person::players[0]->speedmult;
1479 Person::players.back()->loaded = true;
1483 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1484 if (Person::players.back()->numwaypoints < 90) {
1485 Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
1486 Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype;
1487 Person::players.back()->numwaypoints++;
1489 printf("Add waypoint: Reached max number of waypoints (90), aborting.");
1493 /* Connect waypoint */
1494 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1495 if (numpathpoints < 30) {
1496 bool connected = false;
1497 if (numpathpoints > 1) {
1498 for (int i = 0; i < numpathpoints; i++) {
1499 if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) {
1500 bool alreadyconnected = false;
1501 for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) {
1502 if (pathpointconnect[pathpointselected][j] == i) {
1503 alreadyconnected = true;
1506 if (!alreadyconnected) {
1507 numpathpointconnect[pathpointselected]++;
1509 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = i;
1516 pathpoint[numpathpoints - 1] = Person::players[0]->coords;
1517 numpathpointconnect[numpathpoints - 1] = 0;
1518 if (numpathpoints > 1 && pathpointselected != -1) {
1519 numpathpointconnect[pathpointselected]++;
1520 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = numpathpoints - 1;
1522 pathpointselected = numpathpoints - 1;
1525 printf("Connect waypoint: Reached max number of path points (30), aborting.");
1529 /* Select next path waypoint */
1530 if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) {
1531 pathpointselected++;
1532 if (pathpointselected >= numpathpoints) {
1533 pathpointselected = -1;
1537 /* Select previous path waypoint */
1538 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1539 pathpointselected--;
1540 if (pathpointselected <= -2) {
1541 pathpointselected = numpathpoints - 1;
1545 /* Delete path waypoint */
1546 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1547 if (pathpointselected != -1) {
1549 pathpoint[pathpointselected] = pathpoint[numpathpoints];
1550 numpathpointconnect[pathpointselected] = numpathpointconnect[numpathpoints];
1551 for (int i = 0; i < numpathpointconnect[pathpointselected]; i++) {
1552 pathpointconnect[pathpointselected][i] = pathpointconnect[numpathpoints][i];
1554 for (int i = 0; i < numpathpoints; i++) {
1555 for (int j = 0; j < numpathpointconnect[i]; j++) {
1556 if (pathpointconnect[i][j] == pathpointselected) {
1557 pathpointconnect[i][j] = pathpointconnect[i][numpathpointconnect[i] - 1];
1558 numpathpointconnect[i]--;
1560 if (pathpointconnect[i][j] == numpathpoints) {
1561 pathpointconnect[i][j] = pathpointselected;
1565 pathpointselected = numpathpoints - 1;
1569 /* Select previous object type */
1570 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1572 if (editortype == treeleavestype || editortype == 10) {
1575 if (editortype < 0) {
1576 editortype = firetype;
1580 /* Select next object type */
1581 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1583 if (editortype == treeleavestype || editortype == 10) {
1586 if (editortype > firetype) {
1591 /* Decrease size for next object */
1592 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1593 editorsize -= multiplier;
1594 if (editorsize < .1) {
1599 /* Increase size for next object */
1600 if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1601 editorsize += multiplier;
1604 /* Decrease yaw for next object */
1605 if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1606 editoryaw -= multiplier * 100;
1607 if (editoryaw < -.01) {
1612 /* Increase yaw for next object */
1613 if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1614 editoryaw += multiplier * 100;
1617 /* Decrease pitch for next object */
1618 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1619 editorpitch -= multiplier * 100;
1620 if (editorpitch < -.01) {
1625 /* Increase pitch for next object */
1626 if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1627 editorpitch += multiplier * 100;
1630 /* Decrease map radius */
1631 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1632 mapradius -= multiplier * 10;
1635 /* Increase map radius */
1636 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1637 mapradius += multiplier * 10;
1642 void doJumpReversals()
1644 for (unsigned k = 0; k < Person::players.size(); k++) {
1645 for (unsigned i = k + 1; i < Person::players.size(); i++) {
1646 if (Person::players[k]->skeleton.free == 0 &&
1647 Person::players[i]->skeleton.oldfree == 0 &&
1648 (Person::players[i]->animTarget == jumpupanim ||
1649 Person::players[k]->animTarget == jumpupanim) &&
1650 (Person::players[i]->aitype == playercontrolled ||
1651 Person::players[k]->aitype == playercontrolled) &&
1652 ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) ||
1653 (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) {
1654 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) &&
1655 distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
1656 //TODO: refactor two huge similar ifs
1657 if (Person::players[i]->animTarget == jumpupanim &&
1658 Person::players[k]->animTarget != getupfrombackanim &&
1659 Person::players[k]->animTarget != getupfromfrontanim &&
1660 Animation::animations[Person::players[k]->animTarget].height == middleheight &&
1661 normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 &&
1662 ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) ||
1663 Person::players[k]->aitype != playercontrolled)) {
1664 Person::players[i]->victim = Person::players[k];
1665 Person::players[i]->velocity = 0;
1666 Person::players[i]->animCurrent = jumpreversedanim;
1667 Person::players[i]->animTarget = jumpreversedanim;
1668 Person::players[i]->frameCurrent = 0;
1669 Person::players[i]->frameTarget = 1;
1670 Person::players[i]->targettilt2 = 0;
1671 Person::players[k]->victim = Person::players[i];
1672 Person::players[k]->velocity = 0;
1673 Person::players[k]->animCurrent = jumpreversalanim;
1674 Person::players[k]->animTarget = jumpreversalanim;
1675 Person::players[k]->frameCurrent = 0;
1676 Person::players[k]->frameTarget = 1;
1677 Person::players[k]->targettilt2 = 0;
1678 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 1) {
1679 Person::players[i]->animCurrent = rabbitkickreversedanim;
1680 Person::players[i]->animTarget = rabbitkickreversedanim;
1681 Person::players[i]->frameCurrent = 1;
1682 Person::players[i]->frameTarget = 2;
1683 Person::players[k]->animCurrent = rabbitkickreversalanim;
1684 Person::players[k]->animTarget = rabbitkickreversalanim;
1685 Person::players[k]->frameCurrent = 1;
1686 Person::players[k]->frameTarget = 2;
1688 Person::players[i]->target = 0;
1689 Person::players[k]->oldcoords = Person::players[k]->coords;
1690 Person::players[i]->coords = Person::players[k]->coords;
1691 Person::players[k]->targetyaw = Person::players[i]->targetyaw;
1692 Person::players[k]->yaw = Person::players[i]->targetyaw;
1693 if (Person::players[k]->aitype == attacktypecutoff) {
1694 Person::players[k]->stunned = .5;
1697 if (Person::players[k]->animTarget == jumpupanim &&
1698 Person::players[i]->animTarget != getupfrombackanim &&
1699 Person::players[i]->animTarget != getupfromfrontanim &&
1700 Animation::animations[Person::players[i]->animTarget].height == middleheight &&
1701 normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 &&
1702 ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) ||
1703 Person::players[i]->aitype != playercontrolled)) {
1704 Person::players[k]->victim = Person::players[i];
1705 Person::players[k]->velocity = 0;
1706 Person::players[k]->animCurrent = jumpreversedanim;
1707 Person::players[k]->animTarget = jumpreversedanim;
1708 Person::players[k]->frameCurrent = 0;
1709 Person::players[k]->frameTarget = 1;
1710 Person::players[k]->targettilt2 = 0;
1711 Person::players[i]->victim = Person::players[k];
1712 Person::players[i]->velocity = 0;
1713 Person::players[i]->animCurrent = jumpreversalanim;
1714 Person::players[i]->animTarget = jumpreversalanim;
1715 Person::players[i]->frameCurrent = 0;
1716 Person::players[i]->frameTarget = 1;
1717 Person::players[i]->targettilt2 = 0;
1718 if (Person::players[k]->coords.y < Person::players[i]->coords.y + 1) {
1719 Person::players[k]->animTarget = rabbitkickreversedanim;
1720 Person::players[k]->animCurrent = rabbitkickreversedanim;
1721 Person::players[i]->animCurrent = rabbitkickreversalanim;
1722 Person::players[i]->animTarget = rabbitkickreversalanim;
1723 Person::players[k]->frameCurrent = 1;
1724 Person::players[k]->frameTarget = 2;
1725 Person::players[i]->frameCurrent = 1;
1726 Person::players[i]->frameTarget = 2;
1728 Person::players[k]->target = 0;
1729 Person::players[i]->oldcoords = Person::players[i]->coords;
1730 Person::players[k]->coords = Person::players[i]->coords;
1731 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
1732 Person::players[i]->yaw = Person::players[k]->targetyaw;
1733 if (Person::players[i]->aitype == attacktypecutoff) {
1734 Person::players[i]->stunned = .5;
1743 void doAerialAcrobatics()
1745 static XYZ facing, flatfacing;
1746 for (unsigned k = 0; k < Person::players.size(); k++) {
1747 Person::players[k]->turnspeed = 500;
1749 if ((Person::players[k]->isRun() &&
1750 ((Person::players[k]->targetyaw != rabbitrunninganim &&
1751 Person::players[k]->targetyaw != wolfrunninganim) ||
1752 Person::players[k]->frameTarget == 4)) ||
1753 Person::players[k]->animTarget == removeknifeanim ||
1754 Person::players[k]->animTarget == crouchremoveknifeanim ||
1755 Person::players[k]->animTarget == flipanim ||
1756 Person::players[k]->animTarget == fightsidestep ||
1757 Person::players[k]->animTarget == walkanim) {
1758 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed);
1761 if (Person::players[k]->isStop() ||
1762 Person::players[k]->isLanding() ||
1763 Person::players[k]->animTarget == staggerbackhighanim ||
1764 (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) ||
1765 Person::players[k]->animTarget == staggerbackhardanim ||
1766 Person::players[k]->animTarget == backhandspringanim ||
1767 Person::players[k]->animTarget == dodgebackanim ||
1768 Person::players[k]->animTarget == rollanim ||
1769 (Animation::animations[Person::players[k]->animTarget].attack &&
1770 Person::players[k]->animTarget != rabbitkickanim &&
1771 (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) &&
1772 (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) {
1773 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 2);
1776 if (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent != sneakanim) {
1777 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 4);
1780 Person::players[k]->DoStuff();
1781 if (Person::players[k]->immobile && k != 0) {
1782 Person::players[k]->coords = Person::players[k]->realoldcoords;
1785 //if player's position has changed (?)
1786 if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 &&
1787 !Person::players[k]->skeleton.free &&
1788 Person::players[k]->animTarget != climbanim &&
1789 Person::players[k]->animTarget != hanganim) {
1790 XYZ lowpoint, lowpointtarget, lowpoint2, lowpointtarget2, lowpoint3, lowpointtarget3, lowpoint4, lowpointtarget4, lowpoint5, lowpointtarget5, lowpoint6, lowpointtarget6, lowpoint7, lowpointtarget7, colpoint, colpoint2;
1792 bool tempcollide = 0;
1794 if (Person::players[k]->collide < -.3) {
1795 Person::players[k]->collide = -.3;
1797 if (Person::players[k]->collide > 1) {
1798 Person::players[k]->collide = 1;
1800 Person::players[k]->collide -= multiplier * 30;
1803 Person::players[k]->coords.y = max(Person::players[k]->coords.y, terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z));
1805 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1806 unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1807 if (Object::objects[i]->type != rocktype ||
1808 Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled ||
1809 Object::objects[i]->position.y > Person::players[k]->coords.y) {
1810 lowpoint = Person::players[k]->coords;
1811 if (Person::players[k]->animTarget != jumpupanim &&
1812 Person::players[k]->animTarget != jumpdownanim &&
1813 !Person::players[k]->isFlip()) {
1818 if (Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) &&
1819 Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) {
1820 Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z);
1822 if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1823 flatfacing = lowpoint - Person::players[k]->coords;
1824 Person::players[k]->coords = lowpoint;
1825 Person::players[k]->coords.y -= 1.3;
1826 Person::players[k]->collide = 1;
1829 //TODO: refactor four similar blocks
1830 if (Person::players[k]->aitype == playercontrolled &&
1831 (Person::players[k]->animTarget == jumpupanim ||
1832 Person::players[k]->animTarget == jumpdownanim ||
1833 Person::players[k]->isFlip()) &&
1834 !Person::players[k]->jumptogglekeydown &&
1835 Person::players[k]->jumpkeydown) {
1836 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5;
1837 XYZ tempcoords1 = lowpoint;
1838 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1839 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1840 Person::players[k]->setTargetAnimation(walljumpleftanim);
1841 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1843 pause_sound(whooshsound);
1846 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1847 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1848 if (lowpointtarget.z < 0) {
1849 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1851 Person::players[k]->targetyaw = Person::players[k]->yaw;
1852 Person::players[k]->lowyaw = Person::players[k]->yaw;
1857 lowpoint = tempcoords1;
1858 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5;
1859 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1860 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1861 Person::players[k]->setTargetAnimation(walljumprightanim);
1862 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1864 pause_sound(whooshsound);
1867 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1868 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1869 if (lowpointtarget.z < 0) {
1870 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1872 Person::players[k]->targetyaw = Person::players[k]->yaw;
1873 Person::players[k]->lowyaw = Person::players[k]->yaw;
1878 lowpoint = tempcoords1;
1879 lowpointtarget = lowpoint + Person::players[k]->facing * 2;
1880 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1881 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1882 Person::players[k]->setTargetAnimation(walljumpbackanim);
1883 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1885 pause_sound(whooshsound);
1888 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1889 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1890 if (lowpointtarget.z < 0) {
1891 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1893 Person::players[k]->targetyaw = Person::players[k]->yaw;
1894 Person::players[k]->lowyaw = Person::players[k]->yaw;
1899 lowpoint = tempcoords1;
1900 lowpointtarget = lowpoint - Person::players[k]->facing * 2;
1901 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1902 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1903 Person::players[k]->setTargetAnimation(walljumpfrontanim);
1904 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1906 pause_sound(whooshsound);
1909 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1910 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1911 if (lowpointtarget.z < 0) {
1912 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1914 Person::players[k]->yaw += 180;
1915 Person::players[k]->targetyaw = Person::players[k]->yaw;
1916 Person::players[k]->lowyaw = Person::players[k]->yaw;
1926 } else if (Object::objects[i]->type == rocktype) {
1927 lowpoint2 = Person::players[k]->coords;
1928 lowpoint = Person::players[k]->coords;
1930 if (Object::objects[i]->model.LineCheck(&lowpoint, &lowpoint2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
1931 Person::players[k]->coords = colpoint;
1932 Person::players[k]->collide = 1;
1935 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) {
1936 //flipped into a rock
1937 if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) {
1938 Person::players[k]->RagDoll(0);
1941 if (Person::players[k]->animTarget == jumpupanim) {
1942 Person::players[k]->jumppower = -4;
1943 Person::players[k]->animTarget = Person::players[k]->getIdle();
1945 Person::players[k]->target = 0;
1946 Person::players[k]->frameTarget = 0;
1947 Person::players[k]->onterrain = 1;
1949 if (Person::players[k]->id == 0) {
1950 pause_sound(whooshsound);
1951 OPENAL_SetVolume(channels[whooshsound], 0);
1955 if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) {
1956 if (Person::players[k]->isFlip()) {
1957 Person::players[k]->jumppower = -4;
1959 Person::players[k]->animTarget = Person::players[k]->getLanding();
1960 emit_sound_at(landsound, Person::players[k]->coords, 128.);
1962 addEnvSound(Person::players[k]->coords);
1971 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1972 int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1973 lowpoint = Person::players[k]->coords;
1975 if (Object::objects[i]->type != rocktype) {
1976 if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1977 if (Person::players[k]->animTarget != jumpupanim &&
1978 Person::players[k]->animTarget != jumpdownanim &&
1979 Person::players[k]->onterrain) {
1980 Person::players[k]->avoidcollided = 1;
1982 Person::players[k]->coords = lowpoint;
1983 Person::players[k]->coords.y -= 1.35;
1984 Person::players[k]->collide = 1;
1986 if ((Person::players[k]->grabdelay <= 0 || Person::players[k]->aitype != playercontrolled) &&
1987 (Person::players[k]->animCurrent != climbanim &&
1988 Person::players[k]->animCurrent != hanganim &&
1989 !Person::players[k]->isWallJump() ||
1990 Person::players[k]->animTarget == jumpupanim ||
1991 Person::players[k]->animTarget == jumpdownanim)) {
1992 lowpoint = Person::players[k]->coords;
1993 Object::objects[i]->model.SphereCheckPossible(&lowpoint, 1.5, &Object::objects[i]->position, &Object::objects[i]->yaw);
1994 lowpoint = Person::players[k]->coords;
1998 facing = DoRotation(facing, 0, Person::players[k]->targetyaw + 180, 0);
1999 lowpointtarget = lowpoint + facing * 1.4;
2000 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
2001 if (whichhit != -1) {
2002 lowpoint = Person::players[k]->coords;
2004 lowpointtarget = lowpoint + facing * 1.4;
2005 lowpoint2 = lowpoint;
2006 lowpointtarget2 = lowpointtarget;
2007 lowpoint3 = lowpoint;
2008 lowpointtarget3 = lowpointtarget;
2009 lowpoint4 = lowpoint;
2010 lowpointtarget4 = lowpointtarget;
2011 lowpoint5 = lowpoint;
2012 lowpointtarget5 = lowpointtarget;
2013 lowpoint6 = lowpoint;
2014 lowpointtarget6 = lowpointtarget;
2015 lowpoint7 = lowpoint;
2016 lowpointtarget7 = lowpoint;
2018 lowpointtarget2.x += .1;
2020 lowpointtarget3.z += .1;
2022 lowpointtarget4.x -= .1;
2024 lowpointtarget5.z -= .1;
2025 lowpoint6.y += 45 / 13;
2026 lowpointtarget6.y += 45 / 13;
2027 lowpointtarget6 += facing * .6;
2028 lowpointtarget7.y += 90 / 13;
2029 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
2030 if (Object::objects[i]->friction > .5) {
2031 if (whichhit != -1) {
2032 if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) {
2033 Person::players[k]->collided = 1;
2035 if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) {
2036 if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) {
2037 if (Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2,
2038 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2039 Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3,
2040 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2041 Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4,
2042 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2043 Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5,
2044 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
2045 for (int j = 0; j < 45; j++) {
2046 lowpoint = Person::players[k]->coords;
2047 lowpoint.y += (float)j / 13;
2048 lowpointtarget = lowpoint + facing * 1.4;
2049 if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget,
2050 &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) {
2051 if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) {
2054 if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) {
2055 lowpoint = Person::players[k]->coords;
2056 lowpoint.y += (float)j / 13;
2057 lowpointtarget = lowpoint + facing * 1.3;
2058 flatfacing = Person::players[k]->coords;
2059 Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * .01;
2060 Person::players[k]->coords.y = lowpointtarget.y - .07;
2061 Person::players[k]->currentoffset = (flatfacing - Person::players[k]->coords) / Person::players[k]->scale;
2063 if (j > 10 || !Person::players[k]->isRun()) {
2064 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) {
2066 pause_sound(whooshsound);
2069 emit_sound_at(jumpsound, Person::players[k]->coords, 128.);
2071 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
2072 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
2073 if (lowpointtarget.z < 0) {
2074 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
2076 Person::players[k]->targetyaw = Person::players[k]->yaw;
2077 Person::players[k]->lowyaw = Person::players[k]->yaw;
2079 //Person::players[k]->velocity=lowpointtarget*.03;
2080 Person::players[k]->velocity = 0;
2083 if (Person::players[k]->animTarget == jumpupanim) {
2084 Person::players[k]->animTarget = climbanim;
2085 Person::players[k]->jumppower = 0;
2086 Person::players[k]->jumpclimb = 1;
2088 Person::players[k]->transspeed = 6;
2089 Person::players[k]->target = 0;
2090 Person::players[k]->frameTarget = 1;
2093 Person::players[k]->setTargetAnimation(hanganim);
2094 Person::players[k]->jumppower = 0;
2112 if (Person::players[k]->collide <= 0) {
2114 if (!Person::players[k]->onterrain &&
2115 Person::players[k]->animTarget != jumpupanim &&
2116 Person::players[k]->animTarget != jumpdownanim &&
2117 Person::players[k]->animTarget != climbanim &&
2118 Person::players[k]->animTarget != hanganim &&
2119 !Person::players[k]->isWallJump() &&
2120 !Person::players[k]->isFlip()) {
2121 if (Person::players[k]->animCurrent != climbanim &&
2122 Person::players[k]->animCurrent != tempanim &&
2123 Person::players[k]->animTarget != backhandspringanim &&
2124 (Person::players[k]->animTarget != rollanim ||
2125 Person::players[k]->frameTarget < 2 ||
2126 Person::players[k]->frameTarget > 6)) {
2127 //stagger off ledge (?)
2128 if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) {
2129 Person::players[k]->RagDoll(0);
2131 Person::players[k]->setTargetAnimation(jumpdownanim);
2134 emit_sound_at(whooshsound, Person::players[k]->coords, 128.);
2138 Person::players[k]->velocity.y += gravity;
2142 Person::players[k]->realoldcoords = Person::players[k]->coords;
2148 static int randattack;
2149 static bool playerrealattackkeydown = 0;
2151 if (!Input::isKeyDown(attackkey)) {
2155 Person::players[0]->attackkeydown = 0;
2158 playerrealattackkeydown = 0;
2160 if (!oldattackkey) {
2161 playerrealattackkeydown = Input::isKeyDown(attackkey);
2163 if ((Person::players[0]->parriedrecently <= 0 ||
2164 Person::players[0]->weaponactive == -1) &&
2167 Person::players[0]->lastattack != swordslashanim &&
2168 Person::players[0]->lastattack != knifeslashstartanim &&
2169 Person::players[0]->lastattack != staffhitanim &&
2170 Person::players[0]->lastattack != staffspinhitanim))) {
2171 Person::players[0]->attackkeydown = Input::isKeyDown(attackkey);
2173 if (Input::isKeyDown(attackkey) &&
2175 !Person::players[0]->backkeydown) {
2176 for (unsigned k = 0; k < Person::players.size(); k++) {
2177 if ((Person::players[k]->animTarget == swordslashanim ||
2178 Person::players[k]->animTarget == staffhitanim ||
2179 Person::players[k]->animTarget == staffspinhitanim) &&
2180 Person::players[0]->animCurrent != dodgebackanim &&
2181 !Person::players[k]->skeleton.free) {
2182 Person::players[k]->Reverse();
2187 if (!hostile || Dialog::inDialog()) {
2188 Person::players[0]->attackkeydown = 0;
2191 for (unsigned k = 0; k < Person::players.size(); k++) {
2192 if (Dialog::inDialog()) {
2193 Person::players[k]->attackkeydown = 0;
2195 if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) {
2196 if (Person::players[k]->aitype != playercontrolled) {
2197 Person::players[k]->victim = Person::players[0];
2199 //attack key pressed
2200 if (Person::players[k]->attackkeydown) {
2202 if (Person::players[k]->backkeydown &&
2203 Person::players[k]->animTarget != backhandspringanim &&
2204 (Person::players[k]->isIdle() ||
2205 Person::players[k]->isStop() ||
2206 Person::players[k]->isRun() ||
2207 Person::players[k]->animTarget == walkanim)) {
2208 if (Person::players[k]->jumppower <= 1) {
2209 Person::players[k]->jumppower -= 2;
2211 for (unsigned i = 0; i < Person::players.size(); i++) {
2215 if (Person::players[i]->animTarget == swordslashanim ||
2216 Person::players[i]->animTarget == knifeslashstartanim ||
2217 Person::players[i]->animTarget == staffhitanim ||
2218 Person::players[i]->animTarget == staffspinhitanim) {
2219 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) {
2220 Person::players[k]->setTargetAnimation(dodgebackanim);
2221 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2222 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2226 if (Person::players[k]->animTarget != dodgebackanim) {
2230 Person::players[k]->setTargetAnimation(backhandspringanim);
2231 Person::players[k]->targetyaw = -yaw + 180;
2232 if (Person::players[k]->leftkeydown) {
2233 Person::players[k]->targetyaw -= 45;
2235 if (Person::players[k]->rightkeydown) {
2236 Person::players[k]->targetyaw += 45;
2238 Person::players[k]->yaw = Person::players[k]->targetyaw;
2239 Person::players[k]->jumppower -= 2;
2244 if (!Animation::animations[Person::players[k]->animTarget].attack &&
2245 !Person::players[k]->backkeydown &&
2246 (Person::players[k]->isIdle() ||
2247 Person::players[k]->isRun() ||
2248 Person::players[k]->animTarget == walkanim ||
2249 Person::players[k]->animTarget == sneakanim ||
2250 Person::players[k]->isCrouch())) {
2251 const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType();
2252 //normal attacks (?)
2253 Person::players[k]->hasvictim = 0;
2254 if (Person::players.size() > 1) {
2255 for (unsigned i = 0; i < Person::players.size(); i++) {
2256 if (i == k || !(k == 0 || i == 0)) {
2259 if (!Person::players[k]->hasvictim) {
2260 if (Animation::animations[Person::players[k]->animTarget].attack != reversal) {
2262 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2263 if (distance < 4.5 &&
2264 !Person::players[i]->skeleton.free &&
2265 Person::players[i]->howactive < typedead1 &&
2266 Person::players[i]->animTarget != jumpreversedanim &&
2267 Person::players[i]->animTarget != rabbitkickreversedanim &&
2268 Person::players[i]->animTarget != rabbitkickanim &&
2269 Person::players[k]->animTarget != rabbitkickanim &&
2270 Person::players[i]->animTarget != getupfrombackanim &&
2271 (Person::players[i]->animTarget != staggerbackhighanim &&
2272 (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) &&
2273 Person::players[i]->animTarget != jumpdownanim &&
2274 Person::players[i]->animTarget != jumpupanim &&
2275 Person::players[i]->animTarget != getupfromfrontanim) {
2276 Person::players[k]->victim = Person::players[i];
2277 Person::players[k]->hasvictim = 1;
2278 if (Person::players[k]->aitype == playercontrolled) { //human player
2280 if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2281 Person::players[k]->crouchkeydown &&
2282 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2283 Person::players[k]->animTarget = sweepanim;
2285 } else if (distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2286 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2287 !Person::players[k]->forwardkeydown &&
2288 !Person::players[k]->leftkeydown &&
2289 !Person::players[k]->rightkeydown &&
2290 !Person::players[k]->crouchkeydown &&
2293 Person::players[k]->animTarget = winduppunchanim;
2295 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2296 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2297 !Person::players[k]->forwardkeydown &&
2298 !Person::players[k]->leftkeydown &&
2299 !Person::players[k]->rightkeydown &&
2300 !Person::players[k]->crouchkeydown &&
2302 Person::players[k]->animTarget = upunchanim;
2304 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2305 Person::players[i]->staggerdelay > 0 &&
2306 attackweapon == knife &&
2307 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) {
2308 Person::players[k]->animTarget = knifefollowanim;
2310 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2311 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2312 !Person::players[k]->forwardkeydown &&
2313 !Person::players[k]->leftkeydown &&
2314 !Person::players[k]->rightkeydown &&
2315 !Person::players[k]->crouchkeydown &&
2316 attackweapon == knife &&
2317 Person::players[k]->weaponmissdelay <= 0) {
2318 Person::players[k]->animTarget = knifeslashstartanim;
2320 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2321 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2322 !Person::players[k]->crouchkeydown &&
2323 attackweapon == sword &&
2324 Person::players[k]->weaponmissdelay <= 0) {
2325 Person::players[k]->animTarget = swordslashanim;
2327 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2328 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2329 !Person::players[k]->crouchkeydown &&
2330 attackweapon == staff &&
2331 Person::players[k]->weaponmissdelay <= 0 &&
2332 !Person::players[k]->leftkeydown &&
2333 !Person::players[k]->rightkeydown &&
2334 !Person::players[k]->forwardkeydown) {
2335 Person::players[k]->animTarget = staffhitanim;
2337 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2338 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2339 !Person::players[k]->crouchkeydown &&
2340 attackweapon == staff &&
2341 Person::players[k]->weaponmissdelay <= 0) {
2342 Person::players[k]->animTarget = staffspinhitanim;
2344 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2345 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2346 Person::players[k]->animTarget = spinkickanim;
2348 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2349 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2350 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2351 Person::players[k]->animTarget = lowkickanim;
2353 } else { //AI player
2354 if (distance < 4.5 * sq(Person::players[k]->scale * 5)) {
2355 randattack = abs(Random() % 5);
2356 if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) {
2358 if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2359 Person::players[k]->animTarget = sweepanim;
2361 } else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2363 Person::players[k]->animTarget = upunchanim;
2365 } else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2366 Person::players[k]->animTarget = spinkickanim;
2368 } else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) {
2369 Person::players[k]->animTarget = lowkickanim;
2374 if ((!Tutorial::active || !attackweapon) &&
2375 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2377 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2378 Person::players[k]->animTarget = sweepanim;
2380 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2381 attackweapon == knife &&
2382 Person::players[k]->weaponmissdelay <= 0) {
2383 Person::players[k]->animTarget = knifeslashstartanim;
2385 } else if (!(Person::players[0]->victim == Person::players[i] &&
2386 Person::players[0]->hasvictim &&
2387 Person::players[0]->animTarget == swordslashanim) &&
2388 attackweapon == sword &&
2389 Person::players[k]->weaponmissdelay <= 0) {
2390 Person::players[k]->animTarget = swordslashanim;
2392 } else if (!(Person::players[0]->victim == Person::players[i] &&
2393 Person::players[0]->hasvictim &&
2394 Person::players[0]->animTarget == swordslashanim) &&
2395 attackweapon == staff &&
2396 Person::players[k]->weaponmissdelay <= 0 &&
2398 Person::players[k]->animTarget = staffhitanim;
2400 } else if (!(Person::players[0]->victim == Person::players[i] &&
2401 Person::players[0]->hasvictim &&
2402 Person::players[0]->animTarget == swordslashanim) &&
2403 attackweapon == staff &&
2404 Person::players[k]->weaponmissdelay <= 0 &&
2406 Person::players[k]->animTarget = staffspinhitanim;
2408 } else if ((!Tutorial::active || !attackweapon) &&
2409 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2411 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2412 Person::players[k]->animTarget = spinkickanim;
2414 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2415 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2416 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2417 Person::players[k]->animTarget = lowkickanim;
2422 //upunch becomes wolfslap
2423 if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) {
2424 Person::players[k]->animTarget = wolfslapanim;
2428 if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) &&
2429 Person::players[i]->howactive < typedead1 &&
2430 distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2431 !Person::players[i]->skeleton.free &&
2432 Person::players[i]->animTarget != getupfrombackanim &&
2433 Person::players[i]->animTarget != getupfromfrontanim &&
2434 (Person::players[i]->surprised > 0 ||
2435 Person::players[i]->aitype == passivetype ||
2436 attackweapon && Person::players[i]->stunned > 0) &&
2437 normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) {
2439 if (!attackweapon) {
2440 Person::players[k]->animCurrent = sneakattackanim;
2441 Person::players[k]->animTarget = sneakattackanim;
2442 Person::players[i]->animCurrent = sneakattackedanim;
2443 Person::players[i]->animTarget = sneakattackedanim;
2444 Person::players[k]->oldcoords = Person::players[k]->coords;
2445 Person::players[k]->coords = Person::players[i]->coords;
2448 if (attackweapon == knife) {
2449 Person::players[k]->animCurrent = knifesneakattackanim;
2450 Person::players[k]->animTarget = knifesneakattackanim;
2451 Person::players[i]->animCurrent = knifesneakattackedanim;
2452 Person::players[i]->animTarget = knifesneakattackedanim;
2453 Person::players[i]->oldcoords = Person::players[i]->coords;
2454 Person::players[i]->coords = Person::players[k]->coords;
2457 if (attackweapon == sword) {
2458 Person::players[k]->animCurrent = swordsneakattackanim;
2459 Person::players[k]->animTarget = swordsneakattackanim;
2460 Person::players[i]->animCurrent = swordsneakattackedanim;
2461 Person::players[i]->animTarget = swordsneakattackedanim;
2462 Person::players[i]->oldcoords = Person::players[i]->coords;
2463 Person::players[i]->coords = Person::players[k]->coords;
2465 if (attackweapon != staff) {
2466 Person::players[k]->victim = Person::players[i];
2467 Person::players[k]->hasvictim = 1;
2468 Person::players[i]->targettilt2 = 0;
2469 Person::players[i]->frameTarget = 1;
2470 Person::players[i]->frameCurrent = 0;
2471 Person::players[i]->target = 0;
2472 Person::players[i]->velocity = 0;
2473 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2474 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2475 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2476 Person::players[k]->target = Person::players[i]->target;
2477 Person::players[k]->velocity = 0;
2478 Person::players[k]->targetyaw = Person::players[i]->yaw;
2479 Person::players[k]->yaw = Person::players[i]->yaw;
2480 Person::players[i]->targetyaw = Person::players[i]->yaw;
2483 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2484 Person::players[k]->victim == Person::players[i] &&
2485 (!Person::players[i]->skeleton.free)) {
2487 Person::players[k]->frameTarget = 0;
2488 Person::players[k]->target = 0;
2490 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2491 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2492 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2493 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2494 Person::players[k]->lastattack = Person::players[k]->animTarget;
2496 if (Person::players[k]->animTarget == knifefollowanim &&
2497 Person::players[k]->victim == Person::players[i]) {
2499 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2500 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2501 Person::players[k]->victim = Person::players[i];
2502 Person::players[k]->hasvictim = 1;
2503 Person::players[i]->animTarget = knifefollowedanim;
2504 Person::players[i]->animCurrent = knifefollowedanim;
2505 Person::players[i]->targettilt2 = 0;
2506 Person::players[i]->targettilt2 = Person::players[k]->targettilt2;
2507 Person::players[i]->frameTarget = 1;
2508 Person::players[i]->frameCurrent = 0;
2509 Person::players[i]->target = 0;
2510 Person::players[i]->velocity = 0;
2511 Person::players[k]->animCurrent = knifefollowanim;
2512 Person::players[k]->animTarget = knifefollowanim;
2513 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2514 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2515 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2516 Person::players[k]->target = Person::players[i]->target;
2517 Person::players[k]->velocity = 0;
2518 Person::players[k]->oldcoords = Person::players[k]->coords;
2519 Person::players[i]->coords = Person::players[k]->coords;
2520 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
2521 Person::players[i]->yaw = Person::players[k]->targetyaw;
2522 Person::players[k]->yaw = Person::players[k]->targetyaw;
2523 Person::players[i]->yaw = Person::players[k]->targetyaw;
2529 const bool hasstaff = attackweapon == staff;
2530 if (k == 0 && Person::players.size() > 1) {
2531 for (unsigned i = 0; i < Person::players.size(); i++) {
2535 if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) &&
2536 Animation::animations[Person::players[k]->animTarget].attack == neutral) {
2537 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2538 if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) {
2539 if (Person::players[i]->skeleton.free) {
2540 if (distance < 3.5 * sq(Person::players[k]->scale * 5) &&
2541 (Person::players[i]->dead ||
2542 Person::players[i]->skeleton.longdead > 1000 ||
2543 Person::players[k]->isRun() ||
2546 (Person::players[i]->skeleton.longdead > 2000 ||
2547 Person::players[i]->damage > Person::players[i]->damagetolerance / 8 ||
2548 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) &&
2549 distance < 1.5 * sq(Person::players[k]->scale * 5)))) {
2550 Person::players[k]->victim = Person::players[i];
2551 Person::players[k]->hasvictim = 1;
2552 if (attackweapon && !Tutorial::active) {
2554 if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) {
2555 Person::players[k]->animTarget = crouchstabanim;
2558 if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) {
2559 Person::players[k]->animTarget = swordgroundstabanim;
2562 if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) {
2563 Person::players[k]->animTarget = staffgroundsmashanim;
2566 if (distance < 2.5 &&
2567 Person::players[k]->crouchkeydown &&
2568 Person::players[k]->animTarget != crouchstabanim &&
2570 Person::players[i]->dead &&
2571 Person::players[i]->skeleton.free &&
2572 Person::players[i]->skeleton.longdead > 1000) {
2573 Person::players[k]->animTarget = killanim;
2574 terrain.deleteDeadDecals();
2575 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2576 if (Object::objects[l]->model.type == decalstype) {
2577 Object::objects[l]->model.deleteDeadDecals();
2581 if (!Person::players[i]->dead || musictype != 2) {
2582 if (distance < 3.5 &&
2583 (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) &&
2584 Person::players[k]->staggerdelay <= 0 &&
2585 (Person::players[i]->dead ||
2586 Person::players[i]->skeleton.longdead < 300 &&
2587 Person::players[k]->lastattack != spinkickanim &&
2588 Person::players[i]->skeleton.free) &&
2589 (!Person::players[i]->dead || musictype != stream_fighttheme)) {
2590 Person::players[k]->animTarget = dropkickanim;
2591 terrain.deleteDeadDecals();
2592 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2593 if (Object::objects[l]->model.type == decalstype) {
2594 Object::objects[l]->model.deleteDeadDecals();
2602 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2603 Person::players[k]->victim == Person::players[i] &&
2604 (!Person::players[i]->skeleton.free ||
2605 Person::players[k]->animTarget == killanim ||
2606 Person::players[k]->animTarget == crouchstabanim ||
2607 Person::players[k]->animTarget == swordgroundstabanim ||
2608 Person::players[k]->animTarget == staffgroundsmashanim ||
2609 Person::players[k]->animTarget == dropkickanim)) {
2611 Person::players[k]->frameTarget = 0;
2612 Person::players[k]->target = 0;
2614 XYZ targetpoint = Person::players[i]->coords;
2615 if (Person::players[k]->animTarget == crouchstabanim ||
2616 Person::players[k]->animTarget == swordgroundstabanim ||
2617 Person::players[k]->animTarget == staffgroundsmashanim) {
2618 targetpoint += (Person::players[i]->jointPos(abdomen) +
2619 Person::players[i]->jointPos(neck)) /
2621 Person::players[i]->scale;
2623 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, targetpoint);
2624 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, targetpoint);
2626 if (Person::players[k]->animTarget == crouchstabanim || Person::players[k]->animTarget == swordgroundstabanim) {
2627 Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4;
2630 if (Person::players[k]->animTarget == staffgroundsmashanim) {
2631 Person::players[k]->targettilt2 += 10;
2634 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2635 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2636 Person::players[k]->lastattack = Person::players[k]->animTarget;
2638 if (Person::players[k]->animTarget == swordgroundstabanim) {
2639 Person::players[k]->targetyaw += 30;
2645 if (!Person::players[k]->hasvictim) {
2647 for (unsigned i = 0; i < Person::players.size(); i++) {
2648 if (i == k || !(i == 0 || k == 0)) {
2651 if (!Person::players[i]->skeleton.free) {
2652 if (Person::players[k]->hasvictim) {
2653 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) <
2654 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) {
2655 Person::players[k]->victim = Person::players[i];
2658 Person::players[k]->victim = Person::players[i];
2659 Person::players[k]->hasvictim = 1;
2664 if (Person::players[k]->aitype == playercontrolled) {
2666 if (Person::players[k]->attackkeydown &&
2667 Person::players[k]->isRun() &&
2668 Person::players[k]->wasRun() &&
2669 ((Person::players[k]->hasvictim &&
2670 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) &&
2671 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) &&
2672 !Person::players[k]->victim->skeleton.free &&
2673 Person::players[k]->victim->animTarget != getupfrombackanim &&
2674 Person::players[k]->victim->animTarget != getupfromfrontanim &&
2675 Animation::animations[Person::players[k]->victim->animTarget].height != lowheight &&
2676 Person::players[k]->aitype != playercontrolled && //wat???
2677 normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 &&
2678 Person::players[k]->rabbitkickenabled) ||
2679 Person::players[k]->jumpkeydown)) {
2681 Person::players[k]->setTargetAnimation(rabbitkickanim);
2685 if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) {
2687 switch (attackweapon) {
2708 void doPlayerCollisions()
2710 static XYZ rotatetarget;
2711 static float collisionradius;
2712 if (Person::players.size() > 1) {
2713 for (unsigned k = 0; k < Person::players.size(); k++) {
2714 for (unsigned i = k + 1; i < Person::players.size(); i++) {
2715 //neither player is part of a reversal
2716 if ((Animation::animations[Person::players[i]->animTarget].attack != reversed &&
2717 Animation::animations[Person::players[i]->animTarget].attack != reversal &&
2718 Animation::animations[Person::players[k]->animTarget].attack != reversed &&
2719 Animation::animations[Person::players[k]->animTarget].attack != reversal) ||
2720 (i != 0 && k != 0)) {
2721 if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed &&
2722 Animation::animations[Person::players[i]->animCurrent].attack != reversal &&
2723 Animation::animations[Person::players[k]->animCurrent].attack != reversed &&
2724 Animation::animations[Person::players[k]->animCurrent].attack != reversal) ||
2725 (i != 0 && k != 0)) {
2726 //neither is sleeping
2727 if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) {
2728 if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) {
2729 //in same patch, neither is climbing
2730 if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx &&
2731 Person::players[i]->whichpatchz == Person::players[k]->whichpatchz &&
2732 Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free &&
2733 Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free &&
2734 Person::players[i]->animTarget != climbanim &&
2735 Person::players[i]->animTarget != hanganim &&
2736 Person::players[k]->animTarget != climbanim &&
2737 Person::players[k]->animTarget != hanganim) {
2738 //players are close (bounding box test)
2739 if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) {
2740 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) {
2741 if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) {
2742 if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) {
2743 if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) {
2744 if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) {
2745 //spread fire from player to player
2746 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2747 if (Person::players[i]->onfire || Person::players[k]->onfire) {
2748 if (!Person::players[i]->onfire) {
2749 Person::players[i]->CatchFire();
2751 if (!Person::players[k]->onfire) {
2752 Person::players[k]->CatchFire();
2757 XYZ tempcoords1 = Person::players[i]->coords;
2758 XYZ tempcoords2 = Person::players[k]->coords;
2759 if (!Person::players[i]->skeleton.oldfree) {
2760 tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale;
2762 if (!Person::players[k]->skeleton.oldfree) {
2763 tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale;
2765 collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2766 if (Person::players[0]->hasvictim) {
2767 if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) {
2768 collisionradius = 3;
2771 if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) &&
2772 (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
2773 distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) {
2774 //jump down on a dead body
2775 if (k == 0 || i == 0) {
2777 if (Person::players[0]->animTarget == jumpdownanim &&
2778 !Person::players[0]->skeleton.oldfree &&
2779 !Person::players[0]->skeleton.free &&
2780 Person::players[l]->skeleton.oldfree &&
2781 Person::players[l]->skeleton.free &&
2782 Person::players[l]->dead &&
2783 Person::players[0]->lastcollide <= 0 &&
2784 fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 &&
2785 distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) {
2786 Person::players[0]->coords.y = Person::players[l]->coords.y;
2787 Person::players[l]->velocity = Person::players[0]->velocity;
2788 Person::players[l]->skeleton.free = 0;
2789 Person::players[l]->yaw = 0;
2790 Person::players[l]->RagDoll(0);
2791 Person::players[l]->DoDamage(20);
2793 Person::players[l]->skeleton.longdead = 0;
2794 Person::players[0]->lastcollide = 1;
2798 if ((Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) ||
2799 (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) ||
2800 (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) {
2801 rotatetarget = Person::players[k]->velocity - Person::players[i]->velocity;
2802 if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim ||
2803 Person::players[i]->skeleton.free) &&
2804 (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim ||
2805 Person::players[k]->skeleton.free)) {
2806 if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
2807 k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) &&
2808 normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) &&
2810 k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral ||
2811 /*i!=0&&*/ Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) ||
2812 (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) &&
2813 (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) &&
2814 k == 0 && !Person::players[i]->skeleton.oldfree && !Person::players[k]->skeleton.oldfree) {
2816 if ((i != 0 || Person::players[i]->skeleton.free) &&
2817 (k != 0 || Person::players[k]->skeleton.free) ||
2818 (Animation::animations[Person::players[i]->animTarget].height == highheight &&
2819 Animation::animations[Person::players[k]->animTarget].height == highheight)) {
2820 if (!Tutorial::active) {
2821 emit_sound_at(heavyimpactsound, Person::players[i]->coords);
2824 Person::players[i]->RagDoll(0);
2825 if (Person::players[i]->damage > Person::players[i]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[i]->dead) {
2826 award_bonus(0, aimbonus);
2828 Person::players[i]->DoDamage(findLengthfast(&rotatetarget) / 4);
2829 Person::players[k]->RagDoll(0);
2830 if (Person::players[k]->damage > Person::players[k]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[k]->dead) {
2831 award_bonus(0, aimbonus); // Huh, again?
2833 Person::players[k]->DoDamage(findLengthfast(&rotatetarget) / 4);
2835 for (unsigned j = 0; j < Person::players[i]->skeleton.joints.size(); j++) {
2836 Person::players[i]->skeleton.joints[j].velocity = Person::players[i]->skeleton.joints[j].velocity / 5 + Person::players[k]->velocity;
2838 for (unsigned j = 0; j < Person::players[k]->skeleton.joints.size(); j++) {
2839 Person::players[k]->skeleton.joints[j].velocity = Person::players[k]->skeleton.joints[j].velocity / 5 + Person::players[i]->velocity;
2844 if ((Animation::animations[Person::players[i]->animTarget].attack == neutral ||
2845 Animation::animations[Person::players[i]->animTarget].attack == normalattack) &&
2846 (Animation::animations[Person::players[k]->animTarget].attack == neutral ||
2847 Animation::animations[Person::players[k]->animTarget].attack == normalattack)) {
2849 if (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0) {
2850 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < .5 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2851 rotatetarget = Person::players[k]->coords - Person::players[i]->coords;
2852 Normalise(&rotatetarget);
2853 Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2;
2854 Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2855 Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2856 if (Person::players[k]->howactive == typeactive || hostile) {
2857 if (Person::players[k]->isIdle()) {
2858 if (Person::players[k]->howactive < typesleeping) {
2859 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
2860 } else if (Person::players[k]->howactive == typesleeping) {
2861 Person::players[k]->setTargetAnimation(getupfromfrontanim);
2863 if (!editorenabled) {
2864 Person::players[k]->howactive = typeactive;
2868 if (Person::players[i]->howactive == typeactive || hostile) {
2869 if (Person::players[i]->isIdle()) {
2870 if (Person::players[i]->howactive < typesleeping) {
2871 Person::players[i]->setTargetAnimation(Person::players[k]->getStop());
2873 Person::players[i]->setTargetAnimation(getupfromfrontanim);
2875 if (!editorenabled) {
2876 Person::players[i]->howactive = typeactive;
2881 //jump down on player
2883 if (k == 0 && i != 0 && Person::players[k]->animTarget == jumpdownanim &&
2884 !Person::players[i]->isCrouch() &&
2885 Person::players[i]->animTarget != rollanim &&
2886 !Person::players[k]->skeleton.oldfree && !Person::players[k]->skeleton.free &&
2887 Person::players[k]->lastcollide <= 0 &&
2888 Person::players[k]->velocity.y < -10) {
2889 Person::players[i]->velocity = Person::players[k]->velocity;
2890 Person::players[k]->velocity = Person::players[k]->velocity * -.5;
2891 Person::players[k]->velocity.y = Person::players[i]->velocity.y;
2892 Person::players[i]->DoDamage(20);
2893 Person::players[i]->RagDoll(0);
2894 Person::players[k]->lastcollide = 1;
2895 award_bonus(k, AboveBonus);
2897 if (i == 0 && k != 0 && Person::players[i]->animTarget == jumpdownanim &&
2898 !Person::players[k]->isCrouch() &&
2899 Person::players[k]->animTarget != rollanim &&
2900 !Person::players[i]->skeleton.oldfree &&
2901 !Person::players[i]->skeleton.free &&
2902 Person::players[i]->lastcollide <= 0 &&
2903 Person::players[i]->velocity.y < -10) {
2904 Person::players[k]->velocity = Person::players[i]->velocity;
2905 Person::players[i]->velocity = Person::players[i]->velocity * -.3;
2906 Person::players[i]->velocity.y = Person::players[k]->velocity.y;
2907 Person::players[k]->DoDamage(20);
2908 Person::players[k]->RagDoll(0);
2909 Person::players[i]->lastcollide = 1;
2910 award_bonus(i, AboveBonus);
2916 Person::players[i]->CheckKick();
2917 Person::players[k]->CheckKick();
2937 static XYZ facing, flatfacing;
2940 /* Pump SDL input events and process non-gameplay related ones */
2944 Values of mainmenu :
2946 2 Menu pause (resume/end game)
2948 4 Controls configuration menu
2949 5 Main game menu (choose level or challenge)
2950 6 Deleting user menu
2951 7 User managment menu (select/add)
2952 8 Choose difficulty menu
2953 9 Challenge level selection menu
2954 10 End of the campaign congratulation (is that really a menu?)
2955 11 Same that 9 ??? => unused
2956 18 stereo configuration
2961 if (mainmenu && endgame == 1) {
2964 //go to level select after completing a campaign level
2965 if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) {
2972 OPENAL_SetFrequency(OPENAL_ALL);
2973 emit_stream_np(stream_menutheme);
2974 pause_sound(leveltheme);
2986 hostiletime += multiplier;
2991 leveltime += multiplier;
2997 inputText(consoletext[0], &consoleselected);
2999 if (!consoletext[0].empty()) {
3000 cmd_dispatch(consoletext[0]);
3001 for (int k = 14; k >= 1; k--) {
3002 consoletext[k] = consoletext[k - 1];
3004 consoletext[0].clear();
3005 consoleselected = 0;
3009 consoleblinkdelay -= multiplier;
3010 if (consoleblinkdelay <= 0) {
3011 consoleblinkdelay = .3;
3012 consoleblink = !consoleblink;
3016 static int oldwinfreeze;
3017 if (winfreeze && !oldwinfreeze) {
3018 OPENAL_SetFrequency(OPENAL_ALL);
3019 emit_sound_np(consolesuccesssound);
3021 if (winfreeze == 0) {
3022 oldwinfreeze = winfreeze;
3027 if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
3030 static float talkdelay = 0;
3032 if (Dialog::inDialog()) {
3035 talkdelay -= multiplier;
3037 if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) {
3038 for (unsigned i = 0; i < Dialog::dialogs.size(); i++) {
3039 Dialog::dialogs[i].tick(i);
3043 windvar += multiplier;
3044 smoketex += multiplier;
3045 Tutorial::stagetime += multiplier;
3048 static float hotspotvisual[40];
3049 if (Hotspot::hotspots.size()) {
3051 if (editorenabled) {
3052 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3053 hotspotvisual[i] -= multiplier / 320;
3057 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3058 while (hotspotvisual[i] < 0) {
3060 hotspotsprite.x = float(abs(Random() % 100000)) / 100000 * Hotspot::hotspots[i].size;
3061 hotspotsprite = DoRotation(hotspotsprite, 0, 0, Random() % 360);
3062 hotspotsprite = DoRotation(hotspotsprite, 0, Random() % 360, 0);
3063 hotspotsprite += Hotspot::hotspots[i].position;
3064 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite * 0, 1, 0.5, 0, 7, 0.4);
3065 hotspotvisual[i] += 0.1 / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size;
3069 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3070 if (Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type > 0) {
3071 Hotspot::hotspots[i].position = Person::players[Hotspot::hotspots[i].type]->coords;
3077 if (Tutorial::active) {
3078 Tutorial::Do(multiplier);
3082 if (!Tutorial::active) {
3083 if (bonustime == 0 &&
3084 bonus != solidhit &&
3085 bonus != spinecrusher &&
3086 bonus != tracheotomy &&
3087 bonus != backstab &&
3089 emit_sound_np(consolesuccesssound);
3091 } else if (bonustime == 0) {
3092 emit_sound_np(fireendsound);
3094 if (bonustime == 0) {
3095 if (bonus != solidhit &&
3096 bonus != twoxcombo &&
3097 bonus != threexcombo &&
3098 bonus != fourxcombo &&
3099 bonus != megacombo) {
3102 bonusnum[bonus] += 0.15;
3104 if (Tutorial::active) {
3107 if (bonusvalue > 0) {
3108 bonusvalue /= bonusnum[bonus];
3109 if (bonusvalue <= 0) {
3113 bonustotal += bonusvalue;
3115 bonustime += multiplier;
3118 if (environment == snowyenvironment) {
3119 precipdelay -= multiplier;
3120 while (precipdelay < 0) {
3125 XYZ footvel, footpoint;
3128 footpoint = viewer + viewerfacing * 6;
3129 footpoint.y += ((float)abs(Random() % 1200)) / 100 - 6;
3130 footpoint.x += ((float)abs(Random() % 1200)) / 100 - 6;
3131 footpoint.z += ((float)abs(Random() % 1200)) / 100 - 6;
3132 Sprite::MakeSprite(snowsprite, footpoint, footvel, 1, 1, 1, .1, 1);
3136 doAerialAcrobatics();
3138 static XYZ oldviewer;
3141 if (!Dialog::inDialog()) {
3142 Person::players[0]->forwardkeydown = Input::isKeyDown(forwardkey);
3143 Person::players[0]->leftkeydown = Input::isKeyDown(leftkey);
3144 Person::players[0]->backkeydown = Input::isKeyDown(backkey);
3145 Person::players[0]->rightkeydown = Input::isKeyDown(rightkey);
3146 Person::players[0]->jumpkeydown = Input::isKeyDown(jumpkey);
3147 Person::players[0]->crouchkeydown = Input::isKeyDown(crouchkey);
3148 Person::players[0]->drawkeydown = Input::isKeyDown(drawkey);
3149 Person::players[0]->throwkeydown = Input::isKeyDown(throwkey);
3151 Person::players[0]->forwardkeydown = 0;
3152 Person::players[0]->leftkeydown = 0;
3153 Person::players[0]->backkeydown = 0;
3154 Person::players[0]->rightkeydown = 0;
3155 Person::players[0]->jumpkeydown = 0;
3156 Person::players[0]->crouchkeydown = 0;
3157 Person::players[0]->drawkeydown = 0;
3158 Person::players[0]->throwkeydown = 0;
3161 if (!Person::players[0]->jumpkeydown) {
3162 Person::players[0]->jumpclimb = 0;
3165 if (Dialog::inDialog()) {
3167 if (Dialog::directing) {
3171 facing = DoRotation(facing, -pitch, 0, 0);
3172 facing = DoRotation(facing, 0, 0 - yaw, 0);
3177 flatfacing = DoRotation(flatfacing, 0, -yaw, 0);
3179 if (Input::isKeyDown(forwardkey)) {
3180 viewer += facing * multiplier * 4;
3182 if (Input::isKeyDown(backkey)) {
3183 viewer -= facing * multiplier * 4;
3185 if (Input::isKeyDown(leftkey)) {
3186 viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4;
3188 if (Input::isKeyDown(rightkey)) {
3189 viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4;
3191 if (Input::isKeyDown(jumpkey)) {
3192 viewer.y += multiplier * 4;
3194 if (Input::isKeyDown(crouchkey)) {
3195 viewer.y -= multiplier * 4;
3197 if (Input::isKeyPressed(SDL_SCANCODE_1) ||
3198 Input::isKeyPressed(SDL_SCANCODE_2) ||
3199 Input::isKeyPressed(SDL_SCANCODE_3) ||
3200 Input::isKeyPressed(SDL_SCANCODE_4) ||
3201 Input::isKeyPressed(SDL_SCANCODE_5) ||
3202 Input::isKeyPressed(SDL_SCANCODE_6) ||
3203 Input::isKeyPressed(SDL_SCANCODE_7) ||
3204 Input::isKeyPressed(SDL_SCANCODE_8) ||
3205 Input::isKeyPressed(SDL_SCANCODE_9) ||
3206 Input::isKeyPressed(SDL_SCANCODE_0) ||
3207 Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3209 if (Input::isKeyPressed(SDL_SCANCODE_1)) {
3212 if (Input::isKeyPressed(SDL_SCANCODE_2)) {
3215 if (Input::isKeyPressed(SDL_SCANCODE_3)) {
3218 if (Input::isKeyPressed(SDL_SCANCODE_4)) {
3221 if (Input::isKeyPressed(SDL_SCANCODE_5)) {
3224 if (Input::isKeyPressed(SDL_SCANCODE_6)) {
3227 if (Input::isKeyPressed(SDL_SCANCODE_7)) {
3230 if (Input::isKeyPressed(SDL_SCANCODE_8)) {
3233 if (Input::isKeyPressed(SDL_SCANCODE_9)) {
3236 if (Input::isKeyPressed(SDL_SCANCODE_0)) {
3239 if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3242 if (whichend != -1) {
3243 Dialog::currentScene().participantfocus = whichend;
3244 Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords;
3245 Dialog::currentDialog().participantyaw[whichend] = Person::players[whichend]->yaw;
3247 if (whichend == -1) {
3248 Dialog::currentScene().participantfocus = -1;
3250 /* FIXME: potentially accessing -1 in Person::players! */
3251 if (Person::players[Dialog::currentScene().participantfocus]->dead) {
3252 Dialog::indialogue = -1;
3253 Dialog::directing = false;
3256 Dialog::currentScene().camera = viewer;
3257 Dialog::currentScene().camerayaw = yaw;
3258 Dialog::currentScene().camerapitch = pitch;
3259 Dialog::indialogue++;
3260 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3261 if (Dialog::currentScene().sound != 0) {
3262 playdialoguescenesound();
3266 for (unsigned j = 0; j < Person::players.size(); j++) {
3267 Dialog::currentScene().participantfacing[j] = Dialog::currentDialog().scenes[Dialog::indialogue - 1].participantfacing[j];
3270 //TODO: should these be KeyDown or KeyPressed?
3271 if (Input::isKeyDown(SDL_SCANCODE_KP_1) ||
3272 Input::isKeyDown(SDL_SCANCODE_KP_2) ||
3273 Input::isKeyDown(SDL_SCANCODE_KP_3) ||
3274 Input::isKeyDown(SDL_SCANCODE_KP_4) ||
3275 Input::isKeyDown(SDL_SCANCODE_KP_5) ||
3276 Input::isKeyDown(SDL_SCANCODE_KP_6) ||
3277 Input::isKeyDown(SDL_SCANCODE_KP_7) ||
3278 Input::isKeyDown(SDL_SCANCODE_KP_8) ||
3279 Input::isKeyDown(SDL_SCANCODE_KP_9) ||
3280 Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3282 if (Input::isKeyDown(SDL_SCANCODE_KP_1)) {
3285 if (Input::isKeyDown(SDL_SCANCODE_KP_2)) {
3288 if (Input::isKeyDown(SDL_SCANCODE_KP_3)) {
3291 if (Input::isKeyDown(SDL_SCANCODE_KP_4)) {
3294 if (Input::isKeyDown(SDL_SCANCODE_KP_5)) {
3297 if (Input::isKeyDown(SDL_SCANCODE_KP_6)) {
3300 if (Input::isKeyDown(SDL_SCANCODE_KP_7)) {
3303 if (Input::isKeyDown(SDL_SCANCODE_KP_8)) {
3306 if (Input::isKeyDown(SDL_SCANCODE_KP_9)) {
3309 if (Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3312 Dialog::currentScene().participantfacing[whichend] = facing;
3314 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3315 Dialog::indialogue = -1;
3316 Dialog::directing = false;
3320 if (!Dialog::directing) {
3321 pause_sound(whooshsound);
3322 viewer = Dialog::currentScene().camera;
3323 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .1);
3324 yaw = Dialog::currentScene().camerayaw;
3325 pitch = Dialog::currentScene().camerapitch;
3326 if (Dialog::dialoguetime > 0.5) {
3327 if (Input::isKeyPressed(attackkey)) {
3328 Dialog::indialogue++;
3329 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3330 if (Dialog::currentScene().sound != 0) {
3331 playdialoguescenesound();
3332 if (Dialog::currentScene().sound == -5) {
3333 Hotspot::hotspots.emplace_back(Person::players[0]->coords, -1, 10);
3335 if (Dialog::currentScene().sound == -6) {
3339 if (Person::players.at(Dialog::currentScene().participantfocus)->dead) {
3340 Dialog::indialogue = -1;
3341 Dialog::directing = false;
3348 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3349 Dialog::indialogue = -1;
3350 Dialog::directing = false;
3352 if (Dialog::currentDialog().type > 19 && Dialog::currentDialog().type < 30) {
3355 if (Dialog::currentDialog().type > 29 && Dialog::currentDialog().type < 40) {
3358 if (Dialog::currentDialog().type > 49 && Dialog::currentDialog().type < 60) {
3360 for (unsigned i = 1; i < Person::players.size(); i++) {
3361 Person::players[i]->aitype = attacktypecutoff;
3368 if (!Person::players[0]->jumpkeydown) {
3369 Person::players[0]->jumptogglekeydown = 0;
3371 if (Person::players[0]->jumpkeydown &&
3372 Person::players[0]->animTarget != jumpupanim &&
3373 Person::players[0]->animTarget != jumpdownanim &&
3374 !Person::players[0]->isFlip()) {
3375 Person::players[0]->jumptogglekeydown = 1;
3378 Dialog::dialoguetime += multiplier;
3379 hawkyaw += multiplier * 25;
3381 realhawkcoords.x = 25;
3382 realhawkcoords = DoRotation(realhawkcoords, 0, hawkyaw, 0) + hawkcoords;
3383 hawkcalldelay -= multiplier / 2;
3385 if (hawkcalldelay <= 0) {
3386 emit_sound_at(hawksound, realhawkcoords);
3388 hawkcalldelay = 16 + abs(Random() % 8);
3393 doPlayerCollisions();
3397 for (unsigned k = 0; k < Person::players.size(); k++) {
3398 if (k != 0 && Person::players[k]->immobile) {
3399 Person::players[k]->coords = Person::players[k]->realoldcoords;
3403 for (unsigned k = 0; k < Person::players.size(); k++) {
3404 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3405 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3406 Person::players[k]->DoDamage(1000);
3412 static bool respawnkeydown;
3413 if (!editorenabled &&
3414 (whichlevel != -2 &&
3415 (Input::isKeyDown(SDL_SCANCODE_K) &&
3416 Input::isKeyDown(SDL_SCANCODE_LALT) &&
3418 (Input::isKeyDown(jumpkey) &&
3421 Person::players[0]->dead))) {
3422 targetlevel = whichlevel;
3426 respawnkeydown = Input::isKeyDown(jumpkey);
3428 static bool movekey;
3431 for (unsigned i = 0; i < Person::players.size(); i++) {
3432 static float oldtargetyaw;
3433 if (!Person::players[i]->skeleton.free) {
3434 oldtargetyaw = Person::players[i]->targetyaw;
3435 if (i == 0 && !Dialog::inDialog()) {
3436 //TODO: refactor repetitive code
3437 if (!Animation::animations[Person::players[0]->animTarget].attack &&
3438 Person::players[0]->animTarget != staggerbackhighanim &&
3439 Person::players[0]->animTarget != staggerbackhardanim &&
3440 Person::players[0]->animTarget != crouchremoveknifeanim &&
3441 Person::players[0]->animTarget != removeknifeanim &&
3442 Person::players[0]->animTarget != backhandspringanim &&
3443 Person::players[0]->animTarget != dodgebackanim &&
3444 Person::players[0]->animTarget != walljumprightkickanim &&
3445 Person::players[0]->animTarget != walljumpleftkickanim) {
3447 Person::players[0]->targetyaw = 0;
3449 Person::players[0]->targetyaw = -yaw + 180;
3456 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3458 facing = flatfacing;
3460 facing = DoRotation(facing, -pitch, 0, 0);
3461 facing = DoRotation(facing, 0, 0 - yaw, 0);
3464 Person::players[0]->lookyaw = -yaw;
3466 Person::players[i]->targetheadyaw = yaw;
3467 Person::players[i]->targetheadpitch = pitch;
3469 if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) {
3470 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3471 Person::players[i]->animTarget != staggerbackhighanim &&
3472 Person::players[i]->animTarget != staggerbackhardanim &&
3473 Person::players[i]->animTarget != crouchremoveknifeanim &&
3474 Person::players[i]->animTarget != removeknifeanim &&
3475 Person::players[i]->animTarget != backhandspringanim &&
3476 Person::players[i]->animTarget != dodgebackanim &&
3477 Person::players[i]->animTarget != walljumprightkickanim &&
3478 Person::players[i]->animTarget != walljumpleftkickanim) {
3479 Person::players[i]->targetyaw = -Person::players[i]->lookyaw + 180;
3485 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3487 facing = DoRotation(facing, -Person::players[i]->lookpitch, 0, 0);
3488 facing = DoRotation(facing, 0, 0 - Person::players[i]->lookyaw, 0);
3490 Person::players[i]->targetheadyaw = Person::players[i]->lookyaw;
3491 Person::players[i]->targetheadpitch = Person::players[i]->lookpitch;
3493 if (Dialog::inDialog()) {
3494 Person::players[i]->targetheadyaw = 180 - roughDirection(Dialog::currentScene().participantfacing[i]);
3495 Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]);
3498 if (leveltime < .5) {
3502 Person::players[i]->avoidsomething = 0;
3504 //avoid flaming things
3505 for (unsigned int j = 0; j < Object::objects.size(); j++) {
3506 if (Object::objects[j]->onfire) {
3507 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) {
3508 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3509 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3510 Person::players[i]->collided = 0;
3511 Person::players[i]->avoidcollided = 1;
3512 if (Person::players[i]->avoidsomething == 0 ||
3513 distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3514 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3515 Person::players[i]->avoidwhere = Object::objects[j]->position;
3516 Person::players[i]->avoidsomething = 1;
3523 //avoid flaming players
3524 for (unsigned j = 0; j < Person::players.size(); j++) {
3525 if (Person::players[j]->onfire) {
3526 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) {
3527 if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3528 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3529 Person::players[i]->collided = 0;
3530 Person::players[i]->avoidcollided = 1;
3531 if (Person::players[i]->avoidsomething == 0 ||
3532 distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3533 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3534 Person::players[i]->avoidwhere = Person::players[j]->coords;
3535 Person::players[i]->avoidsomething = 1;
3542 if (Person::players[i]->collided > .8) {
3543 Person::players[i]->avoidcollided = 0;
3546 Person::players[i]->doAI();
3548 if (Animation::animations[Person::players[i]->animTarget].attack == reversed) {
3549 //Person::players[i]->targetyaw=Person::players[i]->yaw;
3550 Person::players[i]->forwardkeydown = 0;
3551 Person::players[i]->leftkeydown = 0;
3552 Person::players[i]->backkeydown = 0;
3553 Person::players[i]->rightkeydown = 0;
3554 Person::players[i]->jumpkeydown = 0;
3555 Person::players[i]->attackkeydown = 0;
3556 //Person::players[i]->crouchkeydown=0;
3557 Person::players[i]->throwkeydown = 0;
3560 if (Dialog::inDialog()) {
3561 Person::players[i]->forwardkeydown = 0;
3562 Person::players[i]->leftkeydown = 0;
3563 Person::players[i]->backkeydown = 0;
3564 Person::players[i]->rightkeydown = 0;
3565 Person::players[i]->jumpkeydown = 0;
3566 Person::players[i]->crouchkeydown = 0;
3567 Person::players[i]->drawkeydown = 0;
3568 Person::players[i]->throwkeydown = 0;
3571 if (Person::players[i]->collided < -.3) {
3572 Person::players[i]->collided = -.3;
3574 if (Person::players[i]->collided > 1) {
3575 Person::players[i]->collided = 1;
3577 Person::players[i]->collided -= multiplier * 4;
3578 Person::players[i]->whichdirectiondelay -= multiplier;
3579 if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) {
3580 Person::players[i]->avoidcollided = -.3;
3581 Person::players[i]->whichdirection = abs(Random() % 2);
3582 Person::players[i]->whichdirectiondelay = .4;
3584 if (Person::players[i]->avoidcollided > 1) {
3585 Person::players[i]->avoidcollided = 1;
3587 Person::players[i]->avoidcollided -= multiplier / 4;
3588 if (!Person::players[i]->skeleton.free) {
3589 Person::players[i]->stunned -= multiplier;
3590 Person::players[i]->surprised -= multiplier;
3592 if (i != 0 && Person::players[i]->surprised <= 0 &&
3593 Person::players[i]->aitype == attacktypecutoff &&
3594 !Person::players[i]->dead &&
3595 !Person::players[i]->skeleton.free &&
3596 Animation::animations[Person::players[i]->animTarget].attack == neutral) {
3600 if (!Person::players[i]->throwkeydown) {
3601 Person::players[i]->throwtogglekeydown = 0;
3605 if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) {
3606 if (Person::players[i]->weaponactive == -1 &&
3607 Person::players[i]->num_weapons < 2 &&
3608 (Person::players[i]->isIdle() ||
3609 Person::players[i]->isCrouch() ||
3610 Person::players[i]->animTarget == sneakanim ||
3611 Person::players[i]->animTarget == rollanim ||
3612 Person::players[i]->animTarget == backhandspringanim ||
3613 Person::players[i]->isFlip() ||
3614 Person::players[i]->aitype != playercontrolled)) {
3615 for (unsigned j = 0; j < weapons.size(); j++) {
3616 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3617 Person::players[i]->aitype == playercontrolled) &&
3618 weapons[j].owner == -1 &&
3619 Person::players[i]->weaponactive == -1) {
3620 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) {
3621 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) {
3622 if (Person::players[i]->isCrouch() ||
3623 Person::players[i]->animTarget == sneakanim ||
3624 Person::players[i]->isRun() ||
3625 Person::players[i]->isIdle() ||
3626 Person::players[i]->aitype != playercontrolled) {
3627 Person::players[i]->throwtogglekeydown = 1;
3628 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3629 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3630 Person::players[i]->hasvictim = 0;
3632 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3633 Person::players[i]->throwtogglekeydown = 1;
3634 Person::players[i]->hasvictim = 0;
3636 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3637 Person::players[i]->aitype == playercontrolled) &&
3638 weapons[j].owner == -1 ||
3639 Person::players[i]->victim &&
3640 weapons[j].owner == int(Person::players[i]->victim->id)) {
3641 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) {
3642 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) {
3643 if (weapons[j].getType() != staff) {
3644 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3647 Person::players[i]->takeWeapon(j);
3652 } else if ((Person::players[i]->isIdle() ||
3653 Person::players[i]->isFlip() ||
3654 Person::players[i]->aitype != playercontrolled) &&
3655 distsq(&Person::players[i]->coords, &weapons[j].position) < 5 &&
3656 Person::players[i]->coords.y < weapons[j].position.y) {
3657 if (!Person::players[i]->isFlip()) {
3658 Person::players[i]->throwtogglekeydown = 1;
3659 Person::players[i]->setTargetAnimation(removeknifeanim);
3660 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3662 if (Person::players[i]->isFlip()) {
3663 Person::players[i]->throwtogglekeydown = 1;
3664 Person::players[i]->hasvictim = 0;
3666 for (unsigned k = 0; k < weapons.size(); k++) {
3667 if (Person::players[i]->weaponactive == -1) {
3668 if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 ||
3669 Person::players[i]->aitype == playercontrolled) &&
3670 weapons[k].owner == -1 ||
3671 Person::players[i]->victim &&
3672 weapons[k].owner == int(Person::players[i]->victim->id)) {
3673 if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 &&
3674 Person::players[i]->weaponactive == -1) {
3675 if (weapons[k].getType() != staff) {
3676 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3679 Person::players[i]->takeWeapon(k);
3689 if (Person::players[i]->isCrouch() ||
3690 Person::players[i]->animTarget == sneakanim ||
3691 Person::players[i]->isRun() ||
3692 Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim ||
3693 Person::players[i]->animTarget == backhandspringanim) {
3694 if (Person::players.size() > 1) {
3695 for (unsigned j = 0; j < Person::players.size(); j++) {
3696 if (Person::players[i]->weaponactive == -1) {
3698 if (Person::players[j]->num_weapons &&
3699 Person::players[j]->skeleton.free &&
3700 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ &&
3701 (((Person::players[j]->skeleton.forward.y < 0 &&
3702 Person::players[j]->weaponstuckwhere == 0) ||
3703 (Person::players[j]->skeleton.forward.y > 0 &&
3704 Person::players[j]->weaponstuckwhere == 1)) ||
3705 Person::players[j]->weaponstuck == -1 ||
3706 Person::players[j]->num_weapons > 1)) {
3707 if (Person::players[i]->animTarget != rollanim && Person::players[i]->animTarget != backhandspringanim) {
3708 Person::players[i]->throwtogglekeydown = 1;
3709 Person::players[i]->victim = Person::players[j];
3710 Person::players[i]->hasvictim = 1;
3711 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3712 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3714 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3715 Person::players[i]->throwtogglekeydown = 1;
3716 Person::players[i]->victim = Person::players[j];
3717 Person::players[i]->hasvictim = 1;
3718 int k = Person::players[j]->weaponids[0];
3719 if (Person::players[i]->hasvictim) {
3722 if (Person::players[i]->victim->weaponstuck != -1) {
3723 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3728 if (weapons[k].getType() != staff) {
3729 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3733 emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.);
3736 if (weapons[k].owner != -1) {
3737 if (Person::players[i]->victim->num_weapons == 1) {
3738 Person::players[i]->victim->num_weapons = 0;
3740 Person::players[i]->victim->num_weapons = 1;
3743 Person::players[i]->victim->skeleton.longdead = 0;
3744 Person::players[i]->victim->skeleton.free = 1;
3745 Person::players[i]->victim->skeleton.broken = 0;
3747 for (unsigned l = 0; l < Person::players[i]->victim->skeleton.joints.size(); l++) {
3748 Person::players[i]->victim->skeleton.joints[l].velchange = 0;
3749 Person::players[i]->victim->skeleton.joints[l].locked = 0;
3755 Normalise(&relative);
3756 XYZ footvel, footpoint;
3758 footpoint = weapons[k].position;
3759 if (Person::players[i]->victim->weaponstuck != -1) {
3760 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3762 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
3764 weapons[k].bloody = 2;
3765 weapons[k].blooddrip = 5;
3766 Person::players[i]->victim->weaponstuck = -1;
3767 Person::players[i]->victim->bloodloss += 2000;
3768 Person::players[i]->victim->DoDamage(2000);
3771 if (Person::players[i]->victim->num_weapons > 0) {
3772 if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) {
3773 Person::players[i]->victim->weaponstuck = 0;
3775 if (Person::players[i]->victim->weaponids[0] == k) {
3776 Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons];
3780 Person::players[i]->victim->weaponactive = -1;
3782 Person::players[i]->victim->jointVel(abdomen) += relative * 6;
3783 Person::players[i]->victim->jointVel(neck) += relative * 6;
3784 Person::players[i]->victim->jointVel(rightshoulder) += relative * 6;
3785 Person::players[i]->victim->jointVel(leftshoulder) += relative * 6;
3787 Person::players[i]->takeWeapon(k);
3797 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3798 if (weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3799 if (Person::players[i]->isIdle() ||
3800 Person::players[i]->isRun() ||
3801 Person::players[i]->isCrouch() ||
3802 Person::players[i]->animTarget == sneakanim ||
3803 Person::players[i]->isFlip()) {
3804 if (Person::players.size() > 1) {
3805 for (unsigned j = 0; j < Person::players.size(); j++) {
3807 if (!Tutorial::active || Tutorial::stage == 49) {
3809 if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 &&
3810 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 &&
3811 distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 &&
3812 !Person::players[j]->skeleton.free &&
3813 -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)) {
3814 if (!Person::players[i]->isFlip()) {
3815 Person::players[i]->throwtogglekeydown = 1;
3816 Person::players[i]->victim = Person::players[j];
3817 Person::players[i]->setTargetAnimation(knifethrowanim);
3818 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3819 Person::players[i]->targettilt2 = pitchTo(Person::players[i]->coords, Person::players[j]->coords);
3821 if (Person::players[i]->isFlip()) {
3822 if (Person::players[i]->weaponactive != -1) {
3823 Person::players[i]->throwtogglekeydown = 1;
3824 Person::players[i]->victim = Person::players[j];
3826 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);
3829 aim = DoRotation(aim, (float)abs(Random() % 30) - 15, (float)abs(Random() % 30) - 15, 0);
3831 weapons[Person::players[i]->weaponids[0]].thrown(aim * 50, false);
3832 Person::players[i]->num_weapons--;
3833 if (Person::players[i]->num_weapons) {
3834 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3836 Person::players[i]->weaponactive = -1;
3848 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3849 if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) {
3850 Person::players[i]->throwtogglekeydown = 1;
3851 XYZ tempVelocity = Person::players[i]->velocity * .2;
3852 if (tempVelocity.x == 0) {
3853 tempVelocity.x = .1;
3855 weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false);
3856 Person::players[i]->num_weapons--;
3857 if (Person::players[i]->num_weapons) {
3858 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3859 if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) {
3860 Person::players[i]->weaponstuck = 0;
3864 Person::players[i]->weaponactive = -1;
3865 for (unsigned j = 0; j < Person::players.size(); j++) {
3866 Person::players[j]->wentforweapon = 0;
3873 if (i == 0 || !Person::players[0]->dead || (Person::players[i]->weaponactive != -1)) {
3874 if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown ||
3875 (Person::players[i]->num_weapons == 2) &&
3876 (Person::players[i]->weaponactive == -1) &&
3877 Person::players[i]->isIdle() ||
3878 Person::players[0]->dead &&
3879 (Person::players[i]->weaponactive != -1) &&
3882 if (Person::players[i]->weaponactive != -1) {
3883 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) {
3887 if (isgood && Person::players[i]->creature != wolftype) {
3888 if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3889 Person::players[i]->setTargetAnimation(drawrightanim);
3890 Person::players[i]->drawtogglekeydown = 1;
3892 if ((Person::players[i]->isIdle() ||
3893 (Person::players[i]->aitype != playercontrolled &&
3894 Person::players[0]->weaponactive != -1 &&
3895 Person::players[i]->isRun())) &&
3896 Person::players[i]->num_weapons &&
3897 weapons[Person::players[i]->weaponids[0]].getType() == sword) {
3898 Person::players[i]->setTargetAnimation(drawleftanim);
3899 Person::players[i]->drawtogglekeydown = 1;
3901 if (Person::players[i]->isCrouch() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3902 Person::players[i]->setTargetAnimation(crouchdrawrightanim);
3903 Person::players[i]->drawtogglekeydown = 1;
3910 if (Person::players[i]->weaponactive != -1) {
3911 if (Person::players[i]->isCrouch() &&
3912 weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody &&
3914 Person::players[i]->onterrain &&
3915 Person::players[i]->num_weapons &&
3916 Person::players[i]->attackkeydown &&
3917 musictype != stream_fighttheme) {
3918 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) {
3919 Person::players[i]->setTargetAnimation(crouchstabanim);
3921 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) {
3922 Person::players[i]->setTargetAnimation(swordgroundstabanim);
3924 Person::players[i]->hasvictim = 0;
3928 if (!Person::players[i]->drawkeydown) {
3929 Person::players[i]->drawtogglekeydown = 0;
3935 absflatfacing.z = -1;
3937 absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0);
3939 absflatfacing = flatfacing;
3942 if (Dialog::inDialog()) {
3943 Person::players[i]->forwardkeydown = 0;
3944 Person::players[i]->leftkeydown = 0;
3945 Person::players[i]->backkeydown = 0;
3946 Person::players[i]->rightkeydown = 0;
3947 Person::players[i]->jumpkeydown = 0;
3948 Person::players[i]->crouchkeydown = 0;
3949 Person::players[i]->drawkeydown = 0;
3950 Person::players[i]->throwkeydown = 0;
3954 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3955 Person::players[i]->animTarget != staggerbackhighanim &&
3956 Person::players[i]->animTarget != staggerbackhardanim &&
3957 Person::players[i]->animTarget != backhandspringanim &&
3958 Person::players[i]->animTarget != dodgebackanim) {
3959 if (!Person::players[i]->forwardkeydown) {
3960 Person::players[i]->forwardstogglekeydown = 0;
3962 if (Person::players[i]->crouchkeydown) {
3966 Person::players[i]->superruntoggle = 1;
3967 if (Person::players.size() > 1) {
3968 for (unsigned j = 0; j < Person::players.size(); j++) {
3969 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) {
3970 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) {
3971 Person::players[i]->superruntoggle = 0;
3978 if (Person::players.size() > 1) {
3979 for (unsigned j = 0; j < Person::players.size(); j++) {
3980 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) {
3981 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
3982 Person::players[j]->victim == Person::players[i] &&
3983 (Person::players[j]->animTarget == sweepanim ||
3984 Person::players[j]->animTarget == upunchanim ||
3985 Person::players[j]->animTarget == wolfslapanim ||
3986 ((Person::players[j]->animTarget == swordslashanim ||
3987 Person::players[j]->animTarget == knifeslashstartanim ||
3988 Person::players[j]->animTarget == staffhitanim ||
3989 Person::players[j]->animTarget == staffspinhitanim) &&
3990 distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) {
4001 Person::players[target]->Reverse();
4003 Person::players[i]->lowreversaldelay = .5;
4005 if (Person::players[i]->isIdle()) {
4006 Person::players[i]->setTargetAnimation(Person::players[i]->getCrouch());
4007 Person::players[i]->transspeed = 10;
4009 if (Person::players[i]->isRun() ||
4010 (Person::players[i]->isStop() &&
4011 (Person::players[i]->leftkeydown ||
4012 Person::players[i]->rightkeydown ||
4013 Person::players[i]->forwardkeydown ||
4014 Person::players[i]->backkeydown))) {
4015 Person::players[i]->setTargetAnimation(rollanim);
4016 Person::players[i]->transspeed = 20;
4019 if (!Person::players[i]->crouchkeydown) {
4021 if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) {
4022 Person::players[i]->superruntoggle = 0;
4025 if (Person::players[i]->isCrouch()) {
4026 if (Person::players.size() > 1) {
4027 for (unsigned j = 0; j < Person::players.size(); j++) {
4029 !Person::players[j]->skeleton.free &&
4030 Person::players[j]->victim &&
4031 Person::players[i]->highreversaldelay <= 0) {
4032 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4033 Person::players[j]->victim == Person::players[i] &&
4034 (Person::players[j]->animTarget == spinkickanim) &&
4035 Person::players[i]->isCrouch()) {
4046 Person::players[target]->Reverse();
4048 Person::players[i]->highreversaldelay = .5;
4050 if (Person::players[i]->isCrouch()) {
4051 if (!Person::players[i]->wasCrouch()) {
4052 Person::players[i]->animCurrent = Person::players[i]->getCrouch();
4053 Person::players[i]->frameCurrent = 0;
4055 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4056 Person::players[i]->transspeed = 10;
4059 if (Person::players[i]->animTarget == sneakanim) {
4060 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4061 Person::players[i]->transspeed = 10;
4064 if (Person::players[i]->forwardkeydown) {
4065 if (Person::players[i]->isIdle() ||
4066 (Person::players[i]->isStop() &&
4067 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4068 (Person::players[i]->isLanding() &&
4069 Person::players[i]->frameTarget > 0 &&
4070 !Person::players[i]->jumpkeydown) ||
4071 (Person::players[i]->isLandhard() &&
4072 Person::players[i]->frameTarget > 0 &&
4073 !Person::players[i]->jumpkeydown &&
4074 Person::players[i]->crouchkeydown)) {
4075 if (Person::players[i]->aitype == passivetype) {
4076 Person::players[i]->setTargetAnimation(walkanim);
4078 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4081 if (Person::players[i]->isCrouch()) {
4082 Person::players[i]->animTarget = sneakanim;
4083 if (Person::players[i]->wasCrouch()) {
4084 Person::players[i]->target = 0;
4086 Person::players[i]->frameTarget = 0;
4088 if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) {
4089 Person::players[i]->setTargetAnimation(climbanim);
4090 Person::players[i]->frameTarget = 1;
4091 Person::players[i]->jumpclimb = 1;
4093 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4094 Person::players[i]->velocity += absflatfacing * 5 * multiplier;
4096 Person::players[i]->forwardstogglekeydown = 1;
4099 if (Person::players[i]->rightkeydown) {
4100 if (Person::players[i]->isIdle() ||
4101 (Person::players[i]->isStop() &&
4102 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4103 (Person::players[i]->isLanding() &&
4104 Person::players[i]->frameTarget > 0 &&
4105 !Person::players[i]->jumpkeydown) ||
4106 (Person::players[i]->isLandhard() &&
4107 Person::players[i]->frameTarget > 0 &&
4108 !Person::players[i]->jumpkeydown &&
4109 Person::players[i]->crouchkeydown)) {
4110 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4112 if (Person::players[i]->isCrouch()) {
4113 Person::players[i]->animTarget = sneakanim;
4114 if (Person::players[i]->wasCrouch()) {
4115 Person::players[i]->target = 0;
4117 Person::players[i]->frameTarget = 0;
4119 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4120 Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4122 Person::players[i]->targetyaw -= 90;
4123 if (Person::players[i]->forwardkeydown) {
4124 Person::players[i]->targetyaw += 45;
4126 if (Person::players[i]->backkeydown) {
4127 Person::players[i]->targetyaw -= 45;
4131 if (Person::players[i]->leftkeydown) {
4132 if (Person::players[i]->isIdle() ||
4133 (Person::players[i]->isStop() &&
4134 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4135 (Person::players[i]->isLanding() &&
4136 Person::players[i]->frameTarget > 0 &&
4137 !Person::players[i]->jumpkeydown) ||
4138 (Person::players[i]->isLandhard() &&
4139 Person::players[i]->frameTarget > 0 &&
4140 !Person::players[i]->jumpkeydown &&
4141 Person::players[i]->crouchkeydown)) {
4142 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4144 if (Person::players[i]->isCrouch()) {
4145 Person::players[i]->animTarget = sneakanim;
4146 if (Person::players[i]->wasCrouch()) {
4147 Person::players[i]->target = 0;
4149 Person::players[i]->frameTarget = 0;
4151 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4152 Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4154 Person::players[i]->targetyaw += 90;
4155 if (Person::players[i]->forwardkeydown) {
4156 Person::players[i]->targetyaw -= 45;
4158 if (Person::players[i]->backkeydown) {
4159 Person::players[i]->targetyaw += 45;
4163 if (Person::players[i]->backkeydown) {
4164 if (Person::players[i]->isIdle() ||
4165 (Person::players[i]->isStop() &&
4166 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4167 (Person::players[i]->isLanding() &&
4168 Person::players[i]->frameTarget > 0 &&
4169 !Person::players[i]->jumpkeydown) ||
4170 (Person::players[i]->isLandhard() &&
4171 Person::players[i]->frameTarget > 0 &&
4172 !Person::players[i]->jumpkeydown &&
4173 Person::players[i]->crouchkeydown)) {
4174 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4176 if (Person::players[i]->isCrouch()) {
4177 Person::players[i]->animTarget = sneakanim;
4178 if (Person::players[i]->wasCrouch()) {
4179 Person::players[i]->target = 0;
4181 Person::players[i]->frameTarget = 0;
4183 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4184 Person::players[i]->velocity -= absflatfacing * 5 * multiplier;
4186 if (Person::players[i]->animTarget == hanganim) {
4187 Person::players[i]->animCurrent = jumpdownanim;
4188 Person::players[i]->animTarget = jumpdownanim;
4189 Person::players[i]->target = 0;
4190 Person::players[i]->frameCurrent = 0;
4191 Person::players[i]->frameTarget = 1;
4192 Person::players[i]->velocity = 0;
4193 Person::players[i]->velocity.y += gravity;
4194 Person::players[i]->coords.y -= 1.4;
4195 Person::players[i]->grabdelay = 1;
4197 if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) {
4198 Person::players[i]->targetyaw += 180;
4202 if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) {
4203 if ((((Person::players[i]->isLanding() && Person::players[i]->frameTarget >= 3) ||
4204 Person::players[i]->isRun() ||
4205 Person::players[i]->animTarget == walkanim ||
4206 Person::players[i]->isCrouch() ||
4207 Person::players[i]->animTarget == sneakanim) &&
4208 Person::players[i]->jumppower > 1) &&
4209 ((Person::players[i]->animTarget != rabbitrunninganim &&
4210 Person::players[i]->animTarget != wolfrunninganim) ||
4212 Person::players[i]->jumpstart = 0;
4213 Person::players[i]->setTargetAnimation(jumpupanim);
4214 Person::players[i]->yaw = Person::players[i]->targetyaw;
4215 Person::players[i]->transspeed = 20;
4216 Person::players[i]->FootLand(leftfoot, 1);
4217 Person::players[i]->FootLand(rightfoot, 1);
4221 flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0);
4224 Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale;
4227 Person::players[i]->velocity = 0;
4232 if (Person::players.size() > 1) {
4233 for (unsigned j = 0; j < Person::players.size(); j++) {
4234 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) {
4235 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4236 (Person::players[j]->victim == Person::players[i]) &&
4237 (Person::players[j]->animTarget == sweepanim)) {
4248 Person::players[i]->velocity.y = 1;
4249 } else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) {
4250 Person::players[i]->velocity.y = 7;
4251 Person::players[i]->crouchtogglekeydown = 1;
4253 Person::players[i]->velocity.y = 5;
4256 if (mousejump && i == 0 && devtools) {
4257 if (!Person::players[i]->isLanding()) {
4258 Person::players[i]->tempdeltav = deltav;
4260 if (Person::players[i]->tempdeltav < 0) {
4261 Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000;
4265 Person::players[i]->coords.y += .2;
4266 Person::players[i]->jumppower -= 1;
4269 emit_sound_at(whooshsound, Person::players[i]->coords, 128.);
4272 emit_sound_at(jumpsound, Person::players[i]->coords, 128.);
4274 if ((Person::players[i]->isIdle()) && Person::players[i]->jumppower > 1) {
4275 Person::players[i]->setTargetAnimation(Person::players[i]->getLanding());
4276 Person::players[i]->frameTarget = 2;
4277 Person::players[i]->landhard = 0;
4278 Person::players[i]->jumpstart = 1;
4279 Person::players[i]->tempdeltav = deltav;
4281 if (Person::players[i]->animTarget == jumpupanim &&
4285 Person::players[i]->aitype != playercontrolled)) {
4286 if (Person::players[i]->jumppower > multiplier * 6) {
4287 Person::players[i]->velocity.y += multiplier * 6;
4288 Person::players[i]->jumppower -= multiplier * 6;
4290 if (Person::players[i]->jumppower <= multiplier * 6) {
4291 Person::players[i]->velocity.y += Person::players[i]->jumppower;
4292 Person::players[i]->jumppower = 0;
4295 if (((floatjump || editorenabled) && devtools) && i == 0) {
4296 Person::players[i]->velocity.y += multiplier * 30;
4301 if (Person::players[i]->isRun() || Person::players[i]->animTarget == walkanim) {
4302 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4304 if (Person::players[i]->animTarget == sneakanim) {
4305 Person::players[i]->animTarget = Person::players[i]->getCrouch();
4306 if (Person::players[i]->animCurrent == sneakanim) {
4307 Person::players[i]->target = 0;
4309 Person::players[i]->frameTarget = 0;
4312 if (Person::players[i]->animTarget == walkanim &&
4313 (Person::players[i]->aitype == attacktypecutoff ||
4314 Person::players[i]->aitype == searchtype ||
4315 (Person::players[i]->aitype == passivetype &&
4316 Person::players[i]->numwaypoints <= 1))) {
4317 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4319 if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) {
4320 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4324 if (Person::players[i]->animTarget == rollanim) {
4325 Person::players[i]->targetyaw = oldtargetyaw;
4330 for (unsigned k = 0; k < Person::players.size(); k++) {
4331 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) {
4332 if (Person::players[k]->yaw > Person::players[k]->targetyaw) {
4333 Person::players[k]->yaw -= 360;
4335 Person::players[k]->yaw += 360;
4339 //stop to turn in right direction
4340 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) {
4341 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
4344 if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) {
4345 Person::players[k]->targettilt = 0;
4348 if (Person::players[k]->animTarget != jumpupanim &&
4349 Person::players[k]->animTarget != backhandspringanim &&
4350 Person::players[k]->animTarget != jumpdownanim &&
4351 !Person::players[k]->isFlip()) {
4352 Person::players[k]->targettilt = 0;
4353 if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) {
4354 Person::players[k]->jumppower = 0;
4356 Person::players[k]->jumppower += multiplier * 7;
4357 if (Person::players[k]->isCrouch()) {
4358 Person::players[k]->jumppower += multiplier * 7;
4360 if (Person::players[k]->jumppower > 5) {
4361 Person::players[k]->jumppower = 5;
4365 if (Person::players[k]->isRun()) {
4366 Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4;
4369 Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150);
4370 Person::players[k]->grabdelay -= multiplier;
4374 for (unsigned k = 0; k < Person::players.size(); k++) {
4375 Person::players[k]->DoAnimations();
4376 Person::players[k]->whichpatchx = Person::players[k]->coords.x / (terrain.size / subdivision * terrain.scale);
4377 Person::players[k]->whichpatchz = Person::players[k]->coords.z / (terrain.size / subdivision * terrain.scale);
4383 for (int j = numenvsounds - 1; j >= 0; j--) {
4384 envsoundlife[j] -= multiplier;
4385 if (envsoundlife[j] < 0) {
4387 envsoundlife[j] = envsoundlife[numenvsounds];
4388 envsound[j] = envsound[numenvsounds];
4391 OPENAL_SetFrequency(OPENAL_ALL, slomo);
4393 if (Tutorial::active) {
4394 Tutorial::DoStuff(multiplier);
4398 static float gLoc[3];
4402 static float vel[3];
4403 vel[0] = (viewer.x - oldviewer.x) / multiplier;
4404 vel[1] = (viewer.y - oldviewer.y) / multiplier;
4405 vel[2] = (viewer.z - oldviewer.z) / multiplier;
4407 //Set orientation with forward and up vectors
4408 static XYZ upvector;
4412 upvector = DoRotation(upvector, -pitch + 90, 0, 0);
4413 upvector = DoRotation(upvector, 0, 0 - yaw, 0);
4418 facing = DoRotation(facing, -pitch, 0, 0);
4419 facing = DoRotation(facing, 0, 0 - yaw, 0);
4421 static float ori[6];
4425 ori[3] = -upvector.x;
4426 ori[4] = upvector.y;
4427 ori[5] = -upvector.z;
4429 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
4437 void Game::TickOnce()
4440 yaw += multiplier * 5;
4441 } else if (Dialog::directing || !Dialog::inDialog()) {
4444 pitch -= deltav * .7;
4446 pitch += deltav * .7;
4457 void Game::TickOnceAfter()
4459 static XYZ colviewer;
4460 static XYZ coltarget;
4464 static float changedelay;
4465 static bool alldead;
4466 static float unseendelay;
4467 static float cameraspeed;
4470 static int oldmusictype = musictype;
4472 if (environment == snowyenvironment) {
4473 leveltheme = stream_snowtheme;
4475 if (environment == grassyenvironment) {
4476 leveltheme = stream_grasstheme;
4478 if (environment == desertenvironment) {
4479 leveltheme = stream_deserttheme;
4484 musictype = leveltheme;
4485 for (unsigned i = 0; i < Person::players.size(); i++) {
4486 if ((Person::players[i]->aitype == attacktypecutoff ||
4487 Person::players[i]->aitype == getweapontype ||
4488 Person::players[i]->aitype == gethelptype ||
4489 Person::players[i]->aitype == searchtype) &&
4490 !Person::players[i]->dead &&
4491 (Person::players[i]->animTarget != sneakattackedanim &&
4492 Person::players[i]->animTarget != knifesneakattackedanim &&
4493 Person::players[i]->animTarget != swordsneakattackedanim)) {
4494 musictype = stream_fighttheme;
4498 if (Person::players[0]->dead) {
4499 musictype = stream_menutheme;
4502 if (musictype == stream_fighttheme) {
4506 if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) {
4507 unseendelay -= multiplier;
4508 if (unseendelay > 0) {
4509 musictype = stream_fighttheme;
4514 musictype = stream_menutheme;
4515 musicvolume[2] = 512;
4522 if (musictype != oldmusictype && musictype == stream_fighttheme) {
4523 emit_sound_np(alarmsound);
4526 musicselected = musictype;
4528 if (musicselected == leveltheme) {
4529 musicvolume[0] += multiplier * 450;
4531 musicvolume[0] -= multiplier * 450;
4533 if (musicselected == stream_fighttheme) {
4534 musicvolume[1] += multiplier * 450;
4536 musicvolume[1] -= multiplier * 450;
4538 if (musicselected == stream_menutheme) {
4539 musicvolume[2] += multiplier * 450;
4541 musicvolume[2] -= multiplier * 450;
4544 for (int i = 0; i < 3; i++) {
4545 if (musicvolume[i] < 0) {
4548 if (musicvolume[i] > 512) {
4549 musicvolume[i] = 512;
4553 if (musicvolume[2] > 128 && !loading && !mainmenu) {
4554 musicvolume[2] = 128;
4558 if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) {
4559 emit_stream_np(leveltheme, musicvolume[0]);
4561 if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) {
4562 emit_stream_np(stream_fighttheme, musicvolume[1]);
4564 if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) {
4565 emit_stream_np(stream_menutheme, musicvolume[2]);
4567 if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) {
4568 pause_sound(leveltheme);
4570 if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) {
4571 pause_sound(stream_fighttheme);
4573 if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) {
4574 pause_sound(stream_menutheme);
4577 if (musicvolume[0] != oldmusicvolume[0]) {
4578 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
4580 if (musicvolume[1] != oldmusicvolume[1]) {
4581 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
4583 if (musicvolume[2] != oldmusicvolume[2]) {
4584 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
4587 for (int i = 0; i < 3; i++) {
4588 oldmusicvolume[i] = musicvolume[i];
4591 pause_sound(leveltheme);
4592 pause_sound(stream_fighttheme);
4593 pause_sound(stream_menutheme);
4595 for (int i = 0; i < 4; i++) {
4596 oldmusicvolume[i] = 0;
4601 Hotspot::killhotspot = 2;
4602 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4603 if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) {
4604 if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) {
4605 Hotspot::killhotspot = 0;
4606 } else if (Hotspot::killhotspot == 2) {
4607 Hotspot::killhotspot = 1;
4611 if (Hotspot::killhotspot == 2) {
4612 Hotspot::killhotspot = 0;
4616 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4617 if (Hotspot::hotspots[i].type == -1) {
4618 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size) {
4625 for (unsigned i = 1; i < Person::players.size(); i++) {
4626 if (!Person::players[i]->dead && Person::players[i]->aitype == attacktypecutoff && Person::players[i]->surprised <= 0) {
4630 if (numalarmed > maxalarmed) {
4631 maxalarmed = numalarmed;
4634 if (changedelay <= 0 && !loading && !editorenabled && gameon && !Tutorial::active && changedelay != -999 && !won) {
4635 if (Person::players[0]->dead) {
4637 targetlevel = whichlevel;
4640 for (unsigned i = 1; i < Person::players.size(); i++) {
4641 if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1) {
4647 if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) {
4649 targetlevel = whichlevel + 1;
4650 if (targetlevel > numchallengelevels - 1) {
4654 if (winhotspot || windialogue) {
4656 targetlevel = whichlevel + 1;
4657 if (targetlevel > numchallengelevels - 1) {
4662 if (Hotspot::killhotspot) {
4664 targetlevel = whichlevel + 1;
4665 if (targetlevel > numchallengelevels - 1) {
4670 if (changedelay > 0 && !Person::players[0]->dead && !won) {
4671 //high scores, awards, win
4673 Account::active().winCampaignLevel(whichchoice, bonustotal, leveltime);
4676 wonleveltime = leveltime;
4677 Account::active().winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
4680 Account::saveFile(Folders::getUserSavePath());
4686 if (leveltime < 1) {
4691 Hotspot::killhotspot = 0;
4694 if (!editorenabled && gameon && !mainmenu) {
4695 if (changedelay != -999) {
4696 changedelay -= multiplier / 7;
4698 if (Person::players[0]->dead) {
4699 targetlevel = whichlevel;
4701 if (loading == 2 && !campaign) {
4704 fireSound(firestartsound);
4706 if (!Person::players[0]->dead && targetlevel != whichlevel) {
4707 startbonustotal = bonustotal;
4710 LoadLevel(targetlevel);
4715 if (loading == 2 && targetlevel == whichlevel) {
4719 fireSound(firestartsound);
4721 LoadLevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
4727 if (changedelay <= -999 &&
4730 (Person::players[0]->dead ||
4731 (alldead && maptype == mapkilleveryone) ||
4733 (Hotspot::killhotspot))) {
4736 if ((Person::players[0]->dead ||
4737 (alldead && maptype == mapkilleveryone) ||
4740 (Hotspot::killhotspot)) &&
4742 if (whichlevel != -2 && !loading && !Person::players[0]->dead) {
4746 if (Person::players[0]->dead) {
4753 // campaignchoosenext determines what to do when the level is complete:
4754 // 0 = load next level
4755 // 1 = go back to level select screen
4756 // 2 = stealthload next level
4757 if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) {
4758 if (campaignlevels[actuallevel].nextlevel.empty()) {
4761 } else if (mainmenu == 0 && winfreeze) {
4762 stealthloading = (campaignlevels[actuallevel].choosenext == 2);
4764 if (!stealthloading) {
4765 fireSound(firestartsound);
4770 startbonustotal = 0;
4777 if (!firstLoadDone) {
4781 actuallevel = campaignlevels[actuallevel].nextlevel.front();
4782 visibleloading = true;
4784 LoadLevel(campaignlevels[actuallevel].mapname.c_str());
4788 pause_sound(stream_menutheme);
4799 oldmusictype = musictype;
4805 facing = DoRotation(facing, -pitch, 0, 0);
4806 facing = DoRotation(facing, 0, 0 - yaw, 0);
4807 viewerfacing = facing;
4810 if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) {
4811 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;
4813 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;
4816 if (Person::players[0]->skeleton.free) {
4817 for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
4818 if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) {
4819 target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y;
4824 if (Person::players[0]->skeleton.free != 2) {
4826 if (findLengthfast(&Person::players[0]->velocity) > 400) {
4827 cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96;
4829 if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) {
4832 coltarget = target - cameraloc;
4833 if (findLengthfast(&coltarget) < multiplier * multiplier * 400) {
4836 Normalise(&coltarget);
4837 if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) {
4838 cameraloc = cameraloc + coltarget * multiplier * cameraspeed;
4840 cameraloc = cameraloc + coltarget * multiplier * 8;
4843 if (editorenabled) {
4846 cameradist += multiplier * 5;
4847 if (cameradist > 2.3) {
4850 viewer = cameraloc - facing * cameradist;
4852 coltarget = cameraloc;
4853 Object::SphereCheckPossible(&colviewer, findDistance(&colviewer, &coltarget));
4854 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4855 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4857 coltarget = cameraloc;
4858 if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4862 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4863 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4865 if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4869 cameradist = findDistance(&viewer, &target);
4870 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .6);
4871 if (cameraloc.y < terrain.getHeight(cameraloc.x, cameraloc.z)) {
4872 cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z);
4875 if (camerashake > .8) {
4878 woozy += multiplier;
4879 if (Person::players[0]->dead) {
4882 if (Person::players[0]->dead) {
4885 camerashake -= multiplier * 2;
4886 blackout -= multiplier * 2;
4887 if (camerashake < 0) {
4894 viewer.x += (float)(Random() % 100) * .0005 * camerashake;
4895 viewer.y += (float)(Random() % 100) * .0005 * camerashake;
4896 viewer.z += (float)(Random() % 100) * .0005 * camerashake;