From ce51a88a16d2e7af222929546d250eba4acb299d Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Fri, 3 Mar 2017 15:27:00 +0100 Subject: [PATCH] Moved default scale and default damage tolerance to PersonType. Added a method for type changing in Person. --- Source/Devtools/ConsoleCmds.cpp | 16 +++----------- Source/GameTick.cpp | 33 ++++++++++------------------ Source/Objects/Person.cpp | 38 ++++++++++++++++----------------- Source/Objects/Person.hpp | 2 ++ Source/Objects/PersonType.cpp | 4 ++++ Source/Objects/PersonType.hpp | 2 ++ 6 files changed, 40 insertions(+), 55 deletions(-) diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index e1e553e..38e1600 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -470,20 +470,14 @@ void ch_cellophane(const char*) void ch_funnybunny(const char*) { - Person::players[0]->creature = rabbittype; - Person::players[0]->skeletonLoad(true); - Person::players[0]->scale = .2; + Person::players[0]->changeCreatureType(rabbittype); Person::players[0]->headless = 0; - Person::players[0]->damagetolerance = 200; set_proportion(0, "1 1 1 1"); } void ch_wolfie(const char*) { - Person::players[0]->creature = wolftype; - Person::players[0]->skeletonLoad(); - Person::players[0]->scale = .23; - Person::players[0]->damagetolerance = 300; + Person::players[0]->changeCreatureType(wolftype); set_proportion(0, "1 1 1 1"); } @@ -650,11 +644,7 @@ void ch_default(const char*) Person::players[0]->metallow = 1; Person::players[0]->power = 1; Person::players[0]->speedmult = 1; - if (Person::players[0]->creature == wolftype) { - Person::players[0]->scale = .23; - } else if (Person::players[0]->creature == rabbittype) { - Person::players[0]->scale = .2; - } + Person::players[0]->scale = PersonType::types[Person::players[0]->creature].defaultScale; Person::players[0]->setProportions(1, 1, 1, 1); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index e737a4e..92a36c9 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -1054,23 +1054,26 @@ void Game::ProcessDevInput() editorenabled = !editorenabled; if (editorenabled) { Person::players[0]->damagetolerance = 100000; + Person::players[0]->damage = 0; + Person::players[0]->permanentdamage = 0; + Person::players[0]->superpermanentdamage = 0; + Person::players[0]->burnt = 0; + Person::players[0]->bloodloss = 0; + Person::players[0]->deathbleeding = 0; } 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; - Person::players[0]->burnt = 0; Person::players[0]->permanentdamage = 0; Person::players[0]->superpermanentdamage = 0; + Person::players[0]->burnt = 0; + Person::players[0]->bloodloss = 0; + Person::players[0]->deathbleeding = 0; } /* Change environment */ @@ -1210,22 +1213,8 @@ void Game::ProcessDevInput() } if (closest >= 0) { - if (Person::players[closest]->creature == rabbittype) { - Person::players[closest]->creature = wolftype; - Person::players[closest]->whichskin = 0; - Person::players[closest]->skeletonLoad(); - Person::players[closest]->scale *= 1.15; - - Person::players[closest]->damagetolerance = 300; - } else { // wolftype - Person::players[closest]->creature = rabbittype; - Person::players[closest]->whichskin = 0; - Person::players[closest]->skeletonLoad(true); - - Person::players[closest]->scale /= 1.15; - - Person::players[closest]->damagetolerance = 200; - } + person_type nextType = static_cast((Person::players[closest]->creature + 1) % PersonType::types.size()); + Person::players[closest]->changeCreatureType(nextType); } } diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 7a16709..e9ccbbf 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -130,30 +130,24 @@ Person::Person() , skiddingdelay(0) , deathbleeding(0) , tempdeltav(0) - , - damagetolerance(200) + , damagetolerance(0) , damage(0) , permanentdamage(0) , superpermanentdamage(0) , lastcollide(0) , dead(0) - , - jumppower(5) + , jumppower(5) , onground(false) - , - wentforweapon(0) - , + , wentforweapon(0) - calcrot(false) - , + , calcrot(false) - facing() - , + , facing() - bleeding(0) + , bleeding(0) , bleedx(0) , bleedy(0) , direction(0) @@ -353,6 +347,7 @@ Person::Person() jumpclimb(false) { + damagetolerance = PersonType::types[creature].defaultDamageTolerance; setProportions(1, 1, 1, 1); } @@ -435,22 +430,25 @@ Person::Person(FILE* tfile, int mapvers, unsigned i) loaded = true; - if (creature == wolftype) { - damagetolerance = 300; - } + damagetolerance = PersonType::types[creature].defaultDamageTolerance; if (scale < 0) { - if (creature == wolftype) { - scale = .23; - } else { - scale = .2; - } + scale = PersonType::types[creature].defaultScale; } oldcoords = coords; realoldcoords = coords; } +void Person::changeCreatureType(person_type type) +{ + creature = type; + whichskin = 0; + skeletonLoad(type == rabbittype); + scale = PersonType::types[creature].defaultScale; + damagetolerance = PersonType::types[creature].defaultDamageTolerance; +} + void Person::skeletonLoad(bool clothes) { skeleton.id = id; diff --git a/Source/Objects/Person.hpp b/Source/Objects/Person.hpp index 2ead16e..beaf11c 100644 --- a/Source/Objects/Person.hpp +++ b/Source/Objects/Person.hpp @@ -331,6 +331,8 @@ public: float getProportion(int part) const; XYZ getProportionXYZ(int part) const; + void changeCreatureType(person_type type); + void CheckKick(); void CatchFire(); void DoBlood(float howmuch, int which); diff --git a/Source/Objects/PersonType.cpp b/Source/Objects/PersonType.cpp index 2cddb32..3dc4df8 100644 --- a/Source/Objects/PersonType.cpp +++ b/Source/Objects/PersonType.cpp @@ -76,6 +76,8 @@ void PersonType::Load() types[wolftype].skins[2] = "Textures/FurWolfSnow.jpg"; types[wolftype].power = 2.5; + types[wolftype].defaultDamageTolerance = 300; + types[wolftype].defaultScale = .23; /* Rabbit */ types[rabbittype].proportions[0] = 1.2; @@ -127,4 +129,6 @@ void PersonType::Load() types[rabbittype].skins[9] = "Textures/FurBrownWhite.jpg"; types[rabbittype].power = 1; + types[rabbittype].defaultDamageTolerance = 200; + types[rabbittype].defaultScale = .2; } diff --git a/Source/Objects/PersonType.hpp b/Source/Objects/PersonType.hpp index 119fa20..09333ba 100644 --- a/Source/Objects/PersonType.hpp +++ b/Source/Objects/PersonType.hpp @@ -58,6 +58,8 @@ public: std::vector skins; float power; + unsigned int defaultDamageTolerance; + float defaultScale; GLubyte bloodText[512 * 512 * 3] = { 0 }; -- 2.39.5