Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment SaveInventory::steps and fix state damage algo #1472

Merged
merged 3 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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