X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=blobdiff_plain;f=Source%2FGameTick.cpp;h=827f82b34957ea793ec5da6b8f02253087a9c7ce;hp=7e50cc0d41792850e3ea42b2fdf85ef3b2dd9fa0;hb=88961157fe4a88fb10320b4ce211ca697f639e7e;hpb=8b6e8f3ad7390309795eb35c0959264cb7924402 diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 7e50cc0..827f82b 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) +Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -179,8 +179,9 @@ float roughDirection(XYZ vec) { Normalise(&vec); float angle = -asin(-vec.x) * 180 / M_PI; - if (vec.z < 0) + if (vec.z < 0) { angle = 180 - angle; + } return angle; } float roughDirectionTo(XYZ start, XYZ end) @@ -202,12 +203,13 @@ float sq(float n) } inline float stepTowardf(float from, float to, float by) { - if (fabs(from - to) < by) + if (fabs(from - to) < by) { return to; - else if (from > to) + } else if (from > to) { return from - by; - else + } else { return from + by; + } } void Game::playdialoguescenesound() @@ -286,8 +288,9 @@ void Game::playdialoguescenesound() default: break; } - if (sound != -1) + if (sound != -1) { emit_sound_at(sound, temppos); + } } // ================================================================ @@ -297,11 +300,11 @@ int Game::findClosestPlayer() int closest = -1; float closestdist = std::numeric_limits::max(); - for (unsigned i = 1; i < Person::players.size(); i++) { + for (unsigned int i = 1; i < Person::players.size(); i++) { float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords); if (distance < closestdist) { closestdist = distance; - closest = i; + closest = (int)i; } } return closest; @@ -327,12 +330,13 @@ static void cmd_dispatch(const string cmd) { int i, n_cmds = sizeof(cmd_names) / sizeof(cmd_names[0]); - for (i = 0; i < n_cmds; i++) + for (i = 0; i < n_cmds; i++) { if (cmd.substr(0, cmd.find(' ')) == string(cmd_names[i])) { cout << "|" << cmd.substr(cmd.find(' ') + 1) << "|" << endl; cmd_handlers[i](cmd.substr(cmd.find(' ') + 1).c_str()); break; } + } emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound); } @@ -351,14 +355,18 @@ void Screenshot(void) void Game::SetUpLighting() { - if (environment == snowyenvironment) + if (environment == snowyenvironment) { light.setColors(.65, .65, .7, .4, .4, .44); - if (environment == desertenvironment) + } + if (environment == desertenvironment) { light.setColors(.95, .95, .95, .4, .35, .3); - if (environment == grassyenvironment) + } + if (environment == grassyenvironment) { light.setColors(.95, .95, 1, .4, .4, .44); - if (!skyboxtexture) + } + if (!skyboxtexture) { light.setColors(1, 1, 1, .4, .4, .4); + } float average; average = (skyboxlightr + skyboxlightg + skyboxlightb) / 3; light.color[0] *= (skyboxlightr + average) / 2; @@ -387,8 +395,9 @@ void Setenvironment(int which) if (environment == snowyenvironment) { windvector = 0; windvector.z = 3; - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_wind); + } Object::treetextureptr.load("Textures/SnowTree.png", 0); Object::bushtextureptr.load("Textures/BushSnow.png", 0); @@ -404,8 +413,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/Rock.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(snow)/Front.jpg", "Textures/Skybox(snow)/Left.jpg", "Textures/Skybox(snow)/Back.jpg", @@ -422,8 +432,9 @@ void Setenvironment(int which) Object::rocktextureptr.load("Textures/BoulderDesert.jpg", 1); Object::boxtextureptr.load("Textures/DesertBox.jpg", 1); - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_desertambient); + } footstepsound = footstepsn1; footstepsound2 = footstepsn2; @@ -434,8 +445,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/SandSlope.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(sand)/Front.jpg", "Textures/Skybox(sand)/Left.jpg", "Textures/Skybox(sand)/Back.jpg", @@ -452,8 +464,9 @@ void Setenvironment(int which) Object::rocktextureptr.load("Textures/Boulder.jpg", 1); Object::boxtextureptr.load("Textures/GrassBox.jpg", 1); - if (ambientsound) + if (ambientsound) { emit_stream_np(stream_wind, 100.); + } footstepsound = footstepgr1; footstepsound2 = footstepgr2; @@ -464,8 +477,9 @@ void Setenvironment(int which) terraintexture2.load("Textures/MossRock.jpg", 1); temptexdetail = texdetail; - if (texdetail > 1) + if (texdetail > 1) { texdetail = 4; + } skybox->load("Textures/Skybox(grass)/Front.jpg", "Textures/Skybox(grass)/Left.jpg", "Textures/Skybox(grass)/Back.jpg", @@ -514,12 +528,15 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) LOG(std::string("Loading level...") + name); - if (!gameon) + if (!gameon) { visibleloading = true; - if (stealthloading) + } + if (stealthloading) { visibleloading = false; - if (!stillloading) + } + if (!stillloading) { loadtime = 0; + } gamestarted = 1; numenvsounds = 0; @@ -573,8 +590,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) freeze = 0; winfreeze = 0; - for (unsigned char i = 0; i < 100; i++) + for (unsigned char i = 0; i < 100; i++) { bonusnum[i] = 0; + } numfalls = 0; numflipfail = 0; @@ -622,35 +640,38 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) if (mapvers < 12) { cerr << name << " has obsolete map version " << mapvers << endl; } - if (mapvers >= 15) + if (mapvers >= 15) { funpackf(tfile, "Bi", &indemo); - else + } else { indemo = 0; - if (mapvers >= 5) + } + if (mapvers >= 5) { funpackf(tfile, "Bi", &maptype); - else + } else { maptype = mapkilleveryone; - if (mapvers >= 6) + } + if (mapvers >= 6) { funpackf(tfile, "Bi", &hostile); - else + } else { hostile = 1; - if (mapvers >= 4) + } + if (mapvers >= 4) { funpackf(tfile, "Bf Bf", &viewdistance, &fadestart); - else { + } else { viewdistance = 100; fadestart = .6; } - if (mapvers >= 2) + if (mapvers >= 2) { funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb); - else { + } else { skyboxtexture = 1; skyboxr = 1; skyboxg = 1; skyboxb = 1; } - if (mapvers >= 10) + if (mapvers >= 10) { funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb); - else { + } else { skyboxlightr = skyboxr; skyboxlightg = skyboxg; skyboxlightb = skyboxb; @@ -661,13 +682,14 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) } else { 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); } - if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) + if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5) { for (int j = 0; j < Person::players[0]->num_weapons; j++) { Person::players[0]->weaponids[j] = weapons.size(); int type; funpackf(tfile, "Bi", &type); weapons.push_back(Weapon(type, 0)); } + } Game::LoadingScreen(); @@ -678,9 +700,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) funpackf(tfile, "Bi", &Person::players[0]->numclothes); - if (mapvers >= 9) + if (mapvers >= 9) { funpackf(tfile, "Bi Bi", &Person::players[0]->whichskin, &Person::players[0]->creature); - else { + } else { Person::players[0]->whichskin = 0; Person::players[0]->creature = rabbittype; } @@ -696,16 +718,18 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) for (int k = 0; k < Person::players[0]->numclothes; k++) { funpackf(tfile, "Bi", &templength); - for (int l = 0; l < templength; l++) + for (int l = 0; l < templength; l++) { funpackf(tfile, "Bb", &Person::players[0]->clothes[k][l]); + } Person::players[0]->clothes[k][templength] = '\0'; funpackf(tfile, "Bf Bf Bf", &Person::players[0]->clothestintr[k], &Person::players[0]->clothestintg[k], &Person::players[0]->clothestintb[k]); } funpackf(tfile, "Bi", &environment); - if (environment != oldenvironment) + if (environment != oldenvironment) { Setenvironment(environment); + } oldenvironment = environment; Object::LoadObjectsFromFile(tfile, stealthloading); @@ -721,12 +745,15 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { 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); funpackf(tfile, "Bi", &templength); - if (templength) - for (int l = 0; l < templength; l++) + if (templength) { + for (int l = 0; l < templength; l++) { funpackf(tfile, "Bb", &Hotspot::hotspots[i].text[l]); + } + } Hotspot::hotspots[i].text[templength] = '\0'; - if (Hotspot::hotspots[i].type == -111) + if (Hotspot::hotspots[i].type == -111) { indemo = 1; + } } } else { Hotspot::hotspots.clear(); @@ -758,8 +785,9 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) Game::LoadingScreen(); funpackf(tfile, "Bi", &numpathpoints); - if (numpathpoints > 30 || numpathpoints < 0) + if (numpathpoints > 30 || numpathpoints < 0) { numpathpoints = 0; + } for (int j = 0; j < numpathpoints; j++) { funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x, &pathpoint[j].y, &pathpoint[j].z, &numpathpointconnect[j]); for (int k = 0; k < numpathpointconnect[j]; k++) { @@ -807,10 +835,12 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) Person::players[i]->target = 0; } Person::players[i]->speed = 1 + (float)(Random() % 100) / 1000; - if (difficulty == 0) + if (difficulty == 0) { Person::players[i]->speed -= .2; - if (difficulty == 1) + } + if (difficulty == 1) { Person::players[i]->speed -= .1; + } if (i == 0) { Person::players[i]->velocity = 0; @@ -929,15 +959,143 @@ bool Game::LoadLevel(const std::string& name, bool tutorial) return true; } -void doDevKeys() +/* Process input events that impact settings, console, devtools, etc. + * Gameplay-related input processing is still done in Game::Tick() for now + * as it is tightly coupled to the game logic. + */ +void Game::ProcessInput() { - float headprop, bodyprop, armprop, legprop; - if (!devtools) { + /* Pump SDL input events */ + Input::Tick(); + + /* Menu handling (main menu, leave game) */ + if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) && + (gameon || mainmenu == 0)) { + selected = -1; + if (mainmenu == 0 && !winfreeze) { + mainmenu = 2; // Pause + } else if (mainmenu == 1 || mainmenu == 2) { + mainmenu = 0; // Unpause + } + // Play menu theme + if (musictoggle && (mainmenu == 1 || mainmenu == 2)) { + OPENAL_SetFrequency(OPENAL_ALL); + emit_stream_np(stream_menutheme); + pause_sound(leveltheme); + } + // On resume, play level music + if (!mainmenu) { + pause_sound(stream_menutheme); + resume_stream(leveltheme); + } + } + + /* Challenge mode */ + if (!campaign && !mainmenu) { + if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE))) { + if (winfreeze) { + winfreeze = 0; + } + } + + if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && gameon) { + if (console) { + console = false; + freeze = 0; + } else if (winfreeze) { + mainmenu = 9; + gameon = 0; + } + } + } + + /* Tutorial mode hotkeys */ + if (Tutorial::active) { + // Skip current tutorial stage + if (Input::isKeyPressed(SDL_SCANCODE_TAB)) { + if (Tutorial::stage != 51) { + Tutorial::stagetime = Tutorial::maxtime; + } + emit_sound_np(consolefailsound, 128.); + } + } + + /* Screenshot */ + if (Input::isKeyPressed(SDL_SCANCODE_F1)) { + Screenshot(); + } + + /* Stereo video mode hotkeys */ + if (Input::isKeyPressed(SDL_SCANCODE_F6)) { + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + stereoreverse = true; + printf("Stereo reversed\n"); + } else { + stereoreverse = false; + printf("Stereo unreversed\n"); + } + } + + if (Input::isKeyDown(SDL_SCANCODE_F7)) { + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + stereoseparation -= 0.001; + } else { + stereoseparation -= 0.010; + } + printf("Stereo separation decreased to %f\n", stereoseparation); + } + + if (Input::isKeyDown(SDL_SCANCODE_F8)) { + if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + stereoseparation += 0.001; + } else { + stereoseparation += 0.010; + } + printf("Stereo separation increased to %f\n", stereoseparation); + } + + /* Devtools */ + if (devtools && !mainmenu) { + ProcessDevInput(); + } +} + +void Game::ProcessDevInput() +{ + if (!devtools || mainmenu) { return; } + float headprop, bodyprop, armprop, legprop; + + /* Console */ + if (Input::isKeyPressed(consolekey)) { + console = !console; + if (console) { + OPENAL_SetFrequency(OPENAL_ALL); + } else { + freeze = 0; + waiting = false; + } + } + if (Input::isKeyDown(SDL_SCANCODE_LALT)) { - /* Invicible */ + /* Enable editor */ + if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + editorenabled = !editorenabled; + if (editorenabled) { + Person::players[0]->damagetolerance = 100000; + } else { + Person::players[0]->damagetolerance = 200; + } + Person::players[0]->damage = 0; // these lines were in both if and else, but I think they would better fit in the if + Person::players[0]->permanentdamage = 0; + Person::players[0]->superpermanentdamage = 0; + Person::players[0]->bloodloss = 0; + Person::players[0]->deathbleeding = 0; + } + + /* Nullify damage and give 200000 health */ if (Input::isKeyPressed(SDL_SCANCODE_H)) { Person::players[0]->damagetolerance = 200000; Person::players[0]->damage = 0; @@ -949,8 +1107,9 @@ void doDevKeys() /* Change environment */ if (Input::isKeyPressed(SDL_SCANCODE_J)) { environment++; - if (environment > 2) + if (environment > 2) { environment = 0; + } Setenvironment(environment); } @@ -959,7 +1118,15 @@ void doDevKeys() cameramode = !cameramode; } - /* Toggle Slow motion */ + /* Freeze */ + if (Input::isKeyPressed(SDL_SCANCODE_V)) { + freeze = !freeze; + if (freeze) { + OPENAL_SetFrequency(OPENAL_ALL); + } + } + + /* Toggle slow motion */ if (Input::isKeyPressed(SDL_SCANCODE_B)) { slomo = 1 - slomo; slomodelay = 1000; @@ -968,11 +1135,11 @@ void doDevKeys() /* Ragdoll */ if (Input::isKeyPressed(SDL_SCANCODE_N)) { Person::players[0]->RagDoll(0); - emit_sound_at(whooshsound, Person::players[0]->coords, 128.); } - /* Grow tree leaves?? */ + /* Shrink tree leaves?? */ + // FIXME: Can't see what this does in game. if (Input::isKeyPressed(SDL_SCANCODE_Y)) { for (auto& an_object : Object::objects) { if (an_object->type == treeleavestype) { @@ -990,23 +1157,28 @@ void doDevKeys() if (closest >= 0) { if (Person::players[closest]->num_weapons > 0) { - if (weapons[Person::players[closest]->weaponids[0]].getType() == sword) - weapons[Person::players[closest]->weaponids[0]].setType(staff); - else if (weapons[Person::players[closest]->weaponids[0]].getType() == staff) - weapons[Person::players[closest]->weaponids[0]].setType(knife); - else - weapons[Person::players[closest]->weaponids[0]].setType(sword); + int weapontype = 0; + switch (weapons[Person::players[closest]->weaponids[0]].getType()) { + case knife: + weapontype = sword; + break; + case sword: + weapontype = staff; + break; + case staff: + weapontype = knife; + break; + } + weapons[Person::players[closest]->weaponids[0]].setType(weapontype); } else { Person::players[closest]->weaponids[0] = weapons.size(); - weapons.push_back(Weapon(knife, closest)); - Person::players[closest]->num_weapons = 1; } } } - /* Change yaw? */ + /* Change yaw (rotate around Z axis) */ if (Input::isKeyDown(SDL_SCANCODE_U)) { int closest = 0; if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) { @@ -1021,18 +1193,24 @@ void doDevKeys() /* Toggle fire */ if (Input::isKeyPressed(SDL_SCANCODE_F)) { - Person::players[0]->onfire = 1 - Person::players[0]->onfire; - if (Person::players[0]->onfire) { - Person::players[0]->CatchFire(); + int closest = 0; + if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + closest = findClosestPlayer(); } - if (!Person::players[0]->onfire) { - emit_sound_at(fireendsound, Person::players[0]->coords); - pause_sound(stream_firesound); + + if (closest >= 0) { + Person::players[closest]->onfire = !Person::players[closest]->onfire; + if (Person::players[closest]->onfire) { + Person::players[closest]->CatchFire(); + } else { + emit_sound_at(fireendsound, Person::players[closest]->coords); + pause_sound(stream_firesound); + } } } /* Change skin */ - if (Input::isKeyPressed(SDL_SCANCODE_O) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + if (Input::isKeyPressed(SDL_SCANCODE_T) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = 0; if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) { closest = findClosestPlayer(); @@ -1040,33 +1218,36 @@ void doDevKeys() if (closest >= 0) { Person::players[closest]->whichskin++; - if (Person::players[closest]->whichskin > 9) + if (Person::players[closest]->whichskin > 9) { Person::players[closest]->whichskin = 0; - if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) + } + if (Person::players[closest]->whichskin > 2 && Person::players[closest]->creature == wolftype) { Person::players[closest]->whichskin = 0; + } - Person::players[closest]->skeleton.drawmodel.textureptr.load(creatureskin[Person::players[closest]->creature][Person::players[closest]->whichskin], 1, - &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize); + Person::players[closest]->skeleton.drawmodel.textureptr.load( + creatureskin[Person::players[closest]->creature][Person::players[closest]->whichskin], 1, + &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize); } Person::players[closest]->addClothes(); } /* Change creature type */ - if (Input::isKeyPressed(SDL_SCANCODE_O) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + if (Input::isKeyPressed(SDL_SCANCODE_T) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = 0; if (!Input::isKeyDown(SDL_SCANCODE_LCTRL)) { closest = findClosestPlayer(); } + // FIXME: Those proportions are buggy if (closest >= 0) { if (Person::players[closest]->creature == wolftype) { headprop = Person::players[closest]->proportionhead.x / 1.1; bodyprop = Person::players[closest]->proportionbody.x / 1.1; armprop = Person::players[closest]->proportionarms.x / 1.1; legprop = Person::players[closest]->proportionlegs.x / 1.1; - } else { - // rabbittype + } else { // rabbittype headprop = Person::players[closest]->proportionhead.x / 1.2; bodyprop = Person::players[closest]->proportionbody.x / 1.05; armprop = Person::players[closest]->proportionarms.x / 1.00; @@ -1118,52 +1299,50 @@ void doDevKeys() } } - /* Decapitate */ - if (((Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) { - int closest = -1; - float closestdist = std::numeric_limits::max(); - - for (unsigned i = 1; i < Person::players.size(); i++) { - float distance = distsq(&Person::players[i]->coords, &Person::players[0]->coords); - if (!Person::players[i]->headless) - if (distance < closestdist) { - closestdist = distance; - closest = i; - } - } - - XYZ flatfacing2, flatvelocity2; - XYZ blah; - if (closest != -1 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) { - blah = Person::players[closest]->coords; + /* Explose nearby player's head */ + if (Input::isKeyPressed(SDL_SCANCODE_I) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + int closest = findClosestPlayer(); + if (closest > 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) { + XYZ flatfacing2, flatvelocity2, flatvelocity2_orig; XYZ headspurtdirection; - //int i = Person::players[closest]->skeleton.jointlabels[head]; Joint& headjoint = Person::players[closest]->joint(head); - for (unsigned k = 0; k < Person::players[closest]->skeleton.joints.size(); k++) { - if (!Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) - flatvelocity2 = headjoint.velocity; - if (!Person::players[closest]->skeleton.free) - 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; - if (Person::players[closest]->skeleton.free) - flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords; + + if (!Person::players[closest]->skeleton.free) { + flatvelocity2_orig = Person::players[closest]->velocity; + 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; + } else { + flatvelocity2_orig = headjoint.velocity; + flatfacing2 = headjoint.position * Person::players[closest]->scale + Person::players[closest]->coords; + } + + headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck); + Normalise(&headspurtdirection); + + for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { + flatvelocity2 = flatvelocity2_orig; flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; - headspurtdirection = headjoint.position - Person::players[closest]->jointPos(neck); - Normalise(&headspurtdirection); + printf("Test: %f\n", flatvelocity2.x); + printf("Test orig: %f\n", flatvelocity2_orig.x); Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, .6, 1); flatvelocity2 += headspurtdirection * 8; Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 / 2, 1, 1, 1, .16, 1); } Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5); - emit_sound_at(splattersound, blah); - emit_sound_at(breaksound2, blah, 100.); + emit_sound_at(splattersound, Person::players[closest]->coords); + emit_sound_at(breaksound2, Person::players[closest]->coords, 100.); - if (Person::players[closest]->skeleton.free == 2) + if (Person::players[closest]->skeleton.free == 2) { Person::players[closest]->skeleton.free = 0; + } Person::players[closest]->RagDoll(0); Person::players[closest]->dead = 2; Person::players[closest]->headless = 1; @@ -1173,74 +1352,59 @@ void doDevKeys() } } - /* Explode */ - if (((Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)))) { + /* Explode nearby player */ + if (Input::isKeyPressed(SDL_SCANCODE_I) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = findClosestPlayer(); - XYZ flatfacing2, flatvelocity2; - XYZ blah; if (closest >= 0 && distsq(&Person::players[closest]->coords, &Person::players[0]->coords) < 144) { - blah = Person::players[closest]->coords; - emit_sound_at(splattersound, blah); - emit_sound_at(breaksound2, blah); + XYZ flatfacing2, flatvelocity2, flatvelocity2_orig; + + emit_sound_at(splattersound, Person::players[closest]->coords); + emit_sound_at(breaksound2, Person::players[closest]->coords); for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) - 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; - if (Person::players[closest]->skeleton.free) - flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + if (!Person::players[closest]->skeleton.free) { + flatvelocity2_orig = Person::players[closest]->velocity; + 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; + } else { + flatvelocity2_orig = Person::players[closest]->skeleton.joints[i].velocity; + flatfacing2 = Person::players[closest]->skeleton.joints[i].position * + Person::players[closest]->scale + + Person::players[closest]->coords; + } + + // Animation part 1 + flatvelocity2 = flatvelocity2_orig; flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1); Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .3, 1); Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5); - } - for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) - 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; - if (Person::players[closest]->skeleton.free) - flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + // Animation part 2 + flatvelocity2 = flatvelocity2_orig; flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1); Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1); - } - for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) - 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; - if (Person::players[closest]->skeleton.free) - flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + // Animation part 3 + flatvelocity2 = flatvelocity2_orig; flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, 3, 1); Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2 * 2, 1, 1, 1, .4, 1); - } - for (unsigned i = 0; i < Person::players[closest]->skeleton.joints.size(); i++) { - if (!Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->velocity; - if (Person::players[closest]->skeleton.free) - flatvelocity2 = Person::players[closest]->skeleton.joints[i].velocity; - if (!Person::players[closest]->skeleton.free) - 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; - if (Person::players[closest]->skeleton.free) - flatfacing2 = Person::players[closest]->skeleton.joints[i].position * Person::players[closest]->scale + Person::players[closest]->coords; + // Animation part 4 + flatvelocity2 = flatvelocity2_orig; flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10; flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10; @@ -1250,20 +1414,23 @@ void doDevKeys() XYZ temppos; for (unsigned j = 0; j < Person::players.size(); j++) { - if (int(j) != closest) { - if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) { - Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60); - if (Person::players[j]->skeleton.free == 2) - Person::players[j]->skeleton.free = 1; - Person::players[j]->skeleton.longdead = 0; - Person::players[j]->RagDoll(0); - for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) { - temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords; - if (distsq(&temppos, &Person::players[closest]->coords) < 25) { - flatvelocity2 = temppos - Person::players[closest]->coords; - Normalise(&flatvelocity2); - Person::players[j]->skeleton.joints[i].velocity += flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20); - } + if (int(j) == closest) { + continue; + } + if (distsq(&Person::players[j]->coords, &Person::players[closest]->coords) < 25) { + Person::players[j]->DoDamage((25 - distsq(&Person::players[j]->coords, &Person::players[closest]->coords)) * 60); + if (Person::players[j]->skeleton.free == 2) { + Person::players[j]->skeleton.free = 1; + } + Person::players[j]->skeleton.longdead = 0; + Person::players[j]->RagDoll(0); + for (unsigned i = 0; i < Person::players[j]->skeleton.joints.size(); i++) { + temppos = Person::players[j]->skeleton.joints[i].position + Person::players[j]->coords; + if (distsq(&temppos, &Person::players[closest]->coords) < 25) { + flatvelocity2 = temppos - Person::players[closest]->coords; + Normalise(&flatvelocity2); + Person::players[j]->skeleton.joints[i].velocity += + flatvelocity2 * ((20 - distsq(&temppos, &Person::players[closest]->coords)) * 20); } } } @@ -1278,72 +1445,67 @@ void doDevKeys() camerashake += .6; } } - - /* Enable editor */ - if (Input::isKeyPressed(SDL_SCANCODE_M) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { - editorenabled = !editorenabled; - if (editorenabled) { - Person::players[0]->damagetolerance = 100000; - } else { - Person::players[0]->damagetolerance = 200; - } - Person::players[0]->damage = 0; // these lines were in both if and else, but I think they would better fit in the if - Person::players[0]->permanentdamage = 0; - Person::players[0]->superpermanentdamage = 0; - Person::players[0]->bloodloss = 0; - Person::players[0]->deathbleeding = 0; - } } - //skip level + /* Skip level (only for challenges) */ + // FIXME: Allow skipping levels in campaigns too if (whichlevel != -2 && Input::isKeyPressed(SDL_SCANCODE_K) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !editorenabled) { targetlevel++; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } loading = 1; leveltime = 5; } + /* Editor mode keys */ if (editorenabled) { + /* Closest player deletion */ if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = findClosestPlayer(); - if (closest >= 0) { + if (closest > 0) { Person::players.erase(Person::players.begin() + closest); } } - if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + /* Closest object deletion */ + if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { int closest = findClosestObject(); if (closest >= 0) { - Object::objects[closest]->position.y -= 500; + Object::DeleteObject(closest); } } - if (Input::isKeyPressed(SDL_SCANCODE_M) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + /* Add object */ + if (Input::isKeyPressed(SDL_SCANCODE_O)) { if (Object::objects.size() < max_objects - 1) { - XYZ scenecoords; - scenecoords.x = Person::players[0]->coords.x; - scenecoords.z = Person::players[0]->coords.z; - scenecoords.y = Person::players[0]->coords.y - 3; - if (editortype == bushtype) - scenecoords.y = Person::players[0]->coords.y - .5; - if (editortype == firetype) - scenecoords.y = Person::players[0]->coords.y - .5; - float temprotat, temprotat2; - temprotat = editoryaw; - temprotat2 = editorpitch; - if (temprotat < 0 || editortype == bushtype) - temprotat = Random() % 360; - if (temprotat2 < 0) - temprotat2 = Random() % 360; - - Object::MakeObject(editortype, scenecoords, (int)temprotat - ((int)temprotat) % 30, (int)temprotat2, editorsize); - if (editortype == treetrunktype) - Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (temprotat2 < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize); + XYZ scenecoords = Person::players[0]->coords; + scenecoords.y -= 3; + if (editortype == bushtype || editortype == firetype) { + scenecoords.y -= 3.5; + } else { + scenecoords.y -= 3; + } + + float tmpyaw, tmppitch; + tmpyaw = editoryaw; + tmppitch = editorpitch; + if (tmpyaw < 0 || editortype == bushtype) { + tmpyaw = Random() % 360; + } + if (tmppitch < 0) { + tmppitch = Random() % 360; + } + + Object::MakeObject(editortype, scenecoords, (int)tmpyaw - ((int)tmpyaw) % 30, (int)tmppitch, editorsize); + if (editortype == treetrunktype) { + Object::MakeObject(treeleavestype, scenecoords, Random() % 360 * (tmppitch < 2) + (int)editoryaw - ((int)editoryaw) % 30, editorpitch, editorsize); + } } } - if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + /* Add player */ + if (Input::isKeyPressed(SDL_SCANCODE_P) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { Person::players.push_back(shared_ptr(new Person())); Person::players.back()->id = Person::players.size() - 1; @@ -1351,15 +1513,7 @@ void doDevKeys() Person::players.back()->scale = Person::players[0]->scale; Person::players.back()->creature = rabbittype; Person::players.back()->howactive = editoractive; - - int k = abs(Random() % 2) + 1; - if (k == 0) { - Person::players.back()->whichskin = 0; - } else if (k == 1) { - Person::players.back()->whichskin = 1; - } else { - Person::players.back()->whichskin = 2; - } + Person::players.back()->whichskin = (int)(abs(Random() % 3)); Person::players.back()->skeletonLoad(true); @@ -1439,33 +1593,38 @@ void doDevKeys() Person::players.back()->loaded = true; } - if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { + /* Add waypoint */ + if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { if (Person::players.back()->numwaypoints < 90) { Person::players.back()->waypoints[Person::players.back()->numwaypoints] = Person::players[0]->coords; Person::players.back()->waypointtype[Person::players.back()->numwaypoints] = editorpathtype; Person::players.back()->numwaypoints++; + } else { + printf("Add waypoint: Reached max number of waypoints (90), aborting."); } } - if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + /* Connect waypoint */ + if (Input::isKeyPressed(SDL_SCANCODE_P) && Input::isKeyDown(SDL_SCANCODE_LCTRL) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { if (numpathpoints < 30) { - bool connected, alreadyconnected; - connected = 0; - if (numpathpoints > 1) + bool connected = false; + if (numpathpoints > 1) { for (int i = 0; i < numpathpoints; i++) { if (distsq(&pathpoint[i], &Person::players[0]->coords) < .5 && i != pathpointselected && !connected) { - alreadyconnected = 0; + bool alreadyconnected = false; for (int j = 0; j < numpathpointconnect[pathpointselected]; j++) { - if (pathpointconnect[pathpointselected][j] == i) - alreadyconnected = 1; + if (pathpointconnect[pathpointselected][j] == i) { + alreadyconnected = true; + } } if (!alreadyconnected) { numpathpointconnect[pathpointselected]++; - connected = 1; + connected = true; pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected] - 1] = i; } } } + } if (!connected) { numpathpoints++; pathpoint[numpathpoints - 1] = Person::players[0]->coords; @@ -1476,21 +1635,28 @@ void doDevKeys() } pathpointselected = numpathpoints - 1; } + } else { + printf("Connect waypoint: Reached max number of path points (30), aborting."); } } + /* Select next path waypoint */ if (Input::isKeyPressed(SDL_SCANCODE_PERIOD)) { pathpointselected++; - if (pathpointselected >= numpathpoints) + if (pathpointselected >= numpathpoints) { pathpointselected = -1; + } } + /* Select previous path waypoint */ if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { pathpointselected--; - if (pathpointselected <= -2) + if (pathpointselected <= -2) { pathpointselected = numpathpoints - 1; + } } + /* Delete path waypoint */ if (Input::isKeyPressed(SDL_SCANCODE_COMMA) && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { if (pathpointselected != -1) { numpathpoints--; @@ -1514,66 +1680,76 @@ void doDevKeys() } } + /* Select previous object type */ if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editortype--; - if (editortype == treeleavestype || editortype == 10) + if (editortype == treeleavestype || editortype == 10) { editortype--; - if (editortype < 0) + } + if (editortype < 0) { editortype = firetype; + } } + /* Select next object type */ if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editortype++; - if (editortype == treeleavestype || editortype == 10) + if (editortype == treeleavestype || editortype == 10) { editortype++; - if (editortype > firetype) + } + if (editortype > firetype) { editortype = 0; + } } + /* Decrease size for next object */ + if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + editorsize -= multiplier; + if (editorsize < .1) { + editorsize = .1; + } + } + + /* Increase size for next object */ + if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + editorsize += multiplier; + } + + /* Decrease yaw for next object */ if (Input::isKeyDown(SDL_SCANCODE_LEFT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editoryaw -= multiplier * 100; - if (editoryaw < -.01) + if (editoryaw < -.01) { editoryaw = -.01; + } } + /* Increase yaw for next object */ if (Input::isKeyDown(SDL_SCANCODE_RIGHT) && !Input::isKeyDown(SDL_SCANCODE_LSHIFT) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { editoryaw += multiplier * 100; } - if (Input::isKeyDown(SDL_SCANCODE_UP) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { - editorsize += multiplier; + /* Decrease pitch for next object */ + if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + editorpitch -= multiplier * 100; + if (editorpitch < -.01) { + editorpitch = -.01; + } } - if (Input::isKeyDown(SDL_SCANCODE_DOWN) && !Input::isKeyDown(SDL_SCANCODE_LCTRL)) { - editorsize -= multiplier; - if (editorsize < .1) - editorsize = .1; + /* Increase pitch for next object */ + if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { + editorpitch += multiplier * 100; } + /* Decrease map radius */ if (Input::isKeyPressed(SDL_SCANCODE_LEFT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { mapradius -= multiplier * 10; } + /* Increase map radius */ if (Input::isKeyPressed(SDL_SCANCODE_RIGHT) && Input::isKeyDown(SDL_SCANCODE_LSHIFT) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { mapradius += multiplier * 10; } - - if (Input::isKeyDown(SDL_SCANCODE_UP) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { - editorpitch += multiplier * 100; - } - - if (Input::isKeyDown(SDL_SCANCODE_DOWN) && Input::isKeyDown(SDL_SCANCODE_LCTRL)) { - editorpitch -= multiplier * 100; - if (editorpitch < -.01) - editorpitch = -.01; - } - - if (Input::isKeyPressed(SDL_SCANCODE_DELETE) && Object::objects.size() && Input::isKeyDown(SDL_SCANCODE_LSHIFT)) { - int closest = findClosestObject(); - if (closest >= 0) { - Object::DeleteObject(closest); - } - } } } @@ -1628,8 +1804,9 @@ void doJumpReversals() Person::players[i]->coords = Person::players[k]->coords; Person::players[k]->targetyaw = Person::players[i]->targetyaw; Person::players[k]->yaw = Person::players[i]->targetyaw; - if (Person::players[k]->aitype == attacktypecutoff) + if (Person::players[k]->aitype == attacktypecutoff) { Person::players[k]->stunned = .5; + } } if (Person::players[k]->animTarget == jumpupanim && Person::players[i]->animTarget != getupfrombackanim && @@ -1667,8 +1844,9 @@ void doJumpReversals() Person::players[k]->coords = Person::players[i]->coords; Person::players[i]->targetyaw = Person::players[k]->targetyaw; Person::players[i]->yaw = Person::players[k]->targetyaw; - if (Person::players[i]->aitype == attacktypecutoff) + if (Person::players[i]->aitype == attacktypecutoff) { Person::players[i]->stunned = .5; + } } } } @@ -1714,8 +1892,9 @@ void doAerialAcrobatics() } Person::players[k]->DoStuff(); - if (Person::players[k]->immobile && k != 0) + if (Person::players[k]->immobile && k != 0) { Person::players[k]->coords = Person::players[k]->realoldcoords; + } //if player's position has changed (?) if (distsq(&Person::players[k]->coords, &Person::players[k]->realoldcoords) > 0 && @@ -1726,10 +1905,12 @@ void doAerialAcrobatics() int whichhit; bool tempcollide = 0; - if (Person::players[k]->collide < -.3) + if (Person::players[k]->collide < -.3) { Person::players[k]->collide = -.3; - if (Person::players[k]->collide > 1) + } + if (Person::players[k]->collide > 1) { Person::players[k]->collide = 1; + } Person::players[k]->collide -= multiplier * 30; //clip to terrain @@ -1743,13 +1924,15 @@ void doAerialAcrobatics() lowpoint = Person::players[k]->coords; if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim && - !Person::players[k]->isFlip()) + !Person::players[k]->isFlip()) { lowpoint.y += 1.25; - else + } else { lowpoint.y += 1.3; + } if (Person::players[k]->coords.y < terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) && - Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) + Person::players[k]->coords.y > terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z) - .1) { Person::players[k]->coords.y = terrain.getHeight(Person::players[k]->coords.x, Person::players[k]->coords.z); + } if (Person::players[k]->SphereCheck(&lowpoint, 1.3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) { flatfacing = lowpoint - Person::players[k]->coords; Person::players[k]->coords = lowpoint; @@ -1770,17 +1953,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpleftanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint + DoRotation(Person::players[k]->facing, 0, 90, 0) * 1.5; @@ -1788,17 +1974,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumprightanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint + Person::players[k]->facing * 2; @@ -1806,17 +1995,20 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpbackanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } else { lowpoint = tempcoords1; lowpointtarget = lowpoint - Person::players[k]->facing * 2; @@ -1824,18 +2016,21 @@ void doAerialAcrobatics() if (whichhit != -1 && fabs(Object::objects[i]->model.Triangles[whichhit].facenormal.y) < .3) { Person::players[k]->setTargetAnimation(walljumpfrontanim); emit_sound_at(movewhooshsound, Person::players[k]->coords); - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->yaw += 180; Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; - if (k == 0) + if (k == 0) { numwallflipped++; + } } } } @@ -1853,8 +2048,9 @@ void doAerialAcrobatics() if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) { //flipped into a rock - if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) + if (Person::players[k]->isFlip() && Person::players[k]->targetFrame().label == 7) { Person::players[k]->RagDoll(0); + } if (Person::players[k]->animTarget == jumpupanim) { Person::players[k]->jumppower = -4; @@ -1871,8 +2067,9 @@ void doAerialAcrobatics() //landing if ((Person::players[k]->animTarget == jumpdownanim || Person::players[k]->isFlip()) && !Person::players[k]->wasLanding()) { - if (Person::players[k]->isFlip()) + if (Person::players[k]->isFlip()) { Person::players[k]->jumppower = -4; + } Person::players[k]->animTarget = Person::players[k]->getLanding(); emit_sound_at(landsound, Person::players[k]->coords, 128.); if (k == 0) { @@ -1884,17 +2081,18 @@ void doAerialAcrobatics() } } - if (tempcollide) + if (tempcollide) { for (unsigned int l = 0; l < terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz].size(); l++) { int i = terrain.patchobjects[Person::players[k]->whichpatchx][Person::players[k]->whichpatchz][l]; lowpoint = Person::players[k]->coords; lowpoint.y += 1.35; - if (Object::objects[i]->type != rocktype) + if (Object::objects[i]->type != rocktype) { if (Person::players[k]->SphereCheck(&lowpoint, 1.33, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) { if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim && - Person::players[k]->onterrain) + Person::players[k]->onterrain) { Person::players[k]->avoidcollided = 1; + } Person::players[k]->coords = lowpoint; Person::players[k]->coords.y -= 1.35; Person::players[k]->collide = 1; @@ -1943,12 +2141,13 @@ void doAerialAcrobatics() lowpointtarget6 += facing * .6; lowpointtarget7.y += 90 / 13; whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw); - if (Object::objects[i]->friction > .5) + if (Object::objects[i]->friction > .5) { if (whichhit != -1) { - if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) + if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != jumpdownanim) { Person::players[k]->collided = 1; - if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) - if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) + } + if (Object::checkcollide(lowpoint7, lowpointtarget7) == -1) { + if (Object::checkcollide(lowpoint6, lowpointtarget6) == -1) { if (Object::objects[i]->model.LineCheckPossible(&lowpoint2, &lowpointtarget2, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && Object::objects[i]->model.LineCheckPossible(&lowpoint3, &lowpointtarget3, @@ -1956,15 +2155,16 @@ void doAerialAcrobatics() Object::objects[i]->model.LineCheckPossible(&lowpoint4, &lowpointtarget4, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1 && Object::objects[i]->model.LineCheckPossible(&lowpoint5, &lowpointtarget5, - &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) + &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) { for (int j = 0; j < 45; j++) { lowpoint = Person::players[k]->coords; lowpoint.y += (float)j / 13; lowpointtarget = lowpoint + facing * 1.4; if (Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint2, &Object::objects[i]->position, &Object::objects[i]->yaw) == -1) { - if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) + if (j <= 6 || j <= 25 && Person::players[k]->animTarget == jumpdownanim) { break; + } if (Person::players[k]->animTarget == jumpupanim || Person::players[k]->animTarget == jumpdownanim) { lowpoint = Person::players[k]->coords; lowpoint.y += (float)j / 13; @@ -1976,15 +2176,17 @@ void doAerialAcrobatics() if (j > 10 || !Person::players[k]->isRun()) { if (Person::players[k]->animTarget == jumpdownanim || Person::players[k]->animTarget == jumpupanim) { - if (k == 0) + if (k == 0) { pause_sound(whooshsound); + } } emit_sound_at(jumpsound, Person::players[k]->coords, 128.); lowpointtarget = DoRotation(Object::objects[i]->model.Triangles[whichhit].facenormal, 0, Object::objects[i]->yaw, 0); Person::players[k]->yaw = -asin(0 - lowpointtarget.x) * 180 / M_PI; - if (lowpointtarget.z < 0) + if (lowpointtarget.z < 0) { Person::players[k]->yaw = 180 - Person::players[k]->yaw; + } Person::players[k]->targetyaw = Person::players[k]->yaw; Person::players[k]->lowyaw = Person::players[k]->yaw; @@ -2010,11 +2212,17 @@ void doAerialAcrobatics() } } } + } + } + } } + } } } } + } } + } if (Person::players[k]->collide <= 0) { //in the air if (!Person::players[k]->onterrain && @@ -2031,12 +2239,14 @@ void doAerialAcrobatics() Person::players[k]->frameTarget < 2 || Person::players[k]->frameTarget > 6)) { //stagger off ledge (?) - if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) + if (Person::players[k]->animTarget == staggerbackhighanim || Person::players[k]->animTarget == staggerbackhardanim) { Person::players[k]->RagDoll(0); + } Person::players[k]->setTargetAnimation(jumpdownanim); - if (!k) + if (!k) { emit_sound_at(whooshsound, Person::players[k]->coords, 128.); + } } //gravity Person::players[k]->velocity.y += gravity; @@ -2052,14 +2262,18 @@ void doAttacks() static int randattack; static bool playerrealattackkeydown = 0; - if (!Input::isKeyDown(attackkey)) + if (!Input::isKeyDown(attackkey)) { oldattackkey = 0; - if (oldattackkey) + } + if (oldattackkey) { Person::players[0]->attackkeydown = 0; - if (oldattackkey) + } + if (oldattackkey) { playerrealattackkeydown = 0; - if (!oldattackkey) + } + if (!oldattackkey) { playerrealattackkeydown = Input::isKeyDown(attackkey); + } if ((Person::players[0]->parriedrecently <= 0 || Person::players[0]->weaponactive == -1) && (!oldattackkey || @@ -2067,8 +2281,9 @@ void doAttacks() Person::players[0]->lastattack != swordslashanim && Person::players[0]->lastattack != knifeslashstartanim && Person::players[0]->lastattack != staffhitanim && - Person::players[0]->lastattack != staffspinhitanim))) + Person::players[0]->lastattack != staffspinhitanim))) { Person::players[0]->attackkeydown = Input::isKeyDown(attackkey); + } if (Input::isKeyDown(attackkey) && !oldattackkey && !Person::players[0]->backkeydown) { @@ -2077,20 +2292,24 @@ void doAttacks() Person::players[k]->animTarget == staffhitanim || Person::players[k]->animTarget == staffspinhitanim) && Person::players[0]->animCurrent != dodgebackanim && - !Person::players[k]->skeleton.free) + !Person::players[k]->skeleton.free) { Person::players[k]->Reverse(); + } } } - if (!hostile || Dialog::inDialog()) + if (!hostile || Dialog::inDialog()) { Person::players[0]->attackkeydown = 0; + } for (unsigned k = 0; k < Person::players.size(); k++) { - if (Dialog::inDialog()) + if (Dialog::inDialog()) { Person::players[k]->attackkeydown = 0; + } if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) { - if (Person::players[k]->aitype != playercontrolled) + if (Person::players[k]->aitype != playercontrolled) { Person::players[k]->victim = Person::players[0]; + } //attack key pressed if (Person::players[k]->attackkeydown) { //dodge backward @@ -2104,27 +2323,32 @@ void doAttacks() Person::players[k]->jumppower -= 2; } else { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k) + if (i == k) { continue; + } if (Person::players[i]->animTarget == swordslashanim || Person::players[i]->animTarget == knifeslashstartanim || Person::players[i]->animTarget == staffhitanim || - Person::players[i]->animTarget == staffspinhitanim) + Person::players[i]->animTarget == staffspinhitanim) { if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < 6.5 && !Person::players[i]->skeleton.free) { Person::players[k]->setTargetAnimation(dodgebackanim); Person::players[k]->targetyaw = roughDirectionTo(Person::players[k]->coords, Person::players[i]->coords); Person::players[k]->targettilt2 = pitchTo(Person::players[k]->coords, Person::players[i]->coords); } + } } if (Person::players[k]->animTarget != dodgebackanim) { - if (k == 0) + if (k == 0) { numflipped++; + } Person::players[k]->setTargetAnimation(backhandspringanim); Person::players[k]->targetyaw = -yaw + 180; - if (Person::players[k]->leftkeydown) + if (Person::players[k]->leftkeydown) { Person::players[k]->targetyaw -= 45; - if (Person::players[k]->rightkeydown) + } + if (Person::players[k]->rightkeydown) { Person::players[k]->targetyaw += 45; + } Person::players[k]->yaw = Person::players[k]->targetyaw; Person::players[k]->jumppower -= 2; } @@ -2141,11 +2365,12 @@ void doAttacks() const int attackweapon = Person::players[k]->weaponactive == -1 ? 0 : weapons[Person::players[k]->weaponids[Person::players[k]->weaponactive]].getType(); //normal attacks (?) Person::players[k]->hasvictim = 0; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k || !(k == 0 || i == 0)) + if (i == k || !(k == 0 || i == 0)) { continue; - if (!Person::players[k]->hasvictim) + } + if (!Person::players[k]->hasvictim) { if (Animation::animations[Person::players[k]->animTarget].attack != reversal) { //choose an attack const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords); @@ -2168,146 +2393,150 @@ void doAttacks() //sweep if (distance < 2.5 * sq(Person::players[k]->scale * 5) && Person::players[k]->crouchkeydown && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //winduppunch - else if (distance < 1.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - !attackweapon && - !reversaltrain) + //winduppunch + } else if (distance < 1.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + !attackweapon && + !reversaltrain) { Person::players[k]->animTarget = winduppunchanim; - //upunch - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - !attackweapon) + //upunch + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + !attackweapon) { Person::players[k]->animTarget = upunchanim; - //knifefollow - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Person::players[i]->staggerdelay > 0 && - attackweapon == knife && - Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) + //knifefollow + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Person::players[i]->staggerdelay > 0 && + attackweapon == knife && + Person::players[i]->bloodloss > Person::players[i]->damagetolerance / 2) { Person::players[k]->animTarget = knifefollowanim; - //knifeslashstart - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->forwardkeydown && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->crouchkeydown && - attackweapon == knife && - Person::players[k]->weaponmissdelay <= 0) + //knifeslashstart + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->forwardkeydown && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->crouchkeydown && + attackweapon == knife && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = knifeslashstartanim; - //swordslash - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == sword && - Person::players[k]->weaponmissdelay <= 0) + //swordslash + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == sword && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = swordslashanim; - //staffhit - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - !Person::players[k]->leftkeydown && - !Person::players[k]->rightkeydown && - !Person::players[k]->forwardkeydown) + //staffhit + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + !Person::players[k]->leftkeydown && + !Person::players[k]->rightkeydown && + !Person::players[k]->forwardkeydown) { Person::players[k]->animTarget = staffhitanim; - //staffspinhit - else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight && - !Person::players[k]->crouchkeydown && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0) + //staffspinhit + } else if (distance < 4.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight && + !Person::players[k]->crouchkeydown && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = staffspinhitanim; - //spinkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height == lowheight && - Animation::animations[Person::players[k]->animTarget].attack != normalattack) + //lowkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height == lowheight && + Animation::animations[Person::players[k]->animTarget].attack != normalattack) { Person::players[k]->animTarget = lowkickanim; + } } else { //AI player if (distance < 4.5 * sq(Person::players[k]->scale * 5)) { randattack = abs(Random() % 5); if (!attackweapon && distance < 2.5 * sq(Person::players[k]->scale * 5)) { //sweep - if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) + if (randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //upunch - else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight && - !attackweapon) + //upunch + } else if (randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight && + !attackweapon) { Person::players[k]->animTarget = upunchanim; - //spinkick - else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if (randattack == 2 && Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) + //lowkick + } else if (Animation::animations[Person::players[i]->animTarget].height == lowheight) { Person::players[k]->animTarget = lowkickanim; + } } if (attackweapon) { //sweep if ((!Tutorial::active || !attackweapon) && distance < 2.5 * sq(Person::players[k]->scale * 5) && randattack == 0 && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = sweepanim; - //knifeslashstart - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - attackweapon == knife && - Person::players[k]->weaponmissdelay <= 0) + //knifeslashstart + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + attackweapon == knife && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = knifeslashstartanim; - //swordslash - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == sword && - Person::players[k]->weaponmissdelay <= 0) + //swordslash + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == sword && + Person::players[k]->weaponmissdelay <= 0) { Person::players[k]->animTarget = swordslashanim; - //staffhit - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - randattack < 3) + //staffhit + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + randattack < 3) { Person::players[k]->animTarget = staffhitanim; - //staffspinhit - else if (!(Person::players[0]->victim == Person::players[i] && - Person::players[0]->hasvictim && - Person::players[0]->animTarget == swordslashanim) && - attackweapon == staff && - Person::players[k]->weaponmissdelay <= 0 && - randattack >= 3) + //staffspinhit + } else if (!(Person::players[0]->victim == Person::players[i] && + Person::players[0]->hasvictim && + Person::players[0]->animTarget == swordslashanim) && + attackweapon == staff && + Person::players[k]->weaponmissdelay <= 0 && + randattack >= 3) { Person::players[k]->animTarget = staffspinhitanim; - //spinkick - else if ((!Tutorial::active || !attackweapon) && - distance < 2.5 * sq(Person::players[k]->scale * 5) && - randattack == 1 && - Animation::animations[Person::players[i]->animTarget].height != lowheight) + //spinkick + } else if ((!Tutorial::active || !attackweapon) && + distance < 2.5 * sq(Person::players[k]->scale * 5) && + randattack == 1 && + Animation::animations[Person::players[i]->animTarget].height != lowheight) { Person::players[k]->animTarget = spinkickanim; - //lowkick - else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && - Animation::animations[Person::players[i]->animTarget].height == lowheight && - Animation::animations[Person::players[k]->animTarget].attack != normalattack) + //lowkick + } else if (distance < 2.5 * sq(Person::players[k]->scale * 5) && + Animation::animations[Person::players[i]->animTarget].height == lowheight && + Animation::animations[Person::players[k]->animTarget].attack != normalattack) { Person::players[k]->animTarget = lowkickanim; + } } } } //upunch becomes wolfslap - if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) + if (Person::players[k]->animTarget == upunchanim && Person::players[k]->creature == wolftype) { Person::players[k]->animTarget = wolfslapanim; + } } //sneak attacks if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) && @@ -2408,17 +2637,20 @@ void doAttacks() Person::players[i]->yaw = Person::players[k]->targetyaw; } } + } } + } const bool hasstaff = attackweapon == staff; - if (k == 0 && Person::players.size() > 1) + if (k == 0 && Person::players.size() > 1) { for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k) + if (i == k) { continue; + } if ((playerrealattackkeydown || Person::players[i]->dead || !hasstaff) && Animation::animations[Person::players[k]->animTarget].attack == neutral) { const float distance = distsq(&Person::players[k]->coords, &Person::players[i]->coords); - if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) - if (Person::players[i]->skeleton.free) + if (!Person::players[i]->dead || !realthreat || (!attackweapon && Person::players[k]->crouchkeydown)) { + if (Person::players[i]->skeleton.free) { if (distance < 3.5 * sq(Person::players[k]->scale * 5) && (Person::players[i]->dead || Person::players[i]->skeleton.longdead > 1000 || @@ -2433,14 +2665,17 @@ void doAttacks() Person::players[k]->hasvictim = 1; if (attackweapon && !Tutorial::active) { //crouchstab - if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) + if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) { Person::players[k]->animTarget = crouchstabanim; + } //swordgroundstab - if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) + if (Person::players[k]->crouchkeydown && distance < 1.5 * sq(Person::players[k]->scale * 5) && attackweapon == sword) { Person::players[k]->animTarget = swordgroundstabanim; + } //staffgroundsmash - if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) + if (distance < 3.5 * sq(Person::players[k]->scale * 5) && attackweapon == staff) { Person::players[k]->animTarget = staffgroundsmashanim; + } } if (distance < 2.5 && Person::players[k]->crouchkeydown && @@ -2457,7 +2692,7 @@ void doAttacks() } } } - if (!Person::players[i]->dead || musictype != 2) + if (!Person::players[i]->dead || musictype != 2) { if (distance < 3.5 && (Person::players[k]->isRun() || Person::players[k]->isIdle() && Person::players[k]->attackkeydown) && Person::players[k]->staggerdelay <= 0 && @@ -2474,7 +2709,10 @@ void doAttacks() } } } + } } + } + } if (Animation::animations[Person::players[k]->animTarget].attack == normalattack && Person::players[k]->victim == Person::players[i] && (!Person::players[i]->skeleton.free || @@ -2503,8 +2741,9 @@ void doAttacks() Person::players[k]->targetyaw += (float)(abs(Random() % 100) - 50) / 4; } - if (Person::players[k]->animTarget == staffgroundsmashanim) + if (Person::players[k]->animTarget == staffgroundsmashanim) { Person::players[k]->targettilt2 += 10; + } Person::players[k]->lastattack3 = Person::players[k]->lastattack2; Person::players[k]->lastattack2 = Person::players[k]->lastattack; @@ -2516,16 +2755,19 @@ void doAttacks() } } } + } if (!Person::players[k]->hasvictim) { //find victim for (unsigned i = 0; i < Person::players.size(); i++) { - if (i == k || !(i == 0 || k == 0)) + if (i == k || !(i == 0 || k == 0)) { continue; + } if (!Person::players[i]->skeleton.free) { if (Person::players[k]->hasvictim) { if (distsq(&Person::players[k]->coords, &Person::players[i]->coords) < - distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) + distsq(&Person::players[k]->coords, &Person::players[k]->victim->coords)) { Person::players[k]->victim = Person::players[i]; + } } else { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; @@ -2533,7 +2775,7 @@ void doAttacks() } } } - if (Person::players[k]->aitype == playercontrolled) + if (Person::players[k]->aitype == playercontrolled) { //rabbit kick if (Person::players[k]->attackkeydown && Person::players[k]->isRun() && @@ -2552,6 +2794,7 @@ void doAttacks() oldattackkey = 1; Person::players[k]->setTargetAnimation(rabbitkickanim); } + } //update counts if (Animation::animations[Person::players[k]->animTarget].attack && k == 0) { numattacks++; @@ -2580,23 +2823,23 @@ void doPlayerCollisions() { static XYZ rotatetarget; static float collisionradius; - if (Person::players.size() > 1) - for (unsigned k = 0; k < Person::players.size(); k++) + if (Person::players.size() > 1) { + for (unsigned k = 0; k < Person::players.size(); k++) { for (unsigned i = k + 1; i < Person::players.size(); i++) { //neither player is part of a reversal if ((Animation::animations[Person::players[i]->animTarget].attack != reversed && Animation::animations[Person::players[i]->animTarget].attack != reversal && Animation::animations[Person::players[k]->animTarget].attack != reversed && Animation::animations[Person::players[k]->animTarget].attack != reversal) || - (i != 0 && k != 0)) + (i != 0 && k != 0)) { if ((Animation::animations[Person::players[i]->animCurrent].attack != reversed && Animation::animations[Person::players[i]->animCurrent].attack != reversal && Animation::animations[Person::players[k]->animCurrent].attack != reversed && Animation::animations[Person::players[k]->animCurrent].attack != reversal) || - (i != 0 && k != 0)) + (i != 0 && k != 0)) { //neither is sleeping - if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) - if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) + if (Person::players[i]->howactive <= typesleeping && Person::players[k]->howactive <= typesleeping) { + if (Person::players[i]->howactive != typesittingwall && Person::players[k]->howactive != typesittingwall) { //in same patch, neither is climbing if (Person::players[i]->whichpatchx == Person::players[k]->whichpatchx && Person::players[i]->whichpatchz == Person::players[k]->whichpatchz && @@ -2605,34 +2848,40 @@ void doPlayerCollisions() Person::players[i]->animTarget != climbanim && Person::players[i]->animTarget != hanganim && Person::players[k]->animTarget != climbanim && - Person::players[k]->animTarget != hanganim) + Person::players[k]->animTarget != hanganim) { //players are close (bounding box test) - if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) - if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) - if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) - if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) - if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) + if (Person::players[i]->coords.y > Person::players[k]->coords.y - 3) { + if (Person::players[i]->coords.y < Person::players[k]->coords.y + 3) { + if (Person::players[i]->coords.x > Person::players[k]->coords.x - 3) { + if (Person::players[i]->coords.x < Person::players[k]->coords.x + 3) { + if (Person::players[i]->coords.z > Person::players[k]->coords.z - 3) { if (Person::players[i]->coords.z < Person::players[k]->coords.z + 3) { //spread fire from player to player if (distsq(&Person::players[i]->coords, &Person::players[k]->coords) < 3 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5)) { if (Person::players[i]->onfire || Person::players[k]->onfire) { - if (!Person::players[i]->onfire) + if (!Person::players[i]->onfire) { Person::players[i]->CatchFire(); - if (!Person::players[k]->onfire) + } + if (!Person::players[k]->onfire) { Person::players[k]->CatchFire(); + } } } XYZ tempcoords1 = Person::players[i]->coords; XYZ tempcoords2 = Person::players[k]->coords; - if (!Person::players[i]->skeleton.oldfree) + if (!Person::players[i]->skeleton.oldfree) { tempcoords1.y += Person::players[i]->jointPos(abdomen).y * Person::players[i]->scale; - if (!Person::players[k]->skeleton.oldfree) + } + if (!Person::players[k]->skeleton.oldfree) { tempcoords2.y += Person::players[k]->jointPos(abdomen).y * Person::players[k]->scale; + } collisionradius = 1.2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); - if (Person::players[0]->hasvictim) - if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) + if (Person::players[0]->hasvictim) { + if (Person::players[0]->animTarget == rabbitkickanim && (k == 0 || i == 0) && !Person::players[0]->victim->skeleton.free) { collisionradius = 3; + } + } if ((!Person::players[i]->skeleton.oldfree || !Person::players[k]->skeleton.oldfree) && (distsq(&tempcoords1, &tempcoords2) < collisionradius || distsq(&Person::players[i]->coords, &Person::players[k]->coords) < collisionradius)) { @@ -2667,7 +2916,7 @@ void doPlayerCollisions() if ((Person::players[i]->animTarget != getupfrombackanim && Person::players[i]->animTarget != getupfromfrontanim || Person::players[i]->skeleton.free) && (Person::players[k]->animTarget != getupfrombackanim && Person::players[k]->animTarget != getupfromfrontanim || - Person::players[k]->skeleton.free)) + Person::players[k]->skeleton.free)) { if ((((k != 0 && findLengthfast(&rotatetarget) > 150 || k == 0 && findLengthfast(&rotatetarget) > 50 && Person::players[0]->rabbitkickragdoll) && normaldotproduct(rotatetarget, Person::players[k]->coords - Person::players[i]->coords) > 0) && @@ -2705,6 +2954,7 @@ void doPlayerCollisions() } } } + } if ((Animation::animations[Person::players[i]->animTarget].attack == neutral || Animation::animations[Person::players[i]->animTarget].attack == normalattack) && (Animation::animations[Person::players[k]->animTarget].attack == neutral || @@ -2717,24 +2967,30 @@ void doPlayerCollisions() Person::players[k]->coords = (Person::players[k]->coords + Person::players[i]->coords) / 2; Person::players[i]->coords = Person::players[k]->coords - rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); Person::players[k]->coords += rotatetarget * fast_sqrt(.6) / 2 * sq((Person::players[i]->scale + Person::players[k]->scale) * 2.5); - if (Person::players[k]->howactive == typeactive || hostile) + if (Person::players[k]->howactive == typeactive || hostile) { if (Person::players[k]->isIdle()) { - if (Person::players[k]->howactive < typesleeping) + if (Person::players[k]->howactive < typesleeping) { Person::players[k]->setTargetAnimation(Person::players[k]->getStop()); - else if (Person::players[k]->howactive == typesleeping) + } else if (Person::players[k]->howactive == typesleeping) { Person::players[k]->setTargetAnimation(getupfromfrontanim); - if (!editorenabled) + } + if (!editorenabled) { Person::players[k]->howactive = typeactive; + } } - if (Person::players[i]->howactive == typeactive || hostile) + } + if (Person::players[i]->howactive == typeactive || hostile) { if (Person::players[i]->isIdle()) { - if (Person::players[i]->howactive < typesleeping) + if (Person::players[i]->howactive < typesleeping) { Person::players[i]->setTargetAnimation(Person::players[k]->getStop()); - else + } else { Person::players[i]->setTargetAnimation(getupfromfrontanim); - if (!editorenabled) + } + if (!editorenabled) { Person::players[i]->howactive = typeactive; + } } + } } //jump down on player if (hostile) { @@ -2775,7 +3031,19 @@ void doPlayerCollisions() Person::players[k]->CheckKick(); } } + } + } + } + } + } + } + } + } + } + } } + } + } } void Game::Tick() @@ -2783,42 +3051,8 @@ void Game::Tick() static XYZ facing, flatfacing; static int target; - Input::Tick(); - - if (Input::isKeyPressed(SDL_SCANCODE_F6)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) - stereoreverse = true; - else - stereoreverse = false; - - if (stereoreverse) - printf("Stereo reversed\n"); - else - printf("Stereo unreversed\n"); - } - - if (Input::isKeyDown(SDL_SCANCODE_F7)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) - stereoseparation -= 0.001; - else - stereoseparation -= 0.010; - printf("Stereo decreased increased to %f\n", stereoseparation); - } - - if (Input::isKeyDown(SDL_SCANCODE_F8)) { - if (Input::isKeyDown(SDL_SCANCODE_LSHIFT)) - stereoseparation += 0.001; - else - stereoseparation += 0.010; - printf("Stereo separation increased to %f\n", stereoseparation); - } - - if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) { - if (Tutorial::stage != 51) { - Tutorial::stagetime = Tutorial::maxtime; - } - emit_sound_np(consolefailsound, 128.); - } + /* Pump SDL input events and process non-gameplay related ones */ + ProcessInput(); /* Values of mainmenu : @@ -2838,8 +3072,9 @@ void Game::Tick() if (!console) { //campaign over? - if (mainmenu && endgame == 1) + if (mainmenu && endgame == 1) { mainmenu = 10; + } //go to level select after completing a campaign level if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) { mainmenu = 5; @@ -2854,27 +3089,6 @@ void Game::Tick() } Menu::Load(); } - //escape key pressed - if (Input::isKeyPressed(SDL_SCANCODE_ESCAPE) && - (gameon || mainmenu == 0)) { - selected = -1; - if (mainmenu == 0 && !winfreeze) - mainmenu = 2; //pause - else if (mainmenu == 1 || mainmenu == 2) { - mainmenu = 0; //unpause - } - //play menu theme - if (musictoggle && (mainmenu == 1 || mainmenu == 2)) { - OPENAL_SetFrequency(OPENAL_ALL); - emit_stream_np(stream_menutheme); - pause_sound(leveltheme); - } - //on resume, play level music - if (!mainmenu) { - pause_sound(stream_menutheme); - resume_stream(leveltheme); - } - } } if (mainmenu) { @@ -2882,34 +3096,18 @@ void Game::Tick() } if (!mainmenu) { - if (hostile == 1) + if (hostile == 1) { hostiletime += multiplier; - else + } else { hostiletime = 0; - if (!winfreeze) - leveltime += multiplier; - - //keys - if (Input::isKeyDown(SDL_SCANCODE_LALT) && Input::isKeyPressed(SDL_SCANCODE_V) && devtools) { - freeze = !freeze; - if (freeze) { - OPENAL_SetFrequency(OPENAL_ALL); - } } - - if (Input::isKeyPressed(consolekey) && devtools) { - console = !console; - if (console) { - OPENAL_SetFrequency(OPENAL_ALL); - } else { - freeze = 0; - waiting = false; - } + if (!winfreeze) { + leveltime += multiplier; } - if (console) + if (console) { freeze = 1; - if (console && !Input::isKeyDown(SDL_SCANCODE_LGUI)) { + inputText(consoletext[0], &consoleselected); if (!waiting) { if (!consoletext[0].empty()) { @@ -2934,22 +3132,10 @@ void Game::Tick() OPENAL_SetFrequency(OPENAL_ALL); emit_sound_np(consolesuccesssound); } - if (winfreeze == 0) + if (winfreeze == 0) { oldwinfreeze = winfreeze; - else + } else { oldwinfreeze++; - - if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDL_SCANCODE_SPACE)) && !campaign) - if (winfreeze) - winfreeze = 0; - if ((Input::isKeyDown(SDL_SCANCODE_ESCAPE)) && !campaign && gameon) { - if (console) { - console = false; - freeze = 0; - } else if (winfreeze) { - mainmenu = 9; - gameon = 0; - } } if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) { @@ -2957,8 +3143,9 @@ void Game::Tick() //dialogues static float talkdelay = 0; - if (Dialog::inDialog()) + if (Dialog::inDialog()) { talkdelay = 1; + } talkdelay -= multiplier; if (talkdelay <= 0 && !Dialog::inDialog() && Animation::animations[Person::players[0]->animTarget].height != highheight) { @@ -3023,13 +3210,20 @@ void Game::Tick() bonus != twoxcombo && bonus != threexcombo && bonus != fourxcombo && - bonus != megacombo) + bonus != megacombo) { bonusnum[bonus]++; - else + } else { bonusnum[bonus] += 0.15; - if (Tutorial::active) + } + if (Tutorial::active) { bonusvalue = 0; - bonusvalue /= bonusnum[bonus]; + } + if (bonusvalue > 0) { + bonusvalue /= bonusnum[bonus]; + if (bonusvalue <= 0) { + bonusvalue = 0; + } + } bonustotal += bonusvalue; } bonustime += multiplier; @@ -3039,8 +3233,9 @@ void Game::Tick() precipdelay -= multiplier; while (precipdelay < 0) { precipdelay += .04; - if (!detail) + if (!detail) { precipdelay += .04; + } XYZ footvel, footpoint; footvel = 0; @@ -3077,8 +3272,9 @@ void Game::Tick() Person::players[0]->throwkeydown = 0; } - if (!Person::players[0]->jumpkeydown) + if (!Person::players[0]->jumpkeydown) { Person::players[0]->jumpclimb = 0; + } if (Dialog::inDialog()) { cameramode = 1; @@ -3094,18 +3290,24 @@ void Game::Tick() flatfacing = DoRotation(flatfacing, 0, -yaw, 0); - if (Input::isKeyDown(forwardkey)) + if (Input::isKeyDown(forwardkey)) { viewer += facing * multiplier * 4; - if (Input::isKeyDown(backkey)) + } + if (Input::isKeyDown(backkey)) { viewer -= facing * multiplier * 4; - if (Input::isKeyDown(leftkey)) + } + if (Input::isKeyDown(leftkey)) { viewer += DoRotation(flatfacing * multiplier, 0, 90, 0) * 4; - if (Input::isKeyDown(rightkey)) + } + if (Input::isKeyDown(rightkey)) { viewer += DoRotation(flatfacing * multiplier, 0, -90, 0) * 4; - if (Input::isKeyDown(jumpkey)) + } + if (Input::isKeyDown(jumpkey)) { viewer.y += multiplier * 4; - if (Input::isKeyDown(crouchkey)) + } + if (Input::isKeyDown(crouchkey)) { viewer.y -= multiplier * 4; + } if (Input::isKeyPressed(SDL_SCANCODE_1) || Input::isKeyPressed(SDL_SCANCODE_2) || Input::isKeyPressed(SDL_SCANCODE_3) || @@ -3118,28 +3320,39 @@ void Game::Tick() Input::isKeyPressed(SDL_SCANCODE_0) || Input::isKeyPressed(SDL_SCANCODE_MINUS)) { int whichend; - if (Input::isKeyPressed(SDL_SCANCODE_1)) + if (Input::isKeyPressed(SDL_SCANCODE_1)) { whichend = 1; - if (Input::isKeyPressed(SDL_SCANCODE_2)) + } + if (Input::isKeyPressed(SDL_SCANCODE_2)) { whichend = 2; - if (Input::isKeyPressed(SDL_SCANCODE_3)) + } + if (Input::isKeyPressed(SDL_SCANCODE_3)) { whichend = 3; - if (Input::isKeyPressed(SDL_SCANCODE_4)) + } + if (Input::isKeyPressed(SDL_SCANCODE_4)) { whichend = 4; - if (Input::isKeyPressed(SDL_SCANCODE_5)) + } + if (Input::isKeyPressed(SDL_SCANCODE_5)) { whichend = 5; - if (Input::isKeyPressed(SDL_SCANCODE_6)) + } + if (Input::isKeyPressed(SDL_SCANCODE_6)) { whichend = 6; - if (Input::isKeyPressed(SDL_SCANCODE_7)) + } + if (Input::isKeyPressed(SDL_SCANCODE_7)) { whichend = 7; - if (Input::isKeyPressed(SDL_SCANCODE_8)) + } + if (Input::isKeyPressed(SDL_SCANCODE_8)) { whichend = 8; - if (Input::isKeyPressed(SDL_SCANCODE_9)) + } + if (Input::isKeyPressed(SDL_SCANCODE_9)) { whichend = 9; - if (Input::isKeyPressed(SDL_SCANCODE_0)) + } + if (Input::isKeyPressed(SDL_SCANCODE_0)) { whichend = 0; - if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) + } + if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) { whichend = -1; + } if (whichend != -1) { Dialog::currentScene().participantfocus = whichend; Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords; @@ -3180,26 +3393,36 @@ void Game::Tick() Input::isKeyDown(SDL_SCANCODE_KP_9) || Input::isKeyDown(SDL_SCANCODE_KP_0)) { int whichend; - if (Input::isKeyDown(SDL_SCANCODE_KP_1)) + if (Input::isKeyDown(SDL_SCANCODE_KP_1)) { whichend = 1; - if (Input::isKeyDown(SDL_SCANCODE_KP_2)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_2)) { whichend = 2; - if (Input::isKeyDown(SDL_SCANCODE_KP_3)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_3)) { whichend = 3; - if (Input::isKeyDown(SDL_SCANCODE_KP_4)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_4)) { whichend = 4; - if (Input::isKeyDown(SDL_SCANCODE_KP_5)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_5)) { whichend = 5; - if (Input::isKeyDown(SDL_SCANCODE_KP_6)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_6)) { whichend = 6; - if (Input::isKeyDown(SDL_SCANCODE_KP_7)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_7)) { whichend = 7; - if (Input::isKeyDown(SDL_SCANCODE_KP_8)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_8)) { whichend = 8; - if (Input::isKeyDown(SDL_SCANCODE_KP_9)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_9)) { whichend = 9; - if (Input::isKeyDown(SDL_SCANCODE_KP_0)) + } + if (Input::isKeyDown(SDL_SCANCODE_KP_0)) { whichend = 0; + } Dialog::currentScene().participantfacing[whichend] = facing; } if (Dialog::indialogue >= int(Dialog::currentDialog().scenes.size())) { @@ -3262,8 +3485,9 @@ void Game::Tick() if (Person::players[0]->jumpkeydown && Person::players[0]->animTarget != jumpupanim && Person::players[0]->animTarget != jumpdownanim && - !Person::players[0]->isFlip()) + !Person::players[0]->isFlip()) { Person::players[0]->jumptogglekeydown = 1; + } Dialog::dialoguetime += multiplier; hawkyaw += multiplier * 25; @@ -3278,17 +3502,17 @@ void Game::Tick() hawkcalldelay = 16 + abs(Random() % 8); } - doDevKeys(); - doAttacks(); doPlayerCollisions(); doJumpReversals(); - for (unsigned k = 0; k < Person::players.size(); k++) - if (k != 0 && Person::players[k]->immobile) + for (unsigned k = 0; k < Person::players.size(); k++) { + if (k != 0 && Person::players[k]->immobile) { Person::players[k]->coords = Person::players[k]->realoldcoords; + } + } for (unsigned k = 0; k < Person::players.size(); k++) { if (!isnormal(Person::players[k]->coords.x) || !isnormal(Person::players[k]->coords.y) || !isnormal(Person::players[k]->coords.z)) { @@ -3302,8 +3526,8 @@ void Game::Tick() static bool respawnkeydown; if (!editorenabled && (whichlevel != -2 && - (Input::isKeyDown(SDL_SCANCODE_Z) && - Input::isKeyDown(SDL_SCANCODE_LGUI) && + (Input::isKeyDown(SDL_SCANCODE_K) && + Input::isKeyDown(SDL_SCANCODE_LALT) && devtools) || (Input::isKeyDown(jumpkey) && !respawnkeydown && @@ -3333,10 +3557,11 @@ void Game::Tick() Person::players[0]->animTarget != dodgebackanim && Person::players[0]->animTarget != walljumprightkickanim && Person::players[0]->animTarget != walljumpleftkickanim) { - if (cameramode) + if (cameramode) { Person::players[0]->targetyaw = 0; - else + } else { Person::players[0]->targetyaw = -yaw + 180; + } } facing = 0; @@ -3384,15 +3609,16 @@ void Game::Tick() Person::players[i]->targetheadpitch = pitchOf(Dialog::currentScene().participantfacing[i]); } - if (leveltime < .5) + if (leveltime < .5) { numenvsounds = 0; + } Person::players[i]->avoidsomething = 0; //avoid flaming things - for (unsigned int j = 0; j < Object::objects.size(); j++) - if (Object::objects[j]->onfire) - if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) + for (unsigned int j = 0; j < Object::objects.size(); j++) { + if (Object::objects[j]->onfire) { + if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < sq(Object::objects[j]->scale) * 200) { if (distsq(&Person::players[i]->coords, &Object::objects[j]->position) < distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; @@ -3404,11 +3630,14 @@ void Game::Tick() Person::players[i]->avoidsomething = 1; } } + } + } + } //avoid flaming players - for (unsigned j = 0; j < Person::players.size(); j++) - if (Person::players[j]->onfire) - if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) + for (unsigned j = 0; j < Person::players.size(); j++) { + if (Person::players[j]->onfire) { + if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < sq(0.3) * 200) { if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) < distsq(&Person::players[i]->coords, &Person::players[0]->coords)) { Person::players[i]->collided = 0; @@ -3420,9 +3649,13 @@ void Game::Tick() Person::players[i]->avoidsomething = 1; } } + } + } + } - if (Person::players[i]->collided > .8) + if (Person::players[i]->collided > .8) { Person::players[i]->avoidcollided = 0; + } Person::players[i]->doAI(); @@ -3449,10 +3682,12 @@ void Game::Tick() Person::players[i]->throwkeydown = 0; } - if (Person::players[i]->collided < -.3) + if (Person::players[i]->collided < -.3) { Person::players[i]->collided = -.3; - if (Person::players[i]->collided > 1) + } + if (Person::players[i]->collided > 1) { Person::players[i]->collided = 1; + } Person::players[i]->collided -= multiplier * 4; Person::players[i]->whichdirectiondelay -= multiplier; if (Person::players[i]->avoidcollided < -.3 || Person::players[i]->whichdirectiondelay <= 0) { @@ -3460,8 +3695,9 @@ void Game::Tick() Person::players[i]->whichdirection = abs(Random() % 2); Person::players[i]->whichdirectiondelay = .4; } - if (Person::players[i]->avoidcollided > 1) + if (Person::players[i]->avoidcollided > 1) { Person::players[i]->avoidcollided = 1; + } Person::players[i]->avoidcollided -= multiplier / 4; if (!Person::players[i]->skeleton.free) { Person::players[i]->stunned -= multiplier; @@ -3471,11 +3707,13 @@ void Game::Tick() Person::players[i]->aitype == attacktypecutoff && !Person::players[i]->dead && !Person::players[i]->skeleton.free && - Animation::animations[Person::players[i]->animTarget].attack == neutral) + Animation::animations[Person::players[i]->animTarget].attack == neutral) { numresponded = 1; + } - if (!Person::players[i]->throwkeydown) + if (!Person::players[i]->throwkeydown) { Person::players[i]->throwtogglekeydown = 0; + } //pick up weapon if (Person::players[i]->throwkeydown && !Person::players[i]->throwtogglekeydown) { @@ -3492,7 +3730,7 @@ void Game::Tick() if ((weapons[j].velocity.x == 0 && weapons[j].velocity.y == 0 && weapons[j].velocity.z == 0 || Person::players[i]->aitype == playercontrolled) && weapons[j].owner == -1 && - Person::players[i]->weaponactive == -1) + Person::players[i]->weaponactive == -1) { if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 2) { if (Person::players[i]->isCrouch() || @@ -3513,14 +3751,17 @@ void Game::Tick() Person::players[i]->aitype == playercontrolled) && weapons[j].owner == -1 || Person::players[i]->victim && - weapons[j].owner == int(Person::players[i]->victim->id)) - if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) + weapons[j].owner == int(Person::players[i]->victim->id)) { + if (distsqflat(&Person::players[i]->coords, &weapons[j].position) < 2 && Person::players[i]->weaponactive == -1) { if (distsq(&Person::players[i]->coords, &weapons[j].position) < 1 || Person::players[i]->victim) { - if (weapons[j].getType() != staff) + if (weapons[j].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } Person::players[i]->takeWeapon(j); } + } + } } } else if ((Person::players[i]->isIdle() || Person::players[i]->isFlip() || @@ -3537,33 +3778,37 @@ void Game::Tick() Person::players[i]->hasvictim = 0; for (unsigned k = 0; k < weapons.size(); k++) { - if (Person::players[i]->weaponactive == -1) + if (Person::players[i]->weaponactive == -1) { if ((weapons[k].velocity.x == 0 && weapons[k].velocity.y == 0 && weapons[k].velocity.z == 0 || Person::players[i]->aitype == playercontrolled) && weapons[k].owner == -1 || Person::players[i]->victim && - weapons[k].owner == int(Person::players[i]->victim->id)) + weapons[k].owner == int(Person::players[i]->victim->id)) { if (distsqflat(&Person::players[i]->coords, &weapons[k].position) < 3 && Person::players[i]->weaponactive == -1) { - if (weapons[k].getType() != staff) + if (weapons[k].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } Person::players[i]->takeWeapon(k); } + } + } } } } } + } } if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim || Person::players[i]->isRun() || Person::players[i]->isIdle() || Person::players[i]->animTarget == rollanim || Person::players[i]->animTarget == backhandspringanim) { - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { - if (Person::players[i]->weaponactive == -1) - if (j != i) + if (Person::players[i]->weaponactive == -1) { + if (j != i) { if (Person::players[j]->num_weapons && Person::players[j]->skeleton.free && distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 2 /*&&Person::players[j]->dead*/ && @@ -3594,17 +3839,20 @@ void Game::Tick() } } if (!fleshstuck) { - if (weapons[k].getType() != staff) + if (weapons[k].getType() != staff) { emit_sound_at(knifedrawsound, Person::players[i]->coords, 128.); + } } - if (fleshstuck) + if (fleshstuck) { emit_sound_at(fleshstabremovesound, Person::players[i]->coords, 128.); + } if (weapons[k].owner != -1) { - if (Person::players[i]->victim->num_weapons == 1) + if (Person::players[i]->victim->num_weapons == 1) { Person::players[i]->victim->num_weapons = 0; - else + } else { Person::players[i]->victim->num_weapons = 1; + } Person::players[i]->victim->skeleton.longdead = 0; Person::players[i]->victim->skeleton.free = 1; @@ -3624,8 +3872,9 @@ void Game::Tick() footpoint = weapons[k].position; if (Person::players[i]->victim->weaponstuck != -1) { if (Person::players[i]->victim->weaponids[Person::players[i]->victim->weaponstuck] == k) { - if (bloodtoggle) + if (bloodtoggle) { Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3); + } weapons[k].bloody = 2; weapons[k].blooddrip = 5; Person::players[i]->victim->weaponstuck = -1; @@ -3634,10 +3883,12 @@ void Game::Tick() } } if (Person::players[i]->victim->num_weapons > 0) { - if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) + if (Person::players[i]->victim->weaponstuck != 0 && Person::players[i]->victim->weaponstuck != -1) { Person::players[i]->victim->weaponstuck = 0; - if (Person::players[i]->victim->weaponids[0] == k) + } + if (Person::players[i]->victim->weaponids[0] == k) { Person::players[i]->victim->weaponids[0] = Person::players[i]->victim->weaponids[Person::players[i]->victim->num_weapons]; + } } Person::players[i]->victim->weaponactive = -1; @@ -3651,7 +3902,10 @@ void Game::Tick() } } } + } + } } + } } } if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { @@ -3660,12 +3914,12 @@ void Game::Tick() Person::players[i]->isRun() || Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim || - Person::players[i]->isFlip()) - if (Person::players.size() > 1) + Person::players[i]->isFlip()) { + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { - if (i != j) - if (!Tutorial::active || Tutorial::stage == 49) - if (hostile) + if (i != j) { + if (!Tutorial::active || Tutorial::stage == 49) { + if (hostile) { if (normaldotproduct(Person::players[i]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0 && distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 100 && distsq(&Person::players[i]->coords, &Person::players[j]->coords) > 1.5 && @@ -3697,21 +3951,28 @@ void Game::Tick() } } } + } + } + } } + } + } } } if (Person::players[i]->weaponactive != -1 && Person::players[i]->aitype == playercontrolled) { if (Person::players[i]->isCrouch() || Person::players[i]->animTarget == sneakanim) { Person::players[i]->throwtogglekeydown = 1; XYZ tempVelocity = Person::players[i]->velocity * .2; - if (tempVelocity.x == 0) + if (tempVelocity.x == 0) { tempVelocity.x = .1; + } weapons[Person::players[i]->weaponids[0]].drop(tempVelocity, tempVelocity, false); Person::players[i]->num_weapons--; if (Person::players[i]->num_weapons) { Person::players[i]->weaponids[0] = Person::players[i]->weaponids[Person::players[i]->num_weapons]; - if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) + if (Person::players[i]->weaponstuck == Person::players[i]->num_weapons) { Person::players[i]->weaponstuck = 0; + } } Person::players[i]->weaponactive = -1; @@ -3732,9 +3993,11 @@ void Game::Tick() (Person::players[i]->weaponactive != -1) && i != 0) { bool isgood = true; - if (Person::players[i]->weaponactive != -1) - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) + if (Person::players[i]->weaponactive != -1) { + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == staff) { isgood = false; + } + } if (isgood && Person::players[i]->creature != wolftype) { if (Person::players[i]->isIdle() && Person::players[i]->num_weapons && weapons[Person::players[i]->weaponids[0]].getType() == knife) { Person::players[i]->setTargetAnimation(drawrightanim); @@ -3766,16 +4029,19 @@ void Game::Tick() Person::players[i]->num_weapons && Person::players[i]->attackkeydown && musictype != stream_fighttheme) { - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == knife) { Person::players[i]->setTargetAnimation(crouchstabanim); - if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) + } + if (weapons[Person::players[i]->weaponids[Person::players[i]->weaponactive]].getType() == sword) { Person::players[i]->setTargetAnimation(swordgroundstabanim); + } Person::players[i]->hasvictim = 0; } } - if (!Person::players[i]->drawkeydown) + if (!Person::players[i]->drawkeydown) { Person::players[i]->drawtogglekeydown = 0; + } XYZ absflatfacing; if (i == 0) { @@ -3783,8 +4049,9 @@ void Game::Tick() absflatfacing.z = -1; absflatfacing = DoRotation(absflatfacing, 0, -yaw, 0); - } else + } else { absflatfacing = flatfacing; + } if (Dialog::inDialog()) { Person::players[i]->forwardkeydown = 0; @@ -3803,21 +4070,26 @@ void Game::Tick() Person::players[i]->animTarget != staggerbackhardanim && Person::players[i]->animTarget != backhandspringanim && Person::players[i]->animTarget != dodgebackanim) { - if (!Person::players[i]->forwardkeydown) + if (!Person::players[i]->forwardkeydown) { Person::players[i]->forwardstogglekeydown = 0; + } if (Person::players[i]->crouchkeydown) { //Crouch target = -2; if (i == 0) { Person::players[i]->superruntoggle = 1; - if (Person::players.size() > 1) - for (unsigned j = 0; j < Person::players.size(); j++) - if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) - if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) + if (Person::players.size() > 1) { + for (unsigned j = 0; j < Person::players.size(); j++) { + if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->aitype == passivetype) { + if (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 16) { Person::players[i]->superruntoggle = 0; + } + } + } + } } - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim && Person::players[i]->lowreversaldelay <= 0) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 && @@ -3830,15 +4102,18 @@ void Game::Tick() Person::players[j]->animTarget == staffhitanim || Person::players[j]->animTarget == staffspinhitanim) && distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2))) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[target]->Reverse(); + } Person::players[i]->lowreversaldelay = .5; if (Person::players[i]->isIdle()) { @@ -3857,11 +4132,12 @@ void Game::Tick() } if (!Person::players[i]->crouchkeydown) { //Uncrouch - if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) + if (!Person::players[i]->isRun() && Person::players[i]->animTarget != sneakanim && i == 0) { Person::players[i]->superruntoggle = 0; + } target = -2; if (Person::players[i]->isCrouch()) { - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && @@ -3871,15 +4147,18 @@ void Game::Tick() Person::players[j]->victim == Person::players[i] && (Person::players[j]->animTarget == spinkickanim) && Person::players[i]->isCrouch()) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[target]->Reverse(); + } Person::players[i]->highreversaldelay = .5; if (Person::players[i]->isCrouch()) { @@ -3907,15 +4186,17 @@ void Game::Tick() Person::players[i]->frameTarget > 0 && !Person::players[i]->jumpkeydown && Person::players[i]->crouchkeydown)) { - if (Person::players[i]->aitype == passivetype) + if (Person::players[i]->aitype == passivetype) { Person::players[i]->setTargetAnimation(walkanim); - else + } else { Person::players[i]->setTargetAnimation(Person::players[i]->getRun()); + } } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == hanganim /*&&(!Person::players[i]->forwardstogglekeydown||Person::players[i]->aitype!=playercontrolled)*/) { @@ -3944,18 +4225,21 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { Person::players[i]->velocity += DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0); } Person::players[i]->targetyaw -= 90; - if (Person::players[i]->forwardkeydown) + if (Person::players[i]->forwardkeydown) { Person::players[i]->targetyaw += 45; - if (Person::players[i]->backkeydown) + } + if (Person::players[i]->backkeydown) { Person::players[i]->targetyaw -= 45; + } movekey = 1; } if (Person::players[i]->leftkeydown) { @@ -3973,18 +4257,21 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { Person::players[i]->velocity -= DoRotation(absflatfacing * 5 * multiplier, 0, -90, 0); } Person::players[i]->targetyaw += 90; - if (Person::players[i]->forwardkeydown) + if (Person::players[i]->forwardkeydown) { Person::players[i]->targetyaw -= 45; - if (Person::players[i]->backkeydown) + } + if (Person::players[i]->backkeydown) { Person::players[i]->targetyaw += 45; + } movekey = 1; } if (Person::players[i]->backkeydown) { @@ -4002,8 +4289,9 @@ void Game::Tick() } if (Person::players[i]->isCrouch()) { Person::players[i]->animTarget = sneakanim; - if (Person::players[i]->wasCrouch()) + if (Person::players[i]->wasCrouch()) { Person::players[i]->target = 0; + } Person::players[i]->frameTarget = 0; } if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim || Person::players[i]->isFlip()) { @@ -4020,8 +4308,9 @@ void Game::Tick() Person::players[i]->coords.y -= 1.4; Person::players[i]->grabdelay = 1; } - if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) + if (!Person::players[i]->leftkeydown && !Person::players[i]->rightkeydown) { Person::players[i]->targetyaw += 180; + } movekey = 1; } if ((Person::players[i]->jumpkeydown && !Person::players[i]->jumpclimb) || Person::players[i]->jumpstart) { @@ -4045,46 +4334,54 @@ void Game::Tick() facing.z = -1; flatfacing = DoRotation(facing, 0, Person::players[i]->targetyaw + 180, 0); - if (movekey) + if (movekey) { Person::players[i]->velocity = flatfacing * Person::players[i]->speed * 45 * Person::players[i]->scale; - if (!movekey) + } + if (!movekey) { Person::players[i]->velocity = 0; + } //Dodge sweep? target = -2; - if (Person::players.size() > 1) + if (Person::players.size() > 1) { for (unsigned j = 0; j < Person::players.size(); j++) { if (j != i && !Person::players[j]->skeleton.free && Person::players[j]->victim) { if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 3 && (Person::players[j]->victim == Person::players[i]) && (Person::players[j]->animTarget == sweepanim)) { - if (target >= 0) + if (target >= 0) { target = -1; - else + } else { target = j; + } } } } - if (target >= 0) + } + if (target >= 0) { Person::players[i]->velocity.y = 1; - else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) { + } else if (Person::players[i]->crouchkeydown || Person::players[i]->aitype != playercontrolled) { Person::players[i]->velocity.y = 7; Person::players[i]->crouchtogglekeydown = 1; - } else + } else { Person::players[i]->velocity.y = 5; + } if (mousejump && i == 0 && devtools) { - if (!Person::players[i]->isLanding()) + if (!Person::players[i]->isLanding()) { Person::players[i]->tempdeltav = deltav; - if (Person::players[i]->tempdeltav < 0) + } + if (Person::players[i]->tempdeltav < 0) { Person::players[i]->velocity.y -= (float)(Person::players[i]->tempdeltav) / multiplier / 1000; + } } Person::players[i]->coords.y += .2; Person::players[i]->jumppower -= 1; - if (!i) + if (!i) { emit_sound_at(whooshsound, Person::players[i]->coords, 128.); + } emit_sound_at(jumpsound, Person::players[i]->coords, 128.); } @@ -4109,8 +4406,9 @@ void Game::Tick() Person::players[i]->jumppower = 0; } } - if (((floatjump || editorenabled) && devtools) && i == 0) + if (((floatjump || editorenabled) && devtools) && i == 0) { Person::players[i]->velocity.y += multiplier * 30; + } } if (!movekey) { @@ -4129,48 +4427,58 @@ void Game::Tick() (Person::players[i]->aitype == attacktypecutoff || Person::players[i]->aitype == searchtype || (Person::players[i]->aitype == passivetype && - Person::players[i]->numwaypoints <= 1))) + Person::players[i]->numwaypoints <= 1))) { Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); - if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) + } + if (Person::players[i]->isRun() && (Person::players[i]->aitype == passivetype)) { Person::players[i]->setTargetAnimation(Person::players[i]->getStop()); + } } } - if (Person::players[i]->animTarget == rollanim) + if (Person::players[i]->animTarget == rollanim) { Person::players[i]->targetyaw = oldtargetyaw; + } } //Rotation for (unsigned k = 0; k < Person::players.size(); k++) { if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 180) { - if (Person::players[k]->yaw > Person::players[k]->targetyaw) + if (Person::players[k]->yaw > Person::players[k]->targetyaw) { Person::players[k]->yaw -= 360; - else + } else { Person::players[k]->yaw += 360; + } } //stop to turn in right direction - if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) + if (fabs(Person::players[k]->yaw - Person::players[k]->targetyaw) > 90 && (Person::players[k]->isRun() || Person::players[k]->animTarget == walkanim)) { Person::players[k]->setTargetAnimation(Person::players[k]->getStop()); + } - if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) + if (Person::players[k]->animTarget == backhandspringanim || Person::players[k]->animTarget == dodgebackanim) { Person::players[k]->targettilt = 0; + } if (Person::players[k]->animTarget != jumpupanim && Person::players[k]->animTarget != backhandspringanim && Person::players[k]->animTarget != jumpdownanim && !Person::players[k]->isFlip()) { Person::players[k]->targettilt = 0; - if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) + if (Person::players[k]->jumppower < 0 && !Person::players[k]->jumpkeydown) { Person::players[k]->jumppower = 0; + } Person::players[k]->jumppower += multiplier * 7; - if (Person::players[k]->isCrouch()) + if (Person::players[k]->isCrouch()) { Person::players[k]->jumppower += multiplier * 7; - if (Person::players[k]->jumppower > 5) + } + if (Person::players[k]->jumppower > 5) { Person::players[k]->jumppower = 5; + } } - if (Person::players[k]->isRun()) + if (Person::players[k]->isRun()) { Person::players[k]->targettilt = (Person::players[k]->yaw - Person::players[k]->targetyaw) / 4; + } Person::players[k]->tilt = stepTowardf(Person::players[k]->tilt, Person::players[k]->targettilt, multiplier * 150); Person::players[k]->grabdelay -= multiplier; @@ -4238,9 +4546,6 @@ void Game::Tick() oldviewer = viewer; } } - - if (Input::isKeyPressed(SDL_SCANCODE_F1)) - Screenshot(); } void Game::TickOnce() @@ -4254,10 +4559,12 @@ void Game::TickOnce() } else { pitch += deltav * .7; } - if (pitch > 90) + if (pitch > 90) { pitch = 90; - if (pitch < -70) + } + if (pitch < -70) { pitch = -70; + } } } @@ -4276,12 +4583,15 @@ void Game::TickOnceAfter() if (!mainmenu) { static int oldmusictype = musictype; - if (environment == snowyenvironment) + if (environment == snowyenvironment) { leveltheme = stream_snowtheme; - if (environment == grassyenvironment) + } + if (environment == grassyenvironment) { leveltheme = stream_grasstheme; - if (environment == desertenvironment) + } + if (environment == desertenvironment) { leveltheme = stream_deserttheme; + } realthreat = 0; @@ -4299,16 +4609,19 @@ void Game::TickOnceAfter() realthreat = 1; } } - if (Person::players[0]->dead) + if (Person::players[0]->dead) { musictype = stream_menutheme; + } - if (musictype == stream_fighttheme) + if (musictype == stream_fighttheme) { unseendelay = 1; + } if (oldmusictype == stream_fighttheme && musictype != stream_fighttheme) { unseendelay -= multiplier; - if (unseendelay > 0) + if (unseendelay > 0) { musictype = stream_fighttheme; + } } if (loading == 2) { @@ -4319,57 +4632,75 @@ void Game::TickOnceAfter() musicvolume[3] = 0; } - if (musictoggle) - if (musictype != oldmusictype && musictype == stream_fighttheme) + if (musictoggle) { + if (musictype != oldmusictype && musictype == stream_fighttheme) { emit_sound_np(alarmsound); + } + } musicselected = musictype; - if (musicselected == leveltheme) + if (musicselected == leveltheme) { musicvolume[0] += multiplier * 450; - else + } else { musicvolume[0] -= multiplier * 450; - if (musicselected == stream_fighttheme) + } + if (musicselected == stream_fighttheme) { musicvolume[1] += multiplier * 450; - else + } else { musicvolume[1] -= multiplier * 450; - if (musicselected == stream_menutheme) + } + if (musicselected == stream_menutheme) { musicvolume[2] += multiplier * 450; - else + } else { musicvolume[2] -= multiplier * 450; + } for (int i = 0; i < 3; i++) { - if (musicvolume[i] < 0) + if (musicvolume[i] < 0) { musicvolume[i] = 0; - if (musicvolume[i] > 512) + } + if (musicvolume[i] > 512) { musicvolume[i] = 512; + } } - if (musicvolume[2] > 128 && !loading && !mainmenu) + if (musicvolume[2] > 128 && !loading && !mainmenu) { musicvolume[2] = 128; + } if (musictoggle) { - if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) + if (musicvolume[0] > 0 && oldmusicvolume[0] <= 0) { emit_stream_np(leveltheme, musicvolume[0]); - if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) + } + if (musicvolume[1] > 0 && oldmusicvolume[1] <= 0) { emit_stream_np(stream_fighttheme, musicvolume[1]); - if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) + } + if (musicvolume[2] > 0 && oldmusicvolume[2] <= 0) { emit_stream_np(stream_menutheme, musicvolume[2]); - if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) + } + if (musicvolume[0] <= 0 && oldmusicvolume[0] > 0) { pause_sound(leveltheme); - if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) + } + if (musicvolume[1] <= 0 && oldmusicvolume[1] > 0) { pause_sound(stream_fighttheme); - if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) + } + if (musicvolume[2] <= 0 && oldmusicvolume[2] > 0) { pause_sound(stream_menutheme); + } - if (musicvolume[0] != oldmusicvolume[0]) + if (musicvolume[0] != oldmusicvolume[0]) { OPENAL_SetVolume(channels[leveltheme], musicvolume[0]); - if (musicvolume[1] != oldmusicvolume[1]) + } + if (musicvolume[1] != oldmusicvolume[1]) { OPENAL_SetVolume(channels[stream_fighttheme], musicvolume[1]); - if (musicvolume[2] != oldmusicvolume[2]) + } + if (musicvolume[2] != oldmusicvolume[2]) { OPENAL_SetVolume(channels[stream_menutheme], musicvolume[2]); + } - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { oldmusicvolume[i] = musicvolume[i]; + } } else { pause_sound(leveltheme); pause_sound(stream_fighttheme); @@ -4384,14 +4715,16 @@ void Game::TickOnceAfter() Hotspot::killhotspot = 2; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { if (Hotspot::hotspots[i].type > 10 && Hotspot::hotspots[i].type < 20) { - if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) + if (Person::players[Hotspot::hotspots[i].type - 10]->dead == 0) { Hotspot::killhotspot = 0; - else if (Hotspot::killhotspot == 2) + } else if (Hotspot::killhotspot == 2) { Hotspot::killhotspot = 1; + } } } - if (Hotspot::killhotspot == 2) + if (Hotspot::killhotspot == 2) { Hotspot::killhotspot = 0; + } winhotspot = false; for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) { @@ -4428,21 +4761,24 @@ void Game::TickOnceAfter() if (alldead && !Person::players[0]->dead && maptype == mapkilleveryone) { changedelay = 1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (winhotspot || windialogue) { changedelay = 0.1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (Hotspot::killhotspot) { changedelay = 1; targetlevel = whichlevel + 1; - if (targetlevel > numchallengelevels - 1) + if (targetlevel > numchallengelevels - 1) { targetlevel = 0; + } } if (changedelay > 0 && !Person::players[0]->dead && !won) { @@ -4470,17 +4806,20 @@ void Game::TickOnceAfter() } if (!editorenabled && gameon && !mainmenu) { - if (changedelay != -999) + if (changedelay != -999) { changedelay -= multiplier / 7; - if (Person::players[0]->dead) + } + if (Person::players[0]->dead) { targetlevel = whichlevel; + } if (loading == 2 && !campaign) { flash(); fireSound(firestartsound); - if (!Person::players[0]->dead && targetlevel != whichlevel) + if (!Person::players[0]->dead && targetlevel != whichlevel) { startbonustotal = bonustotal; + } LoadLevel(targetlevel); fireSound(); @@ -4505,8 +4844,9 @@ void Game::TickOnceAfter() (Person::players[0]->dead || (alldead && maptype == mapkilleveryone) || (winhotspot) || - (Hotspot::killhotspot))) + (Hotspot::killhotspot))) { loading = 1; + } if ((Person::players[0]->dead || (alldead && maptype == mapkilleveryone) || (winhotspot) || @@ -4517,8 +4857,9 @@ void Game::TickOnceAfter() winfreeze = true; changedelay = -999; } - if (Person::players[0]->dead) + if (Person::players[0]->dead) { loading = 1; + } } } @@ -4528,8 +4869,9 @@ void Game::TickOnceAfter() // 1 = go back to level select screen // 2 = stealthload next level if (mainmenu == 0 && winfreeze && (campaignlevels[actuallevel].choosenext) == 1) { - if (campaignlevels[actuallevel].nextlevel.empty()) + if (campaignlevels[actuallevel].nextlevel.empty()) { endgame = 1; + } } else if (mainmenu == 0 && winfreeze) { stealthloading = (campaignlevels[actuallevel].choosenext == 2); @@ -4563,8 +4905,9 @@ void Game::TickOnceAfter() } } - if (loading == 3) + if (loading == 3) { loading = 0; + } } oldmusictype = musictype; @@ -4578,15 +4921,17 @@ void Game::TickOnceAfter() viewerfacing = facing; if (!cameramode) { - if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) + if ((Animation::animations[Person::players[0]->animTarget].attack != 3 && Animation::animations[Person::players[0]->animCurrent].attack != 3) || Person::players[0]->skeleton.free) { 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; - else + } else { 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; + } target.y += .1; if (Person::players[0]->skeleton.free) { for (unsigned i = 0; i < Person::players[0]->skeleton.joints.size(); i++) { - if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) + if (Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y > target.y) { target.y = Person::players[0]->skeleton.joints[i].position.y * Person::players[0]->scale + Person::players[0]->coords.y; + } } target.y += .1; } @@ -4595,23 +4940,27 @@ void Game::TickOnceAfter() if (findLengthfast(&Person::players[0]->velocity) > 400) { cameraspeed = 20 + (findLength(&Person::players[0]->velocity) - 20) * .96; } - if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) + if (Person::players[0]->skeleton.free == 0 && Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim) { target.y += 1.4; + } coltarget = target - cameraloc; - if (findLengthfast(&coltarget) < multiplier * multiplier * 400) + if (findLengthfast(&coltarget) < multiplier * multiplier * 400) { cameraloc = target; - else { + } else { Normalise(&coltarget); - if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) + if (Person::players[0]->animTarget != hanganim && Person::players[0]->animTarget != climbanim && Person::players[0]->animCurrent != climbanim && Person::players[0]->currentoffset.x == 0) { cameraloc = cameraloc + coltarget * multiplier * cameraspeed; - else + } else { cameraloc = cameraloc + coltarget * multiplier * 8; + } } - if (editorenabled) + if (editorenabled) { cameraloc = target; + } cameradist += multiplier * 5; - if (cameradist > 2.3) + if (cameradist > 2.3) { cameradist = 2.3; + } viewer = cameraloc - facing * cameradist; colviewer = viewer; coltarget = cameraloc; @@ -4637,19 +4986,24 @@ void Game::TickOnceAfter() cameraloc.y = terrain.getHeight(cameraloc.x, cameraloc.z); } } - if (camerashake > .8) + if (camerashake > .8) { camerashake = .8; + } woozy += multiplier; - if (Person::players[0]->dead) + if (Person::players[0]->dead) { camerashake = 0; - if (Person::players[0]->dead) + } + if (Person::players[0]->dead) { woozy = 0; + } camerashake -= multiplier * 2; blackout -= multiplier * 2; - if (camerashake < 0) + if (camerashake < 0) { camerashake = 0; - if (blackout < 0) + } + if (blackout < 0) { blackout = 0; + } if (camerashake) { viewer.x += (float)(Random() % 100) * .0005 * camerashake; viewer.y += (float)(Random() % 100) * .0005 * camerashake;