|
| 1 | +/* |
| 2 | + * This file is part of EasyRPG Player. |
| 3 | + * |
| 4 | + * EasyRPG Player is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * EasyRPG Player is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +// Headers |
| 19 | +#include "game_constants.h" |
| 20 | +#include "game_variables.h" |
| 21 | +#include "output.h" |
| 22 | +#include "player.h" |
| 23 | + |
| 24 | +std::array<Game_Variables::Var_t, 2> Game_Constants::GetVariableLimits() { |
| 25 | + Game_Variables::Var_t min_var = lcf::Data::system.easyrpg_variable_min_value; |
| 26 | + TryGetOverriddenConstant(ConstantType::MinVarLimit, min_var); |
| 27 | + if (min_var == 0) { |
| 28 | + if (!Player::IsPatchManiac() || Player::game_config.patch_maniac.Get() == 2) { |
| 29 | + min_var = Player::IsRPG2k3() ? Game_Variables::min_2k3 : Game_Variables::min_2k; |
| 30 | + } else { |
| 31 | + min_var = std::numeric_limits<Game_Variables::Var_t>::min(); |
| 32 | + } |
| 33 | + } |
| 34 | + Game_Variables::Var_t max_var = lcf::Data::system.easyrpg_variable_max_value; |
| 35 | + TryGetOverriddenConstant(ConstantType::MaxVarLimit, max_var); |
| 36 | + if (max_var == 0) { |
| 37 | + if (!Player::IsPatchManiac() || Player::game_config.patch_maniac.Get() == 2) { |
| 38 | + max_var = Player::IsRPG2k3() ? Game_Variables::max_2k3 : Game_Variables::max_2k; |
| 39 | + } else { |
| 40 | + max_var = std::numeric_limits<Game_Variables::Var_t>::max(); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return {min_var, max_var}; |
| 45 | +} |
| 46 | + |
| 47 | +int32_t Game_Constants::MaxActorHpValue() { |
| 48 | + auto val = lcf::Data::system.easyrpg_max_actor_hp; |
| 49 | + TryGetOverriddenConstant(ConstantType::MaxActorHP, val); |
| 50 | + if (val == -1) { |
| 51 | + return Player::IsRPG2k() ? 999 : 9'999; |
| 52 | + } |
| 53 | + return val; |
| 54 | +} |
| 55 | + |
| 56 | +int32_t Game_Constants::MaxActorSpValue() { |
| 57 | + auto val = lcf::Data::system.easyrpg_max_actor_sp; |
| 58 | + TryGetOverriddenConstant(ConstantType::MaxActorSP, val); |
| 59 | + if (val == -1) { |
| 60 | + return 999; |
| 61 | + } |
| 62 | + return val; |
| 63 | +} |
| 64 | + |
| 65 | +int32_t Game_Constants::MaxEnemyHpValue() { |
| 66 | + auto val = lcf::Data::system.easyrpg_max_enemy_hp; |
| 67 | + if (val == -1) { |
| 68 | + // Upper bound is an editor limit, not enforced by the engine |
| 69 | + return std::numeric_limits<int32_t>::max(); |
| 70 | + } |
| 71 | + return val; |
| 72 | +} |
| 73 | + |
| 74 | +int32_t Game_Constants::MaxEnemySpValue() { |
| 75 | + auto val = lcf::Data::system.easyrpg_max_enemy_sp; |
| 76 | + if (val == -1) { |
| 77 | + // Upper bound is an editor limit, not enforced by the engine |
| 78 | + return std::numeric_limits<int32_t>::max(); |
| 79 | + } |
| 80 | + return val; |
| 81 | +} |
| 82 | + |
| 83 | +int32_t Game_Constants::MaxStatBaseValue() { |
| 84 | + auto val = lcf::Data::system.easyrpg_max_stat_base_value; |
| 85 | + TryGetOverriddenConstant(ConstantType::MaxStatBaseValue, val); |
| 86 | + if (val == -1) { |
| 87 | + return 999; |
| 88 | + } |
| 89 | + return val; |
| 90 | +} |
| 91 | + |
| 92 | +int32_t Game_Constants::MaxStatBattleValue() { |
| 93 | + auto val = lcf::Data::system.easyrpg_max_stat_battle_value; |
| 94 | + TryGetOverriddenConstant(ConstantType::MaxStatBattleValue, val); |
| 95 | + if (val == -1) { |
| 96 | + return 9'999; |
| 97 | + } |
| 98 | + return val; |
| 99 | +} |
| 100 | + |
| 101 | +int32_t Game_Constants::MaxDamageValue() { |
| 102 | + auto val = lcf::Data::system.easyrpg_max_damage; |
| 103 | + TryGetOverriddenConstant(ConstantType::MaxDamageValue, val); |
| 104 | + if (val == -1) { |
| 105 | + return (Player::IsRPG2k() ? 999 : 9'999); |
| 106 | + } |
| 107 | + return val; |
| 108 | +} |
| 109 | + |
| 110 | +int32_t Game_Constants::MaxExpValue() { |
| 111 | + auto val = lcf::Data::system.easyrpg_max_exp; |
| 112 | + TryGetOverriddenConstant(ConstantType::MaxExpValue, val); |
| 113 | + if (val == -1) { |
| 114 | + return Player::IsRPG2k() ? 999'999 : 9'999'999; |
| 115 | + } |
| 116 | + return val; |
| 117 | +} |
| 118 | + |
| 119 | +int32_t Game_Constants::MaxLevel() { |
| 120 | + auto max_level = Player::IsRPG2k() ? max_level_2k : max_level_2k3; |
| 121 | + if (TryGetOverriddenConstant(ConstantType::MaxLevel, max_level)) { |
| 122 | + return max_level; |
| 123 | + } |
| 124 | + if (lcf::Data::system.easyrpg_max_level > -1) { |
| 125 | + max_level = lcf::Data::system.easyrpg_max_level; |
| 126 | + } |
| 127 | + return max_level; |
| 128 | +} |
| 129 | + |
| 130 | +int32_t Game_Constants::MaxGoldValue() { |
| 131 | + int32_t max_gold = 999'999; |
| 132 | + if (TryGetOverriddenConstant(ConstantType::MaxGoldValue, max_gold)) { |
| 133 | + return max_gold; |
| 134 | + } |
| 135 | + return max_gold; |
| 136 | +} |
| 137 | + |
| 138 | +int32_t Game_Constants::MaxItemCount() { |
| 139 | + int32_t max_item_count = (lcf::Data::system.easyrpg_max_item_count == -1 ? 99 : lcf::Data::system.easyrpg_max_item_count);; |
| 140 | + TryGetOverriddenConstant(ConstantType::MaxItemCount, max_item_count); |
| 141 | + return max_item_count; |
| 142 | +} |
| 143 | + |
| 144 | +int32_t Game_Constants::MaxSaveFiles() { |
| 145 | + int32_t max_savefiles = Utils::Clamp<int32_t>(lcf::Data::system.easyrpg_max_savefiles, 3, 99); |
| 146 | + TryGetOverriddenConstant(ConstantType::MaxSaveFiles, max_savefiles); |
| 147 | + return max_savefiles; |
| 148 | +} |
| 149 | + |
| 150 | +bool Game_Constants::TryGetOverriddenConstant(ConstantType const_type, int32_t& out_value) { |
| 151 | + auto it = constant_overrides.find(const_type); |
| 152 | + if (it != constant_overrides.end()) { |
| 153 | + out_value = (*it).second; |
| 154 | + } |
| 155 | + return it != constant_overrides.end(); |
| 156 | +} |
| 157 | + |
| 158 | +void Game_Constants::OverrideGameConstant(ConstantType const_type, int32_t value) { |
| 159 | + constant_overrides[const_type] = value; |
| 160 | +} |
| 161 | + |
| 162 | +void Game_Constants::PrintActiveOverrides() { |
| 163 | + std::vector<std::tuple<std::string, int32_t>> overridden_constants; |
| 164 | + |
| 165 | + auto it = kConstantType.begin(); |
| 166 | + int32_t value; |
| 167 | + while (it != kConstantType.end()) { |
| 168 | + auto const_type = static_cast<ConstantType>((*it).value); |
| 169 | + if (!TryGetOverriddenConstant(const_type, value)) { |
| 170 | + ++it; |
| 171 | + continue; |
| 172 | + } |
| 173 | + overridden_constants.push_back(std::make_tuple((*it).name, value)); |
| 174 | + ++it; |
| 175 | + } |
| 176 | + |
| 177 | + if (!overridden_constants.empty()) { |
| 178 | + std::string out = "Overridden Game Constants: "; |
| 179 | + bool first = true; |
| 180 | + for (const auto& p : overridden_constants) { |
| 181 | + if (!first) { |
| 182 | + out += ", "; |
| 183 | + } |
| 184 | + out += fmt::format("{}: {}", std::get<std::string>(p), std::get<int32_t>(p)); |
| 185 | + first = false; |
| 186 | + } |
| 187 | + Output::DebugStr(out); |
| 188 | + } |
| 189 | +} |
0 commit comments