diff --git a/src/game_party.cpp b/src/game_party.cpp index 67f6846a1d..6fea5b652a 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 00db8baed8..39c3655a09 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_party->IncSteps(); + } } // ESC-Menu calling