From d550442dfc4af8be014bde9eb84cec09c946de6c Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Fri, 2 Nov 2018 13:54:48 -0400 Subject: [PATCH 1/3] Implement SaveInventory::steps * Ticks when player moves with keyboard * Ticks when plyaer moves with keyboard in a vehicle * Does not tick for events forcing player movement * Does not tick for moving once space to embark/disembark * Tested and matches RPG_RT behavior --- src/game_player.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/game_player.cpp b/src/game_player.cpp index 00db8baed8..bdf9ba8b1a 100644 --- a/src/game_player.cpp +++ b/src/game_player.cpp @@ -414,6 +414,8 @@ void Game_Player::Update() { if (!Game_Map::GetInterpreter().IsRunning() && !Game_Map::IsAnyEventStarting()) { if (IsMovable()) { + auto old_x = GetX(); + auto old_y = GetY(); switch (Input::dir4) { case 2: Move(Down); @@ -427,6 +429,9 @@ void Game_Player::Update() { case 8: Move(Up); } + if (GetX() != old_x || GetY() != old_y) { + ++Main_Data::game_data.inventory.steps; + } } // ESC-Menu calling From 75f64b6fb4ea0c348a516abc3e90dbb0b8fd2c53 Mon Sep 17 00:00:00 2001 From: Matthew Fioravante Date: Fri, 2 Nov 2018 16:43:43 -0400 Subject: [PATCH 2/3] Fix States field damage steps algorithm * Matches RPG_RT * Prevents save scumming to avoid state damage * Fixes a bug there Player would trigger damage on every step if the hp modifier was > 0 but the steps modifier was 0. It should be disable if steps is 0. --- src/game_party.cpp | 31 ++++++++++++------------------- src/game_party.h | 25 +++++++++++++++++++------ src/game_player.cpp | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/game_party.cpp b/src/game_party.cpp index 67f6846a1d..c4d92cc90a 100644 --- a/src/game_party.cpp +++ b/src/game_party.cpp @@ -389,14 +389,6 @@ int Game_Party::GetActorPositionInParty(int actor_id) { return it != data().party.end() ? std::distance(data().party.begin(), it) : -1; } -int Game_Party::GetGold() { - return data().gold; -} - -int Game_Party::GetSteps() { - return data().steps; -} - std::vector Game_Party::GetActors() const { std::vector actors; std::vector::const_iterator it; @@ -596,18 +588,17 @@ bool Game_Party::ApplyStateDamage() { bool damage = false; std::vector states = GetInflictedStates(); - for (auto state_id : states) { - if (static_cast(state_steps_hp.size()) < state_id) { - state_steps_hp.resize(state_id); - } - if (static_cast(state_steps_sp.size()) < state_id) { - state_steps_sp.resize(state_id); - } + const auto steps = GetSteps(); + for (auto state_id : states) { RPG::State *state = ReaderUtil::GetElement(Data::states, state_id); - if (state->hp_change_map_val > 0 && (++state_steps_hp[state_id - 1]) >= state->hp_change_map_steps) { - state_steps_hp[state_id - 1] = 0; + //NOTE: We do steps + 1 here because this gets called before steps are incremented. + + if (state->hp_change_map_steps > 0 + && state->hp_change_map_val > 0 + && (((steps + 1) % state->hp_change_map_steps) == 0) + ) { for (auto actor : GetActors()) { if (actor->HasState(state_id)) { actor->ChangeHp(-std::max(0, std::min(state->hp_change_map_val, actor->GetHp() - 1))); @@ -616,8 +607,10 @@ bool Game_Party::ApplyStateDamage() { } } - if (state->sp_change_map_val > 0 && (++state_steps_sp[state_id - 1]) >= state->sp_change_map_steps) { - state_steps_sp[state_id - 1] = 0; + if (state->sp_change_map_steps > 0 + && state->sp_change_map_val > 0 + && (((steps + 1) % state->sp_change_map_steps) == 0) + ){ for (auto actor : GetActors()) { if (actor->HasState(state_id)) { actor->ChangeSp(-state->sp_change_map_val); diff --git a/src/game_party.h b/src/game_party.h index dcf40c4629..ec24407ea5 100644 --- a/src/game_party.h +++ b/src/game_party.h @@ -178,14 +178,19 @@ class Game_Party : public Game_Party_Base { * * @return gold possessed. */ - int GetGold(); + int GetGold() const; /** * Gets steps walked. * * @return steps walked. */ - int GetSteps(); + int GetSteps() const; + + /** + * Increment the number of steps walked by 1. + */ + void IncSteps(); /** * Gets actors in party list. @@ -334,10 +339,6 @@ class Game_Party : public Game_Party_Base { private: const RPG::SaveInventory& data() const; RPG::SaveInventory& data(); - -private: - std::vector state_steps_hp; - std::vector state_steps_sp; }; // ------ INLINES -------- @@ -382,5 +383,17 @@ inline void Game_Party::IncRunCount() { ++data().escapes; } +inline int Game_Party::GetGold() const { + return data().gold; +} + +inline int Game_Party::GetSteps() const { + return data().steps; +} + +inline void Game_Party::IncSteps() { + ++data().steps; +} + #endif diff --git a/src/game_player.cpp b/src/game_player.cpp index bdf9ba8b1a..39c3655a09 100644 --- a/src/game_player.cpp +++ b/src/game_player.cpp @@ -430,7 +430,7 @@ void Game_Player::Update() { Move(Up); } if (GetX() != old_x || GetY() != old_y) { - ++Main_Data::game_data.inventory.steps; + Main_Data::game_party->IncSteps(); } } From 7406d99074fa6a546505c64abf85d9ff72796b3c Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Sun, 4 Nov 2018 08:15:13 -0500 Subject: [PATCH 3/3] Update src/game_party.cpp Co-Authored-By: fmatthew5876 --- src/game_party.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_party.cpp b/src/game_party.cpp index c4d92cc90a..6fea5b652a 100644 --- a/src/game_party.cpp +++ b/src/game_party.cpp @@ -593,7 +593,7 @@ bool Game_Party::ApplyStateDamage() { for (auto state_id : states) { RPG::State *state = ReaderUtil::GetElement(Data::states, state_id); - //NOTE: We do steps + 1 here because this gets called before steps are incremented. + // NOTE: We do steps + 1 here because this gets called before steps are incremented. if (state->hp_change_map_steps > 0 && state->hp_change_map_val > 0