2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 // Enable full math definitions
22 #define _USE_MATH_DEFINES
26 #include "Animation/Animation.hpp"
27 #include "Audio/openal_wrapper.hpp"
28 #include "Devtools/ConsoleCmds.hpp"
29 #include "Level/Awards.hpp"
30 #include "Level/Campaign.hpp"
31 #include "Level/Dialog.hpp"
32 #include "Level/Hotspot.hpp"
33 #include "Menu/Menu.hpp"
34 #include "User/Settings.hpp"
35 #include "Utils/Folders.hpp"
36 #include "Utils/Input.hpp"
37 #include "Tutorial.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)
64 extern float multiplier;
66 extern int environment;
67 extern Terrain terrain;
68 extern float screenwidth, screenheight;
71 extern float texdetail;
73 extern float slomodelay;
74 extern bool floatjump;
77 extern float camerashake;
79 extern float blackout;
80 extern bool cellophane;
81 extern bool musictoggle;
82 extern int difficulty;
83 extern int bloodtoggle;
84 extern bool invertmouse;
86 extern float precipdelay;
87 extern XYZ viewerfacing;
88 extern bool ambientsound;
89 extern bool mousejump;
90 extern float viewdistance;
92 extern XYZ windvector;
96 extern int oldmainmenu;
97 extern bool visibleloading;
98 extern XYZ envsound[30];
99 extern float envsoundvol[30];
100 extern int numenvsounds;
101 extern float envsoundlife[30];
102 extern float usermousesensitivity;
103 extern bool ismotionblur;
104 extern bool showdamagebar; // (des)activate the damage bar
105 extern bool decalstoggle;
106 extern bool skyboxtexture;
107 extern float skyboxr;
108 extern float skyboxg;
109 extern float skyboxb;
110 extern float skyboxlightr;
111 extern float skyboxlightg;
112 extern float skyboxlightb;
113 extern float fadestart;
114 extern float slomospeed;
115 extern float slomofreq;
116 extern float smoketex;
117 extern bool againbonus;
118 extern bool reversaltrain;
119 extern bool canattack;
120 extern bool cananger;
121 extern float damagedealt;
123 extern int editoractive;
124 extern int editorpathtype;
126 extern float hostiletime;
128 extern bool gamestarted;
132 extern bool stillloading;
133 extern bool winfreeze;
135 extern bool campaign;
137 extern void toggleFullscreen();
141 bool winhotspot = false;
142 bool windialogue = false;
145 float cameradist = 0;
146 bool oldattackkey = 0;
148 float musicvolume[4] = {};
149 float oldmusicvolume[4] = {};
150 int musicselected = 0;
152 const char *rabbitskin[] = {
157 "Textures/Otter.jpg",
159 "Textures/Sable.jpg",
160 "Textures/Chocolate.jpg",
165 const char *wolfskin[] = {
167 "Textures/DarkWolf.jpg",
168 "Textures/SnowWolf.jpg"
171 const char **creatureskin[] = {rabbitskin, wolfskin};
173 #define STATIC_ASSERT(x) extern int s_a_dummy[2 * (!!(x)) - 1];
174 STATIC_ASSERT (rabbittype == 0 && wolftype == 1)
178 // TODO: this is slightly incorrect
179 float roughDirection(XYZ vec)
182 float angle = -asin(-vec.x) * 180 / M_PI;
187 float roughDirectionTo(XYZ start, XYZ end)
189 return roughDirection(end - start);
191 inline float pitchOf(XYZ vec)
194 return -asin(vec.y) * 180 / M_PI;
196 float pitchTo(XYZ start, XYZ end)
198 return pitchOf(end - start);
204 inline float stepTowardf(float from, float to, float by)
206 if (fabs(from - to) < by)
214 void Game::playdialoguescenesound()
217 temppos = Person::players[Dialog::currentScene().participantfocus]->coords;
218 temppos = temppos - viewer;
223 switch (Dialog::currentScene().sound) {
228 sound = consolefailsound;
231 sound = consolesuccesssound;
234 sound = firestartsound;
237 sound = fireendsound;
240 sound = rabbitchitter;
243 sound = rabbitchitter2;
246 sound = rabbitpainsound;
249 sound = rabbitpain1sound;
252 sound = rabbitattacksound;
255 sound = rabbitattack2sound;
258 sound = rabbitattack3sound;
261 sound = rabbitattack4sound;
285 sound = barkgrowlsound;
291 emit_sound_at(sound, temppos);
294 // ================================================================
296 int Game::findClosestPlayer()
299 float closestdist = std::numeric_limits<float>::max();
301 for (unsigned i = 1; i < Person::players.size(); i++) {
302 float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
303 if (distance < closestdist) {
304 closestdist = distance;
311 static int findClosestObject()
314 float closestdist = std::numeric_limits<float>::max();
316 for (unsigned int i = 0; i < Object::objects.size(); i++) {
317 float distance = distsq(&Object::objects[i]->position,
318 &Person::players[0]->coords);
319 if (distance < closestdist) {
320 closestdist = distance;
327 static void cmd_dispatch(const string cmd)
329 int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]);
331 for (i = 0; i < n_cmds; i++)
332 if (cmd.substr(0, cmd.find(' ')) == string(cmd_names[i])) {
333 cout << "|" << cmd.substr(cmd.find(' ') + 1) << "|" << endl;
334 cmd_handlers[i](cmd.substr(cmd.find(' ') + 1).c_str());
337 emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
340 /********************> Tick() <*****/
341 extern bool save_screenshot(const char * fname);
342 void Screenshot (void)
345 time_t t = time(NULL);
346 struct tm *tme = localtime(&t);
347 sprintf(filename, "Screenshot-%04d%02d%02d-%02d%02d%02d.png",
348 tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
350 save_screenshot(filename);
353 void Game::SetUpLighting()
355 if (environment == snowyenvironment)
356 light.setColors(.65, .65, .7, .4, .4, .44);
357 if (environment == desertenvironment)
358 light.setColors(.95, .95, .95, .4, .35, .3);
359 if (environment == grassyenvironment)
360 light.setColors(.95, .95, 1, .4, .4, .44);
362 light.setColors(1, 1, 1, .4, .4, .4);
364 average = (skyboxlightr + skyboxlightg + skyboxlightb) / 3;
365 light.color[0] *= (skyboxlightr + average) / 2;
366 light.color[1] *= (skyboxlightg + average) / 2;
367 light.color[2] *= (skyboxlightb + average) / 2;
368 light.ambient[0] *= (skyboxlightr + average) / 2;
369 light.ambient[1] *= (skyboxlightg + average) / 2;
370 light.ambient[2] *= (skyboxlightb + average) / 2;
373 void Setenvironment(int which)
377 LOG(" Setting environment...");
382 pause_sound(stream_snowtheme);
383 pause_sound(stream_grasstheme);
384 pause_sound(stream_deserttheme);
385 pause_sound(stream_wind);
386 pause_sound(stream_desertambient);
389 if (environment == snowyenvironment) {
393 emit_stream_np(stream_wind);
395 Object::treetextureptr.load("Textures/SnowTree.png", 0);
396 Object::bushtextureptr.load("Textures/BushSnow.png", 0);
397 Object::rocktextureptr.load("Textures/BoulderSnow.jpg", 1);
398 Object::boxtextureptr.load("Textures/SnowBox.jpg", 1);
400 footstepsound = footstepsn1;
401 footstepsound2 = footstepsn2;
402 footstepsound3 = footstepst1;
403 footstepsound4 = footstepst2;
405 terraintexture.load("Textures/Snow.jpg", 1);
406 terraintexture2.load("Textures/Rock.jpg", 1);
409 temptexdetail = texdetail;
412 skybox->load( "Textures/Skybox(snow)/Front.jpg",
413 "Textures/Skybox(snow)/Left.jpg",
414 "Textures/Skybox(snow)/Back.jpg",
415 "Textures/Skybox(snow)/Right.jpg",
416 "Textures/Skybox(snow)/Up.jpg",
417 "Textures/Skybox(snow)/Down.jpg");
420 texdetail = temptexdetail;
421 } else if (environment == desertenvironment) {
424 Object::treetextureptr.load("Textures/DesertTree.png", 0);
425 Object::bushtextureptr.load("Textures/BushDesert.png", 0);
426 Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1);
427 Object::boxtextureptr.load("Textures/DesertBox.jpg", 1);
431 emit_stream_np(stream_desertambient);
433 footstepsound = footstepsn1;
434 footstepsound2 = footstepsn2;
435 footstepsound3 = footstepsn1;
436 footstepsound4 = footstepsn2;
438 terraintexture.load("Textures/Sand.jpg", 1);
439 terraintexture2.load("Textures/SandSlope.jpg", 1);
442 temptexdetail = texdetail;
445 skybox->load( "Textures/Skybox(sand)/Front.jpg",
446 "Textures/Skybox(sand)/Left.jpg",
447 "Textures/Skybox(sand)/Back.jpg",
448 "Textures/Skybox(sand)/Right.jpg",
449 "Textures/Skybox(sand)/Up.jpg",
450 "Textures/Skybox(sand)/Down.jpg");
453 texdetail = temptexdetail;
454 } else if (environment == grassyenvironment) {
457 Object::treetextureptr.load("Textures/Tree.png", 0);
458 Object::bushtextureptr.load("Textures/Bush.png", 0);
459 Object::rocktextureptr.load("Textures/Boulder.jpg", 1);
460 Object::boxtextureptr.load("Textures/GrassBox.jpg", 1);
463 emit_stream_np(stream_wind, 100.);
465 footstepsound = footstepgr1;
466 footstepsound2 = footstepgr2;
467 footstepsound3 = footstepst1;
468 footstepsound4 = footstepst2;
470 terraintexture.load("Textures/GrassDirt.jpg", 1);
471 terraintexture2.load("Textures/MossRock.jpg", 1);
474 temptexdetail = texdetail;
477 skybox->load( "Textures/Skybox(grass)/Front.jpg",
478 "Textures/Skybox(grass)/Left.jpg",
479 "Textures/Skybox(grass)/Back.jpg",
480 "Textures/Skybox(grass)/Right.jpg",
481 "Textures/Skybox(grass)/Up.jpg",
482 "Textures/Skybox(grass)/Down.jpg");
485 texdetail = temptexdetail;
487 temptexdetail = texdetail;
489 terrain.load("Textures/HeightMap.png");
491 texdetail = temptexdetail;
494 void Game::Loadlevel(int which)
500 Loadlevel("tutorial", true);
501 } else if (which >= 0 && which <= 15) {
503 snprintf(buf, 32, "map%d", which + 1); // challenges
506 Loadlevel("mapsave");
510 void Game::Loadlevel(const std::string& name, bool tutorial)
512 int indemo; // FIXME this should be removed
518 LOG(std::string("Loading level...") + name);
521 visibleloading = true;
523 visibleloading = false;
530 Tutorial::active = tutorial;
532 if (Tutorial::active) {
535 if (Tutorial::stage == 0) {
536 Tutorial::stagetime = 0;
537 Tutorial::maxtime = 1;
539 pause_sound(whooshsound);
540 pause_sound(stream_firesound);
545 tfile = Folders::openMandatoryFile( Folders::getResourcePath("Maps/"+name), "rb" );
547 pause_sound(stream_firesound);
553 //~ Animation::animations[bounceidleanim].Load("Idle", middleheight, neutral);
555 Dialog::dialogs.clear();
557 Dialog::indialogue = -1;
563 if (Account::hasActive()) {
564 difficulty = Account::active().getDifficulty();
567 Hotspot::hotspots.clear();
568 Hotspot::current = -1;
579 for (unsigned char i = 0; i < 100; i++)
588 numunarmedattack = 0;
599 bonustotal = startbonustotal;
604 emit_sound_np(consolesuccesssound);
609 if (!stealthloading) {
610 terrain.decals.clear();
611 Sprite::deleteSprites();
613 for (int i = 0; i < subdivision; i++) {
614 for (int j = 0; j < subdivision; j++) {
615 terrain.patchobjectnum[i][j] = 0;
618 Game::LoadingScreen();
622 Person::players.resize(1);
624 funpackf(tfile, "Bi", &mapvers);
626 cerr << name << " has obsolete map version " << mapvers << endl;
629 funpackf(tfile, "Bi", &indemo);
633 funpackf(tfile, "Bi", &maptype);
635 maptype = mapkilleveryone;
637 funpackf(tfile, "Bi", &hostile);
641 funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
647 funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
655 funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
657 skyboxlightr = skyboxr;
658 skyboxlightg = skyboxg;
659 skyboxlightb = skyboxb;
661 /* 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) */
662 if (stealthloading) {
663 funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat, &lamefloat, &lamefloat, &lamefloat, &lamefloat, &Person::players[0]->num_weapons);
665 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);
667 if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5)
668 for (int j = 0; j < Person::players[0]->num_weapons; j++) {
669 Person::players[0]->weaponids[j] = weapons.size();
671 funpackf(tfile, "Bi", &type);
672 weapons.push_back(Weapon(type, 0));
675 Game::LoadingScreen();
677 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->armorhead, &Person::players[0]->armorhigh, &Person::players[0]->armorlow);
678 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->protectionhead, &Person::players[0]->protectionhigh, &Person::players[0]->protectionlow);
679 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->metalhead, &Person::players[0]->metalhigh, &Person::players[0]->metallow);
680 funpackf(tfile, "Bf Bf", &Person::players[0]->power, &Person::players[0]->speedmult);
682 funpackf(tfile, "Bi", &Person::players[0]->numclothes);
685 funpackf(tfile, "Bi Bi", &Person::players[0]->whichskin, &Person::players[0]->creature);
687 Person::players[0]->whichskin = 0;
688 Person::players[0]->creature = rabbittype;
691 Person::players[0]->lastattack = -1;
692 Person::players[0]->lastattack2 = -1;
693 Person::players[0]->lastattack3 = -1;
697 Dialog::loadDialogs(tfile);
700 for (int k = 0; k < Person::players[0]->numclothes; k++) {
701 funpackf(tfile, "Bi", &templength);
702 for (int l = 0; l < templength; l++)
703 funpackf(tfile, "Bb", &Person::players[0]->clothes[k][l]);
704 Person::players[0]->clothes[k][templength] = '\0';
705 funpackf(tfile, "Bf Bf Bf", &Person::players[0]->clothestintr[k], &Person::players[0]->clothestintg[k], &Person::players[0]->clothestintb[k]);
708 funpackf(tfile, "Bi", &environment);
710 if (environment != oldenvironment)
711 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]);
730 Hotspot::hotspots[i].text[templength] = '\0';
731 if (Hotspot::hotspots[i].type == -111)
735 Hotspot::hotspots.clear();
738 Game::LoadingScreen();
740 if (!stealthloading) {
741 Object::ComputeCenter();
742 Object::ComputeRadius();
745 Game::LoadingScreen();
748 funpackf(tfile, "Bi", &numplayers);
749 if (numplayers > maxplayers) {
750 cout << "Warning: this level contains more players than allowed" << endl;
753 for (int i = 1; i < numplayers; i++) {
755 Person::players.push_back(shared_ptr<Person>(new Person(tfile, mapvers, j)));
757 } catch (InvalidPersonException e) {
758 cerr << "Invalid Person found in " << name << endl;
761 Game::LoadingScreen();
763 funpackf(tfile, "Bi", &numpathpoints);
764 if (numpathpoints > 30 || numpathpoints < 0)
766 for (int j = 0; j < numpathpoints; j++) {
767 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x, &pathpoint[j].y, &pathpoint[j].z, &numpathpointconnect[j]);
768 for (int k = 0; k < numpathpointconnect[j]; k++) {
769 funpackf(tfile, "Bi", &pathpointconnect[j][k]);
772 Game::LoadingScreen();
774 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x, &mapcenter.y, &mapcenter.z, &mapradius);
778 if (!stealthloading) {
779 Object::AddObjectsToTerrain();
781 Game::LoadingScreen();
783 Game::LoadingScreen();
788 for (unsigned i = 0; i < Person::players.size(); i++) {
789 Game::LoadingScreen();
791 Person::players[i]->burnt = 0;
792 Person::players[i]->bled = 0;
793 Person::players[i]->onfire = 0;
794 Person::players[i]->scale = .2;
796 Person::players[i]->creature = rabbittype;
799 Person::players[i]->skeleton.free = 0;
801 Person::players[i]->skeletonLoad();
803 Person::players[i]->addClothes();
806 Person::players[i]->animCurrent = bounceidleanim;
807 Person::players[i]->animTarget = bounceidleanim;
808 Person::players[i]->frameCurrent = 0;
809 Person::players[i]->frameTarget = 1;
810 Person::players[i]->target = 0;
812 Person::players[i]->speed = 1 + (float)(Random() % 100) / 1000;
814 Person::players[i]->speed -= .2;
816 Person::players[i]->speed -= .1;
819 Person::players[i]->velocity = 0;
820 Person::players[i]->oldcoords = Person::players[i]->coords;
821 Person::players[i]->realoldcoords = Person::players[i]->coords;
823 Person::players[i]->id = i;
824 Person::players[i]->updatedelay = 0;
825 Person::players[i]->normalsupdatedelay = 0;
827 Person::players[i]->proportionhead = 1.2;
828 Person::players[i]->proportionbody = 1.05;
829 Person::players[i]->proportionarms = 1.00;
830 Person::players[i]->proportionlegs = 1.1;
831 Person::players[i]->proportionlegs.y = 1.05;
832 Person::players[i]->headless = 0;
833 Person::players[i]->currentoffset = 0;
834 Person::players[i]->targetoffset = 0;
835 if (Person::players[i]->creature == wolftype) {
836 Person::players[i]->scale = .23;
837 Person::players[i]->damagetolerance = 300;
839 Person::players[i]->damagetolerance = 200;
844 Game::LoadingScreen();
847 Person::players[i]->proportionhead.z = 0;
848 Person::players[i]->proportionbody.z = 0;
849 Person::players[i]->proportionarms.z = 0;
850 Person::players[i]->proportionlegs.z = 0;
853 Person::players[i]->tempanimation = Animation("Tempanim", lowheight, neutral);
856 Person::players[i]->headmorphness = 0;
857 Person::players[i]->targetheadmorphness = 1;
858 Person::players[i]->headmorphstart = 0;
859 Person::players[i]->headmorphend = 0;
861 Person::players[i]->pausetime = 0;
863 Person::players[i]->dead = 0;
864 Person::players[i]->jumppower = 5;
865 Person::players[i]->damage = 0;
866 Person::players[i]->permanentdamage = 0;
867 Person::players[i]->superpermanentdamage = 0;
869 Person::players[i]->forwardkeydown = 0;
870 Person::players[i]->leftkeydown = 0;
871 Person::players[i]->backkeydown = 0;
872 Person::players[i]->rightkeydown = 0;
873 Person::players[i]->jumpkeydown = 0;
874 Person::players[i]->crouchkeydown = 0;
875 Person::players[i]->throwkeydown = 0;
877 Person::players[i]->collided = -10;
878 Person::players[i]->loaded = 1;
879 Person::players[i]->bloodloss = 0;
880 Person::players[i]->weaponactive = -1;
881 Person::players[i]->weaponstuck = -1;
882 Person::players[i]->bleeding = 0;
883 Person::players[i]->deathbleeding = 0;
884 Person::players[i]->stunned = 0;
885 Person::players[i]->hasvictim = 0;
886 Person::players[i]->wentforweapon = 0;
890 Person::players[0]->aitype = playercontrolled;
892 if (difficulty == 1) {
893 Person::players[0]->power = 1 / .9;
894 Person::players[0]->damagetolerance = 250;
895 } else if (difficulty == 0) {
896 Person::players[0]->power = 1 / .8;
897 Person::players[0]->damagetolerance = 300;
898 Person::players[0]->armorhead *= 1.5;
899 Person::players[0]->armorhigh *= 1.5;
900 Person::players[0]->armorlow *= 1.5;
903 cameraloc = Person::players[0]->coords;
905 yaw = Person::players[0]->yaw;
907 hawkcoords = Person::players[0]->coords;
910 Game::LoadingScreen();
912 LOG("Starting background music...");
914 OPENAL_StopSound(OPENAL_ALL);
916 if (environment == snowyenvironment) {
917 emit_stream_np(stream_wind);
918 } else if (environment == desertenvironment) {
919 emit_stream_np(stream_desertambient);
920 } else if (environment == grassyenvironment) {
921 emit_stream_np(stream_wind, 100.);
924 oldmusicvolume[0] = 0;
925 oldmusicvolume[1] = 0;
926 oldmusicvolume[2] = 0;
927 oldmusicvolume[3] = 0;
931 visibleloading = false;
936 float headprop, bodyprop, armprop, legprop;
941 if (Input::isKeyDown(SDL_SCANCODE_LALT)) {
943 if (Input::isKeyPressed(SDL_SCANCODE_H)) {
944 Person::players[0]->damagetolerance = 200000;
945 Person::players[0]->damage = 0;
946 Person::players[0]->burnt = 0;
947 Person::players[0]->permanentdamage = 0;
948 Person::players[0]->superpermanentdamage = 0;
951 /* Change environment */
952 if (Input::isKeyPressed(SDL_SCANCODE_J)) {
956 Setenvironment(environment);
960 if (Input::isKeyPressed(SDL_SCANCODE_C)) {
961 cameramode = !cameramode;
964 /* Toggle Slow motion */
965 if (Input::isKeyPressed(SDL_SCANCODE_B)) {
971 if (Input::isKeyPressed(SDL_SCANCODE_N)) {
972 Person::players[0]->RagDoll(0);
974 emit_sound_at(whooshsound, Person::players[0]->coords, 128.);
977 /* Grow tree leaves?? */
978 if (Input::isKeyPressed(SDL_SCANCODE_Y)) {
979 for (auto& an_object : Object::objects) {
980 if (an_object->type == treeleavestype) {
981 an_object->scale *= .9;
986 /* Change (or add) weapon */
987 if (Input::isKeyPressed(SDL_SCANCODE_X)) {
989 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
990 closest = findClosestPlayer();
994 if (Person::players[closest]->num_weapons > 0) {
995 if (weapons[Person::players[closest]->weaponids[0]].getType() == sword)
996 weapons[Person::players[closest]->weaponids[0]].setType(staff);
997 else if (weapons[Person::players[closest]->weaponids[0]].getType() == staff)
998 weapons[Person::players[closest]->weaponids[0]].setType(knife);
1000 weapons[Person::players[closest]->weaponids[0]].setType(sword);
1002 Person::players[closest]->weaponids[0] = weapons.size();
1004 weapons.push_back(Weapon(knife, closest));
1006 Person::players[closest]->num_weapons = 1;
1012 if (Input::isKeyDown(SDL_SCANCODE_U)) {
1014 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1015 closest = findClosestPlayer();
1019 Person::players[closest]->yaw += multiplier * 50;
1020 Person::players[closest]->targetyaw = Person::players[closest]->yaw;
1025 if (Input::isKeyPressed(SDL_SCANCODE_F)) {
1026 Person::players[0]->onfire = 1 - Person::players[0]->onfire;
1027 if (Person::players[0]->onfire) {
1028 Person::players[0]->CatchFire();
1030 if (!Person::players[0]->onfire) {
1031 emit_sound_at(fireendsound, Person::players[0]->coords);
1032 pause_sound(stream_firesound);
1037 if (Input::isKeyPressed(SDL_SCANCODE_O) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1039 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1040 closest = findClosestPlayer();
1044 Person::players[closest]->whichskin++;
1045 if (Person::players[closest]->whichskin > 9)
1046 Person::players[closest]->whichskin = 0;
1047 if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype)
1048 Person::players[closest]->whichskin = 0;
1050 Person::players[closest]->skeleton.drawmodel.textureptr.load(creatureskin[Person::players[closest]->creature][Person::players[closest]->whichskin], 1,
1051 &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
1054 Person::players[closest]->addClothes();
1057 /* Change creature type */
1058 if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1060 if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1061 closest = findClosestPlayer();
1065 if (Person::players[closest]->creature == wolftype) {
1066 headprop = Person::players[closest]->proportionhead.x / 1.1;
1067 bodyprop = Person::players[closest]->proportionbody.x / 1.1;
1068 armprop = Person::players[closest]->proportionarms.x / 1.1;
1069 legprop = Person::players[closest]->proportionlegs.x / 1.1;
1072 headprop = Person::players[closest]->proportionhead.x / 1.2;
1073 bodyprop = Person::players[closest]->proportionbody.x / 1.05;
1074 armprop = Person::players[closest]->proportionarms.x / 1.00;
1075 legprop = Person::players[closest]->proportionlegs.x / 1.1;
1079 if (Person::players[closest]->creature == rabbittype) {
1080 Person::players[closest]->creature = wolftype;
1081 Person::players[closest]->whichskin = 0;
1082 Person::players[closest]->skeletonLoad();
1084 Person::players[closest]->proportionhead = 1.1;
1085 Person::players[closest]->proportionbody = 1.1;
1086 Person::players[closest]->proportionarms = 1.1;
1087 Person::players[closest]->proportionlegs = 1.1;
1088 Person::players[closest]->proportionlegs.y = 1.1;
1089 Person::players[closest]->scale = .23 * 5 * Person::players[0]->scale;
1091 Person::players[closest]->damagetolerance = 300;
1093 Person::players[closest]->creature = rabbittype;
1094 Person::players[closest]->whichskin = 0;
1095 Person::players[closest]->skeletonLoad(true);
1097 Person::players[closest]->proportionhead = 1.2;
1098 Person::players[closest]->proportionbody = 1.05;
1099 Person::players[closest]->proportionarms = 1.00;
1100 Person::players[closest]->proportionlegs = 1.1;
1101 Person::players[closest]->proportionlegs.y = 1.05;
1102 Person::players[closest]->scale = .2 * 5 * Person::players[0]->scale;
1104 Person::players[closest]->damagetolerance = 200;
1107 if (Person::players[closest]->creature == wolftype) {
1108 Person::players[closest]->proportionhead = 1.1 * headprop;
1109 Person::players[closest]->proportionbody = 1.1 * bodyprop;
1110 Person::players[closest]->proportionarms = 1.1 * armprop;
1111 Person::players[closest]->proportionlegs = 1.1 * legprop;
1114 if (Person::players[closest]->creature == rabbittype) {
1115 Person::players[closest]->proportionhead = 1.2 * headprop;
1116 Person::players[closest]->proportionbody = 1.05 * bodyprop;
1117 Person::players[closest]->proportionarms = 1.00 * armprop;
1118 Person::players[closest]->proportionlegs = 1.1 * legprop;
1119 Person::players[closest]->proportionlegs.y = 1.05 * legprop;
1126 if (((Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
1128 float closestdist = std::numeric_limits<float>::max();
1130 for (unsigned i = 1; i < Person::players.size(); i++) {
1131 float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords);
1132 if (!Person::players[i]->headless)
1133 if (distance < closestdist) {
1134 closestdist = distance;
1139 XYZ flatfacing2, flatvelocity2;
1141 if (closest != -1 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1142 blah = Person::players[closest]->coords;
1143 XYZ headspurtdirection;
1144 //int i = Person::players[closest]->skeleton.jointlabels[head];
1145 Joint& headjoint = Person::players[closest]->joint(head);
1146 for (unsigned k = 0; k < Person::players[closest]->skeleton.joints.size(); k++) {
1147 if (!Person::players[closest]->skeleton.free)
1148 flatvelocity2 = Person::players[closest]->velocity;
1149 if (Person::players[closest]->skeleton.free)
1150 flatvelocity2 = headjoint.velocity;
1151 if (!Person::players[closest]->skeleton.free)
1152 flatfacing2 = DoRotation(DoRotation(DoRotation(headjoint.position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1153 if (Person::players[closest]->skeleton.free)
1154 flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords;
1155 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1156 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1157 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1158 headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck);
1159 Normalise(&headspurtdirection);
1160 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, .6, 1);
1161 flatvelocity2 += headspurtdirection * 8;
1162 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 / 2, 1, 1, 1, .16, 1);
1164 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1166 emit_sound_at(splattersound, blah);
1167 emit_sound_at(breaksound2, blah, 100.);
1169 if (Person::players[closest]->skeleton.free == 2)
1170 Person::players[closest]->skeleton.free = 0;
1171 Person::players[closest]->RagDoll(0);
1172 Person::players[closest]->dead = 2;
1173 Person::players[closest]->headless = 1;
1174 Person::players[closest]->DoBloodBig(3, 165);
1181 if (((Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) {
1182 int closest = findClosestPlayer();
1183 XYZ flatfacing2, flatvelocity2;
1185 if (closest >= 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) {
1186 blah = Person::players[closest]->coords;
1187 emit_sound_at(splattersound, blah);
1188 emit_sound_at(breaksound2, blah);
1190 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1191 if (!Person::players[closest]->skeleton.free)
1192 flatvelocity2 = Person::players[closest]->velocity;
1193 if (Person::players[closest]->skeleton.free)
1194 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1195 if (!Person::players[closest]->skeleton.free)
1196 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1197 if (Person::players[closest]->skeleton.free)
1198 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1199 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1200 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1201 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1202 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1203 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .3, 1);
1204 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1207 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1208 if (!Person::players[closest]->skeleton.free)
1209 flatvelocity2 = Person::players[closest]->velocity;
1210 if (Person::players[closest]->skeleton.free)
1211 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1212 if (!Person::players[closest]->skeleton.free)
1213 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1214 if (Person::players[closest]->skeleton.free)
1215 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1216 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1217 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1218 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1219 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1220 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1223 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1224 if (!Person::players[closest]->skeleton.free)
1225 flatvelocity2 = Person::players[closest]->velocity;
1226 if (Person::players[closest]->skeleton.free)
1227 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1228 if (!Person::players[closest]->skeleton.free)
1229 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1230 if (Person::players[closest]->skeleton.free)
1231 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1232 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1233 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1234 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1235 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1236 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1239 for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) {
1240 if (!Person::players[closest]->skeleton.free)
1241 flatvelocity2 = Person::players[closest]->velocity;
1242 if (Person::players[closest]->skeleton.free)
1243 flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity;
1244 if (!Person::players[closest]->skeleton.free)
1245 flatfacing2 = DoRotation(DoRotation(DoRotation(Person::players[closest]->skeleton.joints[i].position, 0, 0, Person::players[closest]->tilt), Person::players[closest]->tilt2, 0, 0), 0, Person::players[closest]->yaw, 0) * Person::players[closest]->scale + Person::players[closest]->coords;
1246 if (Person::players[closest]->skeleton.free)
1247 flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords;
1248 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1249 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1250 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1251 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1);
1252 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1);
1256 for (unsigned j = 0; j < Person::players.size(); j++) {
1257 if (int(j) != closest) {
1258 if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) {
1259 Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60);
1260 if (Person::players[j]->skeleton.free == 2)
1261 Person::players[j]->skeleton.free = 1;
1262 Person::players[j]->skeleton.longdead = 0;
1263 Person::players[j]->RagDoll(0);
1264 for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) {
1265 temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords;
1266 if (distsq(&temppos, &Person::players[closest]->coords) < 25) {
1267 flatvelocity2 = temppos - Person::players[closest]->coords;
1268 Normalise(&flatvelocity2);
1269 Person::players[j]->skeleton.joints[i].velocity += flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20);
1276 Person::players[closest]->DoDamage(10000);
1277 Person::players[closest]->RagDoll(0);
1278 Person::players[closest]->dead = 2;
1279 Person::players[closest]->coords = 20;
1280 Person::players[closest]->skeleton.free = 2;
1288 if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1289 editorenabled = !editorenabled;
1290 if (editorenabled) {
1291 Person::players[0]->damagetolerance = 100000;
1293 Person::players[0]->damagetolerance = 200;
1295 Person::players[0]->damage = 0; // these lines were in both if and else, but I think they would better fit in the if
1296 Person::players[0]->permanentdamage = 0;
1297 Person::players[0]->superpermanentdamage = 0;
1298 Person::players[0]->bloodloss = 0;
1299 Person::players[0]->deathbleeding = 0;
1304 if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) {
1306 if (targetlevel > numchallengelevels - 1)
1312 if (editorenabled) {
1313 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1314 int closest = findClosestPlayer();
1316 Person::players.erase(Person::players.begin()+closest);
1320 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1321 int closest = findClosestObject();
1323 Object::objects[closest]->position.y -= 500;
1327 if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1328 if (Object::objects.size() < max_objects - 1) {
1330 scenecoords.x = Person::players[0]->coords.x;
1331 scenecoords.z = Person::players[0]->coords.z;
1332 scenecoords.y = Person::players[0]->coords.y - 3;
1333 if (editortype == bushtype)
1334 scenecoords.y = Person::players[0]->coords.y - .5;
1335 if (editortype == firetype)
1336 scenecoords.y = Person::players[0]->coords.y - .5;
1337 float temprotat, temprotat2;
1338 temprotat = editoryaw;
1339 temprotat2 = editorpitch;
1340 if (temprotat < 0 || editortype == bushtype)
1341 temprotat = Random() % 360;
1343 temprotat2 = Random() % 360;
1345 Object::MakeObject(editortype, scenecoords, (int)temprotat - ((int)temprotat) % 30, (int)temprotat2, editorsize);
1346 if (editortype == treetrunktype)
1347 Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (temprotat2 < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize);
1351 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1352 Person::players.push_back(shared_ptr<Person>(new Person()));
1354 Person::players.back()->id = Person::players.size()-1;
1356 Person::players.back()->scale = Person::players[0]->scale;
1357 Person::players.back()->creature = rabbittype;
1358 Person::players.back()->howactive = editoractive;
1360 int k = abs(Random() % 2) + 1;
1362 Person::players.back()->whichskin = 0;
1363 } else if (k == 1) {
1364 Person::players.back()->whichskin = 1;
1366 Person::players.back()->whichskin = 2;
1369 Person::players.back()->skeletonLoad(true);
1371 Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
1372 Person::players.back()->speed = 1 + (float)(Random() % 100) / 1000;
1374 Person::players.back()->targetyaw = Person::players[0]->targetyaw;
1375 Person::players.back()->yaw = Person::players[0]->yaw;
1377 Person::players.back()->coords = Person::players[0]->coords;
1378 Person::players.back()->oldcoords = Person::players.back()->coords;
1379 Person::players.back()->realoldcoords = Person::players.back()->coords;
1381 if (Person::players[0]->creature == wolftype) {
1382 headprop = Person::players[0]->proportionhead.x / 1.1;
1383 bodyprop = Person::players[0]->proportionbody.x / 1.1;
1384 armprop = Person::players[0]->proportionarms.x / 1.1;
1385 legprop = Person::players[0]->proportionlegs.x / 1.1;
1388 headprop = Person::players[0]->proportionhead.x / 1.2;
1389 bodyprop = Person::players[0]->proportionbody.x / 1.05;
1390 armprop = Person::players[0]->proportionarms.x / 1.00;
1391 legprop = Person::players[0]->proportionlegs.x / 1.1;
1394 if (Person::players.back()->creature == wolftype) {
1395 Person::players.back()->proportionhead = 1.1 * headprop;
1396 Person::players.back()->proportionbody = 1.1 * bodyprop;
1397 Person::players.back()->proportionarms = 1.1 * armprop;
1398 Person::players.back()->proportionlegs = 1.1 * legprop;
1401 if (Person::players.back()->creature == rabbittype) {
1402 Person::players.back()->proportionhead = 1.2 * headprop;
1403 Person::players.back()->proportionbody = 1.05 * bodyprop;
1404 Person::players.back()->proportionarms = 1.00 * armprop;
1405 Person::players.back()->proportionlegs = 1.1 * legprop;
1406 Person::players.back()->proportionlegs.y = 1.05 * legprop;
1410 Person::players.back()->proportionhead.z = 0;
1411 Person::players.back()->proportionbody.z = 0;
1412 Person::players.back()->proportionarms.z = 0;
1413 Person::players.back()->proportionlegs.z = 0;
1416 Person::players.back()->tempanimation = Animation("Tempanim", lowheight, neutral);
1418 Person::players.back()->damagetolerance = 200;
1420 Person::players.back()->protectionhead = Person::players[0]->protectionhead;
1421 Person::players.back()->protectionhigh = Person::players[0]->protectionhigh;
1422 Person::players.back()->protectionlow = Person::players[0]->protectionlow;
1423 Person::players.back()->armorhead = Person::players[0]->armorhead;
1424 Person::players.back()->armorhigh = Person::players[0]->armorhigh;
1425 Person::players.back()->armorlow = Person::players[0]->armorlow;
1426 Person::players.back()->metalhead = Person::players[0]->metalhead;
1427 Person::players.back()->metalhigh = Person::players[0]->metalhigh;
1428 Person::players.back()->metallow = Person::players[0]->metallow;
1430 Person::players.back()->immobile = Person::players[0]->immobile;
1432 Person::players.back()->numclothes = Person::players[0]->numclothes;
1433 for (int i = 0; i < Person::players.back()->numclothes; i++) {
1434 strcpy(Person::players.back()->clothes[i], Person::players[0]->clothes[i]);
1435 Person::players.back()->clothestintr[i] = Person::players[0]->clothestintr[i];
1436 Person::players.back()->clothestintg[i] = Person::players[0]->clothestintg[i];
1437 Person::players.back()->clothestintb[i] = Person::players[0]->clothestintb[i];
1439 Person::players.back()->addClothes();
1441 Person::players.back()->power = Person::players[0]->power;
1442 Person::players.back()->speedmult = Person::players[0]->speedmult;
1444 Person::players.back()->loaded = true;
1447 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1448 if (Person::players.back()->numwaypoints < 90) {
1449 Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords;
1450 Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype;
1451 Person::players.back()->numwaypoints++;
1455 if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1456 if (numpathpoints < 30) {
1457 bool connected, alreadyconnected;
1459 if (numpathpoints > 1)
1460 for (int i = 0; i < numpathpoints; i++) {
1461 if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) {
1462 alreadyconnected = 0;
1463 for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) {
1464 if (pathpointconnect[pathpointselected][j] == i)
1465 alreadyconnected = 1;
1467 if (!alreadyconnected) {
1468 numpathpointconnect[pathpointselected]++;
1470 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = i;
1476 pathpoint[numpathpoints - 1] = Person::players[0]->coords;
1477 numpathpointconnect[numpathpoints - 1] = 0;
1478 if (numpathpoints > 1 && pathpointselected != -1) {
1479 numpathpointconnect[pathpointselected]++;
1480 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = numpathpoints - 1;
1482 pathpointselected = numpathpoints - 1;
1487 if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) {
1488 pathpointselected++;
1489 if (pathpointselected >= numpathpoints)
1490 pathpointselected = -1;
1493 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1494 pathpointselected--;
1495 if (pathpointselected <= -2)
1496 pathpointselected = numpathpoints - 1;
1499 if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1500 if (pathpointselected != -1) {
1502 pathpoint[pathpointselected] = pathpoint[numpathpoints];
1503 numpathpointconnect[pathpointselected] = numpathpointconnect[numpathpoints];
1504 for (int i = 0; i < numpathpointconnect[pathpointselected]; i++) {
1505 pathpointconnect[pathpointselected][i] = pathpointconnect[numpathpoints][i];
1507 for (int i = 0; i < numpathpoints; i++) {
1508 for (int j = 0; j < numpathpointconnect[i]; j++) {
1509 if (pathpointconnect[i][j] == pathpointselected) {
1510 pathpointconnect[i][j] = pathpointconnect[i][numpathpointconnect[i] - 1];
1511 numpathpointconnect[i]--;
1513 if (pathpointconnect[i][j] == numpathpoints) {
1514 pathpointconnect[i][j] = pathpointselected;
1518 pathpointselected = numpathpoints - 1;
1522 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1524 if (editortype == treeleavestype || editortype == 10)
1527 editortype = firetype;
1530 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1532 if (editortype == treeleavestype || editortype == 10)
1534 if (editortype > firetype)
1538 if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1539 editoryaw -= multiplier * 100;
1540 if (editoryaw < -.01)
1544 if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1545 editoryaw += multiplier * 100;
1548 if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1549 editorsize += multiplier;
1552 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1553 editorsize -= multiplier;
1554 if (editorsize < .1)
1559 if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1560 mapradius -= multiplier * 10;
1563 if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1564 mapradius += multiplier * 10;
1567 if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1568 editorpitch += multiplier * 100;
1571 if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) {
1572 editorpitch -= multiplier * 100;
1573 if (editorpitch < -.01)
1577 if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Object::objects.size() && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) {
1578 int closest = findClosestObject();
1580 Object::DeleteObject(closest);
1586 void doJumpReversals()
1588 for (unsigned k = 0; k < Person::players.size(); k++) {
1589 for (unsigned i = k + 1; i < Person::players.size(); i++) {
1590 if ( Person::players[k]->skeleton.free == 0 &&
1591 Person::players[i]->skeleton.oldfree == 0 &&
1592 (Person::players[i]->animTarget == jumpupanim ||
1593 Person::players[k]->animTarget == jumpupanim) &&
1594 (Person::players[i]->aitype == playercontrolled ||
1595 Person::players[k]->aitype == playercontrolled) &&
1596 ((Person::players[i]->aitype == attacktypecutoff && Person::players[i]->stunned <= 0) ||
1597 (Person::players[k]->aitype == attacktypecutoff && Person::players[k]->stunned <= 0))) {
1598 if ( distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 10 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5) &&
1599 distsqflat(&Person::players[i]->coords, &Person::players[k]->coords) < 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
1600 //TODO: refactor two huge similar ifs
1601 if (Person::players[i]->animTarget == jumpupanim &&
1602 Person::players[k]->animTarget != getupfrombackanim &&
1603 Person::players[k]->animTarget != getupfromfrontanim &&
1604 Animation::animations[Person::players[k]->animTarget].height == middleheight &&
1605 normaldotproduct(Person::players[i]->velocity, Person::players[k]->coords - Person::players[i]->coords) < 0 &&
1606 ((Person::players[k]->aitype == playercontrolled && Person::players[k]->attackkeydown) ||
1607 Person::players[k]->aitype != playercontrolled)) {
1608 Person::players[i]->victim = Person::players[k];
1609 Person::players[i]->velocity = 0;
1610 Person::players[i]->animCurrent = jumpreversedanim;
1611 Person::players[i]->animTarget = jumpreversedanim;
1612 Person::players[i]->frameCurrent = 0;
1613 Person::players[i]->frameTarget = 1;
1614 Person::players[i]->targettilt2 = 0;
1615 Person::players[k]->victim = Person::players[i];
1616 Person::players[k]->velocity = 0;
1617 Person::players[k]->animCurrent = jumpreversalanim;
1618 Person::players[k]->animTarget = jumpreversalanim;
1619 Person::players[k]->frameCurrent = 0;
1620 Person::players[k]->frameTarget = 1;
1621 Person::players[k]->targettilt2 = 0;
1622 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 1) {
1623 Person::players[i]->animCurrent = rabbitkickreversedanim;
1624 Person::players[i]->animTarget = rabbitkickreversedanim;
1625 Person::players[i]->frameCurrent = 1;
1626 Person::players[i]->frameTarget = 2;
1627 Person::players[k]->animCurrent = rabbitkickreversalanim;
1628 Person::players[k]->animTarget = rabbitkickreversalanim;
1629 Person::players[k]->frameCurrent = 1;
1630 Person::players[k]->frameTarget = 2;
1632 Person::players[i]->target = 0;
1633 Person::players[k]->oldcoords = Person::players[k]->coords;
1634 Person::players[i]->coords = Person::players[k]->coords;
1635 Person::players[k]->targetyaw = Person::players[i]->targetyaw;
1636 Person::players[k]->yaw = Person::players[i]->targetyaw;
1637 if (Person::players[k]->aitype == attacktypecutoff)
1638 Person::players[k]->stunned = .5;
1640 if (Person::players[k]->animTarget == jumpupanim &&
1641 Person::players[i]->animTarget != getupfrombackanim &&
1642 Person::players[i]->animTarget != getupfromfrontanim &&
1643 Animation::animations[Person::players[i]->animTarget].height == middleheight &&
1644 normaldotproduct(Person::players[k]->velocity, Person::players[i]->coords - Person::players[k]->coords) < 0 &&
1645 ((Person::players[i]->aitype == playercontrolled && Person::players[i]->attackkeydown) ||
1646 Person::players[i]->aitype != playercontrolled)) {
1647 Person::players[k]->victim = Person::players[i];
1648 Person::players[k]->velocity = 0;
1649 Person::players[k]->animCurrent = jumpreversedanim;
1650 Person::players[k]->animTarget = jumpreversedanim;
1651 Person::players[k]->frameCurrent = 0;
1652 Person::players[k]->frameTarget = 1;
1653 Person::players[k]->targettilt2 = 0;
1654 Person::players[i]->victim = Person::players[k];
1655 Person::players[i]->velocity = 0;
1656 Person::players[i]->animCurrent = jumpreversalanim;
1657 Person::players[i]->animTarget = jumpreversalanim;
1658 Person::players[i]->frameCurrent = 0;
1659 Person::players[i]->frameTarget = 1;
1660 Person::players[i]->targettilt2 = 0;
1661 if (Person::players[k]->coords.y < Person::players[i]->coords.y + 1) {
1662 Person::players[k]->animTarget = rabbitkickreversedanim;
1663 Person::players[k]->animCurrent = rabbitkickreversedanim;
1664 Person::players[i]->animCurrent = rabbitkickreversalanim;
1665 Person::players[i]->animTarget = rabbitkickreversalanim;
1666 Person::players[k]->frameCurrent = 1;
1667 Person::players[k]->frameTarget = 2;
1668 Person::players[i]->frameCurrent = 1;
1669 Person::players[i]->frameTarget = 2;
1671 Person::players[k]->target = 0;
1672 Person::players[i]->oldcoords = Person::players[i]->coords;
1673 Person::players[k]->coords = Person::players[i]->coords;
1674 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
1675 Person::players[i]->yaw = Person::players[k]->targetyaw;
1676 if (Person::players[i]->aitype == attacktypecutoff)
1677 Person::players[i]->stunned = .5;
1685 void doAerialAcrobatics()
1687 static XYZ facing, flatfacing;
1688 for (unsigned k = 0; k < Person::players.size(); k++) {
1689 Person::players[k]->turnspeed = 500;
1691 if ((Person::players[k]->isRun() &&
1692 ((Person::players[k]->targetyaw != rabbitrunninganim &&
1693 Person::players[k]->targetyaw != wolfrunninganim) ||
1694 Person::players[k]->frameTarget == 4)) ||
1695 Person::players[k]->animTarget == removeknifeanim ||
1696 Person::players[k]->animTarget == crouchremoveknifeanim ||
1697 Person::players[k]->animTarget == flipanim ||
1698 Person::players[k]->animTarget == fightsidestep ||
1699 Person::players[k]->animTarget == walkanim) {
1700 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed);
1704 if (Person::players[k]->isStop() ||
1705 Person::players[k]->isLanding() ||
1706 Person::players[k]->animTarget == staggerbackhighanim ||
1707 (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent == sneakanim) ||
1708 Person::players[k]->animTarget == staggerbackhardanim ||
1709 Person::players[k]->animTarget == backhandspringanim ||
1710 Person::players[k]->animTarget == dodgebackanim ||
1711 Person::players[k]->animTarget == rollanim ||
1712 (Animation::animations[Person::players[k]->animTarget].attack &&
1713 Person::players[k]->animTarget != rabbitkickanim &&
1714 (Person::players[k]->animTarget != crouchstabanim || Person::players[k]->hasvictim) &&
1715 (Person::players[k]->animTarget != swordgroundstabanim || Person::players[k]->hasvictim))) {
1716 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 2);
1719 if (Person::players[k]->animTarget == sneakanim && Person::players[k]->animCurrent != sneakanim) {
1720 Person::players[k]->yaw = stepTowardf(Person::players[k]->yaw, Person::players[k]->targetyaw, multiplier * Person::players[k]->turnspeed * 4);
1723 Person::players[k]->DoStuff();
1724 if (Person::players[k]->immobile && k != 0)
1725 Person::players[k]->coords = Person::players[k]->realoldcoords;
1727 //if player's position has changed (?)
1728 if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 &&
1729 !Person::players[k]->skeleton.free &&
1730 Person::players[k]->animTarget != climbanim &&
1731 Person::players[k]->animTarget != hanganim) {
1732 XYZ lowpoint, lowpointtarget, lowpoint2, lowpointtarget2, lowpoint3, lowpointtarget3, lowpoint4, lowpointtarget4, lowpoint5, lowpointtarget5, lowpoint6, lowpointtarget6, lowpoint7, lowpointtarget7, colpoint, colpoint2;
1734 bool tempcollide = 0;
1736 if (Person::players[k]->collide < -.3)
1737 Person::players[k]->collide = -.3;
1738 if (Person::players[k]->collide > 1)
1739 Person::players[k]->collide = 1;
1740 Person::players[k]->collide -= multiplier * 30;
1743 Person::players[k]->coords.y = max(Person::players[k]->coords.y, terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z));
1745 for (int l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
1746 int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1747 if (Object::objects[i]->type != rocktype ||
1748 Object::objects[i]->scale > .5 && Person::players[k]->aitype == playercontrolled ||
1749 Object::objects[i]->position.y > Person::players[k]->coords.y) {
1750 lowpoint = Person::players[k]->coords;
1751 if (Person::players[k]->animTarget != jumpupanim &&
1752 Person::players[k]->animTarget != jumpdownanim &&
1753 !Person::players[k]->isFlip())
1757 if ( Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) &&
1758 Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1)
1759 Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z);
1760 if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1761 flatfacing = lowpoint - Person::players[k]->coords;
1762 Person::players[k]->coords = lowpoint;
1763 Person::players[k]->coords.y -= 1.3;
1764 Person::players[k]->collide = 1;
1767 //TODO: refactor four similar blocks
1768 if (Person::players[k]->aitype == playercontrolled &&
1769 (Person::players[k]->animTarget == jumpupanim ||
1770 Person::players[k]->animTarget == jumpdownanim ||
1771 Person::players[k]->isFlip()) &&
1772 !Person::players[k]->jumptogglekeydown &&
1773 Person::players[k]->jumpkeydown) {
1774 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, -90, 0) * 1.5;
1775 XYZ tempcoords1 = lowpoint;
1776 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1777 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1778 Person::players[k]->setTargetAnimation(walljumpleftanim);
1779 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1781 pause_sound(whooshsound);
1783 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1784 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1785 if (lowpointtarget.z < 0)
1786 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1787 Person::players[k]->targetyaw = Person::players[k]->yaw;
1788 Person::players[k]->lowyaw = Person::players[k]->yaw;
1792 lowpoint = tempcoords1;
1793 lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5;
1794 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1795 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1796 Person::players[k]->setTargetAnimation(walljumprightanim);
1797 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1799 pause_sound(whooshsound);
1801 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1802 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1803 if (lowpointtarget.z < 0)
1804 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1805 Person::players[k]->targetyaw = Person::players[k]->yaw;
1806 Person::players[k]->lowyaw = Person::players[k]->yaw;
1810 lowpoint = tempcoords1;
1811 lowpointtarget = lowpoint + Person::players[k]->facing * 2;
1812 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1813 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1814 Person::players[k]->setTargetAnimation(walljumpbackanim);
1815 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1817 pause_sound(whooshsound);
1819 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1820 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1821 if (lowpointtarget.z < 0)
1822 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1823 Person::players[k]->targetyaw = Person::players[k]->yaw;
1824 Person::players[k]->lowyaw = Person::players[k]->yaw;
1828 lowpoint = tempcoords1;
1829 lowpointtarget = lowpoint - Person::players[k]->facing * 2;
1830 whichhit = Object::objects[i]->model.LineCheck(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1831 if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) {
1832 Person::players[k]->setTargetAnimation(walljumpfrontanim);
1833 emit_sound_at(movewhooshsound, Person::players[k]->coords);
1835 pause_sound(whooshsound);
1837 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1838 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1839 if (lowpointtarget.z < 0)
1840 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1841 Person::players[k]->yaw += 180;
1842 Person::players[k]->targetyaw = Person::players[k]->yaw;
1843 Person::players[k]->lowyaw = Person::players[k]->yaw;
1852 } else if (Object::objects[i]->type == rocktype) {
1853 lowpoint2 = Person::players[k]->coords;
1854 lowpoint = Person::players[k]->coords;
1856 if (Object::objects[i]->model.LineCheck(&lowpoint, &lowpoint2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
1857 Person::players[k]->coords = colpoint;
1858 Person::players[k]->collide = 1;
1861 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) {
1862 //flipped into a rock
1863 if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7)
1864 Person::players[k]->RagDoll(0);
1866 if (Person::players[k]->animTarget == jumpupanim) {
1867 Person::players[k]->jumppower = -4;
1868 Person::players[k]->animTarget = Person::players[k]->getIdle();
1870 Person::players[k]->target = 0;
1871 Person::players[k]->frameTarget = 0;
1872 Person::players[k]->onterrain = 1;
1874 if (Person::players[k]->id == 0) {
1875 pause_sound(whooshsound);
1876 OPENAL_SetVolume(channels[whooshsound], 0);
1880 if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) {
1881 if (Person::players[k]->isFlip())
1882 Person::players[k]->jumppower = -4;
1883 Person::players[k]->animTarget = Person::players[k]->getLanding();
1884 emit_sound_at(landsound, Person::players[k]->coords, 128.);
1886 addEnvSound(Person::players[k]->coords);
1895 for (int l = 0; l < terrain.patchobjectnum[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz]; l++) {
1896 int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l];
1897 lowpoint = Person::players[k]->coords;
1899 if (Object::objects[i]->type != rocktype)
1900 if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1901 if (Person::players[k]->animTarget != jumpupanim &&
1902 Person::players[k]->animTarget != jumpdownanim &&
1903 Person::players[k]->onterrain)
1904 Person::players[k]->avoidcollided = 1;
1905 Person::players[k]->coords = lowpoint;
1906 Person::players[k]->coords.y -= 1.35;
1907 Person::players[k]->collide = 1;
1909 if ((Person::players[k]->grabdelay <= 0 || Person::players[k]->aitype != playercontrolled) &&
1910 (Person::players[k]->animCurrent != climbanim &&
1911 Person::players[k]->animCurrent != hanganim &&
1912 !Person::players[k]->isWallJump() ||
1913 Person::players[k]->animTarget == jumpupanim ||
1914 Person::players[k]->animTarget == jumpdownanim)) {
1915 lowpoint = Person::players[k]->coords;
1916 Object::objects[i]->model.SphereCheckPossible(&lowpoint, 1.5, &Object::objects[i]->position, &Object::objects[i]->yaw);
1917 lowpoint = Person::players[k]->coords;
1921 facing = DoRotation(facing, 0, Person::players[k]->targetyaw + 180, 0);
1922 lowpointtarget = lowpoint + facing * 1.4;
1923 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1924 if (whichhit != -1) {
1925 lowpoint = Person::players[k]->coords;
1927 lowpointtarget = lowpoint + facing * 1.4;
1928 lowpoint2 = lowpoint;
1929 lowpointtarget2 = lowpointtarget;
1930 lowpoint3 = lowpoint;
1931 lowpointtarget3 = lowpointtarget;
1932 lowpoint4 = lowpoint;
1933 lowpointtarget4 = lowpointtarget;
1934 lowpoint5 = lowpoint;
1935 lowpointtarget5 = lowpointtarget;
1936 lowpoint6 = lowpoint;
1937 lowpointtarget6 = lowpointtarget;
1938 lowpoint7 = lowpoint;
1939 lowpointtarget7 = lowpoint;
1941 lowpointtarget2.x += .1;
1943 lowpointtarget3.z += .1;
1945 lowpointtarget4.x -= .1;
1947 lowpointtarget5.z -= .1;
1948 lowpoint6.y += 45 / 13;
1949 lowpointtarget6.y += 45 / 13;
1950 lowpointtarget6 += facing * .6;
1951 lowpointtarget7.y += 90 / 13;
1952 whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw);
1953 if (Object::objects[i]->friction > .5)
1954 if (whichhit != -1) {
1955 if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim)
1956 Person::players[k]->collided = 1;
1957 if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1)
1958 if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1)
1959 if ( Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2,
1960 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
1961 Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3,
1962 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
1963 Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4,
1964 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 &&
1965 Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5,
1966 &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1)
1967 for (int j = 0; j < 45; j++) {
1968 lowpoint = Person::players[k]->coords;
1969 lowpoint.y += (float)j / 13;
1970 lowpointtarget = lowpoint + facing * 1.4;
1971 if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget,
1972 &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) {
1973 if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim)
1975 if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) {
1976 lowpoint = Person::players[k]->coords;
1977 lowpoint.y += (float)j / 13;
1978 lowpointtarget = lowpoint + facing * 1.3;
1979 flatfacing = Person::players[k]->coords;
1980 Person::players[k]->coords = colpoint - DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * .01;
1981 Person::players[k]->coords.y = lowpointtarget.y - .07;
1982 Person::players[k]->currentoffset = (flatfacing - Person::players[k]->coords) / Person::players[k]->scale;
1984 if (j > 10 || !Person::players[k]->isRun()) {
1985 if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) {
1987 pause_sound(whooshsound);
1989 emit_sound_at(jumpsound, Person::players[k]->coords, 128.);
1991 lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0);
1992 Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI;
1993 if (lowpointtarget.z < 0)
1994 Person::players[k]->yaw = 180 - Person::players[k]->yaw;
1995 Person::players[k]->targetyaw = Person::players[k]->yaw;
1996 Person::players[k]->lowyaw = Person::players[k]->yaw;
1998 //Person::players[k]->velocity=lowpointtarget*.03;
1999 Person::players[k]->velocity = 0;
2002 if (Person::players[k]->animTarget == jumpupanim) {
2003 Person::players[k]->animTarget = climbanim;
2004 Person::players[k]->jumppower = 0;
2005 Person::players[k]->jumpclimb = 1;
2007 Person::players[k]->transspeed = 6;
2008 Person::players[k]->target = 0;
2009 Person::players[k]->frameTarget = 1;
2012 Person::players[k]->setTargetAnimation(hanganim);
2013 Person::players[k]->jumppower = 0;
2025 if (Person::players[k]->collide <= 0) {
2027 if (!Person::players[k]->onterrain &&
2028 Person::players[k]->animTarget != jumpupanim &&
2029 Person::players[k]->animTarget != jumpdownanim &&
2030 Person::players[k]->animTarget != climbanim &&
2031 Person::players[k]->animTarget != hanganim &&
2032 !Person::players[k]->isWallJump() &&
2033 !Person::players[k]->isFlip()) {
2034 if (Person::players[k]->animCurrent != climbanim &&
2035 Person::players[k]->animCurrent != tempanim &&
2036 Person::players[k]->animTarget != backhandspringanim &&
2037 (Person::players[k]->animTarget != rollanim ||
2038 Person::players[k]->frameTarget < 2 ||
2039 Person::players[k]->frameTarget > 6)) {
2040 //stagger off ledge (?)
2041 if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim)
2042 Person::players[k]->RagDoll(0);
2043 Person::players[k]->setTargetAnimation(jumpdownanim);
2046 emit_sound_at(whooshsound, Person::players[k]->coords, 128.);
2049 Person::players[k]->velocity.y += gravity;
2053 Person::players[k]->realoldcoords = Person::players[k]->coords;
2059 static int randattack;
2060 static bool playerrealattackkeydown = 0;
2062 if (!Input::isKeyDown(attackkey))
2065 Person::players[0]->attackkeydown = 0;
2067 playerrealattackkeydown = 0;
2069 playerrealattackkeydown = Input::isKeyDown(attackkey);
2070 if ((Person::players[0]->parriedrecently <= 0 ||
2071 Person::players[0]->weaponactive == -1) &&
2074 Person::players[0]->lastattack != swordslashanim &&
2075 Person::players[0]->lastattack != knifeslashstartanim &&
2076 Person::players[0]->lastattack != staffhitanim &&
2077 Person::players[0]->lastattack != staffspinhitanim)))
2078 Person::players[0]->attackkeydown = Input::isKeyDown(attackkey);
2079 if (Input::isKeyDown(attackkey) &&
2081 !Person::players[0]->backkeydown) {
2082 for (unsigned k = 0; k < Person::players.size(); k++) {
2083 if ((Person::players[k]->animTarget == swordslashanim ||
2084 Person::players[k]->animTarget == staffhitanim ||
2085 Person::players[k]->animTarget == staffspinhitanim) &&
2086 Person::players[0]->animCurrent != dodgebackanim &&
2087 !Person::players[k]->skeleton.free)
2088 Person::players[k]->Reverse();
2092 if (!hostile || Dialog::inDialog())
2093 Person::players[0]->attackkeydown = 0;
2095 for (unsigned k = 0; k < Person::players.size(); k++) {
2096 if (Dialog::inDialog())
2097 Person::players[k]->attackkeydown = 0;
2098 if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) {
2099 if (Person::players[k]->aitype != playercontrolled)
2100 Person::players[k]->victim = Person::players[0];
2101 //attack key pressed
2102 if (Person::players[k]->attackkeydown) {
2104 if (Person::players[k]->backkeydown &&
2105 Person::players[k]->animTarget != backhandspringanim &&
2106 (Person::players[k]->isIdle() ||
2107 Person::players[k]->isStop() ||
2108 Person::players[k]->isRun() ||
2109 Person::players[k]->animTarget == walkanim)) {
2110 if (Person::players[k]->jumppower <= 1) {
2111 Person::players[k]->jumppower -= 2;
2113 for (unsigned i = 0; i < Person::players.size(); i++) {
2116 if (Person::players[i]->animTarget == swordslashanim ||
2117 Person::players[i]->animTarget == knifeslashstartanim ||
2118 Person::players[i]->animTarget == staffhitanim ||
2119 Person::players[i]->animTarget == staffspinhitanim)
2120 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) {
2121 Person::players[k]->setTargetAnimation(dodgebackanim);
2122 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2123 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2126 if (Person::players[k]->animTarget != dodgebackanim) {
2129 Person::players[k]->setTargetAnimation(backhandspringanim);
2130 Person::players[k]->targetyaw = -yaw + 180;
2131 if (Person::players[k]->leftkeydown)
2132 Person::players[k]->targetyaw -= 45;
2133 if (Person::players[k]->rightkeydown)
2134 Person::players[k]->targetyaw += 45;
2135 Person::players[k]->yaw = Person::players[k]->targetyaw;
2136 Person::players[k]->jumppower -= 2;
2141 if (!Animation::animations[Person::players[k]->animTarget].attack &&
2142 !Person::players[k]->backkeydown &&
2143 (Person::players[k]->isIdle() ||
2144 Person::players[k]->isRun() ||
2145 Person::players[k]->animTarget == walkanim ||
2146 Person::players[k]->animTarget == sneakanim ||
2147 Person::players[k]->isCrouch())) {
2148 const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType();
2149 //normal attacks (?)
2150 Person::players[k]->hasvictim = 0;
2151 if (Person::players.size() > 1)
2152 for (unsigned i = 0; i < Person::players.size(); i++) {
2153 if (i == k || !(k == 0 || i == 0))
2155 if (!Person::players[k]->hasvictim)
2156 if (Animation::animations[Person::players[k]->animTarget].attack != reversal) {
2158 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2159 if (distance < 4.5 &&
2160 !Person::players[i]->skeleton.free &&
2161 Person::players[i]->howactive < typedead1 &&
2162 Person::players[i]->animTarget != jumpreversedanim &&
2163 Person::players[i]->animTarget != rabbitkickreversedanim &&
2164 Person::players[i]->animTarget != rabbitkickanim &&
2165 Person::players[k]->animTarget != rabbitkickanim &&
2166 Person::players[i]->animTarget != getupfrombackanim &&
2167 (Person::players[i]->animTarget != staggerbackhighanim &&
2168 (Person::players[i]->animTarget != staggerbackhardanim || Person::players[i]->targetFrame().label == 6)) &&
2169 Person::players[i]->animTarget != jumpdownanim &&
2170 Person::players[i]->animTarget != jumpupanim &&
2171 Person::players[i]->animTarget != getupfromfrontanim) {
2172 Person::players[k]->victim = Person::players[i];
2173 Person::players[k]->hasvictim = 1;
2174 if (Person::players[k]->aitype == playercontrolled) { //human player
2176 if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2177 Person::players[k]->crouchkeydown &&
2178 Animation::animations[Person::players[i]->animTarget].height != lowheight)
2179 Person::players[k]->animTarget = sweepanim;
2181 else if (distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2182 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2183 !Person::players[k]->forwardkeydown &&
2184 !Person::players[k]->leftkeydown &&
2185 !Person::players[k]->rightkeydown &&
2186 !Person::players[k]->crouchkeydown &&
2189 Person::players[k]->animTarget = winduppunchanim;
2191 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2192 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2193 !Person::players[k]->forwardkeydown &&
2194 !Person::players[k]->leftkeydown &&
2195 !Person::players[k]->rightkeydown &&
2196 !Person::players[k]->crouchkeydown &&
2198 Person::players[k]->animTarget = upunchanim;
2200 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2201 Person::players[i]->staggerdelay > 0 &&
2202 attackweapon == knife &&
2203 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2)
2204 Person::players[k]->animTarget = knifefollowanim;
2206 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2207 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2208 !Person::players[k]->forwardkeydown &&
2209 !Person::players[k]->leftkeydown &&
2210 !Person::players[k]->rightkeydown &&
2211 !Person::players[k]->crouchkeydown &&
2212 attackweapon == knife &&
2213 Person::players[k]->weaponmissdelay <= 0)
2214 Person::players[k]->animTarget = knifeslashstartanim;
2216 else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2217 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2218 !Person::players[k]->crouchkeydown &&
2219 attackweapon == sword &&
2220 Person::players[k]->weaponmissdelay <= 0)
2221 Person::players[k]->animTarget = swordslashanim;
2223 else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2224 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2225 !Person::players[k]->crouchkeydown &&
2226 attackweapon == staff &&
2227 Person::players[k]->weaponmissdelay <= 0 &&
2228 !Person::players[k]->leftkeydown &&
2229 !Person::players[k]->rightkeydown &&
2230 !Person::players[k]->forwardkeydown)
2231 Person::players[k]->animTarget = staffhitanim;
2233 else if (distance < 4.5 * sq(Person::players[k]->scale * 5) &&
2234 Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2235 !Person::players[k]->crouchkeydown &&
2236 attackweapon == staff &&
2237 Person::players[k]->weaponmissdelay <= 0)
2238 Person::players[k]->animTarget = staffspinhitanim;
2240 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2241 Animation::animations[Person::players[i]->animTarget].height != lowheight)
2242 Person::players[k]->animTarget = spinkickanim;
2244 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2245 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2246 Animation::animations[Person::players[k]->animTarget].attack != normalattack)
2247 Person::players[k]->animTarget = lowkickanim;
2248 } else { //AI player
2249 if (distance < 4.5 * sq(Person::players[k]->scale * 5)) {
2250 randattack = abs(Random() % 5);
2251 if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) {
2253 if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight)
2254 Person::players[k]->animTarget = sweepanim;
2256 else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight &&
2258 Person::players[k]->animTarget = upunchanim;
2260 else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight)
2261 Person::players[k]->animTarget = spinkickanim;
2263 else if (Animation::animations[Person::players[i]->animTarget].height == lowheight)
2264 Person::players[k]->animTarget = lowkickanim;
2268 if ((!Tutorial::active || !attackweapon) &&
2269 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2271 Animation::animations[Person::players[i]->animTarget].height != lowheight)
2272 Person::players[k]->animTarget = sweepanim;
2274 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2275 attackweapon == knife &&
2276 Person::players[k]->weaponmissdelay <= 0)
2277 Person::players[k]->animTarget = knifeslashstartanim;
2279 else if (!(Person::players[0]->victim == Person::players[i] &&
2280 Person::players[0]->hasvictim &&
2281 Person::players[0]->animTarget == swordslashanim) &&
2282 attackweapon == sword &&
2283 Person::players[k]->weaponmissdelay <= 0)
2284 Person::players[k]->animTarget = swordslashanim;
2286 else if (!(Person::players[0]->victim == Person::players[i] &&
2287 Person::players[0]->hasvictim &&
2288 Person::players[0]->animTarget == swordslashanim) &&
2289 attackweapon == staff &&
2290 Person::players[k]->weaponmissdelay <= 0 &&
2292 Person::players[k]->animTarget = staffhitanim;
2294 else if (!(Person::players[0]->victim == Person::players[i] &&
2295 Person::players[0]->hasvictim &&
2296 Person::players[0]->animTarget == swordslashanim) &&
2297 attackweapon == staff &&
2298 Person::players[k]->weaponmissdelay <= 0 &&
2300 Person::players[k]->animTarget = staffspinhitanim;
2302 else if ((!Tutorial::active || !attackweapon) &&
2303 distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2305 Animation::animations[Person::players[i]->animTarget].height != lowheight)
2306 Person::players[k]->animTarget = spinkickanim;
2308 else if (distance < 2.5 * sq(Person::players[k]->scale * 5) &&
2309 Animation::animations[Person::players[i]->animTarget].height == lowheight &&
2310 Animation::animations[Person::players[k]->animTarget].attack != normalattack)
2311 Person::players[k]->animTarget = lowkickanim;
2315 //upunch becomes wolfslap
2316 if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype)
2317 Person::players[k]->animTarget = wolfslapanim;
2320 if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) &&
2321 Person::players[i]->howactive < typedead1 &&
2322 distance < 1.5 * sq(Person::players[k]->scale * 5) &&
2323 !Person::players[i]->skeleton.free &&
2324 Person::players[i]->animTarget != getupfrombackanim &&
2325 Person::players[i]->animTarget != getupfromfrontanim &&
2326 (Person::players[i]->surprised > 0 ||
2327 Person::players[i]->aitype == passivetype ||
2328 attackweapon && Person::players[i]->stunned > 0) &&
2329 normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[k]->coords) > 0) {
2331 if (!attackweapon) {
2332 Person::players[k]->animCurrent = sneakattackanim;
2333 Person::players[k]->animTarget = sneakattackanim;
2334 Person::players[i]->animCurrent = sneakattackedanim;
2335 Person::players[i]->animTarget = sneakattackedanim;
2336 Person::players[k]->oldcoords = Person::players[k]->coords;
2337 Person::players[k]->coords = Person::players[i]->coords;
2340 if (attackweapon == knife) {
2341 Person::players[k]->animCurrent = knifesneakattackanim;
2342 Person::players[k]->animTarget = knifesneakattackanim;
2343 Person::players[i]->animCurrent = knifesneakattackedanim;
2344 Person::players[i]->animTarget = knifesneakattackedanim;
2345 Person::players[i]->oldcoords = Person::players[i]->coords;
2346 Person::players[i]->coords = Person::players[k]->coords;
2349 if (attackweapon == sword) {
2350 Person::players[k]->animCurrent = swordsneakattackanim;
2351 Person::players[k]->animTarget = swordsneakattackanim;
2352 Person::players[i]->animCurrent = swordsneakattackedanim;
2353 Person::players[i]->animTarget = swordsneakattackedanim;
2354 Person::players[i]->oldcoords = Person::players[i]->coords;
2355 Person::players[i]->coords = Person::players[k]->coords;
2357 if (attackweapon != staff) {
2358 Person::players[k]->victim = Person::players[i];
2359 Person::players[k]->hasvictim = 1;
2360 Person::players[i]->targettilt2 = 0;
2361 Person::players[i]->frameTarget = 1;
2362 Person::players[i]->frameCurrent = 0;
2363 Person::players[i]->target = 0;
2364 Person::players[i]->velocity = 0;
2365 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2366 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2367 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2368 Person::players[k]->target = Person::players[i]->target;
2369 Person::players[k]->velocity = 0;
2370 Person::players[k]->targetyaw = Person::players[i]->yaw;
2371 Person::players[k]->yaw = Person::players[i]->yaw;
2372 Person::players[i]->targetyaw = Person::players[i]->yaw;
2375 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2376 Person::players[k]->victim == Person::players[i] &&
2377 (!Person::players[i]->skeleton.free)) {
2379 Person::players[k]->frameTarget = 0;
2380 Person::players[k]->target = 0;
2382 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2383 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2384 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2385 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2386 Person::players[k]->lastattack = Person::players[k]->animTarget;
2388 if (Person::players[k]->animTarget == knifefollowanim &&
2389 Person::players[k]->victim == Person::players[i]) {
2391 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords);
2392 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords);
2393 Person::players[k]->victim = Person::players[i];
2394 Person::players[k]->hasvictim = 1;
2395 Person::players[i]->animTarget = knifefollowedanim;
2396 Person::players[i]->animCurrent = knifefollowedanim;
2397 Person::players[i]->targettilt2 = 0;
2398 Person::players[i]->targettilt2 = Person::players[k]->targettilt2;
2399 Person::players[i]->frameTarget = 1;
2400 Person::players[i]->frameCurrent = 0;
2401 Person::players[i]->target = 0;
2402 Person::players[i]->velocity = 0;
2403 Person::players[k]->animCurrent = knifefollowanim;
2404 Person::players[k]->animTarget = knifefollowanim;
2405 Person::players[k]->targettilt2 = Person::players[i]->targettilt2;
2406 Person::players[k]->frameCurrent = Person::players[i]->frameCurrent;
2407 Person::players[k]->frameTarget = Person::players[i]->frameTarget;
2408 Person::players[k]->target = Person::players[i]->target;
2409 Person::players[k]->velocity = 0;
2410 Person::players[k]->oldcoords = Person::players[k]->coords;
2411 Person::players[i]->coords = Person::players[k]->coords;
2412 Person::players[i]->targetyaw = Person::players[k]->targetyaw;
2413 Person::players[i]->yaw = Person::players[k]->targetyaw;
2414 Person::players[k]->yaw = Person::players[k]->targetyaw;
2415 Person::players[i]->yaw = Person::players[k]->targetyaw;
2419 const bool hasstaff = attackweapon == staff;
2420 if (k == 0 && Person::players.size() > 1)
2421 for (unsigned i = 0; i < Person::players.size(); i++) {
2424 if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) &&
2425 Animation::animations[Person::players[k]->animTarget].attack == neutral) {
2426 const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords);
2427 if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown))
2428 if (Person::players[i]->skeleton.free)
2429 if (distance < 3.5 * sq(Person::players[k]->scale * 5) &&
2430 (Person::players[i]->dead ||
2431 Person::players[i]->skeleton.longdead > 1000 ||
2432 Person::players[k]->isRun() ||
2435 (Person::players[i]->skeleton.longdead > 2000 ||
2436 Person::players[i]->damage > Person::players[i]->damagetolerance / 8 ||
2437 Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) &&
2438 distance < 1.5 * sq(Person::players[k]->scale * 5)))) {
2439 Person::players[k]->victim = Person::players[i];
2440 Person::players[k]->hasvictim = 1;
2441 if (attackweapon && !Tutorial::active) {
2443 if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5))
2444 Person::players[k]->animTarget = crouchstabanim;
2446 if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword)
2447 Person::players[k]->animTarget = swordgroundstabanim;
2449 if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff)
2450 Person::players[k]->animTarget = staffgroundsmashanim;
2452 if (distance < 2.5 &&
2453 Person::players[k]->crouchkeydown &&
2454 Person::players[k]->animTarget != crouchstabanim &&
2456 Person::players[i]->dead &&
2457 Person::players[i]->skeleton.free &&
2458 Person::players[i]->skeleton.longdead > 1000) {
2459 Person::players[k]->animTarget = killanim;
2460 terrain.deleteDeadDecals();
2461 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2462 if (Object::objects[l]->model.type == decalstype) {
2463 Object::objects[l]->model.deleteDeadDecals();
2467 if (!Person::players[i]->dead || musictype != 2)
2468 if (distance < 3.5 &&
2469 (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) &&
2470 Person::players[k]->staggerdelay <= 0 &&
2471 (Person::players[i]->dead ||
2472 Person::players[i]->skeleton.longdead < 300 &&
2473 Person::players[k]->lastattack != spinkickanim &&
2474 Person::players[i]->skeleton.free) &&
2475 (!Person::players[i]->dead || musictype != stream_fighttheme)) {
2476 Person::players[k]->animTarget = dropkickanim;
2477 terrain.deleteDeadDecals();
2478 for (unsigned int l = 0; l < Object::objects.size(); l++) {
2479 if (Object::objects[l]->model.type == decalstype) {
2480 Object::objects[l]->model.deleteDeadDecals();
2485 if (Animation::animations[Person::players[k]->animTarget].attack == normalattack &&
2486 Person::players[k]->victim == Person::players[i] &&
2487 (!Person::players[i]->skeleton.free ||
2488 Person::players[k]->animTarget == killanim ||
2489 Person::players[k]->animTarget == crouchstabanim ||
2490 Person::players[k]->animTarget == swordgroundstabanim ||
2491 Person::players[k]->animTarget == staffgroundsmashanim ||
2492 Person::players[k]->animTarget == dropkickanim)) {
2494 Person::players[k]->frameTarget = 0;
2495 Person::players[k]->target = 0;
2497 XYZ targetpoint = Person::players[i]->coords;
2498 if (Person::players[k]->animTarget == crouchstabanim ||
2499 Person::players[k]->animTarget == swordgroundstabanim ||
2500 Person::players[k]->animTarget == staffgroundsmashanim) {
2501 targetpoint += (Person::players[i]->jointPos(abdomen) +
2502 Person::players[i]->jointPos(neck)) / 2 *
2503 Person::players[i]->scale;
2505 Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, targetpoint);
2506 Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, targetpoint);
2508 if (Person::players[k]->animTarget == crouchstabanim || Person::players[k]->animTarget == swordgroundstabanim) {
2509 Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4;
2512 if (Person::players[k]->animTarget == staffgroundsmashanim)
2513 Person::players[k]->targettilt2 += 10;
2515 Person::players[k]->lastattack3 = Person::players[k]->lastattack2;
2516 Person::players[k]->lastattack2 = Person::players[k]->lastattack;
2517 Person::players[k]->lastattack = Person::players[k]->animTarget;
2519 if (Person::players[k]->animTarget == swordgroundstabanim) {
2520 Person::players[k]->targetyaw += 30;
2525 if (!Person::players[k]->hasvictim) {
2527 for (unsigned i = 0; i < Person::players.size(); i++) {
2528 if (i == k || !(i == 0 || k == 0))
2530 if (!Person::players[i]->skeleton.free) {
2531 if (Person::players[k]->hasvictim) {
2532 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) <
2533 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords))
2534 Person::players[k]->victim = Person::players[i];
2536 Person::players[k]->victim = Person::players[i];
2537 Person::players[k]->hasvictim = 1;
2542 if (Person::players[k]->aitype == playercontrolled)
2544 if (Person::players[k]->attackkeydown &&
2545 Person::players[k]->isRun() &&
2546 Person::players[k]->wasRun() &&
2547 ((Person::players[k]->hasvictim &&
2548 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) < 12 * sq(Person::players[k]->scale * 5) &&
2549 distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords) > 7 * sq(Person::players[k]->scale * 5) &&
2550 !Person::players[k]->victim->skeleton.free &&
2551 Person::players[k]->victim->animTarget != getupfrombackanim &&
2552 Person::players[k]->victim->animTarget != getupfromfrontanim &&
2553 Animation::animations[Person::players[k]->victim->animTarget].height != lowheight &&
2554 Person::players[k]->aitype != playercontrolled && //wat???
2555 normaldotproduct(Person::players[k]->facing, Person::players[k]->victim->coords - Person::players[k]->coords) > 0 &&
2556 Person::players[k]->rabbitkickenabled) ||
2557 Person::players[k]->jumpkeydown)) {
2559 Person::players[k]->setTargetAnimation(rabbitkickanim);
2562 if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) {
2564 switch (attackweapon) {
2585 void doPlayerCollisions()
2587 static XYZ rotatetarget;
2588 static float collisionradius;
2589 if (Person::players.size() > 1)
2590 for (unsigned k = 0; k < Person::players.size(); k++)
2591 for (unsigned i = k + 1; i < Person::players.size(); i++) {
2592 //neither player is part of a reversal
2593 if ((Animation::animations[Person::players[i]->animTarget].attack != reversed &&
2594 Animation::animations[Person::players[i]->animTarget].attack != reversal &&
2595 Animation::animations[Person::players[k]->animTarget].attack != reversed &&
2596 Animation::animations[Person::players[k]->animTarget].attack != reversal) || (i != 0 && k != 0))
2597 if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed &&
2598 Animation::animations[Person::players[i]->animCurrent].attack != reversal &&
2599 Animation::animations[Person::players[k]->animCurrent].attack != reversed &&
2600 Animation::animations[Person::players[k]->animCurrent].attack != reversal) || (i != 0 && k != 0))
2601 //neither is sleeping
2602 if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping)
2603 if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall)
2604 //in same patch, neither is climbing
2605 if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx &&
2606 Person::players[i]->whichpatchz == Person::players[k]->whichpatchz &&
2607 Person::players[k]->skeleton.oldfree == Person::players[k]->skeleton.free &&
2608 Person::players[i]->skeleton.oldfree == Person::players[i]->skeleton.free &&
2609 Person::players[i]->animTarget != climbanim &&
2610 Person::players[i]->animTarget != hanganim &&
2611 Person::players[k]->animTarget != climbanim &&
2612 Person::players[k]->animTarget != hanganim)
2613 //players are close (bounding box test)
2614 if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3)
2615 if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3)
2616 if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3)
2617 if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3)
2618 if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3)
2619 if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) {
2620 //spread fire from player to player
2621 if (distsq(&Person::players[i]->coords, &Person::players[k]->coords)
2622 < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2623 if (Person::players[i]->onfire || Person::players[k]->onfire) {
2624 if (!Person::players[i]->onfire)
2625 Person::players[i]->CatchFire();
2626 if (!Person::players[k]->onfire)
2627 Person::players[k]->CatchFire();
2631 XYZ tempcoords1 = Person::players[i]->coords;
2632 XYZ tempcoords2 = Person::players[k]->coords;
2633 if (!Person::players[i]->skeleton.oldfree)
2634 tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale;
2635 if (!Person::players[k]->skeleton.oldfree)
2636 tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale;
2637 collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2638 if (Person::players[0]->hasvictim)
2639 if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free)
2640 collisionradius = 3;
2641 if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) &&
2642 (distsq(&tempcoords1, &tempcoords2) < collisionradius ||
2643 distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) {
2644 //jump down on a dead body
2645 if (k == 0 || i == 0) {
2647 if (Person::players[0]->animTarget == jumpdownanim &&
2648 !Person::players[0]->skeleton.oldfree &&
2649 !Person::players[0]->skeleton.free &&
2650 Person::players[l]->skeleton.oldfree &&
2651 Person::players[l]->skeleton.free &&
2652 Person::players[l]->dead &&
2653 Person::players[0]->lastcollide <= 0 &&
2654 fabs(Person::players[l]->coords.y - Person::players[0]->coords.y) < .2 &&
2655 distsq(&Person::players[0]->coords, &Person::players[l]->coords) < .7 * sq((Person::players[l]->scale + Person::players[0]->scale) * 2.5)) {
2656 Person::players[0]->coords.y = Person::players[l]->coords.y;
2657 Person::players[l]->velocity = Person::players[0]->velocity;
2658 Person::players[l]->skeleton.free = 0;
2659 Person::players[l]->yaw = 0;
2660 Person::players[l]->RagDoll(0);
2661 Person::players[l]->DoDamage(20);
2663 Person::players[l]->skeleton.longdead = 0;
2664 Person::players[0]->lastcollide = 1;
2668 if ( (Person::players[i]->skeleton.oldfree == 1 && findLengthfast(&Person::players[i]->velocity) > 1) ||
2669 (Person::players[k]->skeleton.oldfree == 1 && findLengthfast(&Person::players[k]->velocity) > 1) ||
2670 (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0)) {
2671 rotatetarget = Person::players[k]->velocity - Person::players[i]->velocity;
2672 if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim ||
2673 Person::players[i]->skeleton.free) &&
2674 (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim ||
2675 Person::players[k]->skeleton.free))
2676 if ((((k != 0 && findLengthfast(&rotatetarget) > 150 ||
2677 k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) &&
2678 normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) &&
2680 k != 0 && Person::players[i]->skeleton.oldfree == 1 && Animation::animations[Person::players[k]->animCurrent].attack == neutral ||
2681 /*i!=0&&*/Person::players[k]->skeleton.oldfree == 1 && Animation::animations[Person::players[i]->animCurrent].attack == neutral)) ||
2682 (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) &&
2683 (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) &&
2684 k == 0 && !Person::players[i]->skeleton.oldfree && !Person::players[k]->skeleton.oldfree) {
2686 if ( (i != 0 || Person::players[i]->skeleton.free) &&
2687 (k != 0 || Person::players[k]->skeleton.free) ||
2688 (Animation::animations[Person::players[i]->animTarget].height == highheight &&
2689 Animation::animations[Person::players[k]->animTarget].height == highheight)) {
2690 if (!Tutorial::active) {
2691 emit_sound_at(heavyimpactsound, Person::players[i]->coords);
2694 Person::players[i]->RagDoll(0);
2695 if (Person::players[i]->damage > Person::players[i]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[i]->dead) {
2696 award_bonus(0, aimbonus);
2698 Person::players[i]->DoDamage(findLengthfast(&rotatetarget) / 4);
2699 Person::players[k]->RagDoll(0);
2700 if (Person::players[k]->damage > Person::players[k]->damagetolerance - findLengthfast(&rotatetarget) / 4 && !Person::players[k]->dead) {
2701 award_bonus(0, aimbonus); // Huh, again?
2703 Person::players[k]->DoDamage(findLengthfast(&rotatetarget) / 4);
2705 for (unsigned j = 0; j < Person::players[i]->skeleton.joints.size(); j++) {
2706 Person::players[i]->skeleton.joints[j].velocity = Person::players[i]->skeleton.joints[j].velocity / 5 + Person::players[k]->velocity;
2708 for (unsigned j = 0; j < Person::players[k]->skeleton.joints.size(); j++) {
2709 Person::players[k]->skeleton.joints[j].velocity = Person::players[k]->skeleton.joints[j].velocity / 5 + Person::players[i]->velocity;
2714 if ( (Animation::animations[Person::players[i]->animTarget].attack == neutral ||
2715 Animation::animations[Person::players[i]->animTarget].attack == normalattack) &&
2716 (Animation::animations[Person::players[k]->animTarget].attack == neutral ||
2717 Animation::animations[Person::players[k]->animTarget].attack == normalattack)) {
2719 if (Person::players[i]->skeleton.oldfree == 0 && Person::players[k]->skeleton.oldfree == 0) {
2720 if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < .5 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) {
2721 rotatetarget = Person::players[k]->coords - Person::players[i]->coords;
2722 Normalise(&rotatetarget);
2723 Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2;
2724 Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2
2725 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2726 Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5);
2727 if (Person::players[k]->howactive == typeactive || hostile)
2728 if (Person::players[k]->isIdle()) {
2729 if (Person::players[k]->howactive < typesleeping)
2730 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
2731 else if (Person::players[k]->howactive == typesleeping)
2732 Person::players[k]->setTargetAnimation(getupfromfrontanim);
2734 Person::players[k]->howactive = typeactive;
2736 if (Person::players[i]->howactive == typeactive || hostile)
2737 if (Person::players[i]->isIdle()) {
2738 if (Person::players[i]->howactive < typesleeping)
2739 Person::players[i]->setTargetAnimation(Person::players[k]->getStop());
2741 Person::players[i]->setTargetAnimation(getupfromfrontanim);
2743 Person::players[i]->howactive = typeactive;
2746 //jump down on player
2748 if (k == 0 && i != 0 && Person::players[k]->animTarget == jumpdownanim &&
2749 !Person::players[i]->isCrouch() &&
2750 Person::players[i]->animTarget != rollanim &&
2751 !Person::players[k]->skeleton.oldfree && !
2752 Person::players[k]->skeleton.free &&
2753 Person::players[k]->lastcollide <= 0 &&
2754 Person::players[k]->velocity.y < -10) {
2755 Person::players[i]->velocity = Person::players[k]->velocity;
2756 Person::players[k]->velocity = Person::players[k]->velocity * -.5;
2757 Person::players[k]->velocity.y = Person::players[i]->velocity.y;
2758 Person::players[i]->DoDamage(20);
2759 Person::players[i]->RagDoll(0);
2760 Person::players[k]->lastcollide = 1;
2761 award_bonus(k, AboveBonus);
2763 if (i == 0 && k != 0 && Person::players[i]->animTarget == jumpdownanim &&
2764 !Person::players[k]->isCrouch() &&
2765 Person::players[k]->animTarget != rollanim &&
2766 !Person::players[i]->skeleton.oldfree &&
2767 !Person::players[i]->skeleton.free &&
2768 Person::players[i]->lastcollide <= 0 &&
2769 Person::players[i]->velocity.y < -10) {
2770 Person::players[k]->velocity = Person::players[i]->velocity;
2771 Person::players[i]->velocity = Person::players[i]->velocity * -.3;
2772 Person::players[i]->velocity.y = Person::players[k]->velocity.y;
2773 Person::players[k]->DoDamage(20);
2774 Person::players[k]->RagDoll(0);
2775 Person::players[i]->lastcollide = 1;
2776 award_bonus(i, AboveBonus);
2782 Person::players[i]->CheckKick();
2783 Person::players[k]->CheckKick();
2791 static XYZ facing, flatfacing;
2796 if (Input::isKeyPressed(SDL_SCANCODE_F6)) {
2797 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
2798 stereoreverse = true;
2800 stereoreverse = false;
2803 printf("Stereo reversed\n");
2805 printf("Stereo unreversed\n");
2808 if (Input::isKeyDown(SDL_SCANCODE_F7)) {
2809 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
2810 stereoseparation -= 0.001;
2812 stereoseparation -= 0.010;
2813 printf("Stereo decreased increased to %f\n", stereoseparation);
2816 if (Input::isKeyDown(SDL_SCANCODE_F8)) {
2817 if (Input::isKeyDown(SDL_SCANCODE_LSHIFT))
2818 stereoseparation += 0.001;
2820 stereoseparation += 0.010;
2821 printf("Stereo separation increased to %f\n", stereoseparation);
2825 if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) {
2826 if (Tutorial::stage != 51) {
2827 Tutorial::stagetime = Tutorial::maxtime;
2829 emit_sound_np(consolefailsound, 128.);
2833 Values of mainmenu :
2835 2 Menu pause (resume/end game)
2837 4 Controls configuration menu
2838 5 Main game menu (choose level or challenge)
2839 6 Deleting user menu
2840 7 User managment menu (select/add)
2841 8 Choose difficulty menu
2842 9 Challenge level selection menu
2843 10 End of the campaign congratulation (is that really a menu?)
2844 11 Same that 9 ??? => unused
2845 18 stereo configuration
2850 if (mainmenu && endgame == 1)
2852 //go to level select after completing a campaign level
2853 if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) {
2860 OPENAL_SetFrequency(OPENAL_ALL);
2861 emit_stream_np(stream_menutheme);
2862 pause_sound(leveltheme);
2866 //escape key pressed
2867 if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) &&
2868 (gameon || mainmenu == 0)) {
2870 if (mainmenu == 0 && !winfreeze)
2871 mainmenu = 2; //pause
2872 else if (mainmenu == 1 || mainmenu == 2) {
2873 mainmenu = 0; //unpause
2876 if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
2877 OPENAL_SetFrequency(OPENAL_ALL);
2878 emit_stream_np(stream_menutheme);
2879 pause_sound(leveltheme);
2881 //on resume, play level music
2883 pause_sound(stream_menutheme);
2884 resume_stream(leveltheme);
2895 hostiletime += multiplier;
2899 leveltime += multiplier;
2902 if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V) && devtools) {
2905 OPENAL_SetFrequency(OPENAL_ALL);
2909 if (Input::isKeyPressed(consolekey) && devtools) {
2912 OPENAL_SetFrequency(OPENAL_ALL);
2921 if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) {
2922 inputText(consoletext[0], &consoleselected);
2924 if (!consoletext[0].empty()) {
2925 cmd_dispatch(consoletext[0]);
2926 for (int k = 14; k >= 1; k--) {
2927 consoletext[k] = consoletext[k - 1];
2929 consoletext[0].clear();
2930 consoleselected = 0;
2934 consoleblinkdelay -= multiplier;
2935 if (consoleblinkdelay <= 0) {
2936 consoleblinkdelay = .3;
2937 consoleblink = !consoleblink;
2941 static int oldwinfreeze;
2942 if (winfreeze && !oldwinfreeze) {
2943 OPENAL_SetFrequency(OPENAL_ALL);
2944 emit_sound_np(consolesuccesssound);
2947 oldwinfreeze = winfreeze;
2951 if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign)
2954 if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) {
2958 } else if (winfreeze) {
2966 if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
2969 static float talkdelay = 0;
2971 if (Dialog::inDialog())
2973 talkdelay -= multiplier;
2975 if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) {
2976 for (unsigned i = 0; i < Dialog::dialogs.size(); i++) {
2977 Dialog::dialogs[i].tick(i);
2981 windvar += multiplier;
2982 smoketex += multiplier;
2983 Tutorial::stagetime += multiplier;
2986 static float hotspotvisual[40];
2987 if (Hotspot::hotspots.size()) {
2989 if (editorenabled) {
2990 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
2991 hotspotvisual[i] -= multiplier / 320;
2995 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
2996 while (hotspotvisual[i] < 0) {
2998 hotspotsprite.x = float(abs(Random() % 100000)) / 100000 * Hotspot::hotspots[i].size;
2999 hotspotsprite = DoRotation(hotspotsprite, 0, 0, Random() % 360);
3000 hotspotsprite = DoRotation(hotspotsprite, 0, Random() % 360, 0);
3001 hotspotsprite += Hotspot::hotspots[i].position;
3002 Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite * 0, 1, 0.5, 0, 7, 0.4);
3003 hotspotvisual[i] += 0.1 / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size / Hotspot::hotspots[i].size;
3007 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
3008 if (Hotspot::hotspots[i].type <= 10 && Hotspot::hotspots[i].type > 0) {
3009 Hotspot::hotspots[i].position = Person::players[Hotspot::hotspots[i].type]->coords;
3015 if (Tutorial::active) {
3016 Tutorial::Do(multiplier);
3020 if (!Tutorial::active) {
3021 if (bonustime == 0 &&
3022 bonus != solidhit &&
3023 bonus != spinecrusher &&
3024 bonus != tracheotomy &&
3025 bonus != backstab &&
3027 emit_sound_np(consolesuccesssound);
3029 } else if (bonustime == 0) {
3030 emit_sound_np(fireendsound);
3032 if (bonustime == 0) {
3033 if (bonus != solidhit &&
3034 bonus != twoxcombo &&
3035 bonus != threexcombo &&
3036 bonus != fourxcombo &&
3040 bonusnum[bonus] += 0.15;
3041 if (Tutorial::active)
3043 bonusvalue /= bonusnum[bonus];
3044 bonustotal += bonusvalue;
3046 bonustime += multiplier;
3049 if (environment == snowyenvironment) {
3050 precipdelay -= multiplier;
3051 while (precipdelay < 0) {
3055 XYZ footvel, footpoint;
3058 footpoint = viewer + viewerfacing * 6;
3059 footpoint.y += ((float)abs(Random() % 1200)) / 100 - 6;
3060 footpoint.x += ((float)abs(Random() % 1200)) / 100 - 6;
3061 footpoint.z += ((float)abs(Random() % 1200)) / 100 - 6;
3062 Sprite::MakeSprite(snowsprite, footpoint, footvel, 1, 1, 1, .1, 1);
3067 doAerialAcrobatics();
3070 static XYZ oldviewer;
3073 if (!Dialog::inDialog()) {
3074 Person::players[0]->forwardkeydown = Input::isKeyDown(forwardkey);
3075 Person::players[0]->leftkeydown = Input::isKeyDown(leftkey);
3076 Person::players[0]->backkeydown = Input::isKeyDown(backkey);
3077 Person::players[0]->rightkeydown = Input::isKeyDown(rightkey);
3078 Person::players[0]->jumpkeydown = Input::isKeyDown(jumpkey);
3079 Person::players[0]->crouchkeydown = Input::isKeyDown(crouchkey);
3080 Person::players[0]->drawkeydown = Input::isKeyDown(drawkey);
3081 Person::players[0]->throwkeydown = Input::isKeyDown(throwkey);
3083 Person::players[0]->forwardkeydown = 0;
3084 Person::players[0]->leftkeydown = 0;
3085 Person::players[0]->backkeydown = 0;
3086 Person::players[0]->rightkeydown = 0;
3087 Person::players[0]->jumpkeydown = 0;
3088 Person::players[0]->crouchkeydown = 0;
3089 Person::players[0]->drawkeydown = 0;
3090 Person::players[0]->throwkeydown = 0;
3093 if (!Person::players[0]->jumpkeydown)
3094 Person::players[0]->jumpclimb = 0;
3097 if (Dialog::inDialog()) {
3099 if (Dialog::directing) {
3103 facing = DoRotation(facing, -pitch, 0, 0);
3104 facing = DoRotation(facing, 0, 0 - yaw, 0);
3109 flatfacing = DoRotation(flatfacing, 0, -yaw, 0);
3111 if (Input::isKeyDown(forwardkey))
3112 viewer += facing * multiplier * 4;
3113 if (Input::isKeyDown(backkey))
3114 viewer -= facing * multiplier * 4;
3115 if (Input::isKeyDown(leftkey))
3116 viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4;
3117 if (Input::isKeyDown(rightkey))
3118 viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4;
3119 if (Input::isKeyDown(jumpkey))
3120 viewer.y += multiplier * 4;
3121 if (Input::isKeyDown(crouchkey))
3122 viewer.y -= multiplier * 4;
3123 if ( Input::isKeyPressed(SDL_SCANCODE_1) ||
3124 Input::isKeyPressed(SDL_SCANCODE_2) ||
3125 Input::isKeyPressed(SDL_SCANCODE_3) ||
3126 Input::isKeyPressed(SDL_SCANCODE_4) ||
3127 Input::isKeyPressed(SDL_SCANCODE_5) ||
3128 Input::isKeyPressed(SDL_SCANCODE_6) ||
3129 Input::isKeyPressed(SDL_SCANCODE_7) ||
3130 Input::isKeyPressed(SDL_SCANCODE_8) ||
3131 Input::isKeyPressed(SDL_SCANCODE_9) ||
3132 Input::isKeyPressed(SDL_SCANCODE_0) ||
3133 Input::isKeyPressed(SDL_SCANCODE_MINUS)) {
3135 if (Input::isKeyPressed(SDL_SCANCODE_1)) whichend = 1;
3136 if (Input::isKeyPressed(SDL_SCANCODE_2)) whichend = 2;
3137 if (Input::isKeyPressed(SDL_SCANCODE_3)) whichend = 3;
3138 if (Input::isKeyPressed(SDL_SCANCODE_4)) whichend = 4;
3139 if (Input::isKeyPressed(SDL_SCANCODE_5)) whichend = 5;
3140 if (Input::isKeyPressed(SDL_SCANCODE_6)) whichend = 6;
3141 if (Input::isKeyPressed(SDL_SCANCODE_7)) whichend = 7;
3142 if (Input::isKeyPressed(SDL_SCANCODE_8)) whichend = 8;
3143 if (Input::isKeyPressed(SDL_SCANCODE_9)) whichend = 9;
3144 if (Input::isKeyPressed(SDL_SCANCODE_0)) whichend = 0;
3145 if (Input::isKeyPressed(SDL_SCANCODE_MINUS))
3147 if (whichend != -1) {
3148 Dialog::currentScene().participantfocus = whichend;
3149 Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords;
3150 Dialog::currentDialog().participantyaw[whichend] = Person::players[whichend]->yaw;
3152 if (whichend == -1) {
3153 Dialog::currentScene().participantfocus = -1;
3155 /* FIXME: potentially accessing -1 in Person::players! */
3156 if (Person::players[Dialog::currentScene().participantfocus]->dead) {
3157 Dialog::indialogue = -1;
3158 Dialog::directing = false;
3161 Dialog::currentScene().camera = viewer;
3162 Dialog::currentScene().camerayaw = yaw;
3163 Dialog::currentScene().camerapitch = pitch;
3164 Dialog::indialogue++;
3165 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3166 if (Dialog::currentScene().sound != 0) {
3167 playdialoguescenesound();
3171 for (unsigned j = 0; j < Person::players.size(); j++) {
3172 Dialog::currentScene().participantfacing[j] = Dialog::currentDialog().scenes[Dialog::indialogue - 1].participantfacing[j];
3175 //TODO: should these be KeyDown or KeyPressed?
3176 if ( Input::isKeyDown(SDL_SCANCODE_KP_1) ||
3177 Input::isKeyDown(SDL_SCANCODE_KP_2) ||
3178 Input::isKeyDown(SDL_SCANCODE_KP_3) ||
3179 Input::isKeyDown(SDL_SCANCODE_KP_4) ||
3180 Input::isKeyDown(SDL_SCANCODE_KP_5) ||
3181 Input::isKeyDown(SDL_SCANCODE_KP_6) ||
3182 Input::isKeyDown(SDL_SCANCODE_KP_7) ||
3183 Input::isKeyDown(SDL_SCANCODE_KP_8) ||
3184 Input::isKeyDown(SDL_SCANCODE_KP_9) ||
3185 Input::isKeyDown(SDL_SCANCODE_KP_0)) {
3187 if (Input::isKeyDown(SDL_SCANCODE_KP_1)) whichend = 1;
3188 if (Input::isKeyDown(SDL_SCANCODE_KP_2)) whichend = 2;
3189 if (Input::isKeyDown(SDL_SCANCODE_KP_3)) whichend = 3;
3190 if (Input::isKeyDown(SDL_SCANCODE_KP_4)) whichend = 4;
3191 if (Input::isKeyDown(SDL_SCANCODE_KP_5)) whichend = 5;
3192 if (Input::isKeyDown(SDL_SCANCODE_KP_6)) whichend = 6;
3193 if (Input::isKeyDown(SDL_SCANCODE_KP_7)) whichend = 7;
3194 if (Input::isKeyDown(SDL_SCANCODE_KP_8)) whichend = 8;
3195 if (Input::isKeyDown(SDL_SCANCODE_KP_9)) whichend = 9;
3196 if (Input::isKeyDown(SDL_SCANCODE_KP_0)) whichend = 0;
3197 Dialog::currentScene().participantfacing[whichend] = facing;
3199 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3200 Dialog::indialogue = -1;
3201 Dialog::directing = false;
3205 if (!Dialog::directing) {
3206 pause_sound(whooshsound);
3207 viewer = Dialog::currentScene().camera;
3208 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .1);
3209 yaw = Dialog::currentScene().camerayaw;
3210 pitch = Dialog::currentScene().camerapitch;
3211 if (Dialog::dialoguetime > 0.5) {
3212 if (Input::isKeyPressed(attackkey)) {
3213 Dialog::indialogue++;
3214 if (Dialog::indialogue < int(Dialog::currentDialog().scenes.size())) {
3215 if (Dialog::currentScene().sound != 0) {
3216 playdialoguescenesound();
3217 if (Dialog::currentScene().sound == -5) {
3218 Hotspot::hotspots.emplace_back(Person::players[0]->coords, -1, 10);
3220 if (Dialog::currentScene().sound == -6) {
3224 if (Person::players[Dialog::currentScene().participantfocus]->dead) {
3225 Dialog::indialogue = -1;
3226 Dialog::directing = false;
3233 if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) {
3234 Dialog::indialogue = -1;
3235 Dialog::directing = false;
3237 if (Dialog::currentDialog().type > 19 && Dialog::currentDialog().type < 30) {
3240 if (Dialog::currentDialog().type > 29 && Dialog::currentDialog().type < 40) {
3243 if (Dialog::currentDialog().type > 49 && Dialog::currentDialog().type < 60) {
3245 for (unsigned i = 1; i < Person::players.size(); i++) {
3246 Person::players[i]->aitype = attacktypecutoff;
3253 if (!Person::players[0]->jumpkeydown) {
3254 Person::players[0]->jumptogglekeydown = 0;
3256 if (Person::players[0]->jumpkeydown &&
3257 Person::players[0]->animTarget != jumpupanim &&
3258 Person::players[0]->animTarget != jumpdownanim &&
3259 !Person::players[0]->isFlip())
3260 Person::players[0]->jumptogglekeydown = 1;
3263 Dialog::dialoguetime += multiplier;
3264 hawkyaw += multiplier * 25;
3266 realhawkcoords.x = 25;
3267 realhawkcoords = DoRotation(realhawkcoords, 0, hawkyaw, 0) + hawkcoords;
3268 hawkcalldelay -= multiplier / 2;
3270 if (hawkcalldelay <= 0) {
3271 emit_sound_at(hawksound, realhawkcoords);
3273 hawkcalldelay = 16 + abs(Random() % 8);
3280 doPlayerCollisions();
3284 for (unsigned k = 0; k < Person::players.size(); k++)
3285 if (k != 0 && Person::players[k]->immobile)
3286 Person::players[k]->coords = Person::players[k]->realoldcoords;
3288 for (unsigned k = 0; k < Person::players.size(); k++) {
3289 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3290 if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) {
3291 Person::players[k]->DoDamage(1000);
3297 static bool respawnkeydown;
3298 if (!editorenabled &&
3299 (whichlevel != -2 &&
3300 (Input::isKeyDown(SDL_SCANCODE_Z) &&
3301 Input::isKeyDown(SDL_SCANCODE_LGUI) &&
3303 (Input::isKeyDown(jumpkey) &&
3306 Person::players[0]->dead))) {
3307 targetlevel = whichlevel;
3311 respawnkeydown = Input::isKeyDown(jumpkey);
3314 static bool movekey;
3317 for (unsigned i = 0; i < Person::players.size(); i++) {
3318 static float oldtargetyaw;
3319 if (!Person::players[i]->skeleton.free) {
3320 oldtargetyaw = Person::players[i]->targetyaw;
3321 if (i == 0 && !Dialog::inDialog()) {
3322 //TODO: refactor repetitive code
3323 if (!Animation::animations[Person::players[0]->animTarget].attack &&
3324 Person::players[0]->animTarget != staggerbackhighanim &&
3325 Person::players[0]->animTarget != staggerbackhardanim &&
3326 Person::players[0]->animTarget != crouchremoveknifeanim &&
3327 Person::players[0]->animTarget != removeknifeanim &&
3328 Person::players[0]->animTarget != backhandspringanim &&
3329 Person::players[0]->animTarget != dodgebackanim &&
3330 Person::players[0]->animTarget != walljumprightkickanim &&
3331 Person::players[0]->animTarget != walljumpleftkickanim) {
3333 Person::players[0]->targetyaw = 0;
3335 Person::players[0]->targetyaw = -yaw + 180;
3341 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3343 facing = flatfacing;
3345 facing = DoRotation(facing, -pitch, 0, 0);
3346 facing = DoRotation(facing, 0, 0 - yaw, 0);
3349 Person::players[0]->lookyaw = -yaw;
3351 Person::players[i]->targetheadyaw = yaw;
3352 Person::players[i]->targetheadpitch = pitch;
3354 if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) {
3355 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3356 Person::players[i]->animTarget != staggerbackhighanim &&
3357 Person::players[i]->animTarget != staggerbackhardanim &&
3358 Person::players[i]->animTarget != crouchremoveknifeanim &&
3359 Person::players[i]->animTarget != removeknifeanim &&
3360 Person::players[i]->animTarget != backhandspringanim &&
3361 Person::players[i]->animTarget != dodgebackanim &&
3362 Person::players[i]->animTarget != walljumprightkickanim &&
3363 Person::players[i]->animTarget != walljumpleftkickanim) {
3364 Person::players[i]->targetyaw = -Person::players[i]->lookyaw + 180;
3370 flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0);
3372 facing = DoRotation(facing, -Person::players[i]->lookpitch, 0, 0);
3373 facing = DoRotation(facing, 0, 0 - Person::players[i]->lookyaw, 0);
3375 Person::players[i]->targetheadyaw = Person::players[i]->lookyaw;
3376 Person::players[i]->targetheadpitch = Person::players[i]->lookpitch;
3378 if (Dialog::inDialog()) {
3379 Person::players[i]->targetheadyaw = 180 - roughDirection(Dialog::currentScene().participantfacing[i]);
3380 Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]);
3386 Person::players[i]->avoidsomething = 0;
3388 //avoid flaming things
3389 for (unsigned int j = 0; j < Object::objects.size(); j++)
3390 if (Object::objects[j]->onfire)
3391 if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200)
3392 if ( distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3393 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3394 Person::players[i]->collided = 0;
3395 Person::players[i]->avoidcollided = 1;
3396 if (Person::players[i]->avoidsomething == 0 ||
3397 distsq(&Person::players[i]->coords, &Object::objects[j]->position) <
3398 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3399 Person::players[i]->avoidwhere = Object::objects[j]->position;
3400 Person::players[i]->avoidsomething = 1;
3404 //avoid flaming players
3405 for (unsigned j = 0; j < Person::players.size(); j++)
3406 if (Person::players[j]->onfire)
3407 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200)
3408 if ( distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3409 distsq(&Person::players[i]->coords, &Person::players[0]->coords)) {
3410 Person::players[i]->collided = 0;
3411 Person::players[i]->avoidcollided = 1;
3412 if (Person::players[i]->avoidsomething == 0 ||
3413 distsq(&Person::players[i]->coords, &Person::players[j]->coords) <
3414 distsq(&Person::players[i]->coords, &Person::players[i]->avoidwhere)) {
3415 Person::players[i]->avoidwhere = Person::players[j]->coords;
3416 Person::players[i]->avoidsomething = 1;
3420 if (Person::players[i]->collided > .8)
3421 Person::players[i]->avoidcollided = 0;
3423 Person::players[i]->doAI();
3425 if (Animation::animations[Person::players[i]->animTarget].attack == reversed) {
3426 //Person::players[i]->targetyaw=Person::players[i]->yaw;
3427 Person::players[i]->forwardkeydown = 0;
3428 Person::players[i]->leftkeydown = 0;
3429 Person::players[i]->backkeydown = 0;
3430 Person::players[i]->rightkeydown = 0;
3431 Person::players[i]->jumpkeydown = 0;
3432 Person::players[i]->attackkeydown = 0;
3433 //Person::players[i]->crouchkeydown=0;
3434 Person::players[i]->throwkeydown = 0;
3437 if (Dialog::inDialog()) {
3438 Person::players[i]->forwardkeydown = 0;
3439 Person::players[i]->leftkeydown = 0;
3440 Person::players[i]->backkeydown = 0;
3441 Person::players[i]->rightkeydown = 0;
3442 Person::players[i]->jumpkeydown = 0;
3443 Person::players[i]->crouchkeydown = 0;
3444 Person::players[i]->drawkeydown = 0;
3445 Person::players[i]->throwkeydown = 0;
3448 if (Person::players[i]->collided < -.3)
3449 Person::players[i]->collided = -.3;
3450 if (Person::players[i]->collided > 1)
3451 Person::players[i]->collided = 1;
3452 Person::players[i]->collided -= multiplier * 4;
3453 Person::players[i]->whichdirectiondelay -= multiplier;
3454 if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) {
3455 Person::players[i]->avoidcollided = -.3;
3456 Person::players[i]->whichdirection = abs(Random() % 2);
3457 Person::players[i]->whichdirectiondelay = .4;
3459 if (Person::players[i]->avoidcollided > 1)
3460 Person::players[i]->avoidcollided = 1;
3461 Person::players[i]->avoidcollided -= multiplier / 4;
3462 if (!Person::players[i]->skeleton.free) {
3463 Person::players[i]->stunned -= multiplier;
3464 Person::players[i]->surprised -= multiplier;
3466 if (i != 0 && Person::players[i]->surprised <= 0 &&
3467 Person::players[i]->aitype == attacktypecutoff &&
3468 !Person::players[i]->dead &&
3469 !Person::players[i]->skeleton.free &&
3470 Animation::animations[Person::players[i]->animTarget].attack == neutral)
3473 if (!Person::players[i]->throwkeydown)
3474 Person::players[i]->throwtogglekeydown = 0;
3477 if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) {
3478 if (Person::players[i]->weaponactive == -1 &&
3479 Person::players[i]->num_weapons < 2 &&
3480 (Person::players[i]->isIdle() ||
3481 Person::players[i]->isCrouch() ||
3482 Person::players[i]->animTarget == sneakanim ||
3483 Person::players[i]->animTarget == rollanim ||
3484 Person::players[i]->animTarget == backhandspringanim ||
3485 Person::players[i]->isFlip() ||
3486 Person::players[i]->aitype != playercontrolled)) {
3487 for (unsigned j = 0; j < weapons.size(); j++) {
3488 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3489 Person::players[i]->aitype == playercontrolled) &&
3490 weapons[j].owner == -1 &&
3491 Person::players[i]->weaponactive == -1)
3492 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) {
3493 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) {
3494 if (Person::players[i]->isCrouch() ||
3495 Person::players[i]->animTarget == sneakanim ||
3496 Person::players[i]->isRun() ||
3497 Person::players[i]->isIdle() ||
3498 Person::players[i]->aitype != playercontrolled) {
3499 Person::players[i]->throwtogglekeydown = 1;
3500 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3501 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3502 Person::players[i]->hasvictim = 0;
3504 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3505 Person::players[i]->throwtogglekeydown = 1;
3506 Person::players[i]->hasvictim = 0;
3508 if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 ||
3509 Person::players[i]->aitype == playercontrolled) &&
3510 weapons[j].owner == -1 ||
3511 Person::players[i]->victim &&
3512 weapons[j].owner == int(Person::players[i]->victim->id))
3513 if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1)
3514 if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) {
3515 if (weapons[j].getType() != staff)
3516 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3518 Person::players[i]->takeWeapon(j);
3521 } else if ((Person::players[i]->isIdle() ||
3522 Person::players[i]->isFlip() ||
3523 Person::players[i]->aitype != playercontrolled) &&
3524 distsq(&Person::players[i]->coords, &weapons[j].position) < 5 &&
3525 Person::players[i]->coords.y < weapons[j].position.y) {
3526 if (!Person::players[i]->isFlip()) {
3527 Person::players[i]->throwtogglekeydown = 1;
3528 Person::players[i]->setTargetAnimation(removeknifeanim);
3529 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[j].position);
3531 if (Person::players[i]->isFlip()) {
3532 Person::players[i]->throwtogglekeydown = 1;
3533 Person::players[i]->hasvictim = 0;
3535 for (unsigned k = 0; k < weapons.size(); k++) {
3536 if (Person::players[i]->weaponactive == -1)
3537 if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 ||
3538 Person::players[i]->aitype == playercontrolled) &&
3539 weapons[k].owner == -1 ||
3540 Person::players[i]->victim &&
3541 weapons[k].owner == int(Person::players[i]->victim->id))
3542 if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 &&
3543 Person::players[i]->weaponactive == -1) {
3544 if (weapons[k].getType() != staff)
3545 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3547 Person::players[i]->takeWeapon(k);
3554 if (Person::players[i]->isCrouch() ||
3555 Person::players[i]->animTarget == sneakanim ||
3556 Person::players[i]->isRun() ||
3557 Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim ||
3558 Person::players[i]->animTarget == backhandspringanim) {
3559 if (Person::players.size() > 1)
3560 for (unsigned j = 0; j < Person::players.size(); j++) {
3561 if (Person::players[i]->weaponactive == -1)
3563 if (Person::players[j]->num_weapons &&
3564 Person::players[j]->skeleton.free &&
3565 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2/*&&Person::players[j]->dead*/ &&
3566 (((Person::players[j]->skeleton.forward.y < 0 &&
3567 Person::players[j]->weaponstuckwhere == 0) ||
3568 (Person::players[j]->skeleton.forward.y > 0 &&
3569 Person::players[j]->weaponstuckwhere == 1)) ||
3570 Person::players[j]->weaponstuck == -1 ||
3571 Person::players[j]->num_weapons > 1)) {
3572 if (Person::players[i]->animTarget != rollanim && Person::players[i]->animTarget != backhandspringanim) {
3573 Person::players[i]->throwtogglekeydown = 1;
3574 Person::players[i]->victim = Person::players[j];
3575 Person::players[i]->hasvictim = 1;
3576 Person::players[i]->setTargetAnimation(crouchremoveknifeanim);
3577 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3579 if (Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) {
3580 Person::players[i]->throwtogglekeydown = 1;
3581 Person::players[i]->victim = Person::players[j];
3582 Person::players[i]->hasvictim = 1;
3583 int k = Person::players[j]->weaponids[0];
3584 if (Person::players[i]->hasvictim) {
3587 if (Person::players[i]->victim->weaponstuck != -1) {
3588 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3593 if (weapons[k].getType() != staff)
3594 emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.);
3597 emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.);
3599 if (weapons[k].owner != -1) {
3600 if (Person::players[i]->victim->num_weapons == 1)
3601 Person::players[i]->victim->num_weapons = 0;
3603 Person::players[i]->victim->num_weapons = 1;
3605 Person::players[i]->victim->skeleton.longdead = 0;
3606 Person::players[i]->victim->skeleton.free = 1;
3607 Person::players[i]->victim->skeleton.broken = 0;
3609 for (unsigned l = 0; l < Person::players[i]->victim->skeleton.joints.size(); l++) {
3610 Person::players[i]->victim->skeleton.joints[l].velchange = 0;
3611 Person::players[i]->victim->skeleton.joints[l].locked = 0;
3617 Normalise(&relative);
3618 XYZ footvel, footpoint;
3620 footpoint = weapons[k].position;
3621 if (Person::players[i]->victim->weaponstuck != -1) {
3622 if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) {
3624 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
3625 weapons[k].bloody = 2;
3626 weapons[k].blooddrip = 5;
3627 Person::players[i]->victim->weaponstuck = -1;
3628 Person::players[i]->victim->bloodloss += 2000;
3629 Person::players[i]->victim->DoDamage(2000);
3632 if (Person::players[i]->victim->num_weapons > 0) {
3633 if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1)
3634 Person::players[i]->victim->weaponstuck = 0;
3635 if (Person::players[i]->victim->weaponids[0] == k)
3636 Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons];
3639 Person::players[i]->victim->weaponactive = -1;
3641 Person::players[i]->victim->jointVel(abdomen) += relative * 6;
3642 Person::players[i]->victim->jointVel(neck) += relative * 6;
3643 Person::players[i]->victim->jointVel(rightshoulder) += relative * 6;
3644 Person::players[i]->victim->jointVel(leftshoulder) += relative * 6;
3646 Person::players[i]->takeWeapon(k);
3653 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3654 if (weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3655 if (Person::players[i]->isIdle() ||
3656 Person::players[i]->isRun() ||
3657 Person::players[i]->isCrouch() ||
3658 Person::players[i]->animTarget == sneakanim ||
3659 Person::players[i]->isFlip())
3660 if (Person::players.size() > 1)
3661 for (unsigned j = 0; j < Person::players.size(); j++) {
3663 if (!Tutorial::active || Tutorial::stage == 49)
3665 if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 &&
3666 distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 &&
3667 distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 &&
3668 !Person::players[j]->skeleton.free &&
3669 -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)) {
3670 if (!Person::players[i]->isFlip()) {
3671 Person::players[i]->throwtogglekeydown = 1;
3672 Person::players[i]->victim = Person::players[j];
3673 Person::players[i]->setTargetAnimation(knifethrowanim);
3674 Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[j]->coords);
3675 Person::players[i]->targettilt2 = pitchTo(Person::players[i]->coords, Person::players[j]->coords);
3677 if (Person::players[i]->isFlip()) {
3678 if (Person::players[i]->weaponactive != -1) {
3679 Person::players[i]->throwtogglekeydown = 1;
3680 Person::players[i]->victim = Person::players[j];
3682 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);
3685 aim = DoRotation(aim, (float)abs(Random() % 30) - 15, (float)abs(Random() % 30) - 15, 0);
3687 weapons[Person::players[i]->weaponids[0]].thrown(aim * 50, false);
3688 Person::players[i]->num_weapons--;
3689 if (Person::players[i]->num_weapons) {
3690 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3692 Person::players[i]->weaponactive = -1;
3699 if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) {
3700 if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) {
3701 Person::players[i]->throwtogglekeydown = 1;
3702 XYZ tempVelocity = Person::players[i]->velocity * .2;
3703 if (tempVelocity.x == 0)
3704 tempVelocity.x = .1;
3705 weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false);
3706 Person::players[i]->num_weapons--;
3707 if (Person::players[i]->num_weapons) {
3708 Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons];
3709 if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons)
3710 Person::players[i]->weaponstuck = 0;
3713 Person::players[i]->weaponactive = -1;
3714 for (unsigned j = 0; j < Person::players.size(); j++) {
3715 Person::players[j]->wentforweapon = 0;
3723 if (i == 0 || !Person::players[0]->dead || (Person::players[i]->weaponactive != -1)) {
3724 if (Person::players[i]->drawkeydown && !Person::players[i]->drawtogglekeydown ||
3725 (Person::players[i]->num_weapons == 2) &&
3726 (Person::players[i]->weaponactive == -1) &&
3727 Person::players[i]->isIdle() ||
3728 Person::players[0]->dead &&
3729 (Person::players[i]->weaponactive != -1) &&
3732 if (Person::players[i]->weaponactive != -1)
3733 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff)
3735 if (isgood && Person::players[i]->creature != wolftype) {
3736 if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3737 Person::players[i]->setTargetAnimation(drawrightanim);
3738 Person::players[i]->drawtogglekeydown = 1;
3740 if ((Person::players[i]->isIdle() ||
3741 (Person::players[i]->aitype != playercontrolled &&
3742 Person::players[0]->weaponactive != -1 &&
3743 Person::players[i]->isRun())) &&
3744 Person::players[i]->num_weapons &&
3745 weapons[Person::players[i]->weaponids[0]].getType() == sword) {
3746 Person::players[i]->setTargetAnimation(drawleftanim);
3747 Person::players[i]->drawtogglekeydown = 1;
3749 if (Person::players[i]->isCrouch() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) {
3750 Person::players[i]->setTargetAnimation(crouchdrawrightanim);
3751 Person::players[i]->drawtogglekeydown = 1;
3758 if (Person::players[i]->weaponactive != -1) {
3759 if (Person::players[i]->isCrouch() &&
3760 weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].bloody &&
3762 Person::players[i]->onterrain &&
3763 Person::players[i]->num_weapons &&
3764 Person::players[i]->attackkeydown &&
3765 musictype != stream_fighttheme) {
3766 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife)
3767 Person::players[i]->setTargetAnimation(crouchstabanim);
3768 if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword)
3769 Person::players[i]->setTargetAnimation(swordgroundstabanim);
3770 Person::players[i]->hasvictim = 0;
3774 if (!Person::players[i]->drawkeydown)
3775 Person::players[i]->drawtogglekeydown = 0;
3780 absflatfacing.z = -1;
3782 absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0);
3784 absflatfacing = flatfacing;
3786 if (Dialog::inDialog()) {
3787 Person::players[i]->forwardkeydown = 0;
3788 Person::players[i]->leftkeydown = 0;
3789 Person::players[i]->backkeydown = 0;
3790 Person::players[i]->rightkeydown = 0;
3791 Person::players[i]->jumpkeydown = 0;
3792 Person::players[i]->crouchkeydown = 0;
3793 Person::players[i]->drawkeydown = 0;
3794 Person::players[i]->throwkeydown = 0;
3798 if (!Animation::animations[Person::players[i]->animTarget].attack &&
3799 Person::players[i]->animTarget != staggerbackhighanim &&
3800 Person::players[i]->animTarget != staggerbackhardanim &&
3801 Person::players[i]->animTarget != backhandspringanim &&
3802 Person::players[i]->animTarget != dodgebackanim) {
3803 if (!Person::players[i]->forwardkeydown)
3804 Person::players[i]->forwardstogglekeydown = 0;
3805 if (Person::players[i]->crouchkeydown) {
3809 Person::players[i]->superruntoggle = 1;
3810 if (Person::players.size() > 1)
3811 for (unsigned j = 0; j < Person::players.size(); j++)
3812 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype)
3813 if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16)
3814 Person::players[i]->superruntoggle = 0;
3817 if (Person::players.size() > 1)
3818 for (unsigned j = 0; j < Person::players.size(); j++) {
3819 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) {
3820 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
3821 Person::players[j]->victim == Person::players[i] &&
3822 (Person::players[j]->animTarget == sweepanim ||
3823 Person::players[j]->animTarget == upunchanim ||
3824 Person::players[j]->animTarget == wolfslapanim ||
3825 ((Person::players[j]->animTarget == swordslashanim ||
3826 Person::players[j]->animTarget == knifeslashstartanim ||
3827 Person::players[j]->animTarget == staffhitanim ||
3828 Person::players[j]->animTarget == staffspinhitanim) &&
3829 distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) {
3838 Person::players[target]->Reverse();
3839 Person::players[i]->lowreversaldelay = .5;
3841 if (Person::players[i]->isIdle()) {
3842 Person::players[i]->setTargetAnimation(Person::players[i]->getCrouch());
3843 Person::players[i]->transspeed = 10;
3845 if (Person::players[i]->isRun() ||
3846 (Person::players[i]->isStop() &&
3847 (Person::players[i]->leftkeydown ||
3848 Person::players[i]->rightkeydown ||
3849 Person::players[i]->forwardkeydown ||
3850 Person::players[i]->backkeydown))) {
3851 Person::players[i]->setTargetAnimation(rollanim);
3852 Person::players[i]->transspeed = 20;
3855 if (!Person::players[i]->crouchkeydown) {
3857 if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0)
3858 Person::players[i]->superruntoggle = 0;
3860 if (Person::players[i]->isCrouch()) {
3861 if (Person::players.size() > 1)
3862 for (unsigned j = 0; j < Person::players.size(); j++) {
3864 !Person::players[j]->skeleton.free &&
3865 Person::players[j]->victim &&
3866 Person::players[i]->highreversaldelay <= 0) {
3867 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
3868 Person::players[j]->victim == Person::players[i] &&
3869 (Person::players[j]->animTarget == spinkickanim) &&
3870 Person::players[i]->isCrouch()) {
3879 Person::players[target]->Reverse();
3880 Person::players[i]->highreversaldelay = .5;
3882 if (Person::players[i]->isCrouch()) {
3883 if (!Person::players[i]->wasCrouch()) {
3884 Person::players[i]->animCurrent = Person::players[i]->getCrouch();
3885 Person::players[i]->frameCurrent = 0;
3887 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
3888 Person::players[i]->transspeed = 10;
3891 if (Person::players[i]->animTarget == sneakanim) {
3892 Person::players[i]->setTargetAnimation(Person::players[i]->getIdle());
3893 Person::players[i]->transspeed = 10;
3896 if (Person::players[i]->forwardkeydown) {
3897 if (Person::players[i]->isIdle() ||
3898 (Person::players[i]->isStop() &&
3899 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
3900 (Person::players[i]->isLanding() &&
3901 Person::players[i]->frameTarget > 0 &&
3902 !Person::players[i]->jumpkeydown) ||
3903 (Person::players[i]->isLandhard() &&
3904 Person::players[i]->frameTarget > 0 &&
3905 !Person::players[i]->jumpkeydown &&
3906 Person::players[i]->crouchkeydown)) {
3907 if (Person::players[i]->aitype == passivetype)
3908 Person::players[i]->setTargetAnimation(walkanim);
3910 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
3912 if (Person::players[i]->isCrouch()) {
3913 Person::players[i]->animTarget = sneakanim;
3914 if (Person::players[i]->wasCrouch())
3915 Person::players[i]->target = 0;
3916 Person::players[i]->frameTarget = 0;
3918 if (Person::players[i]->animTarget == hanganim/*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) {
3919 Person::players[i]->setTargetAnimation(climbanim);
3920 Person::players[i]->frameTarget = 1;
3921 Person::players[i]->jumpclimb = 1;
3923 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
3924 Person::players[i]->velocity += absflatfacing * 5 * multiplier;
3926 Person::players[i]->forwardstogglekeydown = 1;
3929 if (Person::players[i]->rightkeydown) {
3930 if (Person::players[i]->isIdle() ||
3931 (Person::players[i]->isStop() &&
3932 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
3933 (Person::players[i]->isLanding() &&
3934 Person::players[i]->frameTarget > 0 &&
3935 !Person::players[i]->jumpkeydown) ||
3936 (Person::players[i]->isLandhard() &&
3937 Person::players[i]->frameTarget > 0 &&
3938 !Person::players[i]->jumpkeydown &&
3939 Person::players[i]->crouchkeydown)) {
3940 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
3942 if (Person::players[i]->isCrouch()) {
3943 Person::players[i]->animTarget = sneakanim;
3944 if (Person::players[i]->wasCrouch())
3945 Person::players[i]->target = 0;
3946 Person::players[i]->frameTarget = 0;
3948 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
3949 Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
3951 Person::players[i]->targetyaw -= 90;
3952 if (Person::players[i]->forwardkeydown)
3953 Person::players[i]->targetyaw += 45;
3954 if (Person::players[i]->backkeydown)
3955 Person::players[i]->targetyaw -= 45;
3958 if ( Person::players[i]->leftkeydown) {
3959 if (Person::players[i]->isIdle() ||
3960 (Person::players[i]->isStop() &&
3961 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
3962 (Person::players[i]->isLanding() &&
3963 Person::players[i]->frameTarget > 0 &&
3964 !Person::players[i]->jumpkeydown) ||
3965 (Person::players[i]->isLandhard() &&
3966 Person::players[i]->frameTarget > 0 &&
3967 !Person::players[i]->jumpkeydown &&
3968 Person::players[i]->crouchkeydown)) {
3969 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
3971 if (Person::players[i]->isCrouch()) {
3972 Person::players[i]->animTarget = sneakanim;
3973 if (Person::players[i]->wasCrouch())
3974 Person::players[i]->target = 0;
3975 Person::players[i]->frameTarget = 0;
3977 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
3978 Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0);
3980 Person::players[i]->targetyaw += 90;
3981 if (Person::players[i]->forwardkeydown)
3982 Person::players[i]->targetyaw -= 45;
3983 if (Person::players[i]->backkeydown)
3984 Person::players[i]->targetyaw += 45;
3987 if (Person::players[i]->backkeydown) {
3988 if (Person::players[i]->isIdle() ||
3989 (Person::players[i]->isStop() &&
3990 Person::players[i]->targetyaw == Person::players[i]->yaw) ||
3991 (Person::players[i]->isLanding() &&
3992 Person::players[i]->frameTarget > 0 &&
3993 !Person::players[i]->jumpkeydown) ||
3994 (Person::players[i]->isLandhard() &&
3995 Person::players[i]->frameTarget > 0 &&
3996 !Person::players[i]->jumpkeydown &&
3997 Person::players[i]->crouchkeydown)) {
3998 Person::players[i]->setTargetAnimation(Person::players[i]->getRun());
4000 if (Person::players[i]->isCrouch()) {
4001 Person::players[i]->animTarget = sneakanim;
4002 if (Person::players[i]->wasCrouch())
4003 Person::players[i]->target = 0;
4004 Person::players[i]->frameTarget = 0;
4006 if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) {
4007 Person::players[i]->velocity -= absflatfacing * 5 * multiplier;
4009 if (Person::players[i]->animTarget == hanganim) {
4010 Person::players[i]->animCurrent = jumpdownanim;
4011 Person::players[i]->animTarget = jumpdownanim;
4012 Person::players[i]->target = 0;
4013 Person::players[i]->frameCurrent = 0;
4014 Person::players[i]->frameTarget = 1;
4015 Person::players[i]->velocity = 0;
4016 Person::players[i]->velocity.y += gravity;
4017 Person::players[i]->coords.y -= 1.4;
4018 Person::players[i]->grabdelay = 1;
4020 if ( !Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown)
4021 Person::players[i]->targetyaw += 180;
4024 if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) {
4025 if ((((Person::players[i]->isLanding() && Person::players[i]->frameTarget >= 3) ||
4026 Person::players[i]->isRun() ||
4027 Person::players[i]->animTarget == walkanim ||
4028 Person::players[i]->isCrouch() ||
4029 Person::players[i]->animTarget == sneakanim) &&
4030 Person::players[i]->jumppower > 1) &&
4031 ((Person::players[i]->animTarget != rabbitrunninganim &&
4032 Person::players[i]->animTarget != wolfrunninganim) || i != 0)) {
4033 Person::players[i]->jumpstart = 0;
4034 Person::players[i]->setTargetAnimation(jumpupanim);
4035 Person::players[i]->yaw = Person::players[i]->targetyaw;
4036 Person::players[i]->transspeed = 20;
4037 Person::players[i]->FootLand(leftfoot, 1);
4038 Person::players[i]->FootLand(rightfoot, 1);
4042 flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0);
4045 Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale;
4047 Person::players[i]->velocity = 0;
4051 if (Person::players.size() > 1)
4052 for (unsigned j = 0; j < Person::players.size(); j++) {
4053 if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) {
4054 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 &&
4055 (Person::players[j]->victim == Person::players[i]) &&
4056 (Person::players[j]->animTarget == sweepanim)) {
4065 Person::players[i]->velocity.y = 1;
4067 if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) {
4068 Person::players[i]->velocity.y = 7;
4069 Person::players[i]->crouchtogglekeydown = 1;
4070 } else Person::players[i]->velocity.y = 5;
4072 if (mousejump && i == 0 && devtools) {
4073 if (!Person::players[i]->isLanding())
4074 Person::players[i]->tempdeltav = deltav;
4075 if (Person::players[i]->tempdeltav < 0)
4076 Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000;
4079 Person::players[i]->coords.y += .2;
4080 Person::players[i]->jumppower -= 1;
4083 emit_sound_at(whooshsound, Person::players[i]->coords, 128.);
4085 emit_sound_at(jumpsound, Person::players[i]->coords, 128.);
4087 if ((Person::players[i]->isIdle()) && Person::players[i]->jumppower > 1) {
4088 Person::players[i]->setTargetAnimation(Person::players[i]->getLanding());
4089 Person::players[i]->frameTarget = 2;
4090 Person::players[i]->landhard = 0;
4091 Person::players[i]->jumpstart = 1;
4092 Person::players[i]->tempdeltav = deltav;
4094 if (Person::players[i]->animTarget == jumpupanim &&
4098 Person::players[i]->aitype != playercontrolled)) {
4099 if (Person::players[i]->jumppower > multiplier * 6) {
4100 Person::players[i]->velocity.y += multiplier * 6;
4101 Person::players[i]->jumppower -= multiplier * 6;
4103 if (Person::players[i]->jumppower <= multiplier * 6) {
4104 Person::players[i]->velocity.y += Person::players[i]->jumppower;
4105 Person::players[i]->jumppower = 0;
4108 if (((floatjump || editorenabled) && devtools) && i == 0)
4109 Person::players[i]->velocity.y += multiplier * 30;
4113 if (Person::players[i]->isRun() || Person::players[i]->animTarget == walkanim) {
4114 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4116 if (Person::players[i]->animTarget == sneakanim) {
4117 Person::players[i]->animTarget = Person::players[i]->getCrouch();
4118 if (Person::players[i]->animCurrent == sneakanim) {
4119 Person::players[i]->target = 0;
4121 Person::players[i]->frameTarget = 0;
4124 if (Person::players[i]->animTarget == walkanim &&
4125 (Person::players[i]->aitype == attacktypecutoff ||
4126 Person::players[i]->aitype == searchtype ||
4127 (Person::players[i]->aitype == passivetype &&
4128 Person::players[i]->numwaypoints <= 1)))
4129 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4130 if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype))
4131 Person::players[i]->setTargetAnimation(Person::players[i]->getStop());
4134 if (Person::players[i]->animTarget == rollanim)
4135 Person::players[i]->targetyaw = oldtargetyaw;
4139 for (unsigned k = 0; k < Person::players.size(); k++) {
4140 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) {
4141 if (Person::players[k]->yaw > Person::players[k]->targetyaw)
4142 Person::players[k]->yaw -= 360;
4144 Person::players[k]->yaw += 360;
4147 //stop to turn in right direction
4148 if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim))
4149 Person::players[k]->setTargetAnimation(Person::players[k]->getStop());
4151 if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim)
4152 Person::players[k]->targettilt = 0;
4154 if (Person::players[k]->animTarget != jumpupanim &&
4155 Person::players[k]->animTarget != backhandspringanim &&
4156 Person::players[k]->animTarget != jumpdownanim &&
4157 !Person::players[k]->isFlip()) {
4158 Person::players[k]->targettilt = 0;
4159 if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown)
4160 Person::players[k]->jumppower = 0;
4161 Person::players[k]->jumppower += multiplier * 7;
4162 if (Person::players[k]->isCrouch())
4163 Person::players[k]->jumppower += multiplier * 7;
4164 if (Person::players[k]->jumppower > 5)
4165 Person::players[k]->jumppower = 5;
4168 if (Person::players[k]->isRun())
4169 Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4;
4171 Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150);
4172 Person::players[k]->grabdelay -= multiplier;
4176 for (unsigned k = 0; k < Person::players.size(); k++) {
4177 Person::players[k]->DoAnimations();
4178 Person::players[k]->whichpatchx = Person::players[k]->coords.x / (terrain.size / subdivision * terrain.scale);
4179 Person::players[k]->whichpatchz = Person::players[k]->coords.z / (terrain.size / subdivision * terrain.scale);
4185 for (int j = numenvsounds - 1; j >= 0; j--) {
4186 envsoundlife[j] -= multiplier;
4187 if (envsoundlife[j] < 0) {
4189 envsoundlife[j] = envsoundlife[numenvsounds];
4190 envsound[j] = envsound[numenvsounds];
4193 OPENAL_SetFrequency(OPENAL_ALL, slomo);
4195 if (Tutorial::active) {
4196 Tutorial::DoStuff(multiplier);
4201 static float gLoc[3];
4205 static float vel[3];
4206 vel[0] = (viewer.x - oldviewer.x) / multiplier;
4207 vel[1] = (viewer.y - oldviewer.y) / multiplier;
4208 vel[2] = (viewer.z - oldviewer.z) / multiplier;
4210 //Set orientation with forward and up vectors
4211 static XYZ upvector;
4215 upvector = DoRotation(upvector, -pitch + 90, 0, 0);
4216 upvector = DoRotation(upvector, 0, 0 - yaw, 0);
4221 facing = DoRotation(facing, -pitch, 0, 0);
4222 facing = DoRotation(facing, 0, 0 - yaw, 0);
4225 static float ori[6];
4229 ori[3] = -upvector.x;
4230 ori[4] = upvector.y;
4231 ori[5] = -upvector.z;
4233 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
4240 if (Input::isKeyPressed(SDL_SCANCODE_F1))
4244 void Game::TickOnce()
4247 yaw += multiplier * 5;
4248 } else if (Dialog::directing || !Dialog::inDialog()) {
4251 pitch -= deltav * .7;
4253 pitch += deltav * .7;
4262 void Game::TickOnceAfter()
4264 static XYZ colviewer;
4265 static XYZ coltarget;
4269 static float changedelay;
4270 static bool alldead;
4271 static float unseendelay;
4272 static float cameraspeed;
4275 static int oldmusictype = musictype;
4277 if (environment == snowyenvironment)
4278 leveltheme = stream_snowtheme;
4279 if (environment == grassyenvironment)
4280 leveltheme = stream_grasstheme;
4281 if (environment == desertenvironment)
4282 leveltheme = stream_deserttheme;
4286 musictype = leveltheme;
4287 for (unsigned i = 0; i < Person::players.size(); i++) {
4288 if ((Person::players[i]->aitype == attacktypecutoff ||
4289 Person::players[i]->aitype == getweapontype ||
4290 Person::players[i]->aitype == gethelptype ||
4291 Person::players[i]->aitype == searchtype) &&
4292 !Person::players[i]->dead &&
4293 (Person::players[i]->animTarget != sneakattackedanim &&
4294 Person::players[i]->animTarget != knifesneakattackedanim &&
4295 Person::players[i]->animTarget != swordsneakattackedanim)) {
4296 musictype = stream_fighttheme;
4300 if (Person::players[0]->dead)
4301 musictype = stream_menutheme;
4304 if (musictype == stream_fighttheme)
4307 if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) {
4308 unseendelay -= multiplier;
4309 if (unseendelay > 0)
4310 musictype = stream_fighttheme;
4315 musictype = stream_menutheme;
4316 musicvolume[2] = 512;
4323 if (musictype != oldmusictype && musictype == stream_fighttheme)
4324 emit_sound_np(alarmsound);
4325 musicselected = musictype;
4327 if (musicselected == leveltheme)
4328 musicvolume[0] += multiplier * 450;
4330 musicvolume[0] -= multiplier * 450;
4331 if (musicselected == stream_fighttheme)
4332 musicvolume[1] += multiplier * 450;
4334 musicvolume[1] -= multiplier * 450;
4335 if (musicselected == stream_menutheme)
4336 musicvolume[2] += multiplier * 450;
4338 musicvolume[2] -= multiplier * 450;
4340 for (int i = 0; i < 3; i++) {
4341 if (musicvolume[i] < 0)
4343 if (musicvolume[i] > 512)
4344 musicvolume[i] = 512;
4347 if (musicvolume[2] > 128 && !loading && !mainmenu)
4348 musicvolume[2] = 128;
4351 if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0)
4352 emit_stream_np(leveltheme, musicvolume[0]);
4353 if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0)
4354 emit_stream_np(stream_fighttheme, musicvolume[1]);
4355 if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0)
4356 emit_stream_np(stream_menutheme, musicvolume[2]);
4357 if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0)
4358 pause_sound(leveltheme);
4359 if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0)
4360 pause_sound(stream_fighttheme);
4361 if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0)
4362 pause_sound(stream_menutheme);
4364 if (musicvolume[0] != oldmusicvolume[0])
4365 OPENAL_SetVolume(channels[leveltheme], musicvolume[0]);
4366 if (musicvolume[1] != oldmusicvolume[1])
4367 OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]);
4368 if (musicvolume[2] != oldmusicvolume[2])
4369 OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]);
4371 for (int i = 0; i < 3; i++)
4372 oldmusicvolume[i] = musicvolume[i];
4374 pause_sound(leveltheme);
4375 pause_sound(stream_fighttheme);
4376 pause_sound(stream_menutheme);
4378 for (int i = 0; i < 4; i++) {
4379 oldmusicvolume[i] = 0;
4384 Hotspot::killhotspot = 2;
4385 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4386 if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) {
4387 if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0)
4388 Hotspot::killhotspot = 0;
4389 else if (Hotspot::killhotspot == 2)
4390 Hotspot::killhotspot = 1;
4393 if (Hotspot::killhotspot == 2)
4394 Hotspot::killhotspot = 0;
4398 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
4399 if (Hotspot::hotspots[i].type == -1) {
4400 if (distsq(&Person::players[0]->coords, &Hotspot::hotspots[i].position) < Hotspot::hotspots[i].size) {
4407 for (unsigned i = 1; i < Person::players.size(); i++) {
4408 if (!Person::players[i]->dead && Person::players[i]->aitype == attacktypecutoff && Person::players[i]->surprised <= 0) {
4412 if (numalarmed > maxalarmed) {
4413 maxalarmed = numalarmed;
4416 if (changedelay <= 0 && !loading && !editorenabled && gameon && !Tutorial::active && changedelay != -999 && !won) {
4417 if (Person::players[0]->dead) {
4419 targetlevel = whichlevel;
4422 for (unsigned i = 1; i < Person::players.size(); i++) {
4423 if (!Person::players[i]->dead && Person::players[i]->howactive < typedead1) {
4430 if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) {
4432 targetlevel = whichlevel + 1;
4433 if (targetlevel > numchallengelevels - 1)
4436 if (winhotspot || windialogue) {
4438 targetlevel = whichlevel + 1;
4439 if (targetlevel > numchallengelevels - 1)
4444 if (Hotspot::killhotspot) {
4446 targetlevel = whichlevel + 1;
4447 if (targetlevel > numchallengelevels - 1)
4451 if (changedelay > 0 && !Person::players[0]->dead && !won) {
4452 //high scores, awards, win
4454 Account::active().winCampaignLevel(whichchoice, bonustotal, leveltime);
4457 wonleveltime = leveltime;
4458 Account::active().winLevel(whichlevel, bonustotal - startbonustotal, leveltime);
4461 Account::saveFile(Folders::getUserSavePath());
4467 if (leveltime < 1) {
4472 Hotspot::killhotspot = 0;
4475 if (!editorenabled && gameon && !mainmenu) {
4476 if (changedelay != -999)
4477 changedelay -= multiplier / 7;
4478 if (Person::players[0]->dead)
4479 targetlevel = whichlevel;
4480 if (loading == 2 && !campaign) {
4483 fireSound(firestartsound);
4485 if (!Person::players[0]->dead && targetlevel != whichlevel)
4486 startbonustotal = bonustotal;
4487 if (Person::players[0]->dead)
4488 Loadlevel(whichlevel);
4490 Loadlevel(targetlevel);
4496 if (loading == 2 && targetlevel == whichlevel) {
4500 fireSound(firestartsound);
4502 Loadlevel(campaignlevels[Account::active().getCampaignChoicesMade()].mapname.c_str());
4508 if (changedelay <= -999 &&
4511 (Person::players[0]->dead ||
4512 (alldead && maptype == mapkilleveryone) ||
4514 (Hotspot::killhotspot)))
4516 if ((Person::players[0]->dead ||
4517 (alldead && maptype == mapkilleveryone) ||
4520 (Hotspot::killhotspot)) &&
4522 if (whichlevel != -2 && !loading && !Person::players[0]->dead) {
4526 if (Person::players[0]->dead)
4532 // campaignchoosenext determines what to do when the level is complete:
4533 // 0 = load next level
4534 // 1 = go back to level select screen
4535 // 2 = stealthload next level
4536 if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) {
4537 if (campaignlevels[actuallevel].nextlevel.empty())
4539 } else if (mainmenu == 0 && winfreeze) {
4540 stealthloading = (campaignlevels[actuallevel].choosenext == 2);
4542 if (!stealthloading) {
4543 fireSound(firestartsound);
4548 startbonustotal = 0;
4555 if (!firstLoadDone) {
4559 actuallevel = campaignlevels[actuallevel].nextlevel.front();
4560 visibleloading = true;
4562 Loadlevel(campaignlevels[actuallevel].mapname.c_str());
4566 pause_sound(stream_menutheme);
4577 oldmusictype = musictype;
4583 facing = DoRotation(facing, -pitch, 0, 0);
4584 facing = DoRotation(facing, 0, 0 - yaw, 0);
4585 viewerfacing = facing;
4588 if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free)
4589 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;
4591 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;
4593 if (Person::players[0]->skeleton.free) {
4594 for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) {
4595 if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y)
4596 target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y;
4600 if (Person::players[0]->skeleton.free != 2) {
4602 if (findLengthfast(&Person::players[0]->velocity) > 400) {
4603 cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96;
4605 if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim)
4607 coltarget = target - cameraloc;
4608 if (findLengthfast(&coltarget) < multiplier * multiplier * 400)
4611 Normalise(&coltarget);
4612 if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0)
4613 cameraloc = cameraloc + coltarget * multiplier * cameraspeed;
4615 cameraloc = cameraloc + coltarget * multiplier * 8;
4619 cameradist += multiplier * 5;
4620 if (cameradist > 2.3)
4622 viewer = cameraloc - facing * cameradist;
4624 coltarget = cameraloc;
4625 Object::SphereCheckPossible(&colviewer, findDistance(&colviewer, &coltarget));
4626 if (terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz])
4627 for (int j = 0; j < terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz]; j++) {
4628 int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4630 coltarget = cameraloc;
4631 if (Object::objects[i]->model.LineCheckPossible(&colviewer, &coltarget, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1)
4634 if (terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz])
4635 for (int j = 0; j < terrain.patchobjectnum[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz]; j++) {
4636 int i = terrain.patchobjects[Person::players[0]->whichpatchx][Person::players[0]->whichpatchz][j];
4638 if (Object::objects[i]->model.SphereCheck(&colviewer, .15, &col, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
4642 cameradist = findDistance(&viewer, &target);
4643 viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .6);
4644 if (cameraloc.y < terrain.getHeight(cameraloc.x, cameraloc.z)) {
4645 cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z);
4648 if (camerashake > .8)
4650 woozy += multiplier;
4651 if (Person::players[0]->dead)
4653 if (Person::players[0]->dead)
4655 camerashake -= multiplier * 2;
4656 blackout -= multiplier * 2;
4657 if (camerashake < 0)
4662 viewer.x += (float)(Random() % 100) * .0005 * camerashake;
4663 viewer.y += (float)(Random() % 100) * .0005 * camerashake;
4664 viewer.z += (float)(Random() % 100) * .0005 * camerashake;