|
68 | 68 | #include "baseui.h"
|
69 | 69 | #include "algo.h"
|
70 | 70 | #include "rand.h"
|
| 71 | +#include <variant> |
71 | 72 |
|
72 | 73 | enum BranchSubcommand {
|
73 | 74 | eOptionBranchElse = 1
|
@@ -826,6 +827,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
|
826 | 827 | return CommandManiacControlStrings(com);
|
827 | 828 | case Cmd::Maniac_CallCommand:
|
828 | 829 | return CommandManiacCallCommand(com);
|
| 830 | + case static_cast <Game_Interpreter::Cmd>(2054) : // Easyrpg_GetIdByName |
| 831 | + return CommandGetIdByName(com); |
829 | 832 | default:
|
830 | 833 | return true;
|
831 | 834 | }
|
@@ -5107,6 +5110,49 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co
|
5107 | 5110 |
|
5108 | 5111 | return true;
|
5109 | 5112 | }
|
| 5113 | +bool Game_Interpreter::CommandGetVarByName(lcf::rpg::EventCommand const& com) { |
| 5114 | + auto& targetData = lcf::Data::variables; |
| 5115 | + |
| 5116 | + int stringVarParam = 6; // string var is detected at com.parameters[n] |
| 5117 | + const std::string targetName = ToString(CommandStringOrVariable(com, stringVarParam, stringVarParam + 1)); |
| 5118 | + if (targetName.empty()) { |
| 5119 | + Output::Warning("The variable name to search is empty."); |
| 5120 | + return true; |
| 5121 | + } |
| 5122 | + |
| 5123 | + const int outputVar = ValueOrVariable(com.parameters[0], com.parameters[1]); |
| 5124 | + if (outputVar <= 0) { |
| 5125 | + Output::Warning("This command requires a valid variable."); |
| 5126 | + return true; |
| 5127 | + } |
| 5128 | + |
| 5129 | + int rangeMin = ValueOrVariable(com.parameters[2], com.parameters[3]); |
| 5130 | + int rangeMax = ValueOrVariable(com.parameters[4], com.parameters[5]); |
| 5131 | + |
| 5132 | + if (rangeMin <= 0) rangeMin = 1; |
| 5133 | + if (rangeMin > static_cast<int>(targetData.size())) rangeMin = static_cast<int>(targetData.size()); |
| 5134 | + if (rangeMax <= 0 || rangeMax >= static_cast<int>(targetData.size())) rangeMax = static_cast<int>(targetData.size()); |
| 5135 | + |
| 5136 | + if (rangeMax < rangeMin) std::swap(rangeMin, rangeMax); |
| 5137 | + |
| 5138 | + auto it = std::find_if(targetData.begin() + rangeMin - 1, targetData.begin() + rangeMax, |
| 5139 | + [&](const auto& entry) { return entry.name == targetName; }); |
| 5140 | + |
| 5141 | + if (it != targetData.end()) { |
| 5142 | + const int id = std::distance(targetData.begin(), it) + 1; |
| 5143 | + |
| 5144 | + if (id >= rangeMin && id <= rangeMax) { |
| 5145 | + Output::Debug(" Variable \"{}\" found at ID: {}. Storing ID in variable {}.", targetName, id, outputVar); |
| 5146 | + |
| 5147 | + Main_Data::game_variables->Set(outputVar, id); |
| 5148 | + Game_Map::SetNeedRefresh(true); |
| 5149 | + return true; |
| 5150 | + } |
| 5151 | + } |
| 5152 | + |
| 5153 | + Output::Warning("Variable \"{}\" not found within the range of variables {} to {}.", targetName, rangeMin, rangeMax); |
| 5154 | + return true; |
| 5155 | +} |
5110 | 5156 |
|
5111 | 5157 | Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
|
5112 | 5158 | return Game_Battle::IsBattleRunning()
|
|
0 commit comments