| 24 | namespace State { |
| 25 | |
| 26 | bool Add(int state_id, StateVec& states, const PermanentStates& ps, bool allow_battle_states) { |
| 27 | const lcf::rpg::State* state = lcf::ReaderUtil::GetElement(lcf::Data::states, state_id); |
| 28 | if (!state) { |
| 29 | Output::Warning("State::Add: Can't add state with invalid ID {}", state_id); |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | if (!allow_battle_states && state->type == lcf::rpg::State::Persistence_ends) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | if (state_id > static_cast<int>(states.size())) { |
| 38 | states.resize(state_id); |
| 39 | } |
| 40 | |
| 41 | states[state_id - 1] = 1; |
| 42 | |
| 43 | // Clear states that are more than 10 priority points below the |
| 44 | // significant state |
| 45 | const lcf::rpg::State* sig_state = GetSignificantState(states); |
| 46 | |
| 47 | for (int i = 0; i < (int)states.size(); ++i) { |
| 48 | if (lcf::Data::states[i].priority <= sig_state->priority - 10 && !ps.Has(i + 1)) { |
| 49 | states[i] = 0; |
| 50 | } |
| 51 | if (states[i]) { |
| 52 | for (int j = 0; j < (int)lcf::Data::states[i].easyrpg_immune_states.size(); ++j) { |
| 53 | if (lcf::Data::states[i].easyrpg_immune_states[j] && !ps.Has(j + 1)) { |
| 54 | states[j] = 0; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return states[state_id - 1] != 0; |
| 61 | } |
| 62 | |
| 63 | bool Remove(int state_id, StateVec& states, const PermanentStates& ps) { |
| 64 | const lcf::rpg::State* state = lcf::ReaderUtil::GetElement(lcf::Data::states, state_id); |
no test coverage detected