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;
844 Game::LoadingScreen();
846 Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral);
848 Person::players[i]->headmorphness = 0;
849 Person::players[i]->targetheadmorphness = 1;
850 Person::players[i]->headmorphstart = 0;
851 Person::players[i]->headmorphend = 0;
853 Person::players[i]->pausetime = 0;
855 Person::players[i]->dead = 0;
856 Person::players[i]->jumppower = 5;
857 Person::players[i]->damage = 0;
858 Person::players[i]->permanentdamage = 0;
859 Person::players[i]->superpermanentdamage = 0;
861 Person::players[i]->forwardkeydown = 0;
862 Person::players[i]->leftkeydown = 0;
863 Person::players[i]->backkeydown = 0;
864 Person::players[i]->rightkeydown = 0;
865 Person::players[i]->jumpkeydown = 0;
866 Person::players[i]->crouchkeydown = 0;
867 Person::players[i]->throwkeydown = 0;
869 Person::players[i]->collided = -10;
870 Person::players[i]->loaded = 1;
871 Person::players[i]->bloodloss = 0;
872 Person::players[i]->weaponactive = -1;
873 Person::players[i]->weaponstuck = -1;
874 Person::players[i]->bleeding = 0;
875 Person::players[i]->deathbleeding = 0;
876 Person::players[i]->stunned = 0;
877 Person::players[i]->hasvictim = 0;
878 Person::players[i]->wentforweapon = 0;
882 Person::players[0]->aitype = playercontrolled;
884 if (difficulty == 1) {
885 Person::players[0]->power = 1 / .9;
886 Person::players[0]->damagetolerance = 250;
887 } else if (difficulty == 0) {
888 Person::players[0]->power = 1 / .8;
889 Person::players[0]->damagetolerance = 300;
890 Person::players[0]->armorhead *= 1.5;
891 Person::players[0]->armorhigh *= 1.5;
892 Person::players[0]->armorlow *= 1.5;
895 cameraloc = Person::players[0]->coords;
897 yaw = Person::players[0]->yaw;
899 hawkcoords = Person::players[0]->coords;
902 Game::LoadingScreen();
904 LOG("Starting background music...");
906 OPENAL_StopSound(OPENAL_ALL);
908 if (environment == snowyenvironment) {
909 emit_stream_np(stream_wind);
910 } else if (environment == desertenvironment) {
911 emit_stream_np(stream_desertambient);
912 } else if (environment == grassyenvironment) {
913 emit_stream_np(stream_wind, 100.);
916 oldmusicvolume[0] = 0;
917 oldmusicvolume[1] = 0;
918 oldmusicvolume[2] = 0;
919 oldmusicvolume[3] = 0;
923 visibleloading = false;
928 /* Process input events that impact settings, console, devtools, etc.
929 * Gameplay-related input processing is still done in Game::Tick() for now
930 * as it is tightly coupled to the game logic.
932 void Game::ProcessInput()
934 /* Pump SDL input events */
937 /* Menu handling (main menu, leave game) */
938 if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
939 (gameon || mainmenu == 0)) {
941 if (mainmenu == 0 && !winfreeze) {
942 mainmenu = 2; // Pause
943 } else if (mainmenu == 1 || mainmenu == 2) {
944 mainmenu = 0; // Unpause
947 if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
948 OPENAL_SetFrequency(OPENAL_ALL);
949 emit_stream_np(stream_menutheme);
950 pause_sound(leveltheme);
952 // On resume, play level music
954 pause_sound(stream_menutheme);
955 resume_stream(leveltheme);
960 if (!campaign && !mainmenu) {
961 if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE))) {
967 if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && gameon) {
971 } else if (winfreeze) {
978 /* Tutorial mode hotkeys */
979 if (Tutorial::active) {
980 // Skip current tutorial stage
981 if (Input::isKeyPressed(SDL_SCANCODE_TAB)) {
982 if (Tutorial::stage != 51) {
983 Tutorial::stagetime = Tutorial::maxtime;
985 emit_sound_np(consolefailsound, 128.);
990 if (Input::isKeyPressed(SDL_SCANCODE_F1)) {
994 /* Stereo video mode hotkeys */
995 if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
996 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
997 stereoreverse = true;
998 printf("Stereo reversed\n");
1000 stereoreverse = false;
1001 printf("Stereo unreversed\n");
1005 if (Input::isKeyDown(SDL_SCANCODE_F7)) {
1006 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1007 stereoseparation -= 0.001;
1009 stereoseparation -= 0.010;
1011 printf("Stereo separation decreased to %f\n", stereoseparation);
1014 if (Input::isKeyDown(SDL_SCANCODE_F8)) {
1015 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1016 stereoseparation += 0.001;
1018 stereoseparation += 0.010;
1020 printf("Stereo separation increased to %f\n", stereoseparation);
1024 if (devtools && !mainmenu) {
1026 if (Input::isKeyPressed(consolekey)) {
1029 OPENAL_SetFrequency(OPENAL_ALL);
1036 /* Other devtools, disabled when the console is shown */
1043 void Game::ProcessDevInput()
1045 if (!devtools || mainmenu || console) {
1049 if (Input::isKeyDown(SDL_SCANCODE_LALT)) {
1051 if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1052 editorenabled = !editorenabled;
1053 if (editorenabled) {
1054 Person::players[0]->damagetolerance = 100000;
1055 Person::players[0]->damage = 0;
1056 Person::players[0]->permanentdamage = 0;
1057 Person::players[0]->superpermanentdamage = 0;
1058 Person::players[0]->burnt = 0;
1059 Person::players[0]->bloodloss = 0;
1060 Person::players[0]->deathbleeding = 0;
1062 Person::players[0]->damagetolerance = 200;
1066 /* Nullify damage and give 200000 health */
1067 if (Input::isKeyPressed(SDL_SCANCODE_H)) {
1068 Person::players[0]->damagetolerance = 200000;
1069 Person::players[0]->damage = 0;
1070 Person::players[0]->permanentdamage = 0;
1071 Person::players[0]->superpermanentdamage = 0;
1072 Person::players[0]->burnt = 0;
1073 Person::players[0]->bloodloss = 0;
1074 Person::players[0]->deathbleeding = 0;
1077 /* Change environment */
1078 if (Input::isKeyPressed(SDL_SCANCODE_J)) {
1080 if (environment > 2) {
1083 Setenvironment(environment);
1087 if (Input::isKeyPressed(SDL_SCANCODE_C)) {
1088 cameramode = !cameramode;
1092 if (Input::isKeyPressed(SDL_SCANCODE_V)) {
1095 OPENAL_SetFrequency(OPENAL_ALL);
1099 /* Toggle slow motion */
1100 if (Input::isKeyPressed(SDL_SCANCODE_B)) {
1106 if (Input::isKeyPressed(SDL_SCANCODE_N)) {
1107 Person::players[0]->RagDoll(0);
1108 emit_sound_at(whooshsound, Person::players[0]->coords, 128.);
1111 /* Shrink tree leaves?? */
1112 // FIXME: Can't see what this does in game.
1113 if (Input::isKeyPressed(SDL_SCANCODE_Y)) {
1114 for (auto& an_object : Object::objects) {
1115 if (an_object->type == treeleavestype) {
1116 an_object->scale *= .9;
1121 /* Change (or add) weapon */
1122 if (Input::isKeyPressed(SDL_SCANCODE_X)) {
1124 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1125 closest = findClosestPlayer();
1129 if (Person::players[closest]->num_weapons > 0) {
1131 switch (weapons[Person::players[closest]->weaponids[0]].getType()) {
1142 weapons[Person::players[closest]->weaponids[0]].setType(weapontype);
1144 Person::players[closest]->weaponids[0] = weapons.size();
1145 weapons.push_back(Weapon(knife, closest));
1146 Person::players[closest]->num_weapons = 1;
1151 /* Change yaw (rotate around Z axis) */
1152 if (Input::isKeyDown(SDL_SCANCODE_U)) {
1154 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1155 closest = findClosestPlayer();
1159 Person::players[closest]->yaw += multiplier * 50;
1160 Person::players[closest]->targetyaw = Person::players[closest]->yaw;
1165 if (Input::isKeyPressed(SDL_SCANCODE_F)) {
1167 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1168 closest = findClosestPlayer();
1172 Person::players[closest]->onfire = !Person::players[closest]->onfire;
1173 if (Person::players[closest]->onfire) {
1174 Person::players[closest]->CatchFire();
1176 emit_sound_at(fireendsound, Person::players[closest]->coords);
1177 pause_sound(stream_firesound);
1183 if (Input::isKeyPressed(SDL_SCANCODE_T) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1185 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1186 closest = findClosestPlayer();
1190 Person::players[closest]->whichskin++;
1191 if (Person::players[closest]->whichskin > 9) {
1192 Person::players[closest]->whichskin = 0;
1194 if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) {
1195 Person::players[closest]->whichskin = 0;
1198 Person::players[closest]->skeleton.drawmodel.textureptr.load(
1199 PersonType::types[Person::players[closest]->creature].skins[Person::players[closest]->whichskin], 1,
1200 &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
1203 Person::players[closest]->addClothes();
1206 /* Change creature type */
1207 if (Input::isKeyPressed(SDL_SCANCODE_T) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1209 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1210 closest = findClosestPlayer();
1214 person_type nextType = static_cast<person_type>((Person::players[closest]->creature + 1) % PersonType::types.size());
1215 Person::players[closest]->changeCreatureType(nextType);
1219 /* Explose nearby player's head */
1220 if (Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1221 int closest = findClosestPlayer();
1222 if (closest > 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1223 XYZ flatfacing2, flatvelocity2, flatvelocity2_orig;
1224 XYZ headspurtdirection;
1225 Joint& headjoint = Person::players[closest]->joint(head);
1227 if (!Person::players[closest]->skeleton.free) {
1228 flatvelocity2_orig = Person::players[closest]->velocity;
1229 flatfacing2 = DoRotation(
1231 DoRotation(headjoint.position, 0, 0, Person::players[closest]->tilt),
1232 Person::players[closest]->tilt2, 0, 0),
1233 0, Person::players[closest]->yaw, 0) *
1234 Person::players[closest]->scale +
1235 Person::players[closest]->coords;
1237 flatvelocity2_orig = headjoint.velocity;
1238 flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords;
1241 headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck);
1242 Normalise(&headspurtdirection);
1244 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1245 flatvelocity2 = flatvelocity2_orig;
1246 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1247 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1248 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1249 printf("Test: %f\n", flatvelocity2.x);
1250 printf("Test orig: %f\n", flatvelocity2_orig.x);
1251 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, .6, 1);
1252 flatvelocity2 += headspurtdirection * 8;
1253 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 / 2, 1, 1, 1, .16, 1);
1255 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1257 emit_sound_at(splattersound, Person::players[closest]->coords);
1258 emit_sound_at(breaksound2, Person::players[closest]->coords, 100.);
1260 if (Person::players[closest]->skeleton.free == 2) {
1261 Person::players[closest]->skeleton.free = 0;
1263 Person::players[closest]->RagDoll(0);
1264 Person::players[closest]->dead = 2;
1265 Person::players[closest]->headless = 1;
1266 Person::players[closest]->DoBloodBig(3, 165);
1272 /* Explode nearby player */
1273 if (Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1274 int closest = findClosestPlayer();
1275 if (closest >= 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1276 XYZ flatfacing2, flatvelocity2, flatvelocity2_orig;
1278 emit_sound_at(splattersound, Person::players[closest]->coords);
1279 emit_sound_at(breaksound2, Person::players[closest]->coords);
1281 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1282 if (!Person::players[closest]->skeleton.free) {
1283 flatvelocity2_orig = Person::players[closest]->velocity;
1284 flatfacing2 = DoRotation(
1286 DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt),
1287 Person::players[closest]->tilt2, 0, 0),
1288 0, Person::players[closest]->yaw, 0) *
1289 Person::players[closest]->scale +
1290 Person::players[closest]->coords;
1292 flatvelocity2_orig = Person::players[closest]->skeleton.joints[i].velocity;
1293 flatfacing2 = Person::players[closest]->skeleton.joints[i].position *
1294 Person::players[closest]->scale +
1295 Person::players[closest]->coords;
1299 flatvelocity2 = flatvelocity2_orig;
1300 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1301 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1302 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1303 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1304 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .3, 1);
1305 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1308 flatvelocity2 = flatvelocity2_orig;
1309 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1310 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1311 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1312 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1313 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1316 flatvelocity2 = flatvelocity2_orig;
1317 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1318 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1319 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1320 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1321 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1324 flatvelocity2 = flatvelocity2_orig;
1325 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1326 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1327 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1328 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1329 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1333 for (unsigned j = 0; j < Person::players.size(); j++) {
1334 if (int(j) == closest) {
1337 if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) {
1338 Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60);
1339 if (Person::players[j]->skeleton.free == 2) {
1340 Person::players[j]->skeleton.free = 1;
1342 Person::players[j]->skeleton.longdead = 0;
1343 Person::players[j]->RagDoll(0);
1344 for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) {
1345 temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords;
1346 if (distsq(&temppos, &Person::players[closest]->coords) < 25) {
1347 flatvelocity2 = temppos - Person::players[closest]->coords;
1348 Normalise(&flatvelocity2);
1349 Person::players[j]->skeleton.joints[i].velocity +=
1350 flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20);
1356 Person::players[closest]->DoDamage(10000);
1357 Person::players[closest]->RagDoll(0);
1358 Person::players[closest]->dead = 2;
1359 Person::players[closest]->coords = 20;
1360 Person::players[closest]->skeleton.free = 2;
1367 /* Skip level (only for challenges) */
1368 // FIXME: Allow skipping levels in campaigns too
1369 if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) {
1371 if (targetlevel > numchallengelevels - 1) {
1378 /* Editor mode keys */
1379 if (editorenabled) {
1380 /* Closest player deletion */
1381 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1382 int closest = findClosestPlayer();
1384 Person::players.erase(Person::players.begin() + closest);
1388 /* Closest object deletion */
1389 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1390 int closest = findClosestObject();
1392 Object::DeleteObject(closest);
1397 if (Input::isKeyPressed(SDL_SCANCODE_O)) {
1398 if (Object::objects.size() < max_objects - 1) {
1399 XYZ scenecoords = Person::players[0]->coords;
1401 if (editortype == bushtype || editortype == firetype) {
1402 scenecoords.y -= 3.5;
1407 float tmpyaw, tmppitch;
1409 tmppitch = editorpitch;
1410 if (tmpyaw < 0 || editortype == bushtype) {
1411 tmpyaw = Random() % 360;
1414 tmppitch = Random() % 360;
1417 Object::MakeObject(editortype, scenecoords, (int)tmpyaw - ((int)tmpyaw) % 30, (int)tmppitch, editorsize);
1418 if (editortype == treetrunktype) {
1419 Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (tmppitch < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize);
1425 if (Input::isKeyPressed(SDL_SCANCODE_P) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1426 Person::players.push_back(shared_ptr<Person>(new Person()));
1428 Person::players.back()->id = Person::players.size() - 1;
1430 Person::players.back()->scale = Person::players[0]->scale;
1431 Person::players.back()->creature = rabbittype;
1432 Person::players.back()->howactive = editoractive;
1433 Person::players.back()->whichskin = (int)(abs(Random() % 3));
1435 Person::players.back()->skeletonLoad();
1437 Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
1438 Person::players.back()->speed = 1 + (float)(Random() % 100) / 1000;
1440 Person::players.back()->targetyaw = Person::players[0]->targetyaw;
1441 Person::players.back()->yaw = Person::players[0]->yaw;
1443 Person::players.back()->coords = Person::players[0]->coords;
1444 Person::players.back()->oldcoords = Person::players.back()->coords;
1445 Person::players.back()->realoldcoords = Person::players.back()->coords;
1447 Person::players.back()->setProportions(1, 1, 1, 1);
1449 Person::players.back()->damagetolerance = 200;
1451 Person::players.back()->protectionhead = Person::players[0]->protectionhead;
1452 Person::players.back()->protectionhigh = Person::players[0]->protectionhigh;
1453 Person::players.back()->protectionlow = Person::players[0]->protectionlow;
1454 Person::players.back()->armorhead = Person::players[0]->armorhead;
1455 Person::players.back()->armorhigh = Person::players[0]->armorhigh;
1456 Person::players.back()->armorlow = Person::players[0]->armorlow;
1457 Person::players.back()->metalhead = Person::players[0]->metalhead;
1458 Person::players.back()->metalhigh = Person::players[0]->metalhigh;
1459 Person::players.back()->metallow = Person::players[0]->metallow;
1461 Person::players.back()->immobile = Person::players[0]->immobile;
1463 Person::players.back()->numclothes = Person::players[0]->numclothes;
1464 for (int i = 0; i < Person::players.back()->numclothes; i++) {
1465 strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
1466 Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
1467 Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
1468 Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
1470 Person::players.back()->addClothes();
1472 Person::players.back()->power = Person::players[0]->power;
1473 Person::players.back()->speedmult = Person::players[0]->speedmult;
1475 Person::players.back()->loaded = true;
1479 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1480 if (Person::players.back()->numwaypoints < 90) {
1481 Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
1482 Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype;
1483 Person::players.back()->numwaypoints++;
1485 printf("Add waypoint: Reached max number of waypoints (90), aborting.");
1489 /* Connect waypoint */
1490 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1491 if (numpathpoints < 30) {
1492 bool connected = false;
1493 if (numpathpoints > 1) {
1494 for (int i = 0; i < numpathpoints; i++) {
1495 if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) {
1496 bool alreadyconnected = false;
1497 for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) {
1498 if (pathpointconnect[pathpointselected][j] == i) {
1499 alreadyconnected = true;
1502 if (!alreadyconnected) {
1503 numpathpointconnect[pathpointselected]++;
1505 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = i;
1512 pathpoint[numpathpoints - 1] = Person::players[0]->coords;
1513 numpathpointconnect[numpathpoints - 1] = 0;
1514 if (numpathpoints > 1 && pathpointselected != -1) {
1515 numpathpointconnect[pathpointselected]++;
1516 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = numpathpoints - 1;
1518 pathpointselected = numpathpoints - 1;
1521 printf("Connect waypoint: Reached max number of path points (30), aborting.");
1525 /* Select next path waypoint */
1526 if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) {
1527 pathpointselected++;
1528 if (pathpointselected >= numpathpoints) {
1529 pathpointselected = -1;
1533 /* Select previous path waypoint */
1534 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1535 pathpointselected--;
1536 if (pathpointselected <= -2) {
1537 pathpointselected = numpathpoints - 1;
1541 /* Delete path waypoint */
1542 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1543 if (pathpointselected != -1) {
1545 pathpoint[pathpointselected] = pathpoint[numpathpoints];
1546 numpathpointconnect[pathpointselected] = numpathpointconnect[numpathpoints];
1547 for (int i = 0; i < numpathpointconnect[pathpointselected]; i++) {
1548 pathpointconnect[pathpointselected][i] = pathpointconnect[numpathpoints][i];
1550 for (int i = 0; i < numpathpoints; i++) {
1551 for (int j = 0; j < numpathpointconnect[i]; j++) {
1552 if (pathpointconnect[i][j] == pathpointselected) {
1553 pathpointconnect[i][j] = pathpointconnect[i][numpathpointconnect[i] - 1];
1554 numpathpointconnect[i]--;
1556 if (pathpointconnect[i][j] == numpathpoints) {
1557 pathpointconnect[i][j] = pathpointselected;
1561 pathpointselected = numpathpoints - 1;
1565 /* Select previous object type */
1566 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1568 if (editortype == treeleavestype || editortype == 10) {
1571 if (editortype < 0) {
1572 editortype = firetype;
1576 /* Select next object type */
1577 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1579 if (editortype == treeleavestype || editortype == 10) {
1582 if (editortype > firetype) {
1587 /* Decrease size for next object */
1588 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1589 editorsize -= multiplier;
1590 if (editorsize < .1) {
1595 /* Increase size for next object */
1596 if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1597 editorsize += multiplier;
1600 /* Decrease yaw for next object */
1601 if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1602 editoryaw -= multiplier * 100;
1603 if (editoryaw < -.01) {
1608 /* Increase yaw for next object */
1609 if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1610 editoryaw += multiplier * 100;
1613 /* Decrease pitch for next object */
1614 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1615 editorpitch -= multiplier * 100;
1616 if (editorpitch < -.01) {
1621 /* Increase pitch for next object */
1622 if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1623 editorpitch += multiplier * 100;
1626 /* Decrease map radius */
1627 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1628 mapradius -= multiplier * 10;
1631 /* Increase map radius */
1632 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1633 mapradius += multiplier * 10;
1638 void doJumpReversals()
1640 for (unsigned k = 0; k < Person::players.size(); k++) {
1641 for (unsigned i = k + 1; i < Person::players.size(); i++) {
1642 if (Person::players[k]->skeleton.free == 0 &&
1643 Person::players[i]->skeleton.oldfree == 0 &&
1644 (Person::players[i]->animTarget == jumpupanim ||
1645 Person::players[k]->animTarget == jumpupanim) &&
1646 (Person::players[i]->isPlayerControlled() ||
1647 Person::players[k]->isPlayerControlled()) &&
1648 ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) ||
1649 (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) {
1650 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) &&
1651 distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
1652 //TODO: refactor two huge similar ifs
1653 if (Person::players[i]->animTarget == jumpupanim &&
1654 Person::players[k]->animTarget != getupfrombackanim &&
1655 Person::players[k]->animTarget != getupfromfrontanim &&
1656 Animation::animations[Person::players[k]->animTarget].height == middleheight &&
1657 normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 &&
1658 ((Person::players[k]->isPlayerControlled() && Person::players[k]->attackkeydown) ||
1659 !Person::players[k]->isPlayerControlled())) {
1660 Person::players[i]->victim = Person::players[k];
1661 Person::players[i]->velocity = 0;
1662 Person::players[i]->animCurrent = jumpreversedanim;
1663 Person::players[i]->animTarget = jumpreversedanim;
1664 Person::players[i]->frameCurrent = 0;
1665 Person::players[i]->frameTarget = 1;
1666 Person::players[i]->targettilt2 = 0;
1667 Person::players[k]->victim = Person::players[i];
1668 Person::players[k]->velocity = 0;
1669 Person::players[k]->animCurrent = jumpreversalanim;
1670 Person::players[k]->animTarget = jumpreversalanim;
1671 Person::players[k]->frameCurrent = 0;
1672 Person::players[k]->frameTarget = 1;
1673 Person::players[k]->targettilt2 = 0;
1674 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 1) {
1675 Person::players[i]->animCurrent = rabbitkickreversedanim;
1676 Person::players[i]->animTarget = rabbitkickreversedanim;
1677 Person::players[i]->frameCurrent = 1;
1678 Person::players[i]->frameTarget = 2;
1679 Person::players[k]->animCurrent = rabbitkickreversalanim;
1680 Person::players[k]->animTarget = rabbitkickreversalanim;
1681 Person::players[k]->frameCurrent = 1;
1682 Person::players[k]->frameTarget = 2;
1684 Person::players[i]->target = 0;
1685 Person::players[k]->oldcoords = Person::players[k]->coords;
1686 Person::players[i]->coords = Person::players[k]->coords;
1687 Person::players[k]->targetyaw = Person::players[i]->targetyaw;
1688 Person::players[k]->yaw = Person::players[i]->targetyaw;
1689 if (Person::players[k]->aitype == attacktypecutoff) {
1690 Person::players[k]->stunned = .5;
1693 if (Person::players[k]->animTarget == jumpupanim &&
1694 Person::players[i]->animTarget != getupfrombackanim &&
1695 Person::players[i]->animTarget != getupfromfrontanim &&
1696 Animation::animations[Person::players[i]->animTarget].height == middleheight &&
1697 normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 &&
1698 ((Person::players[i]->isPlayerControlled() && Person::players[i]->attackkeydown) ||
1699 !Person::players[i]->isPlayerControlled())) {
1700 Person::players[k]->victim = Person::players[i];
1701 Person::players[k]->velocity = 0;
1702 Person::players[k]->animCurrent = jumpreversedanim;
1703 Person::players[k]->animTarget = jumpreversedanim;
1704 Person::players[k]->frameCurrent = 0;
1705 Person::players[k]->frameTarget = 1;
1706 Person::players[k]->targettilt2 = 0;
1707 Person::players[i]->victim = Person::players[k];
1708 Person::players[i]->velocity = 0;
1709 Person::players[i]->animCurrent = jumpreversalanim;
1710 Person::players[i]->animTarget = jumpreversalanim;
1711 Person::players[i]->frameCurrent = 0;
1712 Person::players[i]->frameTarget = 1;
1713 Person::players[i]->targettilt2 = 0;
1714 if (Person::players[k]->coords.y < Person::players[i]->coords.y + 1) {
1715 Person::players[k]->animTarget = rabbitkickreversedanim;
1716 Person::players[k]->animCurrent = rabbitkickreversedanim;
1717 Person::players[i]->animCurrent = rabbitkickreversalanim;
1718 Person::players[i]->animTarget = rabbitkickreversalanim;
1719 Person::players[k]->frameCurrent = 1;
1720 Person::players[k]->frameTarget = 2;
1721 Person::players[i]->frameCurrent = 1;
1722 Person::players[i]->frameTarget = 2;
1724 Person::players[k]->target = 0;
1725 Person::players[i]->oldcoords = Person::players[i]->coords;
1726 Person::players[k]->coords = Person::players[i]->coords;
1727 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
1728 Person::players[i]->yaw = Person::players[k]->targetyaw;
1729 if (Person::players[i]->aitype == attacktypecutoff) {
1730 Person::players[i]->stunned = .5;
1739 void doAerialAcrobatics()
1741 static XYZ facing, flatfacing;
1742 for (unsigned k = 0; k < Person::players.size(); k++) {
1743 Person::players[k]->turnspeed = 500;
1745 if ((Person::players[k]->isRun() &&
1746 ((Person::players[k]->targetyaw != rabbitrunninganim &&
1747 Person::players[k]->targetyaw != wolfrunninganim) ||
1748 Person::players[k]->frameTarget == 4)) ||
1749 Person::players[k]->animTarget == removeknifeanim ||
1750 Person::players[k]->animTarget == crouchremoveknifeanim ||
1751 Person::players[k]->animTarget == flipanim ||
1752 Person::players[k]->animTarget == fightsidestep ||
1753 Person::players[k]->animTarget == walkanim) {
1754 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed);
1757 if (Person::players[k]->isStop() ||
1758 Person::players[k]->isLanding() ||
1759 Person::players[k]->animTarget == staggerbackhighanim ||
1760 (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) ||
1761 Person::players[k]->animTarget == staggerbackhardanim ||
1762 Person::players[k]->animTarget == backhandspringanim ||
1763 Person::players[k]->animTarget == dodgebackanim ||
1764 Person::players[k]->animTarget == rollanim ||
1765 (Animation::animations[Person::players[k]->animTarget].attack &&
1766 Person::players[k]->animTarget != rabbitkickanim &&
1767 (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) &&
1768 (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) {
1769 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 2);
1772 if (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent != sneakanim) {
1773 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 4);
1776 Person::players[k]->DoStuff();
1777 if (Person::players[k]->immobile && k != 0) {
1778 Person::players[k]->coords = Person::players[k]->realoldcoords;
1781 //if player's position has changed (?)
1782 if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 &&
1783 !Person::players[k]->skeleton.free &&
1784 Person::players[k]->animTarget != climbanim &&
1785 Person::players[k]->animTarget != hanganim) {
1786 XYZ lowpoint, lowpointtarget, lowpoint2, lowpointtarget2, lowpoint3, lowpointtarget3, lowpoint4, lowpointtarget4, lowpoint5, lowpointtarget5, lowpoint6, lowpointtarget6, lowpoint7, lowpointtarget7, colpoint, colpoint2;
1788 bool tempcollide = 0;
1790 if (Person::players[k]->collide < -.3) {
1791 Person::players[k]->collide = -.3;
1793 if (Person::players[k]->collide > 1) {
1794 Person::players[k]->collide = 1;
1796 Person::players[k]->collide -= multiplier * 30;
1799 Person::players[k]->coords.y = max(Person::players[k]->coords.y, terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z));
1801 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1802 unsigned int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1803 if (Object::objects[i]->type != rocktype ||
1804 Object::objects[i]->scale > .5 && Person::players[k]->isPlayerControlled() ||
1805 Object::objects[i]->position.y > Person::players[k]->coords.y) {
1806 lowpoint = Person::players[k]->coords;
1807 if (Person::players[k]->animTarget != jumpupanim &&
1808 Person::players[k]->animTarget != jumpdownanim &&
1809 !Person::players[k]->isFlip()) {
1814 if (Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) &&
1815 Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) {
1816 Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z);
1818 if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1819 flatfacing = lowpoint - Person::players[k]->coords;
1820 Person::players[k]->coords = lowpoint;
1821 Person::players[k]->coords.y -= 1.3;
1822 Person::players[k]->collide = 1;
1825 //TODO: refactor four similar blocks
1826 if (Person::players[k]->isPlayerControlled() &&
1827 (Person::players[k]->animTarget == jumpupanim ||
1828 Person::players[k]->animTarget == jumpdownanim ||
1829 Person::players[k]->isFlip()) &&
1830 !Person::players[k]->jumptogglekeydown &&
1831 Person::players[k]->jumpkeydown) {
1832 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5;
1833 XYZ tempcoords1 = lowpoint;
1834 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1835 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1836 Person::players[k]->setTargetAnimation(walljumpleftanim);
1837 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1839 pause_sound(whooshsound);
1842 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1843 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1844 if (lowpointtarget.z < 0) {
1845 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1847 Person::players[k]->targetyaw = Person::players[k]->yaw;
1848 Person::players[k]->lowyaw = Person::players[k]->yaw;
1853 lowpoint = tempcoords1;
1854 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5;
1855 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1856 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1857 Person::players[k]->setTargetAnimation(walljumprightanim);
1858 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1860 pause_sound(whooshsound);
1863 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1864 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1865 if (lowpointtarget.z < 0) {
1866 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1868 Person::players[k]->targetyaw = Person::players[k]->yaw;
1869 Person::players[k]->lowyaw = Person::players[k]->yaw;
1874 lowpoint = tempcoords1;
1875 lowpointtarget = lowpoint + Person::players[k]->facing * 2;
1876 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1877 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1878 Person::players[k]->setTargetAnimation(walljumpbackanim);
1879 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1881 pause_sound(whooshsound);
1884 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1885 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1886 if (lowpointtarget.z < 0) {
1887 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1889 Person::players[k]->targetyaw = Person::players[k]->yaw;
1890 Person::players[k]->lowyaw = Person::players[k]->yaw;
1895 lowpoint = tempcoords1;
1896 lowpointtarget = lowpoint - Person::players[k]->facing * 2;
1897 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1898 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1899 Person::players[k]->setTargetAnimation(walljumpfrontanim);
1900 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1902 pause_sound(whooshsound);
1905 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1906 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1907 if (lowpointtarget.z < 0) {
1908 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1910 Person::players[k]->yaw += 180;
1911 Person::players[k]->targetyaw = Person::players[k]->yaw;
1912 Person::players[k]->lowyaw = Person::players[k]->yaw;
1922 } else if (Object::objects[i]->type == rocktype) {
1923 lowpoint2 = Person::players[k]->coords;
1924 lowpoint = Person::players[k]->coords;
1926 if (Object::objects[i]->model.LineCheck(&lowpoint, &lowpoint2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
1927 Person::players[k]->coords = colpoint;
1928 Person::players[k]->collide = 1;
1931 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) {
1932 //flipped into a rock
1933 if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) {
1934 Person::players[k]->RagDoll(0);
1937 if (Person::players[k]->animTarget == jumpupanim) {
1938 Person::players[k]->jumppower = -4;
1939 Person::players[k]->animTarget = Person::players[k]->getIdle();
1941 Person::players[k]->target = 0;
1942 Person::players[k]->frameTarget = 0;
1943 Person::players[k]->onterrain = 1;
1945 if (Person::players[k]->id == 0) {
1946 pause_sound(whooshsound);
1947 OPENAL_SetVolume(channels[whooshsound], 0);
1951 if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) {
1952 if (Person::players[k]->isFlip()) {
1953 Person::players[k]->jumppower = -4;
1955 Person::players[k]->animTarget = Person::players[k]->getLanding();
1956 emit_sound_at(landsound, Person::players[k]->coords, 128.);
1958 addEnvSound(Person::players[k]->coords);
1967 for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) {
1968 int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1969 lowpoint = Person::players[k]->coords;
1971 if (Object::objects[i]->type != rocktype) {
1972 if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1973 if (Person::players[k]->animTarget != jumpupanim &&
1974 Person::players[k]->animTarget != jumpdownanim &&
1975 Person::players[k]->onterrain) {
1976 Person::players[k]->avoidcollided = 1;
1978 Person::players[k]->coords = lowpoint;
1979 Person::players[k]->coords.y -= 1.35;
1980 Person::players[k]->collide = 1;
1982 if ((Person::players[k]->grabdelay <= 0 || !Person::players[k]->isPlayerControlled()) &&
1983 (Person::players[k]->animCurrent != climbanim &&
1984 Person::players[k]->animCurrent != hanganim &&
1985 !Person::players[k]->isWallJump() ||
1986 Person::players[k]->animTarget == jumpupanim ||
1987 Person::players[k]->animTarget == jumpdownanim)) {
1988 lowpoint = Person::players[k]->coords;
1989 Object::objects[i]->model.SphereCheckPossible(&lowpoint, 1.5, &Object::objects[i]->position, &Object::objects[i]->yaw);
1990 lowpoint = Person::players[k]->coords;
1994 facing = DoRotation(facing, 0, Person::players[k]->targetyaw + 180, 0);
1995 lowpointtarget = lowpoint + facing * 1.4;
1996 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1997 if (whichhit != -1) {
1998 lowpoint = Person::players[k]->coords;
2000 lowpointtarget = lowpoint + facing * 1.4;
2001 lowpoint2 = lowpoint;
2002 lowpointtarget2 = lowpointtarget;
2003 lowpoint3 = lowpoint;
2004 lowpointtarget3 = lowpointtarget;
2005 lowpoint4 = lowpoint;
2006 lowpointtarget4 = lowpointtarget;
2007 lowpoint5 = lowpoint;
2008 lowpointtarget5 = lowpointtarget;
2009 lowpoint6 = lowpoint;
2010 lowpointtarget6 = lowpointtarget;
2011 lowpoint7 = lowpoint;
2012 lowpointtarget7 = lowpoint;
2014 lowpointtarget2.x += .1;
2016 lowpointtarget3.z += .1;
2018 lowpointtarget4.x -= .1;
2020 lowpointtarget5.z -= .1;
2021 lowpoint6.y += 45 / 13;
2022 lowpointtarget6.y += 45 / 13;
2023 lowpointtarget6 += facing * .6;
2024 lowpointtarget7.y += 90 / 13;
2025 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
2026 if (Object::objects[i]->friction > .5) {
2027 if (whichhit != -1) {
2028 if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) {
2029 Person::players[k]->collided = 1;
2031 if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) {
2032 if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) {
2033 if (Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2,
2034 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2035 Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3,
2036 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2037 Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4,
2038 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
2039 Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5,
2040 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
2041 for (int j = 0; j < 45; j++) {
2042 lowpoint = Person::players[k]->coords;
2043 lowpoint.y += (float)j / 13;
2044 lowpointtarget = lowpoint + facing * 1.4;
2045 if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget,
2046 &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) {
2047 if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) {
2050 if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) {
2051 lowpoint = Person::players[k]->coords;
2052 lowpoint.y += (float)j / 13;
2053 lowpointtarget = lowpoint + facing * 1.3;
2054 flatfacing = Person::players[k]->coords;
2055 Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * .01;
2056 Person::players[k]->coords.y = lowpointtarget.y - .07;
2057 Person::players[k]->currentoffset = (flatfacing - Person::players[k]->coords) / Person::players[k]->scale;
2059 if (j > 10 || !Person::players[k]->isRun()) {
2060 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) {
2062 pause_sound(whooshsound);
2065 emit_sound_at(jumpsound, Person::players[k]->coords, 128.);
2067 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
2068 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
2069 if (lowpointtarget.z < 0) {
2070 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
2072 Person::players[k]->targetyaw = Person::players[k]->yaw;
2073 Person::players[k]->lowyaw = Person::players[k]->yaw;
2075 //Person::players[k]->velocity=lowpointtarget*.03;
2076 Person::players[k]->velocity = 0;
2079 if (Person::players[k]->animTarget == jumpupanim) {
2080 Person::players[k]->animTarget = climbanim;
2081 Person::players[k]->jumppower = 0;
2082 Person::players[k]->jumpclimb = 1;
2084 Person::players[k]->transspeed = 6;
2085 Person::players[k]->target = 0;
2086 Person::players[k]->frameTarget = 1;
2089 Person::players[k]->setTargetAnimation(hanganim);
2090 Person::players[k]->jumppower = 0;
2108 if (Person::players[k]->collide <= 0) {
2110 if (!Person::players[k]->onterrain &&
2111 Person::players[k]->animTarget != jumpupanim &&
2112 Person::players[k]->animTarget != jumpdownanim &&
2113 Person::players[k]->animTarget != climbanim &&
2114 Person::players[k]->animTarget != hanganim &&
2115 !Person::players[k]->isWallJump() &&
2116 !Person::players[k]->isFlip()) {
2117 if (Person::players[k]->animCurrent != climbanim &&
2118 Person::players[k]->animCurrent != tempanim &&
2119 Person::players[k]->animTarget != backhandspringanim &&
2120 (Person::players[k]->animTarget != rollanim ||
2121 Person::players[k]->frameTarget < 2 ||
2122 Person::players[k]->frameTarget > 6)) {
2123 //stagger off ledge (?)
2124 if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) {
2125 Person::players[k]->RagDoll(0);
2127 Person::players[k]->setTargetAnimation(jumpdownanim);
2130 emit_sound_at(whooshsound, Person::players[k]->coords, 128.);
2134 Person::players[k]->velocity.y += gravity;
2138 Person::players[k]->realoldcoords = Person::players[k]->coords;
2144 static int randattack;
2145 static bool playerrealattackkeydown = 0;
2147 if (!Input::isKeyDown(attackkey)) {
2151 Person::players[0]->attackkeydown = 0;
2154 playerrealattackkeydown = 0;
2156 if (!oldattackkey) {
2157 playerrealattackkeydown = Input::isKeyDown(attackkey);
2159 if ((Person::players[0]->parriedrecently <= 0 ||
2160 !Person::players[0]->hasWeapon()) &&
2163 Person::players[0]->lastattack != swordslashanim &&
2164 Person::players[0]->lastattack != knifeslashstartanim &&
2165 Person::players[0]->lastattack != staffhitanim &&
2166 Person::players[0]->lastattack != staffspinhitanim))) {
2167 Person::players[0]->attackkeydown = Input::isKeyDown(attackkey);
2169 if (Input::isKeyDown(attackkey) &&
2171 !Person::players[0]->backkeydown) {
2172 for (unsigned k = 0; k < Person::players.size(); k++) {
2173 if ((Person::players[k]->animTarget == swordslashanim ||
2174 Person::players[k]->animTarget == staffhitanim ||
2175 Person::players[k]->animTarget == staffspinhitanim) &&
2176 Person::players[0]->animCurrent != dodgebackanim &&
2177 !Person::players[k]->skeleton.free) {
2178 Person::players[k]->Reverse();
2183 if (!hostile || Dialog::inDialog()) {
2184 Person::players[0]->attackkeydown = 0;
2187 for (unsigned k = 0; k < Person::players.size(); k++) {
2188 if (Dialog::inDialog()) {
2189 Person::players[k]->attackkeydown = 0;
2191 if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) {
2192 if (!Person::players[k]->isPlayerControlled()) {
2193 Person::players[k]->victim = Person::players[0];
2195 //attack key pressed
2196 if (Person::players[k]->attackkeydown) {
2198 if (Person::players[k]->backkeydown &&
2199 Person::players[k]->animTarget != backhandspringanim &&
2200 (Person::players[k]->isIdle() ||
2201 Person::players[k]->isStop() ||
2202 Person::players[k]->isRun() ||
2203 Person::players[k]->animTarget == walkanim)) {
2204 if (Person::players[k]->jumppower <= 1) {
2205 Person::players[k]->jumppower -= 2;
2207 for (unsigned i = 0; i < Person::players.size(); i++) {
2211 if (Person::players[i]->animTarget == swordslashanim ||
2212 Person::players[i]->animTarget == knifeslashstartanim ||
2213 Person::players[i]->animTarget == staffhitanim ||
2214 Person::players[i]->animTarget == staffspinhitanim) {
2215 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) {
2216 Person::players[k]->setTargetAnimation(dodgebackanim);
2217 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2218 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2222 if (Person::players[k]->animTarget != dodgebackanim) {
2226 Person::players[k]->setTargetAnimation(backhandspringanim);
2227 Person::players[k]->targetyaw = -yaw + 180;
2228 if (Person::players[k]->leftkeydown) {
2229 Person::players[k]->targetyaw -= 45;
2231 if (Person::players[k]->rightkeydown) {
2232 Person::players[k]->targetyaw += 45;
2234 Person::players[k]->yaw = Person::players[k]->targetyaw;
2235 Person::players[k]->jumppower -= 2;
2240 if (!Animation::animations[Person::players[k]->animTarget].attack &&
2241 !Person::players[k]->backkeydown &&
2242 (Person::players[k]->isIdle() ||
2243 Person::players[k]->isRun() ||
2244 Person::players[k]->animTarget == walkanim ||
2245 Person::players[k]->animTarget == sneakanim ||
2246 Person::players[k]->isCrouch())) {
2247 const int attackweapon = (Person::players[k]->hasWeapon() ? weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType() : 0);
2248 //normal attacks (?)
2249 Person::players[k]->hasvictim = 0;
2250 if (Person::players.size() > 1) {
2251 for (unsigned i = 0; i < Person::players.size(); i++) {
2252 if (i == k || !(k == 0 || i == 0)) {
2255 if (!Person::players[k]->hasvictim) {
2256 if (Animation::animations[Person::players[k]->animTarget].attack != reversal) {
2258 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2259 if (distance < 4.5 &&
2260 !Person::players[i]->skeleton.free &&
2261 Person::players[i]->howactive < typedead1 &&
2262 Person::players[i]->animTarget != jumpreversedanim &&
2263 Person::players[i]->animTarget != rabbitkickreversedanim &&
2264 Person::players[i]->animTarget != rabbitkickanim &&
2265 Person::players[k]->animTarget != rabbitkickanim &&
2266 Person::players[i]->animTarget != getupfrombackanim &&
2267 (Person::players[i]->animTarget != staggerbackhighanim &&
2268 (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) &&
2269 Person::players[i]->animTarget != jumpdownanim &&
2270 Person::players[i]->animTarget != jumpupanim &&
2271 Person::players[i]->animTarget != getupfromfrontanim) {
2272 Person::players[k]->victim = Person::players[i];
2273 Person::players[k]->hasvictim = 1;
2274 if (Person::players[k]->isPlayerControlled()) { //human player
2276 if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2277 Person::players[k]->crouchkeydown &&
2278 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2279 Person::players[k]->animTarget = sweepanim;
2281 } else if (distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2282 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2283 !Person::players[k]->forwardkeydown &&
2284 !Person::players[k]->leftkeydown &&
2285 !Person::players[k]->rightkeydown &&
2286 !Person::players[k]->crouchkeydown &&
2289 Person::players[k]->animTarget = winduppunchanim;
2291 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2292 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2293 !Person::players[k]->forwardkeydown &&
2294 !Person::players[k]->leftkeydown &&
2295 !Person::players[k]->rightkeydown &&
2296 !Person::players[k]->crouchkeydown &&
2298 Person::players[k]->animTarget = upunchanim;
2300 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2301 Person::players[i]->staggerdelay > 0 &&
2302 attackweapon == knife &&
2303 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) {
2304 Person::players[k]->animTarget = knifefollowanim;
2306 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2307 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2308 !Person::players[k]->forwardkeydown &&
2309 !Person::players[k]->leftkeydown &&
2310 !Person::players[k]->rightkeydown &&
2311 !Person::players[k]->crouchkeydown &&
2312 attackweapon == knife &&
2313 Person::players[k]->weaponmissdelay <= 0) {
2314 Person::players[k]->animTarget = knifeslashstartanim;
2316 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2317 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2318 !Person::players[k]->crouchkeydown &&
2319 attackweapon == sword &&
2320 Person::players[k]->weaponmissdelay <= 0) {
2321 Person::players[k]->animTarget = swordslashanim;
2323 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2324 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2325 !Person::players[k]->crouchkeydown &&
2326 attackweapon == staff &&
2327 Person::players[k]->weaponmissdelay <= 0 &&
2328 !Person::players[k]->leftkeydown &&
2329 !Person::players[k]->rightkeydown &&
2330 !Person::players[k]->forwardkeydown) {
2331 Person::players[k]->animTarget = staffhitanim;
2333 } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2334 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2335 !Person::players[k]->crouchkeydown &&
2336 attackweapon == staff &&
2337 Person::players[k]->weaponmissdelay <= 0) {
2338 Person::players[k]->animTarget = staffspinhitanim;
2340 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2341 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2342 Person::players[k]->animTarget = spinkickanim;
2344 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2345 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2346 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2347 Person::players[k]->animTarget = lowkickanim;
2349 } else { //AI player
2350 if (distance < 4.5 * sq(Person::players[k]->scale * 5)) {
2351 randattack = abs(Random() % 5);
2352 if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) {
2354 if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2355 Person::players[k]->animTarget = sweepanim;
2357 } else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2359 Person::players[k]->animTarget = upunchanim;
2361 } else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2362 Person::players[k]->animTarget = spinkickanim;
2364 } else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) {
2365 Person::players[k]->animTarget = lowkickanim;
2370 if ((!Tutorial::active || !attackweapon) &&
2371 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2373 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2374 Person::players[k]->animTarget = sweepanim;
2376 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2377 attackweapon == knife &&
2378 Person::players[k]->weaponmissdelay <= 0) {
2379 Person::players[k]->animTarget = knifeslashstartanim;
2381 } else if (!(Person::players[0]->victim == Person::players[i] &&
2382 Person::players[0]->hasvictim &&
2383 Person::players[0]->animTarget == swordslashanim) &&
2384 attackweapon == sword &&
2385 Person::players[k]->weaponmissdelay <= 0) {
2386 Person::players[k]->animTarget = swordslashanim;
2388 } else if (!(Person::players[0]->victim == Person::players[i] &&
2389 Person::players[0]->hasvictim &&
2390 Person::players[0]->animTarget == swordslashanim) &&
2391 attackweapon == staff &&
2392 Person::players[k]->weaponmissdelay <= 0 &&
2394 Person::players[k]->animTarget = staffhitanim;
2396 } else if (!(Person::players[0]->victim == Person::players[i] &&
2397 Person::players[0]->hasvictim &&
2398 Person::players[0]->animTarget == swordslashanim) &&
2399 attackweapon == staff &&
2400 Person::players[k]->weaponmissdelay <= 0 &&
2402 Person::players[k]->animTarget = staffspinhitanim;
2404 } else if ((!Tutorial::active || !attackweapon) &&
2405 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2407 Animation::animations[Person::players[i]->animTarget].height != lowheight) {
2408 Person::players[k]->animTarget = spinkickanim;
2410 } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2411 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2412 Animation::animations[Person::players[k]->animTarget].attack != normalattack) {
2413 Person::players[k]->animTarget = lowkickanim;
2418 //upunch becomes wolfslap
2419 if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) {
2420 Person::players[k]->animTarget = wolfslapanim;
2424 if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) &&
2425 Person::players[i]->howactive < typedead1 &&
2426 distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2427 !Person::players[i]->skeleton.free &&
2428 Person::players[i]->animTarget != getupfrombackanim &&
2429 Person::players[i]->animTarget != getupfromfrontanim &&
2430 (Person::players[i]->surprised > 0 ||
2431 Person::players[i]->aitype == passivetype ||
2432 attackweapon && Person::players[i]->stunned > 0) &&
2433 normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) {
2435 if (!attackweapon) {
2436 Person::players[k]->animCurrent = sneakattackanim;
2437 Person::players[k]->animTarget = sneakattackanim;
2438 Person::players[i]->animCurrent = sneakattackedanim;
2439 Person::players[i]->animTarget = sneakattackedanim;
2440 Person::players[k]->oldcoords = Person::players[k]->coords;
2441 Person::players[k]->coords = Person::players[i]->coords;
2444 if (attackweapon == knife) {
2445 Person::players[k]->animCurrent = knifesneakattackanim;
2446 Person::players[k]->animTarget = knifesneakattackanim;
2447 Person::players[i]->animCurrent = knifesneakattackedanim;
2448 Person::players[i]->animTarget = knifesneakattackedanim;
2449 Person::players[i]->oldcoords = Person::players[i]->coords;
2450 Person::players[i]->coords = Person::players[k]->coords;
2453 if (attackweapon == sword) {
2454 Person::players[k]->animCurrent = swordsneakattackanim;
2455 Person::players[k]->animTarget = swordsneakattackanim;
2456 Person::players[i]->animCurrent = swordsneakattackedanim;
2457 Person::players[i]->animTarget = swordsneakattackedanim;
2458 Person::players[i]->oldcoords = Person::players[i]->coords;
2459 Person::players[i]->coords = Person::players[k]->coords;
2461 if (attackweapon != staff) {
2462 Person::players[k]->victim = Person::players[i];
2463 Person::players[k]->hasvictim = 1;
2464 Person::players[i]->targettilt2 = 0;
2465 Person::players[i]->frameTarget = 1;
2466 Person::players[i]->frameCurrent = 0;
2467 Person::players[i]->target = 0;
2468 Person::players[i]->velocity = 0;
2469 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2470 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2471 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2472 Person::players[k]->target = Person::players[i]->target;
2473 Person::players[k]->velocity = 0;
2474 Person::players[k]->targetyaw = Person::players[i]->yaw;
2475 Person::players[k]->yaw = Person::players[i]->yaw;
2476 Person::players[i]->targetyaw = Person::players[i]->yaw;
2479 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2480 Person::players[k]->victim == Person::players[i] &&
2481 (!Person::players[i]->skeleton.free)) {
2483 Person::players[k]->frameTarget = 0;
2484 Person::players[k]->target = 0;
2486 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2487 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2488 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2489 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2490 Person::players[k]->lastattack = Person::players[k]->animTarget;
2492 if (Person::players[k]->animTarget == knifefollowanim &&
2493 Person::players[k]->victim == Person::players[i]) {
2495 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2496 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2497 Person::players[k]->victim = Person::players[i];
2498 Person::players[k]->hasvictim = 1;
2499 Person::players[i]->animTarget = knifefollowedanim;
2500 Person::players[i]->animCurrent = knifefollowedanim;
2501 Person::players[i]->targettilt2 = 0;
2502 Person::players[i]->targettilt2 = Person::players[k]->targettilt2;
2503 Person::players[i]->frameTarget = 1;
2504 Person::players[i]->frameCurrent = 0;
2505 Person::players[i]->target = 0;
2506 Person::players[i]->velocity = 0;
2507 Person::players[k]->animCurrent = knifefollowanim;
2508 Person::players[k]->animTarget = knifefollowanim;
2509 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2510 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2511 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2512 Person::players[k]->target = Person::players[i]->target;
2513 Person::players[k]->velocity = 0;
2514 Person::players[k]->oldcoords = Person::players[k]->coords;
2515 Person::players[i]->coords = Person::players[k]->coords;
2516 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
2517 Person::players[i]->yaw = Person::players[k]->targetyaw;
2518 Person::players[k]->yaw = Person::players[k]->targetyaw;
2519 Person::players[i]->yaw = Person::players[k]->targetyaw;
2525 const bool hasstaff = attackweapon == staff;
2526 if (k == 0 && Person::players.size() > 1) {
2527 for (unsigned i = 0; i < Person::players.size(); i++) {
2531 if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) &&
2532 Animation::animations[Person::players[k]->animTarget].attack == neutral) {
2533 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2534 if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) {
2535 if (Person::players[i]->skeleton.free) {
2536 if (distance < 3.5 * sq(Person::players[k]->scale * 5) &&
2537 (Person::players[i]->dead ||
2538 Person::players[i]->skeleton.longdead > 1000 ||
2539 Person::players[k]->isRun() ||
2542 (Person::players[i]->skeleton.longdead > 2000 ||
2543 Person::players[i]->damage > Person::players[i]->damagetolerance / 8 ||
2544 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) &&
2545 distance < 1.5 * sq(Person::players[k]->scale * 5)))) {
2546 Person::players[k]->victim = Person::players[i];
2547 Person::players[k]->hasvictim = 1;
2548 if (attackweapon && !Tutorial::active) {
2550 if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) {
2551 Person::players[k]->animTarget = crouchstabanim;
2554 if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) {
2555 Person::players[k]->animTarget = swordgroundstabanim;
2558 if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) {
2559 Person::players[k]->animTarget = staffgroundsmashanim;
2562 if (distance < 2.5 &&
2563 Person::players[k]->crouchkeydown &&
2564 Person::players[k]->animTarget != crouchstabanim &&
2566 Person::players[i]->dead &&
2567 Person::players[i]->skeleton.free &&
2568 Person::players[i]->skeleton.longdead > 1000) {
2569 Person::players[k]->animTarget = killanim;
2570 terrain.deleteDeadDecals();
2571 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2572 if (Object::objects[l]->model.type == decalstype) {
2573 Object::objects[l]->model.deleteDeadDecals();
2577 if (!Person::players[i]->dead || musictype != 2) {
2578 if (distance < 3.5 &&
2579 (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) &&
2580 Person::players[k]->staggerdelay <= 0 &&
2581 (Person::players[i]->dead ||
2582 Person::players[i]->skeleton.longdead < 300 &&
2583 Person::players[k]->lastattack != spinkickanim &&
2584 Person::players[i]->skeleton.free) &&
2585 (!Person::players[i]->dead || musictype != stream_fighttheme)) {
2586 Person::players[k]->animTarget = dropkickanim;
2587 terrain.deleteDeadDecals();
2588 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2589 if (Object::objects[l]->model.type == decalstype) {
2590 Object::objects[l]->model.deleteDeadDecals();
2598 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2599 Person::players[k]->victim == Person::players[i] &&
2600 (!Person::players[i]->skeleton.free ||
2601 Person::players[k]->animTarget == killanim ||
2602 Person::players[k]->animTarget == crouchstabanim ||
2603 Person::players[k]->animTarget == swordgroundstabanim ||
2604 Person::players[k]->animTarget == staffgroundsmashanim ||
2605 Person::players[k]->animTarget == dropkickanim)) {
2607 Person::players[k]->frameTarget = 0;
2608 Person::players[k]->target = 0;
2610 XYZ targetpoint = Person::players[i]->coords;
2611 if (Person::players[k]->animTarget == crouchstabanim ||
2612 Person::players[k]->animTarget == swordgroundstabanim ||
2613 Person::players[k]->animTarget == staffgroundsmashanim) {
2614 targetpoint += (Person::players[i]->jointPos(abdomen) +
2615 Person::players[i]->jointPos(neck)) /
2617 Person::players[i]->scale;
2619 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, targetpoint);
2620 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, targetpoint);
2622 if (Person::players[k]->animTarget == crouchstabanim || Person::players[k]->animTarget == swordgroundstabanim) {
2623 Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4;
2626 if (Person::players[k]->animTarget == staffgroundsmashanim) {
2627 Person::players[k]->targettilt2 += 10;
2630 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2631 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2632 Person::players[k]->lastattack = Person::players[k]->animTarget;
2634 if (Person::players[k]->animTarget == swordgroundstabanim) {
2635 Person::players[k]->targetyaw += 30;
2641 if (!Person::players[k]->hasvictim) {
2643 for (unsigned i = 0; i < Person::players.size(); i++) {
2644 if (i == k || !(i == 0 || k == 0)) {
2647 if (!Person::players[i]->skeleton.free) {
2648 if (Person::players[k]->hasvictim) {
2649 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) <
2650 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) {
2651 Person::players[k]->victim = Person::players[i];
2654 Person::players[k]->victim = Person::players[i];
2655 Person::players[k]->hasvictim = 1;
2660 if (Person::players[k]->isPlayerControlled()) {
2662 if (Person::players[k]->attackkeydown &&
2663 Person::players[k]->isRun() &&
2664 Person::players[k]->wasRun() &&
2665 ((Person::players[k]->hasvictim &&
2666 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) &&
2667 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) &&
2668 !Person::players[k]->victim->skeleton.free &&
2669 Person::players[k]->victim->animTarget != getupfrombackanim &&
2670 Person::players[k]->victim->animTarget != getupfromfrontanim &&
2671 Animation::animations[Person::players[k]->victim->animTarget].height != lowheight &&
2672 !Person::players[k]->isPlayerControlled() && //wat???
2673 normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 &&
2674 Person::players[k]->rabbitkickenabled) ||
2675 Person::players[k]->jumpkeydown)) {
2677 Person::players[k]->setTargetAnimation(rabbitkickanim);
2681 if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) {
2683 switch (attackweapon) {
2704 void doPlayerCollisions()
2706 static XYZ rotatetarget;
2707 static float collisionradius;
2708 if (Person::players.size() > 1) {
2709 for (unsigned k = 0; k < Person::players.size(); k++) {
2710 for (unsigned i = k + 1; i < Person::players.size(); i++) {
2711 //neither player is part of a reversal
2712 if ((Animation::animations[Person::players[i]->animTarget].attack != reversed &&
2713 Animation::animations[Person::players[i]->animTarget].attack != reversal &&
2714 Animation::animations[Person::players[k]->animTarget].attack != reversed &&
2715 Animation::animations[Person::players[k]->animTarget].attack != reversal) ||
2716 (i != 0 && k != 0)) {
2717 if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed &&
2718 Animation::animations[Person::players[i]->animCurrent].attack != reversal &&
2719 Animation::animations[Person::players[k]->animCurrent].attack != reversed &&
2720 Animation::animations[Person::players[k]->animCurrent].attack != reversal) ||
2721 (i != 0 && k != 0)) {
2722 //neither is sleeping
2723 if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) {
2724 if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) {
2725 //in same patch, neither is climbing
2726 if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx &&
2727 Person::players[i]->whichpatchz == Person::players[k]->whichpatchz &&
2728 Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free &&
2729 Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free &&
2730 Person::players[i]->animTarget != climbanim &&
2731 Person::players[i]->animTarget != hanganim &&
2732 Person::players[k]->animTarget != climbanim &&
2733 Person::players[k]->animTarget != hanganim) {
2734 //players are close (bounding box test)
2735 if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) {
2736 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) {
2737 if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) {
2738 if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) {
2739 if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) {
2740 if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) {
2741 //spread fire from player to player
2742 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2743 if (Person::players[i]->onfire || Person::players[k]->onfire) {
2744 if (!Person::players[i]->onfire) {
2745 Person::players[i]->CatchFire();
2747 if (!Person::players[k]->onfire) {
2748 Person::players[k]->CatchFire();
2753 XYZ tempcoords1 = Person::players[i]->coords;
2754 XYZ tempcoords2 = Person::players[k]->coords;
2755 if (!Person::players[i]->skeleton.oldfree) {
2756 tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale;
2758 if (!Person::players[k]->skeleton.oldfree) {
2759 tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale;
2761 collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2762 if (Person::players[0]->hasvictim) {
2763 if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) {
2764 collisionradius = 3;
2767 if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) &&
2768 (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
2769 distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) {
2770 //jump down on a dead body
2771 if (k == 0 || i == 0) {
2773 if (Person::players[0]->animTarget == jumpdownanim &&
2774 !Person::players[0]->skeleton.oldfree &&
2775 !Person::players[0]->skeleton.free &&
2776 Person::players[l]->skeleton.oldfree &&
2777 Person::players[l]->skeleton.free &&
2778 Person::players[l]->dead &&
2779 Person::players[0]->lastcollide <= 0 &&
2780 fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 &&
2781 distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) {
2782 Person::players[0]->coords.y = Person::players[l]->coords.y;
2783 Person::players[l]->velocity = Person::players[0]->velocity;
2784 Person::players[l]->skeleton.free = 0;
2785 Person::players[l]->yaw = 0;
2786 Person::players[l]->RagDoll(0);
2787 Person::players[l]->DoDamage(20);
2789 Person::players[l]->skeleton.longdead = 0;
2790 Person::players[0]->lastcollide = 1;
2794 if ((Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) ||
2795 (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) ||
2796 (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) {
2797 rotatetarget = Person::players[k]->velocity - Person::players[i]->velocity;
2798 if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim ||
2799 Person::players[i]->skeleton.free) &&
2800 (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim ||
2801 Person::players[k]->skeleton.free)) {
2802 if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
2803 k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) &&
2804 normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) &&
2806 k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral ||
2807 /*i!=0&&*/ Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) ||
2808 (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) &&
2809 (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) &&
2810 k == 0 && !Person::players[i]->skeleton.oldfree && !Person::players[k]->skeleton.oldfree) {
2812 if ((i != 0 || Person::players[i]->skeleton.free) &&
2813 (k != 0 || Person::players[k]->skeleton.free) ||
2814 (Animation::animations[Person::players[i]->animTarget].height == highheight &&
2815 Animation::animations[Person::players[k]->animTarget].height == highheight)) {
2816 if (!Tutorial::active) {
2817 emit_sound_at(heavyimpactsound, Person::players[i]->coords);
2820 Person::players[i]->RagDoll(0);
2821 if (Person::players[i]->damage > Person::players[i]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[i]->dead) {
2822 award_bonus(0, aimbonus);
2824 Person::players[i]->DoDamage(findLengthfast(&rotatetarget) / 4);
2825 Person::players[k]->RagDoll(0);
2826 if (Person::players[k]->damage > Person::players[k]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[k]->dead) {
2827 award_bonus(0, aimbonus); // Huh, again?
2829 Person::players[k]->DoDamage(findLengthfast(&rotatetarget) / 4);
2831 for (unsigned j = 0; j < Person::players[i]->skeleton.joints.size(); j++) {
2832 Person::players[i]->skeleton.joints[j].velocity = Person::players[i]->skeleton.joints[j].velocity / 5 + Person::players[k]->velocity;
2834 for (unsigned j = 0; j < Person::players[k]->skeleton.joints.size(); j++) {
2835 Person::players[k]->skeleton.joints[j].velocity = Person::players[k]->skeleton.joints[j].velocity / 5 + Person::players[i]->velocity;
2840 if ((Animation::animations[Person::players[i]->animTarget].attack == neutral ||
2841 Animation::animations[Person::players[i]->animTarget].attack == normalattack) &&
2842 (Animation::animations[Person::players[k]->animTarget].attack == neutral ||
2843 Animation::animations[Person::players[k]->animTarget].attack == normalattack)) {
2845 if (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0) {
2846 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < .5 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2847 rotatetarget = Person::players[k]->coords - Person::players[i]->coords;
2848 Normalise(&rotatetarget);
2849 Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2;
2850 Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2851 Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2852 if (Person::players[k]->howactive == typeactive || hostile) {
2853 if (Person::players[k]->isIdle()) {
2854 if (Person::players[k]->howactive < typesleeping) {
2855 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
2856 } else if (Person::players[k]->howactive == typesleeping) {
2857 Person::players[k]->setTargetAnimation(getupfromfrontanim);
2859 if (!editorenabled) {
2860 Person::players[k]->howactive = typeactive;
2864 if (Person::players[i]->howactive == typeactive || hostile) {
2865 if (Person::players[i]->isIdle()) {
2866 if (Person::players[i]->howactive < typesleeping) {
2867 Person::players[i]->setTargetAnimation(Person::players[k]->getStop());
2869 Person::players[i]->setTargetAnimation(getupfromfrontanim);
2871 if (!editorenabled) {
2872 Person::players[i]->howactive = typeactive;
2877 //jump down on player
2879 if (k == 0 && i != 0 && Person::players[k]->animTarget == jumpdownanim &&
2880 !Person::players[i]->isCrouch() &&
2881 Person::players[i]->animTarget != rollanim &&
2882 !Person::players[k]->skeleton.oldfree && !Person::players[k]->skeleton.free &&
2883 Person::players[k]->lastcollide <= 0 &&
2884 Person::players[k]->velocity.y < -10) {
2885 Person::players[i]->velocity = Person::players[k]->velocity;
2886 Person::players[k]->velocity = Person::players[k]->velocity * -.5;
2887 Person::players[k]->velocity.y = Person::players[i]->velocity.y;
2888 Person::players[i]->DoDamage(20);
2889 Person::players[i]->RagDoll(0);
2890 Person::players[k]->lastcollide = 1;
2891 award_bonus(k, AboveBonus);
2893 if (i == 0 && k != 0 && Person::players[i]->animTarget == jumpdownanim &&
2894 !Person::players[k]->isCrouch() &&
2895 Person::players[k]->animTarget != rollanim &&
2896 !Person::players[i]->skeleton.oldfree &&
2897 !Person::players[i]->skeleton.free &&
2898 Person::players[i]->lastcollide <= 0 &&
2899 Person::players[i]->velocity.y < -10) {
2900 Person::players[k]->velocity = Person::players[i]->velocity;
2901 Person::players[i]->velocity = Person::players[i]->velocity * -.3;
2902 Person::players[i]->velocity.y = Person::players[k]->velocity.y;
2903 Person::players[k]->DoDamage(20);
2904 Person::players[k]->RagDoll(0);
2905 Person::players[i]->lastcollide = 1;
2906 award_bonus(i, AboveBonus);
2912 Person::players[i]->CheckKick();
2913 Person::players[k]->CheckKick();
2933 static XYZ facing, flatfacing;
2936 /* Pump SDL input events and process non-gameplay related ones */
2940 Values of mainmenu :
2942 2 Menu pause (resume/end game)
2944 4 Controls configuration menu
2945 5 Main game menu (choose level or challenge)
2946 6 Deleting user menu
2947 7 User managment menu (select/add)
2948 8 Choose difficulty menu
2949 9 Challenge level selection menu
2950 10 End of the campaign congratulation (is that really a menu?)
2951 11 Same that 9 ??? => unused
2952 18 stereo configuration
2957 if (mainmenu && endgame == 1) {
2960 //go to level select after completing a campaign level
2961 if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) {
2968 OPENAL_SetFrequency(OPENAL_ALL);
2969 emit_stream_np(stream_menutheme);
2970 pause_sound(leveltheme);
2982 hostiletime += multiplier;
2987 leveltime += multiplier;
2993 inputText(consoletext[0], &consoleselected);
2995 if (!consoletext[0].empty()) {
2996 cmd_dispatch(consoletext[0]);
2997 for (int k = 14; k >= 1; k--) {
2998 consoletext[k] = consoletext[k - 1];
3000 consoletext[0].clear();
3001 consoleselected = 0;
3005 consoleblinkdelay -= multiplier;
3006 if (consoleblinkdelay <= 0) {
3007 consoleblinkdelay = .3;
3008 consoleblink = !consoleblink;
3012 static int oldwinfreeze;
3013 if (winfreeze && !oldwinfreeze) {
3014 OPENAL_SetFrequency(OPENAL_ALL);
3015 emit_sound_np(consolesuccesssound);
3017 if (winfreeze == 0) {
3018 oldwinfreeze = winfreeze;
3023 if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
3026 static float talkdelay = 0;
3028 if (Dialog::inDialog()) {
3031 talkdelay -= multiplier;
3033 if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) {
3034 for (unsigned i = 0; i < Dialog::dialogs.size(); i++) {
3035 Dialog::dialogs[i].tick(i);
3039 windvar += multiplier;
3040 smoketex += multiplier;
3041 Tutorial::stagetime += multiplier;
3044 static float hotspotvisual[40];
3045 if (Hotspot::hotspots.size()) {
3047 if (editorenabled) {
3048 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3049 hotspotvisual[i] -= multiplier / 320;
3053 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3054 while (hotspotvisual[i] < 0) {
3056 hotspotsprite.x = float(abs(Random() % 100000)) / 100000 * Hotspot::hotspots[i].size;
3057 hotspotsprite = DoRotation(hotspotsprite, 0, 0, Random() % 360);
3058 hotspotsprite = DoRotation(hotspotsprite, 0, Random() % 360, 0);
3059 hotspotsprite += Hotspot::hotspots[i].position;
3060 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite * 0, 1, 0.5, 0, 7, 0.4);
3061 hotspotvisual[i] += 0.1 / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size;
3065 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3066 if (Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type > 0) {
3067 Hotspot::hotspots[i].position = Person::players[Hotspot::hotspots[i].type]->coords;
3073 if (Tutorial::active) {
3074 Tutorial::Do(multiplier);
3078 if (!Tutorial::active) {
3079 if (bonustime == 0 &&
3080 bonus != solidhit &&
3081 bonus != spinecrusher &&
3082 bonus != tracheotomy &&
3083 bonus != backstab &&
3085 emit_sound_np(consolesuccesssound);
3087 } else if (bonustime == 0) {
3088 emit_sound_np(fireendsound);
3090 if (bonustime == 0) {
3091 if (bonus != solidhit &&
3092 bonus != twoxcombo &&
3093 bonus != threexcombo &&
3094 bonus != fourxcombo &&
3095 bonus != megacombo) {
3098 bonusnum[bonus] += 0.15;
3100 if (Tutorial::active) {
3103 if (bonusvalue > 0) {
3104 bonusvalue /= bonusnum[bonus];
3105 if (bonusvalue <= 0) {
3109 bonustotal += bonusvalue;
3111 bonustime += multiplier;
3114 if (environment == snowyenvironment) {
3115 precipdelay -= multiplier;
3116 while (precipdelay < 0) {
3121 XYZ footvel, footpoint;
3124 footpoint = viewer + viewerfacing * 6;
3125 footpoint.y += ((float)abs(Random() % 1200)) / 100 - 6;
3126 footpoint.x += ((float)abs(Random() % 1200)) / 100 - 6;
3127 footpoint.z += ((float)abs(Random() % 1200)) / 100 - 6;
3128 Sprite::MakeSprite(snowsprite, footpoint, footvel, 1, 1, 1, .1, 1);
3132 doAerialAcrobatics();
3134 static XYZ oldviewer;
3137 if (!Dialog::inDialog()) {
3138 Person::players[0]->forwardkeydown = Input::isKeyDown(forwardkey);
3139 Person::players[0]->leftkeydown = Input::isKeyDown(leftkey);
3140 Person::players[0]->backkeydown = Input::isKeyDown(backkey);
3141 Person::players[0]->rightkeydown = Input::isKeyDown(rightkey);
3142 Person::players[0]->jumpkeydown = Input::isKeyDown(jumpkey);
3143 Person::players[0]->crouchkeydown = Input::isKeyDown(crouchkey);
3144 Person::players[0]->drawkeydown = Input::isKeyDown(drawkey);
3145 Person::players[0]->throwkeydown = Input::isKeyDown(throwkey);
3147 Person::players[0]->forwardkeydown = 0;
3148 Person::players[0]->leftkeydown = 0;
3149 Person::players[0]->backkeydown = 0;
3150 Person::players[0]->rightkeydown = 0;
3151 Person::players[0]->jumpkeydown = 0;
3152 Person::players[0]->crouchkeydown = 0;
3153 Person::players[0]->drawkeydown = 0;
3154 Person::players[0]->throwkeydown = 0;
3157 if (!Person::players[0]->jumpkeydown) {
3158 Person::players[0]->jumpclimb = 0;
3161 if (Dialog::inDialog()) {
3163 if (Dialog::directing) {
3167 facing = DoRotation(facing, -pitch, 0, 0);
3168 facing = DoRotation(facing, 0, 0 - yaw, 0);
3173 flatfacing = DoRotation(flatfacing, 0, -yaw, 0);
3175 if (Input::isKeyDown(forwardkey)) {
3176 viewer += facing * multiplier * 4;
3178 if (Input::isKeyDown(backkey)) {
3179 viewer -= facing * multiplier * 4;
3181 if (Input::isKeyDown(leftkey)) {
3182 viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4;
3184 if (Input::isKeyDown(rightkey)) {
3185 viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4;
3187 if (Input::isKeyDown(jumpkey)) {
3188 viewer.y += multiplier * 4;
3190 if (Input::isKeyDown(crouchkey)) {
3191 viewer.y -= multiplier * 4;
3193 if (Input::isKeyPressed(SDL_SCANCODE_1) ||
3194 Input::isKeyPressed(SDL_SCANCODE_2) ||
3195 Input::isKeyPressed(SDL_SCANCODE_3) ||
3196 Input::isKeyPressed(SDL_SCANCODE_4) ||
3197 Input::isKeyPressed(SDL_SCANCODE_5) ||
3198 Input::isKeyPressed(SDL_SCANCODE_6) ||
3199 Input::isKeyPressed(SDL_SCANCODE_7) ||
3200 Input::isKeyPressed(SDL_SCANCODE_8) ||
3201 Input::isKeyPressed(SDL_SCANCODE_9) ||
3202 Input::isKeyPressed(SDL_SCANCODE_0) ||
3203 Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3205 if (Input::isKeyPressed(SDL_SCANCODE_1)) {
3208 if (Input::isKeyPressed(SDL_SCANCODE_2)) {
3211 if (Input::isKeyPressed(SDL_SCANCODE_3)) {
3214 if (Input::isKeyPressed(SDL_SCANCODE_4)) {
3217 if (Input::isKeyPressed(SDL_SCANCODE_5)) {
3220 if (Input::isKeyPressed(SDL_SCANCODE_6)) {
3223 if (Input::isKeyPressed(SDL_SCANCODE_7)) {
3226 if (Input::isKeyPressed(SDL_SCANCODE_8)) {
3229 if (Input::isKeyPressed(SDL_SCANCODE_9)) {
3232 if (Input::isKeyPressed(SDL_SCANCODE_0)) {
3235 if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3238 if (whichend != -1) {
3239 Dialog::currentScene().participantfocus = whichend;
3240 Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords;
3241 Dialog::currentDialog().participantyaw[whichend] = Person::players[whichend]->yaw;
3243 if (whichend == -1) {
3244 Dialog::currentScene().participantfocus = -1;
3246 /* FIXME: potentially accessing -1 in Person::players! */
3247 if (Person::players[Dialog::currentScene().participantfocus]->dead) {
3248 Dialog::indialogue = -1;
3249 Dialog::directing = false;
3252 Dialog::currentScene().camera = viewer;
3253 Dialog::currentScene().camerayaw = yaw;
3254 Dialog::currentScene().camerapitch = pitch;
3255 Dialog::indialogue++;
3256 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3257 if (Dialog::currentScene().sound != 0) {
3258 playdialoguescenesound();
3262 for (unsigned j = 0; j < Person::players.size(); j++) {
3263 Dialog::currentScene().participantfacing[j] = Dialog::currentDialog().scenes[Dialog::indialogue - 1].participantfacing[j];
3266 //TODO: should these be KeyDown or KeyPressed?
3267 if (Input::isKeyDown(SDL_SCANCODE_KP_1) ||
3268 Input::isKeyDown(SDL_SCANCODE_KP_2) ||
3269 Input::isKeyDown(SDL_SCANCODE_KP_3) ||
3270 Input::isKeyDown(SDL_SCANCODE_KP_4) ||
3271 Input::isKeyDown(SDL_SCANCODE_KP_5) ||
3272 Input::isKeyDown(SDL_SCANCODE_KP_6) ||
3273 Input::isKeyDown(SDL_SCANCODE_KP_7) ||
3274 Input::isKeyDown(SDL_SCANCODE_KP_8) ||
3275 Input::isKeyDown(SDL_SCANCODE_KP_9) ||
3276 Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3278 if (Input::isKeyDown(SDL_SCANCODE_KP_1)) {
3281 if (Input::isKeyDown(SDL_SCANCODE_KP_2)) {
3284 if (Input::isKeyDown(SDL_SCANCODE_KP_3)) {
3287 if (Input::isKeyDown(SDL_SCANCODE_KP_4)) {
3290 if (Input::isKeyDown(SDL_SCANCODE_KP_5)) {
3293 if (Input::isKeyDown(SDL_SCANCODE_KP_6)) {
3296 if (Input::isKeyDown(SDL_SCANCODE_KP_7)) {
3299 if (Input::isKeyDown(SDL_SCANCODE_KP_8)) {
3302 if (Input::isKeyDown(SDL_SCANCODE_KP_9)) {
3305 if (Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3308 Dialog::currentScene().participantfacing[whichend] = facing;
3310 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3311 Dialog::indialogue = -1;
3312 Dialog::directing = false;
3316 if (!Dialog::directing) {
3317 pause_sound(whooshsound);
3318 viewer = Dialog::currentScene().camera;
3319 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .1);
3320 yaw = Dialog::currentScene().camerayaw;
3321 pitch = Dialog::currentScene().camerapitch;
3322 if (Dialog::dialoguetime > 0.5) {
3323 if (Input::isKeyPressed(attackkey)) {
3324 Dialog::indialogue++;
3325 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3326 if (Dialog::currentScene().sound != 0) {
3327 playdialoguescenesound();
3328 if (Dialog::currentScene().sound == -5) {
3329 Hotspot::hotspots.emplace_back(Person::players[0]->coords, -1, 10);
3331 if (Dialog::currentScene().sound == -6) {
3335 if (Person::players.at(Dialog::currentScene().participantfocus)->dead) {
3336 Dialog::indialogue = -1;
3337 Dialog::directing = false;
3344 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3345 Dialog::indialogue = -1;
3346 Dialog::directing = false;
3348 if (Dialog::currentDialog().type > 19 && Dialog::currentDialog().type < 30) {
3351 if (Dialog::currentDialog().type > 29 && Dialog::currentDialog().type < 40) {
3354 if (Dialog::currentDialog().type > 49 && Dialog::currentDialog().type < 60) {
3356 for (unsigned i = 1; i < Person::players.size(); i++) {
3357 Person::players[i]->aitype = attacktypecutoff;
3364 if (!Person::players[0]->jumpkeydown) {
3365 Person::players[0]->jumptogglekeydown = 0;
3367 if (Person::players[0]->jumpkeydown &&
3368 Person::players[0]->animTarget != jumpupanim &&
3369 Person::players[0]->animTarget != jumpdownanim &&
3370 !Person::players[0]->isFlip()) {
3371 Person::players[0]->jumptogglekeydown = 1;
3374 Dialog::dialoguetime += multiplier;
3375 hawkyaw += multiplier * 25;
3377 realhawkcoords.x = 25;
3378 realhawkcoords = DoRotation(realhawkcoords, 0, hawkyaw, 0) + hawkcoords;
3379 hawkcalldelay -= multiplier / 2;
3381 if (hawkcalldelay <= 0) {
3382 emit_sound_at(hawksound, realhawkcoords);
3384 hawkcalldelay = 16 + abs(Random() % 8);
3389 doPlayerCollisions();
3393 for (unsigned k = 0; k < Person::players.size(); k++) {
3394 if (k != 0 && Person::players[k]->immobile) {
3395 Person::players[k]->coords = Person::players[k]->realoldcoords;
3399 for (unsigned k = 0; k < Person::players.size(); k++) {
3400 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3401 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3402 Person::players[k]->DoDamage(1000);
3408 static bool respawnkeydown;
3409 if (!editorenabled &&
3410 (whichlevel != -2 &&
3411 (Input::isKeyDown(SDL_SCANCODE_K) &&
3412 Input::isKeyDown(SDL_SCANCODE_LALT) &&
3414 (Input::isKeyDown(jumpkey) &&
3417 Person::players[0]->dead))) {
3418 targetlevel = whichlevel;
3422 respawnkeydown = Input::isKeyDown(jumpkey);
3424 static bool movekey;
3427 for (unsigned i = 0; i < Person::players.size(); i++) {
3428 static float oldtargetyaw;
3429 if (!Person::players[i]->skeleton.free) {
3430 oldtargetyaw = Person::players[i]->targetyaw;
3431 if (i == 0 && !Dialog::inDialog()) {
3432 //TODO: refactor repetitive code
3433 if (!Animation::animations[Person::players[0]->animTarget].attack &&
3434 Person::players[0]->animTarget != staggerbackhighanim &&
3435 Person::players[0]->animTarget != staggerbackhardanim &&
3436 Person::players[0]->animTarget != crouchremoveknifeanim &&
3437 Person::players[0]->animTarget != removeknifeanim &&
3438 Person::players[0]->animTarget != backhandspringanim &&
3439 Person::players[0]->animTarget != dodgebackanim &&
3440 Person::players[0]->animTarget != walljumprightkickanim &&
3441 Person::players[0]->animTarget != walljumpleftkickanim) {
3443 Person::players[0]->targetyaw = 0;
3445 Person::players[0]->targetyaw = -yaw + 180;
3452 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3454 facing = flatfacing;
3456 facing = DoRotation(facing, -pitch, 0, 0);
3457 facing = DoRotation(facing, 0, 0 - yaw, 0);
3460 Person::players[0]->lookyaw = -yaw;
3462 Person::players[i]->targetheadyaw = yaw;
3463 Person::players[i]->targetheadpitch = pitch;
3465 if (i != 0 && Person::players[i]->isPlayerControlled() && !Dialog::inDialog()) {
3466 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3467 Person::players[i]->animTarget != staggerbackhighanim &&
3468 Person::players[i]->animTarget != staggerbackhardanim &&
3469 Person::players[i]->animTarget != crouchremoveknifeanim &&
3470 Person::players[i]->animTarget != removeknifeanim &&
3471 Person::players[i]->animTarget != backhandspringanim &&
3472 Person::players[i]->animTarget != dodgebackanim &&
3473 Person::players[i]->animTarget != walljumprightkickanim &&
3474 Person::players[i]->animTarget != walljumpleftkickanim) {
3475 Person::players[i]->targetyaw = -Person::players[i]->lookyaw + 180;
3481 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3483 facing = DoRotation(facing, -Person::players[i]->lookpitch, 0, 0);
3484 facing = DoRotation(facing, 0, 0 - Person::players[i]->lookyaw, 0);
3486 Person::players[i]->targetheadyaw = Person::players[i]->lookyaw;
3487 Person::players[i]->targetheadpitch = Person::players[i]->lookpitch;
3489 if (Dialog::inDialog()) {
3490 Person::players[i]->targetheadyaw = 180 - roughDirection(Dialog::currentScene().participantfacing[i]);
3491 Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]);
3494 if (leveltime < .5) {
3498 Person::players[i]->avoidsomething = 0;
3500 //avoid flaming things
3501 for (unsigned int j = 0; j < Object::objects.size(); j++) {
3502 if (Object::objects[j]->onfire) {
3503 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) {
3504 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3505 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3506 Person::players[i]->collided = 0;
3507 Person::players[i]->avoidcollided = 1;
3508 if (Person::players[i]->avoidsomething == 0 ||
3509 distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3510 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3511 Person::players[i]->avoidwhere = Object::objects[j]->position;
3512 Person::players[i]->avoidsomething = 1;
3519 //avoid flaming players
3520 for (unsigned j = 0; j < Person::players.size(); j++) {
3521 if (Person::players[j]->onfire) {
3522 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) {
3523 if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3524 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3525 Person::players[i]->collided = 0;
3526 Person::players[i]->avoidcollided = 1;
3527 if (Person::players[i]->avoidsomething == 0 ||
3528 distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3529 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3530 Person::players[i]->avoidwhere = Person::players[j]->coords;
3531 Person::players[i]->avoidsomething = 1;
3538 if (Person::players[i]->collided > .8) {
3539 Person::players[i]->avoidcollided = 0;
3542 Person::players[i]->doAI();
3544 if (Animation::animations[Person::players[i]->animTarget].attack == reversed) {
3545 //Person::players[i]->targetyaw=Person::players[i]->yaw;
3546 Person::players[i]->forwardkeydown = 0;
3547 Person::players[i]->leftkeydown = 0;
3548 Person::players[i]->backkeydown = 0;
3549 Person::players[i]->rightkeydown = 0;
3550 Person::players[i]->jumpkeydown = 0;
3551 Person::players[i]->attackkeydown = 0;
3552 //Person::players[i]->crouchkeydown=0;
3553 Person::players[i]->throwkeydown = 0;
3556 if (Dialog::inDialog()) {
3557 Person::players[i]->forwardkeydown = 0;
3558 Person::players[i]->leftkeydown = 0;
3559 Person::players[i]->backkeydown = 0;
3560 Person::players[i]->rightkeydown = 0;
3561 Person::players[i]->jumpkeydown = 0;
3562 Person::players[i]->crouchkeydown = 0;
3563 Person::players[i]->drawkeydown = 0;
3564 Person::players[i]->throwkeydown = 0;
3567 if (Person::players[i]->collided < -.3) {
3568 Person::players[i]->collided = -.3;
3570 if (Person::players[i]->collided > 1) {
3571 Person::players[i]->collided = 1;
3573 Person::players[i]->collided -= multiplier * 4;
3574 Person::players[i]->whichdirectiondelay -= multiplier;
3575 if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) {
3576 Person::players[i]->avoidcollided = -.3;
3577 Person::players[i]->whichdirection = abs(Random() % 2);
3578 Person::players[i]->whichdirectiondelay = .4;
3580 if (Person::players[i]->avoidcollided > 1) {
3581 Person::players[i]->avoidcollided = 1;
3583 Person::players[i]->avoidcollided -= multiplier / 4;
3584 if (!Person::players[i]->skeleton.free) {
3585 Person::players[i]->stunned -= multiplier;
3586 Person::players[i]->surprised -= multiplier;
3588 if (i != 0 && Person::players[i]->surprised <= 0 &&
3589 Person::players[i]->aitype == attacktypecutoff &&
3590 !Person::players[i]->dead &&
3591 !Person::players[i]->skeleton.free &&
3592 Animation::animations[Person::players[i]->animTarget].attack == neutral) {
3596 if (!Person::players[i]->throwkeydown) {
3597 Person::players[i]->throwtogglekeydown = 0;
3601 if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) {
3602 if (!Person::players[i]->hasWeapon() &&
3603 Person::players[i]->num_weapons < 2 &&
3604 (Person::players[i]->isIdle() ||
3605 Person::players[i]->isCrouch() ||
3606 Person::players[i]->animTarget == sneakanim ||
3607 Person::players[i]->animTarget == rollanim ||
3608 Person::players[i]->animTarget == backhandspringanim ||
3609 Person::players[i]->isFlip() ||
3610 !Person::players[i]->isPlayerControlled())) {
3611 for (unsigned j = 0; j < weapons.size(); j++) {
3612 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3613 Person::players[i]->isPlayerControlled()) &&
3614 weapons[j].owner == -1 &&
3615 !Person::players[i]->hasWeapon()) {
3616 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) {
3617 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) {
3618 if (Person::players[i]->isCrouch() ||
3619 Person::players[i]->animTarget == sneakanim ||
3620 Person::players[i]->isRun() ||
3621 Person::players[i]->isIdle() ||
3622 !Person::players[i]->isPlayerControlled()) {
3623 Person::players[i]->throwtogglekeydown = 1;
3624 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3625 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3626 Person::players[i]->hasvictim = 0;
3628 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3629 Person::players[i]->throwtogglekeydown = 1;
3630 Person::players[i]->hasvictim = 0;
3632 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3633 Person::players[i]->isPlayerControlled()) &&
3634 weapons[j].owner == -1 ||
3635 Person::players[i]->victim &&
3636 weapons[j].owner == int(Person::players[i]->victim->id)) {
3637 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && !Person::players[i]->hasWeapon()) {
3638 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) {
3639 if (weapons[j].getType() != staff) {
3640 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3643 Person::players[i]->takeWeapon(j);
3648 } else if ((Person::players[i]->isIdle() ||
3649 Person::players[i]->isFlip() ||
3650 !Person::players[i]->isPlayerControlled()) &&
3651 distsq(&Person::players[i]->coords, &weapons[j].position) < 5 &&
3652 Person::players[i]->coords.y < weapons[j].position.y) {
3653 if (!Person::players[i]->isFlip()) {
3654 Person::players[i]->throwtogglekeydown = 1;
3655 Person::players[i]->setTargetAnimation(removeknifeanim);
3656 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3658 if (Person::players[i]->isFlip()) {
3659 Person::players[i]->throwtogglekeydown = 1;
3660 Person::players[i]->hasvictim = 0;
3662 for (unsigned k = 0; k < weapons.size(); k++) {
3663 if (!Person::players[i]->hasWeapon()) {
3664 if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 ||
3665 Person::players[i]->isPlayerControlled()) &&
3666 weapons[k].owner == -1 ||
3667 Person::players[i]->victim &&
3668 weapons[k].owner == int(Person::players[i]->victim->id)) {
3669 if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 &&
3670 !Person::players[i]->hasWeapon()) {
3671 if (weapons[k].getType() != staff) {
3672 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3675 Person::players[i]->takeWeapon(k);
3685 if (Person::players[i]->isCrouch() ||
3686 Person::players[i]->animTarget == sneakanim ||
3687 Person::players[i]->isRun() ||
3688 Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim ||
3689 Person::players[i]->animTarget == backhandspringanim) {
3690 if (Person::players.size() > 1) {
3691 for (unsigned j = 0; j < Person::players.size(); j++) {
3692 if (!Person::players[i]->hasWeapon()) {
3694 if (Person::players[j]->num_weapons &&
3695 Person::players[j]->skeleton.free &&
3696 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ &&
3697 (((Person::players[j]->skeleton.forward.y < 0 &&
3698 Person::players[j]->weaponstuckwhere == 0) ||
3699 (Person::players[j]->skeleton.forward.y > 0 &&
3700 Person::players[j]->weaponstuckwhere == 1)) ||
3701 Person::players[j]->weaponstuck == -1 ||
3702 Person::players[j]->num_weapons > 1)) {
3703 if (Person::players[i]->animTarget != rollanim && Person::players[i]->animTarget != backhandspringanim) {
3704 Person::players[i]->throwtogglekeydown = 1;
3705 Person::players[i]->victim = Person::players[j];
3706 Person::players[i]->hasvictim = 1;
3707 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3708 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3710 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3711 Person::players[i]->throwtogglekeydown = 1;
3712 Person::players[i]->victim = Person::players[j];
3713 Person::players[i]->hasvictim = 1;
3714 int k = Person::players[j]->weaponids[0];
3715 if (Person::players[i]->hasvictim) {
3718 if (Person::players[i]->victim->weaponstuck != -1) {
3719 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3724 if (weapons[k].getType() != staff) {
3725 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3729 emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.);
3732 if (weapons[k].owner != -1) {
3733 if (Person::players[i]->victim->num_weapons == 1) {
3734 Person::players[i]->victim->num_weapons = 0;
3736 Person::players[i]->victim->num_weapons = 1;
3739 Person::players[i]->victim->skeleton.longdead = 0;
3740 Person::players[i]->victim->skeleton.free = 1;
3741 Person::players[i]->victim->skeleton.broken = 0;
3743 for (unsigned l = 0; l < Person::players[i]->victim->skeleton.joints.size(); l++) {
3744 Person::players[i]->victim->skeleton.joints[l].velchange = 0;
3745 Person::players[i]->victim->skeleton.joints[l].locked = 0;
3751 Normalise(&relative);
3752 XYZ footvel, footpoint;
3754 footpoint = weapons[k].position;
3755 if (Person::players[i]->victim->weaponstuck != -1) {
3756 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3758 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
3760 weapons[k].bloody = 2;
3761 weapons[k].blooddrip = 5;
3762 Person::players[i]->victim->weaponstuck = -1;
3763 Person::players[i]->victim->bloodloss += 2000;
3764 Person::players[i]->victim->DoDamage(2000);
3767 if (Person::players[i]->victim->num_weapons > 0) {
3768 if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) {
3769 Person::players[i]->victim->weaponstuck = 0;
3771 if (Person::players[i]->victim->weaponids[0] == k) {
3772 Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons];
3776 Person::players[i]->victim->weaponactive = -1;
3778 Person::players[i]->victim->jointVel(abdomen) += relative * 6;
3779 Person::players[i]->victim->jointVel(neck) += relative * 6;
3780 Person::players[i]->victim->jointVel(rightshoulder) += relative * 6;
3781 Person::players[i]->victim->jointVel(leftshoulder) += relative * 6;
3783 Person::players[i]->takeWeapon(k);
3793 if (Person::players[i]->hasWeapon() && Person::players[i]->isPlayerControlled()) {
3794 if (weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3795 if (Person::players[i]->isIdle() ||
3796 Person::players[i]->isRun() ||
3797 Person::players[i]->isCrouch() ||
3798 Person::players[i]->animTarget == sneakanim ||
3799 Person::players[i]->isFlip()) {
3800 if (Person::players.size() > 1) {
3801 for (unsigned j = 0; j < Person::players.size(); j++) {
3803 if (!Tutorial::active || Tutorial::stage == 49) {
3805 if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 &&
3806 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 &&
3807 distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 &&
3808 !Person::players[j]->skeleton.free &&
3809 -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)) {
3810 if (!Person::players[i]->isFlip()) {
3811 Person::players[i]->throwtogglekeydown = 1;
3812 Person::players[i]->victim = Person::players[j];
3813 Person::players[i]->setTargetAnimation(knifethrowanim);
3814 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3815 Person::players[i]->targettilt2 = pitchTo(Person::players[i]->coords, Person::players[j]->coords);
3817 if (Person::players[i]->isFlip()) {
3818 if (Person::players[i]->hasWeapon()) {
3819 Person::players[i]->throwtogglekeydown = 1;
3820 Person::players[i]->victim = Person::players[j];
3822 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);
3825 aim = DoRotation(aim, (float)abs(Random() % 30) - 15, (float)abs(Random() % 30) - 15, 0);
3827 weapons[Person::players[i]->weaponids[0]].thrown(aim * 50, false);
3828 Person::players[i]->num_weapons--;
3829 if (Person::players[i]->num_weapons) {
3830 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3832 Person::players[i]->weaponactive = -1;
3844 if (Person::players[i]->hasWeapon() && Person::players[i]->isPlayerControlled()) {
3845 if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) {
3846 Person::players[i]->throwtogglekeydown = 1;
3847 XYZ tempVelocity = Person::players[i]->velocity * .2;
3848 if (tempVelocity.x == 0) {
3849 tempVelocity.x = .1;
3851 weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false);
3852 Person::players[i]->num_weapons--;
3853 if (Person::players[i]->num_weapons) {
3854 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3855 if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) {
3856 Person::players[i]->weaponstuck = 0;
3860 Person::players[i]->weaponactive = -1;
3861 for (unsigned j = 0; j < Person::players.size(); j++) {
3862 Person::players[j]->wentforweapon = 0;
3869 if (i == 0 || !Person::players[0]->dead || (Person::players[i]->hasWeapon())) {
3870 if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown ||
3871 (Person::players[i]->num_weapons == 2) &&
3872 (!Person::players[i]->hasWeapon()) &&
3873 Person::players[i]->isIdle() ||
3874 Person::players[0]->dead &&
3875 (Person::players[i]->hasWeapon()) &&
3878 if (Person::players[i]->hasWeapon()) {
3879 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) {
3883 if (isgood && Person::players[i]->creature != wolftype) {
3884 if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3885 Person::players[i]->setTargetAnimation(drawrightanim);
3886 Person::players[i]->drawtogglekeydown = 1;
3888 if ((Person::players[i]->isIdle() ||
3889 (!Person::players[i]->isPlayerControlled() &&
3890 Person::players[0]->hasWeapon() &&
3891 Person::players[i]->isRun())) &&
3892 Person::players[i]->num_weapons &&
3893 weapons[Person::players[i]->weaponids[0]].getType() == sword) {
3894 Person::players[i]->setTargetAnimation(drawleftanim);
3895 Person::players[i]->drawtogglekeydown = 1;
3897 if (Person::players[i]->isCrouch() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3898 Person::players[i]->setTargetAnimation(crouchdrawrightanim);
3899 Person::players[i]->drawtogglekeydown = 1;
3906 if (Person::players[i]->hasWeapon()) {
3907 if (Person::players[i]->isCrouch() &&
3908 weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody &&
3910 Person::players[i]->onterrain &&
3911 Person::players[i]->num_weapons &&
3912 Person::players[i]->attackkeydown &&
3913 musictype != stream_fighttheme) {
3914 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) {
3915 Person::players[i]->setTargetAnimation(crouchstabanim);
3917 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) {
3918 Person::players[i]->setTargetAnimation(swordgroundstabanim);
3920 Person::players[i]->hasvictim = 0;
3924 if (!Person::players[i]->drawkeydown) {
3925 Person::players[i]->drawtogglekeydown = 0;
3931 absflatfacing.z = -1;
3933 absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0);
3935 absflatfacing = flatfacing;
3938 if (Dialog::inDialog()) {
3939 Person::players[i]->forwardkeydown = 0;
3940 Person::players[i]->leftkeydown = 0;
3941 Person::players[i]->backkeydown = 0;
3942 Person::players[i]->rightkeydown = 0;
3943 Person::players[i]->jumpkeydown = 0;
3944 Person::players[i]->crouchkeydown = 0;
3945 Person::players[i]->drawkeydown = 0;
3946 Person::players[i]->throwkeydown = 0;
3950 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3951 Person::players[i]->animTarget != staggerbackhighanim &&
3952 Person::players[i]->animTarget != staggerbackhardanim &&
3953 Person::players[i]->animTarget != backhandspringanim &&
3954 Person::players[i]->animTarget != dodgebackanim) {
3955 if (!Person::players[i]->forwardkeydown) {
3956 Person::players[i]->forwardstogglekeydown = 0;
3958 if (Person::players[i]->crouchkeydown) {
3962 Person::players[i]->superruntoggle = 1;
3963 if (Person::players.size() > 1) {
3964 for (unsigned j = 0; j < Person::players.size(); j++) {
3965 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) {
3966 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) {
3967 Person::players[i]->superruntoggle = 0;
3974 if (Person::players.size() > 1) {
3975 for (unsigned j = 0; j < Person::players.size(); j++) {
3976 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) {
3977 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
3978 Person::players[j]->victim == Person::players[i] &&
3979 (Person::players[j]->animTarget == sweepanim ||
3980 Person::players[j]->animTarget == upunchanim ||
3981 Person::players[j]->animTarget == wolfslapanim ||
3982 ((Person::players[j]->animTarget == swordslashanim ||
3983 Person::players[j]->animTarget == knifeslashstartanim ||
3984 Person::players[j]->animTarget == staffhitanim ||
3985 Person::players[j]->animTarget == staffspinhitanim) &&
3986 distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) {
3997 Person::players[target]->Reverse();
3999 Person::players[i]->lowreversaldelay = .5;
4001 if (Person::players[i]->isIdle()) {
4002 Person::players[i]->setTargetAnimation(Person::players[i]->getCrouch());
4003 Person::players[i]->transspeed = 10;
4005 if (Person::players[i]->isRun() ||
4006 (Person::players[i]->isStop() &&
4007 (Person::players[i]->leftkeydown ||
4008 Person::players[i]->rightkeydown ||
4009 Person::players[i]->forwardkeydown ||
4010 Person::players[i]->backkeydown))) {
4011 Person::players[i]->setTargetAnimation(rollanim);
4012 Person::players[i]->transspeed = 20;
4015 if (!Person::players[i]->crouchkeydown) {
4017 if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) {
4018 Person::players[i]->superruntoggle = 0;
4021 if (Person::players[i]->isCrouch()) {
4022 if (Person::players.size() > 1) {
4023 for (unsigned j = 0; j < Person::players.size(); j++) {
4025 !Person::players[j]->skeleton.free &&
4026 Person::players[j]->victim &&
4027 Person::players[i]->highreversaldelay <= 0) {
4028 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4029 Person::players[j]->victim == Person::players[i] &&
4030 (Person::players[j]->animTarget == spinkickanim) &&
4031 Person::players[i]->isCrouch()) {
4042 Person::players[target]->Reverse();
4044 Person::players[i]->highreversaldelay = .5;
4046 if (Person::players[i]->isCrouch()) {
4047 if (!Person::players[i]->wasCrouch()) {
4048 Person::players[i]->animCurrent = Person::players[i]->getCrouch();
4049 Person::players[i]->frameCurrent = 0;
4051 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4052 Person::players[i]->transspeed = 10;
4055 if (Person::players[i]->animTarget == sneakanim) {
4056 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
4057 Person::players[i]->transspeed = 10;
4060 if (Person::players[i]->forwardkeydown) {
4061 if (Person::players[i]->isIdle() ||
4062 (Person::players[i]->isStop() &&
4063 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4064 (Person::players[i]->isLanding() &&
4065 Person::players[i]->frameTarget > 0 &&
4066 !Person::players[i]->jumpkeydown) ||
4067 (Person::players[i]->isLandhard() &&
4068 Person::players[i]->frameTarget > 0 &&
4069 !Person::players[i]->jumpkeydown &&
4070 Person::players[i]->crouchkeydown)) {
4071 if (Person::players[i]->aitype == passivetype) {
4072 Person::players[i]->setTargetAnimation(walkanim);
4074 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4077 if (Person::players[i]->isCrouch()) {
4078 Person::players[i]->animTarget = sneakanim;
4079 if (Person::players[i]->wasCrouch()) {
4080 Person::players[i]->target = 0;
4082 Person::players[i]->frameTarget = 0;
4084 if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||!Person::players[i]->isPlayerControlled())*/) {
4085 Person::players[i]->setTargetAnimation(climbanim);
4086 Person::players[i]->frameTarget = 1;
4087 Person::players[i]->jumpclimb = 1;
4089 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4090 Person::players[i]->velocity += absflatfacing * 5 * multiplier;
4092 Person::players[i]->forwardstogglekeydown = 1;
4095 if (Person::players[i]->rightkeydown) {
4096 if (Person::players[i]->isIdle() ||
4097 (Person::players[i]->isStop() &&
4098 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4099 (Person::players[i]->isLanding() &&
4100 Person::players[i]->frameTarget > 0 &&
4101 !Person::players[i]->jumpkeydown) ||
4102 (Person::players[i]->isLandhard() &&
4103 Person::players[i]->frameTarget > 0 &&
4104 !Person::players[i]->jumpkeydown &&
4105 Person::players[i]->crouchkeydown)) {
4106 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4108 if (Person::players[i]->isCrouch()) {
4109 Person::players[i]->animTarget = sneakanim;
4110 if (Person::players[i]->wasCrouch()) {
4111 Person::players[i]->target = 0;
4113 Person::players[i]->frameTarget = 0;
4115 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4116 Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4118 Person::players[i]->targetyaw -= 90;
4119 if (Person::players[i]->forwardkeydown) {
4120 Person::players[i]->targetyaw += 45;
4122 if (Person::players[i]->backkeydown) {
4123 Person::players[i]->targetyaw -= 45;
4127 if (Person::players[i]->leftkeydown) {
4128 if (Person::players[i]->isIdle() ||
4129 (Person::players[i]->isStop() &&
4130 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4131 (Person::players[i]->isLanding() &&
4132 Person::players[i]->frameTarget > 0 &&
4133 !Person::players[i]->jumpkeydown) ||
4134 (Person::players[i]->isLandhard() &&
4135 Person::players[i]->frameTarget > 0 &&
4136 !Person::players[i]->jumpkeydown &&
4137 Person::players[i]->crouchkeydown)) {
4138 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4140 if (Person::players[i]->isCrouch()) {
4141 Person::players[i]->animTarget = sneakanim;
4142 if (Person::players[i]->wasCrouch()) {
4143 Person::players[i]->target = 0;
4145 Person::players[i]->frameTarget = 0;
4147 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4148 Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
4150 Person::players[i]->targetyaw += 90;
4151 if (Person::players[i]->forwardkeydown) {
4152 Person::players[i]->targetyaw -= 45;
4154 if (Person::players[i]->backkeydown) {
4155 Person::players[i]->targetyaw += 45;
4159 if (Person::players[i]->backkeydown) {
4160 if (Person::players[i]->isIdle() ||
4161 (Person::players[i]->isStop() &&
4162 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
4163 (Person::players[i]->isLanding() &&
4164 Person::players[i]->frameTarget > 0 &&
4165 !Person::players[i]->jumpkeydown) ||
4166 (Person::players[i]->isLandhard() &&
4167 Person::players[i]->frameTarget > 0 &&
4168 !Person::players[i]->jumpkeydown &&
4169 Person::players[i]->crouchkeydown)) {
4170 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4172 if (Person::players[i]->isCrouch()) {
4173 Person::players[i]->animTarget = sneakanim;
4174 if (Person::players[i]->wasCrouch()) {
4175 Person::players[i]->target = 0;
4177 Person::players[i]->frameTarget = 0;
4179 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4180 Person::players[i]->velocity -= absflatfacing * 5 * multiplier;
4182 if (Person::players[i]->animTarget == hanganim) {
4183 Person::players[i]->animCurrent = jumpdownanim;
4184 Person::players[i]->animTarget = jumpdownanim;
4185 Person::players[i]->target = 0;
4186 Person::players[i]->frameCurrent = 0;
4187 Person::players[i]->frameTarget = 1;
4188 Person::players[i]->velocity = 0;
4189 Person::players[i]->velocity.y += gravity;
4190 Person::players[i]->coords.y -= 1.4;
4191 Person::players[i]->grabdelay = 1;
4193 if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) {
4194 Person::players[i]->targetyaw += 180;
4198 if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) {
4199 if ((((Person::players[i]->isLanding() && Person::players[i]->frameTarget >= 3) ||
4200 Person::players[i]->isRun() ||
4201 Person::players[i]->animTarget == walkanim ||
4202 Person::players[i]->isCrouch() ||
4203 Person::players[i]->animTarget == sneakanim) &&
4204 Person::players[i]->jumppower > 1) &&
4205 ((Person::players[i]->animTarget != rabbitrunninganim &&
4206 Person::players[i]->animTarget != wolfrunninganim) ||
4208 Person::players[i]->jumpstart = 0;
4209 Person::players[i]->setTargetAnimation(jumpupanim);
4210 Person::players[i]->yaw = Person::players[i]->targetyaw;
4211 Person::players[i]->transspeed = 20;
4212 Person::players[i]->FootLand(leftfoot, 1);
4213 Person::players[i]->FootLand(rightfoot, 1);
4217 flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0);
4220 Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale;
4223 Person::players[i]->velocity = 0;
4228 if (Person::players.size() > 1) {
4229 for (unsigned j = 0; j < Person::players.size(); j++) {
4230 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) {
4231 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4232 (Person::players[j]->victim == Person::players[i]) &&
4233 (Person::players[j]->animTarget == sweepanim)) {
4244 Person::players[i]->velocity.y = 1;
4245 } else if (Person::players[i]->crouchkeydown || !Person::players[i]->isPlayerControlled()) {
4246 Person::players[i]->velocity.y = 7;
4247 Person::players[i]->crouchtogglekeydown = 1;
4249 Person::players[i]->velocity.y = 5;
4252 if (mousejump && i == 0 && devtools) {
4253 if (!Person::players[i]->isLanding()) {
4254 Person::players[i]->tempdeltav = deltav;
4256 if (Person::players[i]->tempdeltav < 0) {
4257 Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000;
4261 Person::players[i]->coords.y += .2;
4262 Person::players[i]->jumppower -= 1;
4265 emit_sound_at(whooshsound, Person::players[i]->coords, 128.);
4268 emit_sound_at(jumpsound, Person::players[i]->coords, 128.);
4270 if ((Person::players[i]->isIdle()) && Person::players[i]->jumppower > 1) {
4271 Person::players[i]->setTargetAnimation(Person::players[i]->getLanding());
4272 Person::players[i]->frameTarget = 2;
4273 Person::players[i]->landhard = 0;
4274 Person::players[i]->jumpstart = 1;
4275 Person::players[i]->tempdeltav = deltav;
4277 if (Person::players[i]->animTarget == jumpupanim &&
4281 !Person::players[i]->isPlayerControlled())) {
4282 if (Person::players[i]->jumppower > multiplier * 6) {
4283 Person::players[i]->velocity.y += multiplier * 6;
4284 Person::players[i]->jumppower -= multiplier * 6;
4286 if (Person::players[i]->jumppower <= multiplier * 6) {
4287 Person::players[i]->velocity.y += Person::players[i]->jumppower;
4288 Person::players[i]->jumppower = 0;
4291 if (((floatjump || editorenabled) && devtools) && i == 0) {
4292 Person::players[i]->velocity.y += multiplier * 30;
4297 if (Person::players[i]->isRun() || Person::players[i]->animTarget == walkanim) {
4298 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4300 if (Person::players[i]->animTarget == sneakanim) {
4301 Person::players[i]->animTarget = Person::players[i]->getCrouch();
4302 if (Person::players[i]->animCurrent == sneakanim) {
4303 Person::players[i]->target = 0;
4305 Person::players[i]->frameTarget = 0;
4308 if (Person::players[i]->animTarget == walkanim &&
4309 (Person::players[i]->aitype == attacktypecutoff ||
4310 Person::players[i]->aitype == searchtype ||
4311 (Person::players[i]->aitype == passivetype &&
4312 Person::players[i]->numwaypoints <= 1))) {
4313 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4315 if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) {
4316 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4320 if (Person::players[i]->animTarget == rollanim) {
4321 Person::players[i]->targetyaw = oldtargetyaw;
4326 for (unsigned k = 0; k < Person::players.size(); k++) {
4327 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) {
4328 if (Person::players[k]->yaw > Person::players[k]->targetyaw) {
4329 Person::players[k]->yaw -= 360;
4331 Person::players[k]->yaw += 360;
4335 //stop to turn in right direction
4336 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) {
4337 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
4340 if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) {
4341 Person::players[k]->targettilt = 0;
4344 if (Person::players[k]->animTarget != jumpupanim &&
4345 Person::players[k]->animTarget != backhandspringanim &&
4346 Person::players[k]->animTarget != jumpdownanim &&
4347 !Person::players[k]->isFlip()) {
4348 Person::players[k]->targettilt = 0;
4349 if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) {
4350 Person::players[k]->jumppower = 0;
4352 Person::players[k]->jumppower += multiplier * 7;
4353 if (Person::players[k]->isCrouch()) {
4354 Person::players[k]->jumppower += multiplier * 7;
4356 if (Person::players[k]->jumppower > 5) {
4357 Person::players[k]->jumppower = 5;
4361 if (Person::players[k]->isRun()) {
4362 Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4;
4365 Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150);
4366 Person::players[k]->grabdelay -= multiplier;
4370 for (unsigned k = 0; k < Person::players.size(); k++) {
4371 Person::players[k]->DoAnimations();
4372 Person::players[k]->whichpatchx = Person::players[k]->coords.x / (terrain.size / subdivision * terrain.scale);
4373 Person::players[k]->whichpatchz = Person::players[k]->coords.z / (terrain.size / subdivision * terrain.scale);
4379 for (int j = numenvsounds - 1; j >= 0; j--) {
4380 envsoundlife[j] -= multiplier;
4381 if (envsoundlife[j] < 0) {
4383 envsoundlife[j] = envsoundlife[numenvsounds];
4384 envsound[j] = envsound[numenvsounds];
4387 OPENAL_SetFrequency(OPENAL_ALL, slomo);
4389 if (Tutorial::active) {
4390 Tutorial::DoStuff(multiplier);
4394 static float gLoc[3];
4398 static float vel[3];
4399 vel[0] = (viewer.x - oldviewer.x) / multiplier;
4400 vel[1] = (viewer.y - oldviewer.y) / multiplier;
4401 vel[2] = (viewer.z - oldviewer.z) / multiplier;
4403 //Set orientation with forward and up vectors
4404 static XYZ upvector;
4408 upvector = DoRotation(upvector, -pitch + 90, 0, 0);
4409 upvector = DoRotation(upvector, 0, 0 - yaw, 0);
4414 facing = DoRotation(facing, -pitch, 0, 0);
4415 facing = DoRotation(facing, 0, 0 - yaw, 0);
4417 static float ori[6];
4421 ori[3] = -upvector.x;
4422 ori[4] = upvector.y;
4423 ori[5] = -upvector.z;
4425 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
4433 void Game::TickOnce()
4436 yaw += multiplier * 5;
4437 } else if (Dialog::directing || !Dialog::inDialog()) {
4440 pitch -= deltav * .7;
4442 pitch += deltav * .7;
4453 void Game::TickOnceAfter()
4455 static XYZ colviewer;
4456 static XYZ coltarget;
4460 static float changedelay;
4461 static bool alldead;
4462 static float unseendelay;
4463 static float cameraspeed;
4466 static int oldmusictype = musictype;
4468 if (environment == snowyenvironment) {
4469 leveltheme = stream_snowtheme;
4471 if (environment == grassyenvironment) {
4472 leveltheme = stream_grasstheme;
4474 if (environment == desertenvironment) {
4475 leveltheme = stream_deserttheme;
4480 musictype = leveltheme;
4481 for (unsigned i = 0; i < Person::players.size(); i++) {
4482 if ((Person::players[i]->aitype == attacktypecutoff ||
4483 Person::players[i]->aitype == getweapontype ||
4484 Person::players[i]->aitype == gethelptype ||
4485 Person::players[i]->aitype == searchtype) &&
4486 !Person::players[i]->dead &&
4487 (Person::players[i]->animTarget != sneakattackedanim &&
4488 Person::players[i]->animTarget != knifesneakattackedanim &&
4489 Person::players[i]->animTarget != swordsneakattackedanim)) {
4490 musictype = stream_fighttheme;
4494 if (Person::players[0]->dead) {
4495 musictype = stream_menutheme;
4498 if (musictype == stream_fighttheme) {
4502 if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) {
4503 unseendelay -= multiplier;
4504 if (unseendelay > 0) {
4505 musictype = stream_fighttheme;
4510 musictype = stream_menutheme;
4511 musicvolume[2] = 512;
4518 if (musictype != oldmusictype && musictype == stream_fighttheme) {
4519 emit_sound_np(alarmsound);
4522 musicselected = musictype;
4524 if (musicselected == leveltheme) {
4525 musicvolume[0] += multiplier * 450;
4527 musicvolume[0] -= multiplier * 450;
4529 if (musicselected == stream_fighttheme) {
4530 musicvolume[1] += multiplier * 450;
4532 musicvolume[1] -= multiplier * 450;
4534 if (musicselected == stream_menutheme) {
4535 musicvolume[2] += multiplier * 450;
4537 musicvolume[2] -= multiplier * 450;
4540 for (int i = 0; i < 3; i++) {
4541 if (musicvolume[i] < 0) {
4544 if (musicvolume[i] > 512) {
4545 musicvolume[i] = 512;
4549 if (musicvolume[2] > 128 && !loading && !mainmenu) {
4550 musicvolume[2] = 128;
4554 if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) {
4555 emit_stream_np(leveltheme, musicvolume[0]);
4557 if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) {
4558 emit_stream_np(stream_fighttheme, musicvolume[1]);
4560 if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) {
4561 emit_stream_np(stream_menutheme, musicvolume[2]);
4563 if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) {
4564 pause_sound(leveltheme);
4566 if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) {
4567 pause_sound(stream_fighttheme);
4569 if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) {
4570 pause_sound(stream_menutheme);
4573 if (musicvolume[0] != oldmusicvolume[0]) {
4574 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
4576 if (musicvolume[1] != oldmusicvolume[1]) {
4577 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
4579 if (musicvolume[2] != oldmusicvolume[2]) {
4580 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
4583 for (int i = 0; i < 3; i++) {
4584 oldmusicvolume[i] = musicvolume[i];
4587 pause_sound(leveltheme);
4588 pause_sound(stream_fighttheme);
4589 pause_sound(stream_menutheme);
4591 for (int i = 0; i < 4; i++) {
4592 oldmusicvolume[i] = 0;
4597 Hotspot::killhotspot = 2;
4598 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4599 if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) {
4600 if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) {
4601 Hotspot::killhotspot = 0;
4602 } else if (Hotspot::killhotspot == 2) {
4603 Hotspot::killhotspot = 1;
4607 if (Hotspot::killhotspot == 2) {
4608 Hotspot::killhotspot = 0;
4612 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4613 if (Hotspot::hotspots[i].type == -1) {
4614 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size) {
4621 for (unsigned i = 1; i < Person::players.size(); i++) {
4622 if (!Person::players[i]->dead && Person::players[i]->aitype == attacktypecutoff && Person::players[i]->surprised <= 0) {
4626 if (numalarmed > maxalarmed) {
4627 maxalarmed = numalarmed;
4630 if (changedelay <= 0 && !loading && !editorenabled && gameon && !Tutorial::active && changedelay != -999 && !won) {
4631 if (Person::players[0]->dead) {
4633 targetlevel = whichlevel;
4636 for (unsigned i = 1; i < Person::players.size(); i++) {
4637 if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1) {
4643 if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) {
4645 targetlevel = whichlevel + 1;
4646 if (targetlevel > numchallengelevels - 1) {
4650 if (winhotspot || windialogue) {
4652 targetlevel = whichlevel + 1;
4653 if (targetlevel > numchallengelevels - 1) {
4658 if (Hotspot::killhotspot) {
4660 targetlevel = whichlevel + 1;
4661 if (targetlevel > numchallengelevels - 1) {
4666 if (changedelay > 0 && !Person::players[0]->dead && !won) {
4667 //high scores, awards, win
4669 Account::active().winCampaignLevel(whichchoice, bonustotal, leveltime);
4672 wonleveltime = leveltime;
4673 Account::active().winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
4676 Account::saveFile(Folders::getUserSavePath());
4682 if (leveltime < 1) {
4687 Hotspot::killhotspot = 0;
4690 if (!editorenabled && gameon && !mainmenu) {
4691 if (changedelay != -999) {
4692 changedelay -= multiplier / 7;
4694 if (Person::players[0]->dead) {
4695 targetlevel = whichlevel;
4697 if (loading == 2 && !campaign) {
4700 fireSound(firestartsound);
4702 if (!Person::players[0]->dead && targetlevel != whichlevel) {
4703 startbonustotal = bonustotal;
4706 LoadLevel(targetlevel);
4711 if (loading == 2 && targetlevel == whichlevel) {
4715 fireSound(firestartsound);
4717 LoadLevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
4723 if (changedelay <= -999 &&
4726 (Person::players[0]->dead ||
4727 (alldead && maptype == mapkilleveryone) ||
4729 (Hotspot::killhotspot))) {
4732 if ((Person::players[0]->dead ||
4733 (alldead && maptype == mapkilleveryone) ||
4736 (Hotspot::killhotspot)) &&
4738 if (whichlevel != -2 && !loading && !Person::players[0]->dead) {
4742 if (Person::players[0]->dead) {
4749 // campaignchoosenext determines what to do when the level is complete:
4750 // 0 = load next level
4751 // 1 = go back to level select screen
4752 // 2 = stealthload next level
4753 if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) {
4754 if (campaignlevels[actuallevel].nextlevel.empty()) {
4757 } else if (mainmenu == 0 && winfreeze) {
4758 stealthloading = (campaignlevels[actuallevel].choosenext == 2);
4760 if (!stealthloading) {
4761 fireSound(firestartsound);
4766 startbonustotal = 0;
4773 if (!firstLoadDone) {
4777 actuallevel = campaignlevels[actuallevel].nextlevel.front();
4778 visibleloading = true;
4780 LoadLevel(campaignlevels[actuallevel].mapname.c_str());
4784 pause_sound(stream_menutheme);
4795 oldmusictype = musictype;
4801 facing = DoRotation(facing, -pitch, 0, 0);
4802 facing = DoRotation(facing, 0, 0 - yaw, 0);
4803 viewerfacing = facing;
4806 if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) {
4807 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;
4809 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;
4812 if (Person::players[0]->skeleton.free) {
4813 for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
4814 if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) {
4815 target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y;
4820 if (Person::players[0]->skeleton.free != 2) {
4822 if (findLengthfast(&Person::players[0]->velocity) > 400) {
4823 cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96;
4825 if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) {
4828 coltarget = target - cameraloc;
4829 if (findLengthfast(&coltarget) < multiplier * multiplier * 400) {
4832 Normalise(&coltarget);
4833 if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) {
4834 cameraloc = cameraloc + coltarget * multiplier * cameraspeed;
4836 cameraloc = cameraloc + coltarget * multiplier * 8;
4839 if (editorenabled) {
4842 cameradist += multiplier * 5;
4843 if (cameradist > 2.3) {
4846 viewer = cameraloc - facing * cameradist;
4848 coltarget = cameraloc;
4849 Object::SphereCheckPossible(&colviewer, findDistance(&colviewer, &coltarget));
4850 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4851 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4853 coltarget = cameraloc;
4854 if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4858 for (unsigned int j = 0; j < terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz].size(); j++) {
4859 unsigned int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4861 if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4865 cameradist = findDistance(&viewer, &target);
4866 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .6);
4867 if (cameraloc.y < terrain.getHeight(cameraloc.x, cameraloc.z)) {
4868 cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z);
4871 if (camerashake > .8) {
4874 woozy += multiplier;
4875 if (Person::players[0]->dead) {
4878 if (Person::players[0]->dead) {
4881 camerashake -= multiplier * 2;
4882 blackout -= multiplier * 2;
4883 if (camerashake < 0) {
4890 viewer.x += (float)(Random() % 100) * .0005 * camerashake;
4891 viewer.y += (float)(Random() % 100) * .0005 * camerashake;
4892 viewer.z += (float)(Random() % 100) * .0005 * camerashake;