X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGameTick.cpp;h=514ab54a9f094b94f266a90bdb6495af12df7dec;hb=2b4f2692c6fd8799948e85f2148c4bef2db52e90;hp=e4fb6401d5b9cb5a8a883da45f34e476fe764095;hpb=9d126720312b8fa13279c144b2f74bc3d2c66fd9;p=lugaru.git diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index e4fb640..514ab54 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -34,6 +34,7 @@ along with Lugaru. If not, see . #include "User/Settings.hpp" #include "Utils/Folders.hpp" #include "Utils/Input.hpp" +#include "Tutorial.hpp" #if PLATFORM_UNIX #include @@ -112,12 +113,7 @@ extern float skyboxlightb; extern float fadestart; extern float slomospeed; extern float slomofreq; -extern int tutoriallevel; extern float smoketex; -extern float tutorialstagetime; -extern int tutorialstage; -extern float tutorialmaxtime; -extern float tutorialsuccess; extern bool againbonus; extern bool reversaltrain; extern bool canattack; @@ -180,7 +176,7 @@ STATIC_ASSERT (rabbittype == 0 && wolftype == 1) // utility functions // TODO: this is slightly incorrect -inline float roughDirection(XYZ vec) +float roughDirection(XYZ vec) { Normalise(&vec); float angle = -asin(-vec.x) * 180 / M_PI; @@ -188,7 +184,7 @@ inline float roughDirection(XYZ vec) angle = 180 - angle; return angle; } -inline float roughDirectionTo(XYZ start, XYZ end) +float roughDirectionTo(XYZ start, XYZ end) { return roughDirection(end - start); } @@ -197,11 +193,11 @@ inline float pitchOf(XYZ vec) Normalise(&vec); return -asin(vec.y) * 180 / M_PI; } -inline float pitchTo(XYZ start, XYZ end) +float pitchTo(XYZ start, XYZ end) { return pitchOf(end - start); } -inline float sq(float n) +float sq(float n) { return n * n; } @@ -373,115 +369,6 @@ void Game::SetUpLighting() light.ambient[2] *= (skyboxlightb + average) / 2; } -int findPathDist(int start, int end) -{ - int smallestcount, count, connected; - int last, last2, last3, last4; - int closest; - - smallestcount = 1000; - for (int i = 0; i < 50; i++) { - count = 0; - last = start; - last2 = -1; - last3 = -1; - last4 = -1; - while (last != end && count < 30) { - closest = -1; - for (int j = 0; j < numpathpoints; j++) { - if (j != last && j != last2 && j != last3 && j != last4) { - connected = 0; - if (numpathpointconnect[j]) - for (int k = 0; k < numpathpointconnect[j]; k++) { - if (pathpointconnect[j][k] == last)connected = 1; - } - if (!connected) - if (numpathpointconnect[last]) - for (int k = 0; k < numpathpointconnect[last]; k++) { - if (pathpointconnect[last][k] == j)connected = 1; - } - if (connected) - if (closest == -1 || Random() % 2 == 0) { - closest = j; - } - } - } - last4 = last3; - last3 = last2; - last2 = last; - last = closest; - count++; - } - if (count < smallestcount) - smallestcount = count; - } - return smallestcount; -} - -int Game::checkcollide(XYZ startpoint, XYZ endpoint) -{ - float minx, minz, maxx, maxz, miny, maxy; - - minx = min(startpoint.x, endpoint.x) - 1; - miny = min(startpoint.y, endpoint.y) - 1; - minz = min(startpoint.z, endpoint.z) - 1; - maxx = max(startpoint.x, endpoint.x) + 1; - maxy = max(startpoint.y, endpoint.y) + 1; - maxz = max(startpoint.z, endpoint.z) + 1; - - for (int i = 0; i < Object::objects.size(); i++) { - if (checkcollide(startpoint, endpoint, i, minx, miny, minz, maxx, maxy, maxz) != -1) { - return i; - } - } - - return -1; -} - -int Game::checkcollide(XYZ startpoint, XYZ endpoint, int what) -{ - float minx, minz, maxx, maxz, miny, maxy; - - minx = min(startpoint.x, endpoint.x) - 1; - miny = min(startpoint.y, endpoint.y) - 1; - minz = min(startpoint.z, endpoint.z) - 1; - maxx = max(startpoint.x, endpoint.x) + 1; - maxy = max(startpoint.y, endpoint.y) + 1; - maxz = max(startpoint.z, endpoint.z) + 1; - - return checkcollide(startpoint, endpoint, what, minx, miny, minz, maxx, maxy, maxz); -} - -int Game::checkcollide(XYZ startpoint, XYZ endpoint, int what, float minx, float miny, float minz, float maxx, float maxy, float maxz) -{ - XYZ colpoint, colviewer, coltarget; - - if (what == 1000) { - if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) { - return what; - } - } else { - if ( Object::objects[what]->position.x > minx - Object::objects[what]->model.boundingsphereradius && - Object::objects[what]->position.x < maxx + Object::objects[what]->model.boundingsphereradius && - Object::objects[what]->position.y > miny - Object::objects[what]->model.boundingsphereradius && - Object::objects[what]->position.y < maxy + Object::objects[what]->model.boundingsphereradius && - Object::objects[what]->position.z > minz - Object::objects[what]->model.boundingsphereradius && - Object::objects[what]->position.z < maxz + Object::objects[what]->model.boundingsphereradius) { - if ( Object::objects[what]->type != treeleavestype && - Object::objects[what]->type != bushtype && - Object::objects[what]->type != firetype) { - colviewer = startpoint; - coltarget = endpoint; - if (Object::objects[what]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[what]->position, &Object::objects[what]->yaw) != -1) { - return what; - } - } - } - } - - return -1; -} - void Setenvironment(int which) { LOGFUNC; @@ -614,8 +501,7 @@ void Game::Loadlevel(int which) whichlevel = which; if (which == -1) { - tutoriallevel = -1; - Loadlevel("tutorial"); + Loadlevel("tutorial", true); } else if (which >= 0 && which <= 15) { char buf[32]; snprintf(buf, 32, "map%d", which + 1); // challenges @@ -624,7 +510,7 @@ void Game::Loadlevel(int which) Loadlevel("mapsave"); } -void Game::Loadlevel(const std::string& name) +void Game::Loadlevel(const std::string& name, bool tutorial) { int indemo; // FIXME this should be removed int templength; @@ -635,25 +521,23 @@ void Game::Loadlevel(const std::string& name) LOG(std::string("Loading level...") + name); if (!gameon) - visibleloading = 1; + visibleloading = true; if (stealthloading) - visibleloading = 0; + visibleloading = false; if (!stillloading) loadtime = 0; gamestarted = 1; numenvsounds = 0; - if (tutoriallevel != -1) - tutoriallevel = 0; - else - tutoriallevel = 1; + Tutorial::active = tutorial; - if (tutoriallevel == 1) - tutorialstage = 0; - if (tutorialstage == 0) { - tutorialstagetime = 0; - tutorialmaxtime = 1; + if (Tutorial::active) { + Tutorial::stage = 0; + } + if (Tutorial::stage == 0) { + Tutorial::stagetime = 0; + Tutorial::maxtime = 1; } pause_sound(whooshsound); pause_sound(stream_firesound); @@ -734,8 +618,7 @@ void Game::Loadlevel(const std::string& name) terrain.patchobjectnum[i][j] = 0; } } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); } weapons.clear(); @@ -792,8 +675,7 @@ void Game::Loadlevel(const std::string& name) weapons.push_back(Weapon(type, 0)); } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); funpackf(tfile, "Bf Bf Bf", &Person::players[0]->armorhead, &Person::players[0]->armorhigh, &Person::players[0]->armorlow); funpackf(tfile, "Bf Bf Bf", &Person::players[0]->protectionhead, &Person::players[0]->protectionhigh, &Person::players[0]->protectionlow); @@ -852,20 +734,14 @@ void Game::Loadlevel(const std::string& name) Hotspot::hotspots.clear(); } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); if (!stealthloading) { Object::ComputeCenter(); - - if (visibleloading) - LoadingScreen(); - Object::ComputeRadius(); } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); int numplayers; funpackf(tfile, "Bi", &numplayers); @@ -881,8 +757,7 @@ void Game::Loadlevel(const std::string& name) cerr << "Invalid Person found in " << name << endl; } } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); funpackf(tfile, "Bi", &numpathpoints); if (numpathpoints > 30 || numpathpoints < 0) @@ -893,8 +768,7 @@ void Game::Loadlevel(const std::string& name) funpackf(tfile, "Bi", &pathpointconnect[j][k]); } } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x, &mapcenter.y, &mapcenter.z, &mapradius); @@ -906,18 +780,15 @@ void Game::Loadlevel(const std::string& name) if (!stealthloading) { Object::AddObjectsToTerrain(); terrain.DoShadows(); - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); Object::DoShadows(); - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); } fclose(tfile); for (unsigned i = 0; i < Person::players.size(); i++) { - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); if (i == 0) { Person::players[i]->burnt = 0; Person::players[i]->bled = 0; @@ -972,8 +843,7 @@ void Game::Loadlevel(const std::string& name) } - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); if (cellophane) { Person::players[i]->proportionhead.z = 0; @@ -1039,8 +909,7 @@ void Game::Loadlevel(const std::string& name) hawkcoords = Person::players[0]->coords; hawkcoords.y += 30; - if (visibleloading) - LoadingScreen(); + Game::LoadingScreen(); LOG("Starting background music..."); @@ -1064,536 +933,7 @@ void Game::Loadlevel(const std::string& name) leveltime = 0; wonleveltime = 0; - visibleloading = 0; -} - -void doTutorial() -{ - if (tutorialstagetime > tutorialmaxtime) { - tutorialstage++; - tutorialsuccess = 0; - if (tutorialstage <= 1) { - canattack = 0; - cananger = 0; - reversaltrain = 0; - } - switch (tutorialstage) { - case 1: - tutorialmaxtime = 5; - break; - case 2: - tutorialmaxtime = 2; - break; - case 3: - tutorialmaxtime = 600; - break; - case 4: - tutorialmaxtime = 1000; - break; - case 5: - tutorialmaxtime = 600; - break; - case 6: - tutorialmaxtime = 600; - break; - case 7: - tutorialmaxtime = 600; - break; - case 8: - tutorialmaxtime = 600; - break; - case 9: - tutorialmaxtime = 600; - break; - case 10: - tutorialmaxtime = 2; - break; - case 11: - tutorialmaxtime = 1000; - break; - case 12: - tutorialmaxtime = 1000; - break; - case 13: - tutorialmaxtime = 2; - break; - case 14: { - tutorialmaxtime = 3; - - XYZ temp, temp2; - - temp.x = 1011; - temp.y = 84; - temp.z = 491; - temp2.x = 1025; - temp2.y = 75; - temp2.z = 447; - - Person::players[1]->coords = (temp + temp2) / 2; - - emit_sound_at(fireendsound, Person::players[1]->coords); - - for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { - if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) - temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) - temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) - temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) - temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; - Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); - } - } - } - break; - case 15: - tutorialmaxtime = 500; - break; - case 16: - tutorialmaxtime = 500; - break; - case 17: - tutorialmaxtime = 500; - break; - case 18: - tutorialmaxtime = 500; - break; - case 19: - tutorialstage = 20; - break; - case 20: - tutorialmaxtime = 500; - break; - case 21: - tutorialmaxtime = 500; - if (bonus == cannon) { - bonus = Slicebonus; - againbonus = 1; - } else - againbonus = 0; - break; - case 22: - tutorialmaxtime = 500; - break; - case 23: - tutorialmaxtime = 500; - break; - case 24: - tutorialmaxtime = 500; - break; - case 25: - tutorialmaxtime = 500; - break; - case 26: - tutorialmaxtime = 2; - break; - case 27: - tutorialmaxtime = 4; - reversaltrain = 1; - cananger = 1; - Person::players[1]->aitype = attacktypecutoff; - break; - case 28: - tutorialmaxtime = 400; - break; - case 29: - tutorialmaxtime = 400; - Person::players[0]->escapednum = 0; - break; - case 30: - tutorialmaxtime = 4; - reversaltrain = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - break; - case 31: - tutorialmaxtime = 13; - break; - case 32: - tutorialmaxtime = 8; - break; - case 33: - tutorialmaxtime = 400; - cananger = 1; - canattack = 1; - Person::players[1]->aitype = attacktypecutoff; - break; - case 34: - tutorialmaxtime = 400; - break; - case 35: - tutorialmaxtime = 400; - break; - case 36: - tutorialmaxtime = 2; - reversaltrain = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - break; - case 37: - damagedealt = 0; - damagetaken = 0; - tutorialmaxtime = 50; - cananger = 1; - canattack = 1; - Person::players[1]->aitype = attacktypecutoff; - break; - case 38: - tutorialmaxtime = 4; - canattack = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - break; - case 39: { - XYZ temp, temp2; - - temp.x = 1011; - temp.y = 84; - temp.z = 491; - temp2.x = 1025; - temp2.y = 75; - temp2.z = 447; - - Weapon w(knife, -1); - w.position = (temp + temp2) / 2; - w.tippoint = (temp + temp2) / 2; - - w.velocity = 0.1; - w.tipvelocity = 0.1; - w.missed = 1; - w.hitsomething = 0; - w.freetime = 0; - w.firstfree = 1; - w.physics = 1; - - weapons.push_back(w); - } - break; - case 40: - tutorialmaxtime = 300; - break; - case 41: - tutorialmaxtime = 300; - break; - case 42: - tutorialmaxtime = 8; - break; - case 43: - tutorialmaxtime = 300; - break; - case 44: - weapons[0].owner = 1; - Person::players[0]->weaponactive = -1; - Person::players[0]->num_weapons = 0; - Person::players[1]->weaponactive = 0; - Person::players[1]->num_weapons = 1; - Person::players[1]->weaponids[0] = 0; - - cananger = 1; - canattack = 1; - Person::players[1]->aitype = attacktypecutoff; - - tutorialmaxtime = 300; - break; - case 45: - weapons[0].owner = 1; - Person::players[0]->weaponactive = -1; - Person::players[0]->num_weapons = 0; - Person::players[1]->weaponactive = 0; - Person::players[1]->num_weapons = 1; - Person::players[1]->weaponids[0] = 0; - - tutorialmaxtime = 300; - break; - case 46: - weapons[0].owner = 1; - Person::players[0]->weaponactive = -1; - Person::players[0]->num_weapons = 0; - Person::players[1]->weaponactive = 0; - Person::players[1]->num_weapons = 1; - Person::players[1]->weaponids[0] = 0; - - weapons[0].setType(sword); - - tutorialmaxtime = 300; - break; - case 47: { - tutorialmaxtime = 10; - - XYZ temp, temp2; - - temp.x = 1011; - temp.y = 84; - temp.z = 491; - temp2.x = 1025; - temp2.y = 75; - temp2.z = 447; - - Weapon w(sword, -1); - w.position = (temp + temp2) / 2; - w.tippoint = (temp + temp2) / 2; - - w.velocity = 0.1; - w.tipvelocity = 0.1; - w.missed = 1; - w.hitsomething = 0; - w.freetime = 0; - w.firstfree = 1; - w.physics = 1; - - weapons.push_back(w); - - weapons[0].owner = 1; - weapons[1].owner = 0; - Person::players[0]->weaponactive = 0; - Person::players[0]->num_weapons = 1; - Person::players[0]->weaponids[0] = 1; - Person::players[1]->weaponactive = 0; - Person::players[1]->num_weapons = 1; - Person::players[1]->weaponids[0] = 0; - - } - break; - case 48: - canattack = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - - tutorialmaxtime = 15; - - weapons[0].owner = 1; - weapons[1].owner = 0; - Person::players[0]->weaponactive = 0; - Person::players[0]->num_weapons = 1; - Person::players[0]->weaponids[0] = 1; - Person::players[1]->weaponactive = 0; - Person::players[1]->num_weapons = 1; - Person::players[1]->weaponids[0] = 0; - - if (Person::players[0]->weaponactive != -1) - weapons[Person::players[0]->weaponids[Person::players[0]->weaponactive]].setType(staff); - else - weapons[0].setType(staff); - break; - case 49: - canattack = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - - tutorialmaxtime = 200; - - weapons[1].position = 1000; - weapons[1].tippoint = 1000; - - weapons[0].setType(knife); - - weapons[0].owner = 0; - Person::players[1]->weaponactive = -1; - Person::players[1]->num_weapons = 0; - Person::players[0]->weaponactive = 0; - Person::players[0]->num_weapons = 1; - Person::players[0]->weaponids[0] = 0; - - break; - case 50: { - tutorialmaxtime = 8; - - XYZ temp, temp2; - emit_sound_at(fireendsound, Person::players[1]->coords); - - for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { - if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) - temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) - temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) - temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) - temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; - Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); - } - } - - Person::players[1]->num_weapons = 0; - Person::players[1]->weaponstuck = -1; - Person::players[1]->weaponactive = -1; - - weapons.clear(); - } - break; - case 51: - tutorialmaxtime = 80000; - break; - default: - break; - } - if (tutorialstage <= 51) - tutorialstagetime = 0; - } - - //Tutorial success - if (tutorialstagetime < tutorialmaxtime - 3) { - switch (tutorialstage) { - case 3: - if (deltah || deltav) - tutorialsuccess += multiplier; - break; - case 4: - if (Person::players[0]->forwardkeydown || Person::players[0]->backkeydown || Person::players[0]->leftkeydown || Person::players[0]->rightkeydown) - tutorialsuccess += multiplier; - break; - case 5: - if (Person::players[0]->jumpkeydown) - tutorialsuccess = 1; - break; - case 6: - if (Person::players[0]->isCrouch()) - tutorialsuccess = 1; - break; - case 7: - if (Person::players[0]->animTarget == rollanim) - tutorialsuccess = 1; - break; - case 8: - if (Person::players[0]->animTarget == sneakanim) - tutorialsuccess += multiplier; - break; - case 9: - if (Person::players[0]->animTarget == rabbitrunninganim || Person::players[0]->animTarget == wolfrunninganim) - tutorialsuccess += multiplier; - break; - case 11: - if (Person::players[0]->isWallJump()) - tutorialsuccess = 1; - break; - case 12: - if (Person::players[0]->animTarget == flipanim) - tutorialsuccess = 1; - break; - case 15: - if (Person::players[0]->animTarget == upunchanim || Person::players[0]->animTarget == winduppunchanim) - tutorialsuccess = 1; - break; - case 16: - if (Person::players[0]->animTarget == winduppunchanim) - tutorialsuccess = 1; - break; - case 17: - if (Person::players[0]->animTarget == spinkickanim) - tutorialsuccess = 1; - break; - case 18: - if (Person::players[0]->animTarget == sweepanim) - tutorialsuccess = 1; - break; - case 19: - if (Person::players[0]->animTarget == dropkickanim) - tutorialsuccess = 1; - break; - case 20: - if (Person::players[0]->animTarget == rabbitkickanim) - tutorialsuccess = 1; - break; - case 21: - if (bonus == cannon) - tutorialsuccess = 1; - break; - case 22: - if (bonus == spinecrusher) - tutorialsuccess = 1; - break; - case 23: - if (Person::players[0]->animTarget == walljumprightkickanim || Person::players[0]->animTarget == walljumpleftkickanim) - tutorialsuccess = 1; - break; - case 24: - if (Person::players[0]->animTarget == rabbittacklinganim) - tutorialsuccess = 1; - break; - case 25: - if (Person::players[0]->animTarget == backhandspringanim) - tutorialsuccess = 1; - break; - case 28: - if (Animation::animations[Person::players[0]->animTarget].attack == reversed && Person::players[0]->feint) - tutorialsuccess = 1; - break; - case 29: - if (Person::players[0]->escapednum == 2) { - tutorialsuccess = 1; - reversaltrain = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - } - break; - case 33: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) - tutorialsuccess = 1; - break; - case 34: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) - tutorialsuccess = 1; - break; - case 35: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) { - tutorialsuccess = 1; - reversaltrain = 0; - cananger = 0; - Person::players[1]->aitype = passivetype; - } - break; - case 40: - if (Person::players[0]->num_weapons > 0) - tutorialsuccess = 1; - break; - case 41: - if (Person::players[0]->weaponactive == -1 && Person::players[0]->num_weapons > 0) - tutorialsuccess = 1; - break; - case 43: - if (Person::players[0]->animTarget == knifeslashstartanim) - tutorialsuccess = 1; - break; - case 44: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) - tutorialsuccess = 1; - break; - case 45: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) - tutorialsuccess = 1; - break; - case 46: - if (Animation::animations[Person::players[0]->animTarget].attack == reversal) - tutorialsuccess = 1; - break; - case 49: - if (Person::players[1]->weaponstuck != -1) - tutorialsuccess = 1; - break; - default: - break; - } - if (tutorialsuccess >= 1) - tutorialstagetime = tutorialmaxtime - 3; - - - if (tutorialstagetime == tutorialmaxtime - 3) { - emit_sound_np(consolesuccesssound); - } - - if (tutorialsuccess >= 1) { - if (tutorialstage == 34 || tutorialstage == 35) - tutorialstagetime = tutorialmaxtime - 1; - } - } - - if (tutorialstage < 14 || tutorialstage >= 50) { - Person::players[1]->coords.y = 300; - Person::players[1]->velocity = 0; - } + visibleloading = false; } void doDevKeys() @@ -2618,10 +1958,10 @@ void doAerialAcrobatics() whichhit = Object::objects[i]->model.LineCheckPossible(&lowpoint, &lowpointtarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw); if (Object::objects[i]->friction > .5) if (whichhit != -1) { - if (whichhit != -1 && 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 (checkcollide(lowpoint7, lowpointtarget7) == -1) - if (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, @@ -2931,7 +2271,7 @@ void doAttacks() } if (attackweapon) { //sweep - if ((tutoriallevel != 1 || !attackweapon) && + if ((!Tutorial::active || !attackweapon) && distance < 2.5 * sq(Person::players[k]->scale * 5) && randattack == 0 && Animation::animations[Person::players[i]->animTarget].height != lowheight) @@ -2965,7 +2305,7 @@ void doAttacks() randattack >= 3) Person::players[k]->animTarget = staffspinhitanim; //spinkick - else if ((tutoriallevel != 1 || !attackweapon) && + else if ((!Tutorial::active || !attackweapon) && distance < 2.5 * sq(Person::players[k]->scale * 5) && randattack == 1 && Animation::animations[Person::players[i]->animTarget].height != lowheight) @@ -2983,7 +2323,7 @@ void doAttacks() Person::players[k]->animTarget = wolfslapanim; } //sneak attacks - if ((k == 0) && (tutoriallevel != 1 || tutorialstage == 22) && + if ((k == 0) && (!Tutorial::active || Tutorial::stage == 22) && Person::players[i]->howactive < typedead1 && distance < 1.5 * sq(Person::players[k]->scale * 5) && !Person::players[i]->skeleton.free && @@ -3104,7 +2444,7 @@ void doAttacks() distance < 1.5 * sq(Person::players[k]->scale * 5)))) { Person::players[k]->victim = Person::players[i]; Person::players[k]->hasvictim = 1; - if (attackweapon && tutoriallevel != 1) { + if (attackweapon && !Tutorial::active) { //crouchstab if (Person::players[k]->crouchkeydown && attackweapon == knife && distance < 1.5 * sq(Person::players[k]->scale * 5)) Person::players[k]->animTarget = crouchstabanim; @@ -3372,7 +2712,7 @@ void doPlayerCollisions() (k != 0 || Person::players[k]->skeleton.free) || (Animation::animations[Person::players[i]->animTarget].height == highheight && Animation::animations[Person::players[k]->animTarget].height == highheight)) { - if (tutoriallevel != 1) { + if (!Tutorial::active) { emit_sound_at(heavyimpactsound, Person::players[i]->coords); } @@ -3471,985 +2811,6 @@ void doPlayerCollisions() } } -void doAI(unsigned i) -{ - static bool connected; - if (Person::players[i]->aitype != playercontrolled && !Dialog::inDialog()) { - Person::players[i]->jumpclimb = 0; - //disable movement in editor - if (editorenabled) - Person::players[i]->stunned = 1; - - Person::players[i]->pause = 0; - if (distsqflat(&Person::players[0]->coords, &Person::players[i]->coords) < 30 && - Person::players[0]->coords.y > Person::players[i]->coords.y + 2 && - !Person::players[0]->onterrain) - Person::players[i]->pause = 1; - - //pathfinding - if (Person::players[i]->aitype == pathfindtype) { - if (Person::players[i]->finalpathfindpoint == -1) { - float closestdistance; - float tempdist; - int closest; - XYZ colpoint; - closest = -1; - closestdistance = -1; - for (int j = 0; j < numpathpoints; j++) { - if (closest == -1 || distsq(&Person::players[i]->finalfinaltarget, &pathpoint[j]) < closestdistance) { - closestdistance = distsq(&Person::players[i]->finalfinaltarget, &pathpoint[j]); - closest = j; - Person::players[i]->finaltarget = pathpoint[j]; - } - } - Person::players[i]->finalpathfindpoint = closest; - for (int j = 0; j < numpathpoints; j++) { - for (int k = 0; k < numpathpointconnect[j]; k++) { - DistancePointLine(&Person::players[i]->finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint); - if (sq(tempdist) < closestdistance) - if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) < - findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) { - closestdistance = sq(tempdist); - closest = j; - Person::players[i]->finaltarget = colpoint; - } - } - } - Person::players[i]->finalpathfindpoint = closest; - - } - if (Person::players[i]->targetpathfindpoint == -1) { - float closestdistance; - float tempdist; - int closest; - XYZ colpoint; - closest = -1; - closestdistance = -1; - if (Person::players[i]->lastpathfindpoint == -1) { - for (int j = 0; j < numpathpoints; j++) { - if (j != Person::players[i]->lastpathfindpoint) - if (closest == -1 || (distsq(&Person::players[i]->coords, &pathpoint[j]) < closestdistance)) { - closestdistance = distsq(&Person::players[i]->coords, &pathpoint[j]); - closest = j; - } - } - Person::players[i]->targetpathfindpoint = closest; - for (int j = 0; j < numpathpoints; j++) - if (j != Person::players[i]->lastpathfindpoint) - for (int k = 0; k < numpathpointconnect[j]; k++) { - DistancePointLine(&Person::players[i]->coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist, &colpoint ); - if (sq(tempdist) < closestdistance) { - if (findDistance(&colpoint, &pathpoint[j]) + findDistance(&colpoint, &pathpoint[pathpointconnect[j][k]]) < - findDistance(&pathpoint[j], &pathpoint[pathpointconnect[j][k]]) + .1) { - closestdistance = sq(tempdist); - closest = j; - } - } - } - Person::players[i]->targetpathfindpoint = closest; - } else { - for (int j = 0; j < numpathpoints; j++) - if (j != Person::players[i]->lastpathfindpoint && - j != Person::players[i]->lastpathfindpoint2 && - j != Person::players[i]->lastpathfindpoint3 && - j != Person::players[i]->lastpathfindpoint4) { - connected = 0; - if (numpathpointconnect[j]) - for (int k = 0; k < numpathpointconnect[j]; k++) - if (pathpointconnect[j][k] == Person::players[i]->lastpathfindpoint) - connected = 1; - if (!connected) - if (numpathpointconnect[Person::players[i]->lastpathfindpoint]) - for (int k = 0; k < numpathpointconnect[Person::players[i]->lastpathfindpoint]; k++) - if (pathpointconnect[Person::players[i]->lastpathfindpoint][k] == j) - connected = 1; - if (connected) { - tempdist = findPathDist(j, Person::players[i]->finalpathfindpoint); - if (closest == -1 || tempdist < closestdistance) { - closestdistance = tempdist; - closest = j; - } - } - } - Person::players[i]->targetpathfindpoint = closest; - } - } - Person::players[i]->losupdatedelay -= multiplier; - - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, pathpoint[Person::players[i]->targetpathfindpoint]); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - - //reached target point - if (distsqflat(&Person::players[i]->coords, &pathpoint[Person::players[i]->targetpathfindpoint]) < .6) { - Person::players[i]->lastpathfindpoint4 = Person::players[i]->lastpathfindpoint3; - Person::players[i]->lastpathfindpoint3 = Person::players[i]->lastpathfindpoint2; - Person::players[i]->lastpathfindpoint2 = Person::players[i]->lastpathfindpoint; - Person::players[i]->lastpathfindpoint = Person::players[i]->targetpathfindpoint; - if (Person::players[i]->lastpathfindpoint2 == -1) - Person::players[i]->lastpathfindpoint2 = Person::players[i]->lastpathfindpoint; - if (Person::players[i]->lastpathfindpoint3 == -1) - Person::players[i]->lastpathfindpoint3 = Person::players[i]->lastpathfindpoint2; - if (Person::players[i]->lastpathfindpoint4 == -1) - Person::players[i]->lastpathfindpoint4 = Person::players[i]->lastpathfindpoint3; - Person::players[i]->targetpathfindpoint = -1; - } - if ( distsqflat(&Person::players[i]->coords, &Person::players[i]->finalfinaltarget) < - distsqflat(&Person::players[i]->coords, &Person::players[i]->finaltarget) || - distsqflat(&Person::players[i]->coords, &Person::players[i]->finaltarget) < .6 * sq(Person::players[i]->scale * 5) || - Person::players[i]->lastpathfindpoint == Person::players[i]->finalpathfindpoint) { - Person::players[i]->aitype = passivetype; - } - - Person::players[i]->forwardkeydown = 1; - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->attackkeydown = 0; - Person::players[i]->throwkeydown = 0; - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - - if (Person::players[i]->collided < 1 || Person::players[i]->animTarget != jumpupanim) - Person::players[i]->jumpkeydown = 0; - if ((Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5)) - Person::players[i]->jumpkeydown = 1; - - if ((tutoriallevel != 1 || cananger) && - hostile && - !Person::players[0]->dead && - distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 400 && - Person::players[i]->occluded < 25) { - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && - !editorenabled && - (Person::players[0]->coords.y < Person::players[i]->coords.y + 5 || Person::players[0]->onterrain)) - Person::players[i]->aitype = attacktypecutoff; - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && - !editorenabled) - Person::players[i]->aitype = attacktypecutoff; - - if (Person::players[i]->losupdatedelay < 0 && !editorenabled && Person::players[i]->occluded < 2) { - Person::players[i]->losupdatedelay = .2; - for (unsigned j = 0; j < Person::players.size(); j++) - if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) - if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) - if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 400) - if (normaldotproduct(Person::players[i]->facing, Person::players[j]->coords - Person::players[i]->coords) > 0) - if (Person::players[j]->coords.y < Person::players[i]->coords.y + 5 || Person::players[j]->onterrain) - if (!Person::players[j]->isWallJump() && -1 == checkcollide( - DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0) - *Person::players[i]->scale + Person::players[i]->coords, - DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) - *Person::players[j]->scale + Person::players[j]->coords) || - (Person::players[j]->animTarget == hanganim && - normaldotproduct(Person::players[j]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0)) { - Person::players[i]->aitype = searchtype; - Person::players[i]->lastchecktime = 12; - Person::players[i]->lastseen = Person::players[j]->coords; - Person::players[i]->lastseentime = 12; - } - } - } - if (Person::players[i]->aitype == attacktypecutoff && musictype != 2) - if (Person::players[i]->creature != wolftype) { - Person::players[i]->stunned = .6; - Person::players[i]->surprised = .6; - } - } - - if (Person::players[i]->aitype != passivetype && leveltime > .5) - Person::players[i]->howactive = typeactive; - - if (Person::players[i]->aitype == passivetype) { - Person::players[i]->aiupdatedelay -= multiplier; - Person::players[i]->losupdatedelay -= multiplier; - Person::players[i]->lastseentime += multiplier; - Person::players[i]->pausetime -= multiplier; - if (Person::players[i]->lastseentime > 1) - Person::players[i]->lastseentime = 1; - - if (Person::players[i]->aiupdatedelay < 0) { - if (Person::players[i]->numwaypoints > 1 && Person::players[i]->howactive == typeactive && Person::players[i]->pausetime <= 0) { - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[i]->waypoints[Person::players[i]->waypoint]); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - Person::players[i]->aiupdatedelay = .05; - - if (distsqflat(&Person::players[i]->coords, &Person::players[i]->waypoints[Person::players[i]->waypoint]) < 1) { - if (Person::players[i]->waypointtype[Person::players[i]->waypoint] == wppause) - Person::players[i]->pausetime = 4; - Person::players[i]->waypoint++; - if (Person::players[i]->waypoint > Person::players[i]->numwaypoints - 1) - Person::players[i]->waypoint = 0; - - } - } - - if (Person::players[i]->numwaypoints > 1 && Person::players[i]->howactive == typeactive && Person::players[i]->pausetime <= 0) - Person::players[i]->forwardkeydown = 1; - else - Person::players[i]->forwardkeydown = 0; - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->attackkeydown = 0; - Person::players[i]->throwkeydown = 0; - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) { - if (!Person::players[i]->avoidsomething) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - else { - XYZ leftpos, rightpos; - float leftdist, rightdist; - leftpos = Person::players[i]->coords + DoRotation(Person::players[i]->facing, 0, 90, 0); - rightpos = Person::players[i]->coords - DoRotation(Person::players[i]->facing, 0, 90, 0); - leftdist = distsq(&leftpos, &Person::players[i]->avoidwhere); - rightdist = distsq(&rightpos, &Person::players[i]->avoidwhere); - if (leftdist < rightdist) - Person::players[i]->targetyaw += 90; - else - Person::players[i]->targetyaw -= 90; - } - } - } - if (Person::players[i]->collided < 1 || Person::players[i]->animTarget != jumpupanim) - Person::players[i]->jumpkeydown = 0; - if ((Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5)) - Person::players[i]->jumpkeydown = 1; - - - //hearing sounds - if (!editorenabled) { - if (Person::players[i]->howactive <= typesleeping) - if (numenvsounds > 0 && (tutoriallevel != 1 || cananger) && hostile) - for (int j = 0; j < numenvsounds; j++) { - float vol = Person::players[i]->howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j]; - if (vol > 0 && distsq(&Person::players[i]->coords, &envsound[j]) < - 2 * (vol + vol * (Person::players[i]->creature == rabbittype) * 3)) - Person::players[i]->aitype = attacktypecutoff; - } - - if (Person::players[i]->aitype != passivetype) { - if (Person::players[i]->howactive == typesleeping) - Person::players[i]->setAnimation(getupfromfrontanim); - Person::players[i]->howactive = typeactive; - } - } - - if (Person::players[i]->howactive < typesleeping && - ((tutoriallevel != 1 || cananger) && hostile) && - !Person::players[0]->dead && - distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 400 && - Person::players[i]->occluded < 25) { - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 12 && - Animation::animations[Person::players[0]->animTarget].height != lowheight && !editorenabled) - Person::players[i]->aitype = attacktypecutoff; - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 30 && - Animation::animations[Person::players[0]->animTarget].height == highheight && !editorenabled) - Person::players[i]->aitype = attacktypecutoff; - - //wolf smell - if (Person::players[i]->creature == wolftype) { - XYZ windsmell; - for (unsigned j = 0; j < Person::players.size(); j++) { - if (j == 0 || (Person::players[j]->dead && Person::players[j]->bloodloss > 0)) { - float smelldistance = 50; - if (j == 0 && Person::players[j]->num_weapons > 0) { - if (weapons[Person::players[j]->weaponids[0]].bloody) - smelldistance = 100; - if (Person::players[j]->num_weapons == 2) - if (weapons[Person::players[j]->weaponids[1]].bloody) - smelldistance = 100; - } - if (j != 0) - smelldistance = 100; - windsmell = windvector; - Normalise(&windsmell); - windsmell = windsmell * 2 + Person::players[j]->coords; - if (distsq(&Person::players[i]->coords, &windsmell) < smelldistance && !editorenabled) - Person::players[i]->aitype = attacktypecutoff; - } - } - } - - if (Person::players[i]->howactive < typesleeping && Person::players[i]->losupdatedelay < 0 && !editorenabled && Person::players[i]->occluded < 2) { - Person::players[i]->losupdatedelay = .2; - for (unsigned j = 0; j < Person::players.size(); j++) { - if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) { - if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) - if (distsq(&Person::players[i]->coords, &Person::players[j]->coords) < 400) - if (normaldotproduct(Person::players[i]->facing, Person::players[j]->coords - Person::players[i]->coords) > 0) - if ((-1 == checkcollide( - DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0)* - Person::players[i]->scale + Person::players[i]->coords, - DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0)* - Person::players[j]->scale + Person::players[j]->coords) && - !Person::players[j]->isWallJump()) || - (Person::players[j]->animTarget == hanganim && - normaldotproduct(Person::players[j]->facing, Person::players[i]->coords - Person::players[j]->coords) < 0)) { - Person::players[i]->lastseentime -= .2; - if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) - Person::players[i]->lastseentime -= .4; - else - Person::players[i]->lastseentime -= .6; - } - if (Person::players[i]->lastseentime <= 0) { - Person::players[i]->aitype = searchtype; - Person::players[i]->lastchecktime = 12; - Person::players[i]->lastseen = Person::players[j]->coords; - Person::players[i]->lastseentime = 12; - } - } - } - } - } - //alerted surprise - if (Person::players[i]->aitype == attacktypecutoff && musictype != 2) { - if (Person::players[i]->creature != wolftype) { - Person::players[i]->stunned = .6; - Person::players[i]->surprised = .6; - } - if (Person::players[i]->creature == wolftype) { - Person::players[i]->stunned = .47; - Person::players[i]->surprised = .47; - } - numseen++; - } - } - - //search for player - int j; - if (Person::players[i]->aitype == searchtype) { - Person::players[i]->aiupdatedelay -= multiplier; - Person::players[i]->losupdatedelay -= multiplier; - if (!Person::players[i]->pause) - Person::players[i]->lastseentime -= multiplier; - Person::players[i]->lastchecktime -= multiplier; - - if (Person::players[i]->isRun() && !Person::players[i]->onground) { - if (Person::players[i]->coords.y > terrain.getHeight(Person::players[i]->coords.x, Person::players[i]->coords.z) + 10) { - XYZ test2 = Person::players[i]->coords + Person::players[i]->facing; - test2.y += 5; - XYZ test = Person::players[i]->coords + Person::players[i]->facing; - test.y -= 10; - j = checkcollide(test2, test, Person::players[i]->laststanding); - if (j == -1) - j = checkcollide(test2, test); - if (j == -1) { - Person::players[i]->velocity = 0; - Person::players[i]->setAnimation(Person::players[i]->getStop()); - Person::players[i]->targetyaw += 180; - Person::players[i]->stunned = .5; - //Person::players[i]->aitype=passivetype; - Person::players[i]->aitype = pathfindtype; - Person::players[i]->finalfinaltarget = Person::players[i]->waypoints[Person::players[i]->waypoint]; - Person::players[i]->finalpathfindpoint = -1; - Person::players[i]->targetpathfindpoint = -1; - Person::players[i]->lastpathfindpoint = -1; - Person::players[i]->lastpathfindpoint2 = -1; - Person::players[i]->lastpathfindpoint3 = -1; - Person::players[i]->lastpathfindpoint4 = -1; - } else - Person::players[i]->laststanding = j; - } - } - //check out last seen location - if (Person::players[i]->aiupdatedelay < 0) { - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[i]->lastseen); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - Person::players[i]->aiupdatedelay = .05; - Person::players[i]->forwardkeydown = 1; - - if (distsqflat(&Person::players[i]->coords, &Person::players[i]->lastseen) < 1 * sq(Person::players[i]->scale * 5) || Person::players[i]->lastchecktime < 0) { - Person::players[i]->forwardkeydown = 0; - Person::players[i]->aiupdatedelay = 1; - Person::players[i]->lastseen.x += (float(Random() % 100) - 50) / 25; - Person::players[i]->lastseen.z += (float(Random() % 100) - 50) / 25; - Person::players[i]->lastchecktime = 3; - } - - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->attackkeydown = 0; - Person::players[i]->throwkeydown = 0; - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) { - if (!Person::players[i]->avoidsomething) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - else { - XYZ leftpos, rightpos; - float leftdist, rightdist; - leftpos = Person::players[i]->coords + DoRotation(Person::players[i]->facing, 0, 90, 0); - rightpos = Person::players[i]->coords - DoRotation(Person::players[i]->facing, 0, 90, 0); - leftdist = distsq(&leftpos, &Person::players[i]->avoidwhere); - rightdist = distsq(&rightpos, &Person::players[i]->avoidwhere); - if (leftdist < rightdist) - Person::players[i]->targetyaw += 90; - else - Person::players[i]->targetyaw -= 90; - } - } - } - if (Person::players[i]->collided < 1 || Person::players[i]->animTarget != jumpupanim) - Person::players[i]->jumpkeydown = 0; - if ((Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5)) - Person::players[i]->jumpkeydown = 1; - - if (numenvsounds > 0 && ((tutoriallevel != 1 || cananger) && hostile)) - for (int k = 0; k < numenvsounds; k++) { - if (distsq(&Person::players[i]->coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (Person::players[i]->creature == rabbittype) * 3)) { - Person::players[i]->aitype = attacktypecutoff; - } - } - - if (!Person::players[0]->dead && - Person::players[i]->losupdatedelay < 0 && - !editorenabled && - Person::players[i]->occluded < 2 && - ((tutoriallevel != 1 || cananger) && hostile)) { - Person::players[i]->losupdatedelay = .2; - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 4 && Animation::animations[Person::players[i]->animTarget].height != lowheight) { - Person::players[i]->aitype = attacktypecutoff; - Person::players[i]->lastseentime = 1; - } - if (abs(Random() % 2) || Animation::animations[Person::players[i]->animTarget].height != lowheight) - //TODO: factor out canSeePlayer() - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 400) - if (normaldotproduct(Person::players[i]->facing, Person::players[0]->coords - Person::players[i]->coords) > 0) - if ((checkcollide( - DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0)* - Person::players[i]->scale + Person::players[i]->coords, - DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0)* - Person::players[0]->scale + Person::players[0]->coords) == -1) || - (Person::players[0]->animTarget == hanganim && normaldotproduct( - Person::players[0]->facing, Person::players[i]->coords - Person::players[0]->coords) < 0)) { - /* //TODO: changed j to 0 on a whim, make sure this is correct - (Person::players[j]->animTarget==hanganim&&normaldotproduct( - Person::players[j]->facing,Person::players[i]->coords-Person::players[j]->coords)<0) - */ - Person::players[i]->aitype = attacktypecutoff; - Person::players[i]->lastseentime = 1; - } - } - //player escaped - if (Person::players[i]->lastseentime < 0) { - //Person::players[i]->aitype=passivetype; - numescaped++; - Person::players[i]->aitype = pathfindtype; - Person::players[i]->finalfinaltarget = Person::players[i]->waypoints[Person::players[i]->waypoint]; - Person::players[i]->finalpathfindpoint = -1; - Person::players[i]->targetpathfindpoint = -1; - Person::players[i]->lastpathfindpoint = -1; - Person::players[i]->lastpathfindpoint2 = -1; - Person::players[i]->lastpathfindpoint3 = -1; - Person::players[i]->lastpathfindpoint4 = -1; - } - } - - if (Person::players[i]->aitype != gethelptype) - Person::players[i]->runninghowlong = 0; - - //get help from buddies - if (Person::players[i]->aitype == gethelptype) { - Person::players[i]->runninghowlong += multiplier; - Person::players[i]->aiupdatedelay -= multiplier; - - if (Person::players[i]->aiupdatedelay < 0 || Person::players[i]->ally == 0) { - Person::players[i]->aiupdatedelay = .2; - - //find closest ally - //TODO: factor out closest search somehow - if (!Person::players[i]->ally) { - int closest = -1; - float closestdist = -1; - for (unsigned k = 0; k < Person::players.size(); k++) { - if (k != i && k != 0 && !Person::players[k]->dead && - Person::players[k]->howactive < typedead1 && - !Person::players[k]->skeleton.free && - Person::players[k]->aitype == passivetype) { - float distance = distsq(&Person::players[i]->coords, &Person::players[k]->coords); - if (closestdist == -1 || distance < closestdist) { - closestdist = distance; - closest = k; - } - closest = k; - } - } - if (closest != -1) - Person::players[i]->ally = closest; - else - Person::players[i]->ally = 0; - Person::players[i]->lastseen = Person::players[0]->coords; - Person::players[i]->lastseentime = 12; - } - - - Person::players[i]->lastchecktime = 12; - - XYZ facing = Person::players[i]->coords; - XYZ flatfacing = Person::players[Person::players[i]->ally]->coords; - facing.y += Person::players[i]->jointPos(head).y * Person::players[i]->scale; - flatfacing.y += Person::players[Person::players[i]->ally]->jointPos(head).y * Person::players[Person::players[i]->ally]->scale; - if (-1 != checkcollide(facing, flatfacing)) - Person::players[i]->lastseentime -= .1; - - //no available ally, run back to player - if (Person::players[i]->ally <= 0 || - Person::players[Person::players[i]->ally]->skeleton.free || - Person::players[Person::players[i]->ally]->aitype != passivetype || - Person::players[i]->lastseentime <= 0) { - Person::players[i]->aitype = searchtype; - Person::players[i]->lastseentime = 12; - } - - //seek out ally - if (Person::players[i]->ally > 0) { - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, Person::players[Person::players[i]->ally]->coords); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - Person::players[i]->aiupdatedelay = .05; - Person::players[i]->forwardkeydown = 1; - - if (distsqflat(&Person::players[i]->coords, &Person::players[Person::players[i]->ally]->coords) < 3) { - Person::players[i]->aitype = searchtype; - Person::players[i]->lastseentime = 12; - Person::players[Person::players[i]->ally]->aitype = searchtype; - if (Person::players[Person::players[i]->ally]->lastseentime < Person::players[i]->lastseentime) { - Person::players[Person::players[i]->ally]->lastseen = Person::players[i]->lastseen; - Person::players[Person::players[i]->ally]->lastseentime = Person::players[i]->lastseentime; - Person::players[Person::players[i]->ally]->lastchecktime = Person::players[i]->lastchecktime; - } - } - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) { - if (!Person::players[i]->avoidsomething) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - else { - XYZ leftpos, rightpos; - float leftdist, rightdist; - leftpos = Person::players[i]->coords + DoRotation(Person::players[i]->facing, 0, 90, 0); - rightpos = Person::players[i]->coords - DoRotation(Person::players[i]->facing, 0, 90, 0); - leftdist = distsq(&leftpos, &Person::players[i]->avoidwhere); - rightdist = distsq(&rightpos, &Person::players[i]->avoidwhere); - if (leftdist < rightdist) - Person::players[i]->targetyaw += 90; - else - Person::players[i]->targetyaw -= 90; - } - } - } - - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->attackkeydown = 0; - } - if (Person::players[i]->collided < 1 || Person::players[i]->animTarget != jumpupanim) - Person::players[i]->jumpkeydown = 0; - if (Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5) - Person::players[i]->jumpkeydown = 1; - } - - //retreiving a weapon on the ground - if (Person::players[i]->aitype == getweapontype) { - Person::players[i]->aiupdatedelay -= multiplier; - Person::players[i]->lastchecktime -= multiplier; - - if (Person::players[i]->aiupdatedelay < 0) { - Person::players[i]->aiupdatedelay = .2; - - //ALLY IS WEPON - if (Person::players[i]->ally < 0) { - int closest = -1; - float closestdist = -1; - for (unsigned k = 0; k < weapons.size(); k++) - if (weapons[k].owner == -1) { - float distance = distsq(&Person::players[i]->coords, &weapons[k].position); - if (closestdist == -1 || distance < closestdist) { - closestdist = distance; - closest = k; - } - closest = k; - } - if (closest != -1) - Person::players[i]->ally = closest; - else - Person::players[i]->ally = -1; - } - - Person::players[i]->lastseentime = 12; - - if (!Person::players[0]->dead && ((tutoriallevel != 1 || cananger) && hostile)) - if (Person::players[i]->ally < 0 || Person::players[i]->weaponactive != -1 || Person::players[i]->lastchecktime <= 0) { - Person::players[i]->aitype = attacktypecutoff; - Person::players[i]->lastseentime = 1; - } - if (!Person::players[0]->dead) - if (Person::players[i]->ally >= 0) { - if (weapons[Person::players[i]->ally].owner != -1 || - distsq(&Person::players[i]->coords, &weapons[Person::players[i]->ally].position) > 16) { - Person::players[i]->aitype = attacktypecutoff; - Person::players[i]->lastseentime = 1; - } - //TODO: factor these out as moveToward() - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, weapons[Person::players[i]->ally].position); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - Person::players[i]->aiupdatedelay = .05; - Person::players[i]->forwardkeydown = 1; - - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) { - if (!Person::players[i]->avoidsomething) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - else { - XYZ leftpos, rightpos; - float leftdist, rightdist; - leftpos = Person::players[i]->coords + DoRotation(Person::players[i]->facing, 0, 90, 0); - rightpos = Person::players[i]->coords - DoRotation(Person::players[i]->facing, 0, 90, 0); - leftdist = distsq(&leftpos, &Person::players[i]->avoidwhere); - rightdist = distsq(&rightpos, &Person::players[i]->avoidwhere); - if (leftdist < rightdist) - Person::players[i]->targetyaw += 90; - else - Person::players[i]->targetyaw -= 90; - } - } - } - - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->attackkeydown = 0; - Person::players[i]->throwkeydown = 1; - Person::players[i]->crouchkeydown = 0; - if (Person::players[i]->animTarget != crouchremoveknifeanim && - Person::players[i]->animTarget != removeknifeanim) - Person::players[i]->throwtogglekeydown = 0; - Person::players[i]->drawkeydown = 0; - } - if (Person::players[i]->collided < 1 || Person::players[i]->animTarget != jumpupanim) - Person::players[i]->jumpkeydown = 0; - if ((Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5)) - Person::players[i]->jumpkeydown = 1; - } - - if (Person::players[i]->aitype == attacktypecutoff) { - Person::players[i]->aiupdatedelay -= multiplier; - //dodge or reverse rabbit kicks, knife throws, flips - if (Person::players[i]->damage < Person::players[i]->damagetolerance * 2 / 3) - if ((Person::players[0]->animTarget == rabbitkickanim || - Person::players[0]->animTarget == knifethrowanim || - (Person::players[0]->isFlip() && - normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - Person::players[i]->coords) < 0)) && - !Person::players[0]->skeleton.free && - (Person::players[i]->aiupdatedelay < .1)) { - Person::players[i]->attackkeydown = 0; - if (Person::players[i]->isIdle()) - Person::players[i]->crouchkeydown = 1; - if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) { - if (weapons[Person::players[0]->weaponids[0]].getType() == knife) { - if (Person::players[i]->isIdle() || Person::players[i]->isCrouch() || Person::players[i]->isRun() || Person::players[i]->isFlip()) { - if (abs(Random() % 2) == 0) - Person::players[i]->setAnimation(backhandspringanim); - else - Person::players[i]->setAnimation(rollanim); - Person::players[i]->targetyaw += 90 * (abs(Random() % 2) * 2 - 1); - Person::players[i]->wentforweapon = 0; - } - if (Person::players[i]->animTarget == jumpupanim || Person::players[i]->animTarget == jumpdownanim) - Person::players[i]->setAnimation(flipanim); - } - } - Person::players[i]->forwardkeydown = 0; - Person::players[i]->aiupdatedelay = .02; - } - //get confused by flips - if (Person::players[0]->isFlip() && - !Person::players[0]->skeleton.free && - Person::players[0]->animTarget != walljumprightkickanim && - Person::players[0]->animTarget != walljumpleftkickanim) { - if (distsq(&Person::players[0]->coords, &Person::players[i]->coords) < 25) - if ((1 - Person::players[i]->damage / Person::players[i]->damagetolerance) > .5) - Person::players[i]->stunned = 1; - } - //go for weapon on the ground - if (Person::players[i]->wentforweapon < 3) - for (unsigned k = 0; k < weapons.size(); k++) - if (Person::players[i]->creature != wolftype) - if (Person::players[i]->num_weapons == 0 && - weapons[k].owner == -1 && - weapons[i].velocity.x == 0 && - weapons[i].velocity.z == 0 && - weapons[i].velocity.y == 0) { - if (distsq(&Person::players[i]->coords, &weapons[k].position) < 16) { - Person::players[i]->wentforweapon++; - Person::players[i]->lastchecktime = 6; - Person::players[i]->aitype = getweapontype; - Person::players[i]->ally = -1; - } - } - //dodge/reverse walljump kicks - if (Person::players[i]->damage < Person::players[i]->damagetolerance / 2) - if (Animation::animations[Person::players[i]->animTarget].height != highheight) - if (Person::players[i]->damage < Person::players[i]->damagetolerance * .5 && - ((Person::players[0]->animTarget == walljumprightkickanim || - Person::players[0]->animTarget == walljumpleftkickanim) && - ((Person::players[i]->aiupdatedelay < .15 && - difficulty == 2) || - (Person::players[i]->aiupdatedelay < .08 && - difficulty != 2)))) { - Person::players[i]->crouchkeydown = 1; - } - //walked off a ledge (?) - if (Person::players[i]->isRun() && !Person::players[i]->onground) - if (Person::players[i]->coords.y > terrain.getHeight(Person::players[i]->coords.x, Person::players[i]->coords.z) + 10) { - XYZ test2 = Person::players[i]->coords + Person::players[i]->facing; - test2.y += 5; - XYZ test = Person::players[i]->coords + Person::players[i]->facing; - test.y -= 10; - j = checkcollide(test2, test, Person::players[i]->laststanding); - if (j == -1) - j = checkcollide(test2, test); - if (j == -1) { - Person::players[i]->velocity = 0; - Person::players[i]->setAnimation(Person::players[i]->getStop()); - Person::players[i]->targetyaw += 180; - Person::players[i]->stunned = .5; - Person::players[i]->aitype = pathfindtype; - Person::players[i]->finalfinaltarget = Person::players[i]->waypoints[Person::players[i]->waypoint]; - Person::players[i]->finalpathfindpoint = -1; - Person::players[i]->targetpathfindpoint = -1; - Person::players[i]->lastpathfindpoint = -1; - Person::players[i]->lastpathfindpoint2 = -1; - Person::players[i]->lastpathfindpoint3 = -1; - Person::players[i]->lastpathfindpoint4 = -1; - } else - Person::players[i]->laststanding = j; - } - //lose sight of player in the air (?) - if (Person::players[0]->coords.y > Person::players[i]->coords.y + 5 && - Animation::animations[Person::players[0]->animTarget].height != highheight && - !Person::players[0]->onterrain) { - Person::players[i]->aitype = pathfindtype; - Person::players[i]->finalfinaltarget = Person::players[i]->waypoints[Person::players[i]->waypoint]; - Person::players[i]->finalpathfindpoint = -1; - Person::players[i]->targetpathfindpoint = -1; - Person::players[i]->lastpathfindpoint = -1; - Person::players[i]->lastpathfindpoint2 = -1; - Person::players[i]->lastpathfindpoint3 = -1; - Person::players[i]->lastpathfindpoint4 = -1; - } - //it's time to think (?) - if (Person::players[i]->aiupdatedelay < 0 && - !Animation::animations[Person::players[i]->animTarget].attack && - Person::players[i]->animTarget != staggerbackhighanim && - Person::players[i]->animTarget != staggerbackhardanim && - Person::players[i]->animTarget != backhandspringanim && - Person::players[i]->animTarget != dodgebackanim) { - //draw weapon - if (Person::players[i]->weaponactive == -1 && Person::players[i]->num_weapons > 0) - Person::players[i]->drawkeydown = Random() % 2; - else - Person::players[i]->drawkeydown = 0; - Person::players[i]->rabbitkickenabled = Random() % 2; - //chase player - XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity; - XYZ targetpoint = Person::players[0]->coords; - if (distsq(&Person::players[0]->coords, &Person::players[i]->coords) < - distsq(&rotatetarget, &Person::players[i]->coords)) - targetpoint += Person::players[0]->velocity * - findDistance(&Person::players[0]->coords, &Person::players[i]->coords) / findLength(&Person::players[i]->velocity); - Person::players[i]->targetyaw = roughDirectionTo(Person::players[i]->coords, targetpoint); - Person::players[i]->lookyaw = Person::players[i]->targetyaw; - Person::players[i]->aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000); - - if (distsq(&Person::players[i]->coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || Person::players[i]->weaponactive != -1)) - Person::players[i]->forwardkeydown = 1; - else if ((distsq(&Person::players[i]->coords, &Person::players[0]->coords) > 16 || - distsq(&Person::players[i]->coords, &Person::players[0]->coords) < 9) && - Person::players[0]->weaponactive != -1) - Person::players[i]->forwardkeydown = 1; - else if (Random() % 6 == 0 || (Person::players[i]->creature == wolftype && Random() % 3 == 0)) - Person::players[i]->forwardkeydown = 1; - else - Person::players[i]->forwardkeydown = 0; - //chill out around the corpse - if (Person::players[0]->dead) { - Person::players[i]->forwardkeydown = 0; - if (Random() % 10 == 0) - Person::players[i]->forwardkeydown = 1; - if (Random() % 100 == 0) { - Person::players[i]->aitype = pathfindtype; - Person::players[i]->finalfinaltarget = Person::players[i]->waypoints[Person::players[i]->waypoint]; - Person::players[i]->finalpathfindpoint = -1; - Person::players[i]->targetpathfindpoint = -1; - Person::players[i]->lastpathfindpoint = -1; - Person::players[i]->lastpathfindpoint2 = -1; - Person::players[i]->lastpathfindpoint3 = -1; - Person::players[i]->lastpathfindpoint4 = -1; - } - } - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->throwkeydown = 0; - - if (Person::players[i]->avoidcollided > .8 && !Person::players[i]->jumpkeydown && Person::players[i]->collided < .8) - Person::players[i]->targetyaw += 90 * (Person::players[i]->whichdirection * 2 - 1); - //attack!!! - if (Random() % 2 == 0 || Person::players[i]->weaponactive != -1 || Person::players[i]->creature == wolftype) - Person::players[i]->attackkeydown = 1; - else - Person::players[i]->attackkeydown = 0; - if (Person::players[i]->isRun() && Random() % 6 && distsq(&Person::players[i]->coords, &Person::players[0]->coords) > 7) - Person::players[i]->attackkeydown = 0; - - //TODO: wat - if (Person::players[i]->aitype != playercontrolled && - (Person::players[i]->isIdle() || - Person::players[i]->isCrouch() || - Person::players[i]->isRun())) { - int target = -2; - for (unsigned j = 0; j < Person::players.size(); j++) - if (j != i && !Person::players[j]->skeleton.free && - Person::players[j]->hasvictim && - (tutoriallevel == 1 && reversaltrain || - Random() % 2 == 0 && difficulty == 2 || - Random() % 4 == 0 && difficulty == 1 || - Random() % 8 == 0 && difficulty == 0 || - Person::players[j]->lastattack2 == Person::players[j]->animTarget && - Person::players[j]->lastattack3 == Person::players[j]->animTarget && - (Random() % 2 == 0 || difficulty == 2) || - (Person::players[i]->isIdle() || Person::players[i]->isRun()) && - Person::players[j]->weaponactive != -1 || - Person::players[j]->animTarget == swordslashanim && - Person::players[i]->weaponactive != -1 || - Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim)) - if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 && - Person::players[j]->victim == Person::players[i] && - (Person::players[j]->animTarget == sweepanim || - Person::players[j]->animTarget == spinkickanim || - Person::players[j]->animTarget == staffhitanim || - Person::players[j]->animTarget == staffspinhitanim || - Person::players[j]->animTarget == winduppunchanim || - Person::players[j]->animTarget == upunchanim || - Person::players[j]->animTarget == wolfslapanim || - Person::players[j]->animTarget == knifeslashstartanim || - Person::players[j]->animTarget == swordslashanim && - (distsq(&Person::players[j]->coords, &Person::players[i]->coords) < 2 || - Person::players[i]->weaponactive != -1))) { - if (target >= 0) - target = -1; - else - target = j; - } - if (target >= 0) - Person::players[target]->Reverse(); - } - - if (Person::players[i]->collided < 1) - Person::players[i]->jumpkeydown = 0; - if (Person::players[i]->collided > .8 && Person::players[i]->jumppower >= 5 || - distsq(&Person::players[i]->coords, &Person::players[0]->coords) > 400 && - Person::players[i]->onterrain && - Person::players[i]->creature == rabbittype) - Person::players[i]->jumpkeydown = 1; - //TODO: why are we controlling the human? - if (normaldotproduct(Person::players[i]->facing, Person::players[0]->coords - Person::players[i]->coords) > 0) - Person::players[0]->jumpkeydown = 0; - if (Person::players[0]->animTarget == jumpdownanim && - distsq(&Person::players[0]->coords, &Person::players[i]->coords) < 40) - Person::players[i]->crouchkeydown = 1; - if (Person::players[i]->jumpkeydown) - Person::players[i]->attackkeydown = 0; - - if (tutoriallevel == 1) - if (!canattack) - Person::players[i]->attackkeydown = 0; - - - XYZ facing = Person::players[i]->coords; - XYZ flatfacing = Person::players[0]->coords; - facing.y += Person::players[i]->jointPos(head).y * Person::players[i]->scale; - flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale; - if (Person::players[i]->occluded >= 2) - if (-1 != checkcollide(facing, flatfacing)) { - if (!Person::players[i]->pause) - Person::players[i]->lastseentime -= .2; - if (Person::players[i]->lastseentime <= 0 && - (Person::players[i]->creature != wolftype || - Person::players[i]->weaponstuck == -1)) { - Person::players[i]->aitype = searchtype; - Person::players[i]->lastchecktime = 12; - Person::players[i]->lastseen = Person::players[0]->coords; - Person::players[i]->lastseentime = 12; - } - } else - Person::players[i]->lastseentime = 1; - } - } - if (Animation::animations[Person::players[0]->animTarget].height == highheight && - (Person::players[i]->aitype == attacktypecutoff || - Person::players[i]->aitype == searchtype)) - if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) { - XYZ test = Person::players[0]->coords; - test.y -= 40; - if (-1 == checkcollide(Person::players[0]->coords, test)) - Person::players[i]->stunned = 1; - } - //stunned - if (Person::players[i]->aitype == passivetype && !(Person::players[i]->numwaypoints > 1) || - Person::players[i]->stunned > 0 || - Person::players[i]->pause && Person::players[i]->damage > Person::players[i]->superpermanentdamage) { - if (Person::players[i]->pause) - Person::players[i]->lastseentime = 1; - Person::players[i]->targetyaw = Person::players[i]->yaw; - Person::players[i]->forwardkeydown = 0; - Person::players[i]->leftkeydown = 0; - Person::players[i]->backkeydown = 0; - Person::players[i]->rightkeydown = 0; - Person::players[i]->jumpkeydown = 0; - Person::players[i]->attackkeydown = 0; - Person::players[i]->crouchkeydown = 0; - Person::players[i]->throwkeydown = 0; - } - - - XYZ facing; - facing = 0; - facing.z = -1; - - XYZ flatfacing = DoRotation(facing, 0, Person::players[i]->yaw + 180, 0); - facing = flatfacing; - - if (Person::players[i]->aitype == attacktypecutoff) { - Person::players[i]->targetheadyaw = 180 - roughDirectionTo(Person::players[i]->coords, Person::players[0]->coords); - Person::players[i]->targetheadpitch = pitchTo(Person::players[i]->coords, Person::players[0]->coords); - } else if (Person::players[i]->howactive >= typesleeping) { - Person::players[i]->targetheadyaw = Person::players[i]->targetyaw; - Person::players[i]->targetheadpitch = 0; - } else { - if (Person::players[i]->interestdelay <= 0) { - Person::players[i]->interestdelay = .7 + (float)(abs(Random() % 100)) / 100; - Person::players[i]->headtarget = Person::players[i]->coords; - Person::players[i]->headtarget.x += (float)(abs(Random() % 200) - 100) / 100; - Person::players[i]->headtarget.z += (float)(abs(Random() % 200) - 100) / 100; - Person::players[i]->headtarget.y += (float)(abs(Random() % 200) - 100) / 300; - Person::players[i]->headtarget += Person::players[i]->facing * 1.5; - } - Person::players[i]->targetheadyaw = 180 - roughDirectionTo(Person::players[i]->coords, Person::players[i]->headtarget); - Person::players[i]->targetheadpitch = pitchTo(Person::players[i]->coords, Person::players[i]->headtarget); - } - } -} - void Game::Tick() { static XYZ facing, flatfacing; @@ -4486,9 +2847,10 @@ void Game::Tick() } - if (Input::isKeyPressed(SDL_SCANCODE_TAB) && tutoriallevel) { - if (tutorialstage != 51) - tutorialstagetime = tutorialmaxtime; + if (Input::isKeyPressed(SDL_SCANCODE_TAB) && Tutorial::active) { + if (Tutorial::stage != 51) { + Tutorial::stagetime = Tutorial::maxtime; + } emit_sound_np(consolefailsound, 128.); } @@ -4643,7 +3005,7 @@ void Game::Tick() windvar += multiplier; smoketex += multiplier; - tutorialstagetime += multiplier; + Tutorial::stagetime += multiplier; //hotspots static float hotspotvisual[40]; @@ -4675,12 +3037,12 @@ void Game::Tick() } //Tutorial - if (tutoriallevel) { - doTutorial(); + if (Tutorial::active) { + Tutorial::Do(multiplier); } //bonuses - if (tutoriallevel != 1) { + if (!Tutorial::active) { if (bonustime == 0 && bonus != solidhit && bonus != spinecrusher && @@ -4701,7 +3063,7 @@ void Game::Tick() bonusnum[bonus]++; else bonusnum[bonus] += 0.15; - if (tutoriallevel) + if (Tutorial::active) bonusvalue = 0; bonusvalue /= bonusnum[bonus]; bonustotal += bonusvalue; @@ -5083,7 +3445,7 @@ void Game::Tick() if (Person::players[i]->collided > .8) Person::players[i]->avoidcollided = 0; - doAI(i); + Person::players[i]->doAI(); if (Animation::animations[Person::players[i]->animTarget].attack == reversed) { //Person::players[i]->targetyaw=Person::players[i]->yaw; @@ -5323,13 +3685,13 @@ void Game::Tick() if (Person::players.size() > 1) for (unsigned j = 0; j < Person::players.size(); j++) { if (i != j) - if (tutoriallevel != 1 || tutorialstage == 49) + 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 && !Person::players[j]->skeleton.free && - -1 == checkcollide(DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0)*Person::players[j]->scale + Person::players[j]->coords, DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0)*Person::players[i]->scale + Person::players[i]->coords)) { + -1 == Object::checkcollide(DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0)*Person::players[j]->scale + Person::players[j]->coords, DoRotation(Person::players[i]->jointPos(head), 0, Person::players[i]->yaw, 0)*Person::players[i]->scale + Person::players[i]->coords)) { if (!Person::players[i]->isFlip()) { Person::players[i]->throwtogglekeydown = 1; Person::players[i]->victim = Person::players[j]; @@ -5853,79 +4215,8 @@ void Game::Tick() } OPENAL_SetFrequency(OPENAL_ALL, slomo); - if (tutoriallevel == 1) { - XYZ temp; - XYZ temp2; - XYZ temp3; - XYZ oldtemp; - XYZ oldtemp2; - temp.x = 1011; - temp.y = 84; - temp.z = 491; - temp2.x = 1025; - temp2.y = 75; - temp2.z = 447; - temp3.x = 1038; - temp3.y = 76; - temp3.z = 453; - oldtemp = temp; - oldtemp2 = temp2; - if (tutorialstage >= 51) - if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) { - OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... - OPENAL_SetFrequency(OPENAL_ALL); - - emit_stream_np(stream_menutheme); - - gameon = 0; - mainmenu = 5; - - fireSound(); - - flash(); - } - if (tutorialstage < 51) - if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) { - emit_sound_at(fireendsound, Person::players[0]->coords); - - Person::players[0]->coords = (oldtemp + oldtemp2) / 2; - - flash(); - } - if (tutorialstage >= 14 && tutorialstage < 50) - if (distsq(&temp, &Person::players[1]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[1]->coords) < 4) { - emit_sound_at(fireendsound, Person::players[1]->coords); - - for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { - if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) - temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) - temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) - temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) - temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; - Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); - } - } - - Person::players[1]->coords = (oldtemp + oldtemp2) / 2; - for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) { - Person::players[1]->skeleton.joints[i].velocity = 0; - if (Random() % 2 == 0) { - if (!Person::players[1]->skeleton.free) - temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2; - if (Person::players[1]->skeleton.free) - temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2; - if (!Person::players[1]->skeleton.free) - temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords; - if (Person::players[1]->skeleton.free) - temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords; - Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1); - } - } - } + if (Tutorial::active) { + Tutorial::DoStuff(multiplier); } @@ -6145,8 +4436,8 @@ void Game::TickOnceAfter() maxalarmed = numalarmed; } - if (changedelay <= 0 && !loading && !editorenabled && gameon && !tutoriallevel && changedelay != -999 && !won) { - if (Person::players[0]->dead && changedelay <= 0) { + if (changedelay <= 0 && !loading && !editorenabled && gameon && !Tutorial::active && changedelay != -999 && !won) { + if (Person::players[0]->dead) { changedelay = 1; targetlevel = whichlevel; } @@ -6288,7 +4579,7 @@ void Game::TickOnceAfter() LoadStuff(); whichchoice = 0; actuallevel = campaignlevels[actuallevel].nextlevel.front(); - visibleloading = 1; + visibleloading = true; stillloading = 1; Loadlevel(campaignlevels[actuallevel].mapname.c_str()); campaign = 1;