Skip to content

Commit

Permalink
Merge pull request #1472 from fmatthew5876/steps
Browse files Browse the repository at this point in the history
Increment SaveInventory::steps and fix state damage algo
  • Loading branch information
carstene1ns authored Nov 4, 2018
2 parents b7475ac + 7406d99 commit c71d914
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
31 changes: 12 additions & 19 deletions src/game_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_Actor*> Game_Party::GetActors() const {
std::vector<Game_Actor*> actors;
std::vector<int16_t>::const_iterator it;
Expand Down Expand Up @@ -596,18 +588,17 @@ bool Game_Party::ApplyStateDamage() {
bool damage = false;
std::vector<int16_t> states = GetInflictedStates();

for (auto state_id : states) {
if (static_cast<int>(state_steps_hp.size()) < state_id) {
state_steps_hp.resize(state_id);
}
if (static_cast<int>(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<int>(0, std::min<int>(state->hp_change_map_val, actor->GetHp() - 1)));
Expand All @@ -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);
Expand Down
25 changes: 19 additions & 6 deletions src/game_party.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -334,10 +339,6 @@ class Game_Party : public Game_Party_Base {
private:
const RPG::SaveInventory& data() const;
RPG::SaveInventory& data();

private:
std::vector<int> state_steps_hp;
std::vector<int> state_steps_sp;
};

// ------ INLINES --------
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit c71d914

Please sign in to comment.