@@ -5110,47 +5110,148 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co
5110
5110
5111
5111
return true ;
5112
5112
}
5113
- bool Game_Interpreter::CommandGetVarByName (lcf::rpg::EventCommand const & com) {
5114
- auto & targetData = lcf::Data::variables ;
5113
+ bool Game_Interpreter::CommandGetIdByName (lcf::rpg::EventCommand const & com) {
5114
+ const int dataType = ValueOrVariable (com. parameters [ 0 ], com. parameters [ 1 ]) ;
5115
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 ]);
5116
+ const int outputVar = ValueOrVariable (com.parameters [2 ], com.parameters [3 ]);
5124
5117
if (outputVar <= 0 ) {
5125
5118
Output::Warning (" This command requires a valid variable." );
5126
5119
return true ;
5127
5120
}
5128
5121
5129
- int rangeMin = ValueOrVariable (com.parameters [2 ], com.parameters [3 ]);
5130
- int rangeMax = ValueOrVariable (com.parameters [4 ], com.parameters [5 ]);
5122
+ int rangeMin = ValueOrVariable (com.parameters [4 ], com.parameters [5 ]);
5123
+ int rangeMax = ValueOrVariable (com.parameters [6 ], com.parameters [7 ]);
5131
5124
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 ());
5125
+ const std::string targetName = ToString (CommandStringOrVariable (com, 8 , 9 ));
5126
+ if (targetName.empty ()) {
5127
+ Output::Warning (" The name to search is empty." );
5128
+ return true ;
5129
+ }
5135
5130
5136
- if (rangeMax < rangeMin) std::swap (rangeMin, rangeMax);
5131
+ auto GetName = [](const auto & obj) -> std::string {
5132
+ using T = std::decay_t <decltype (obj)>;
5137
5133
5138
- auto it = std::find_if (targetData.begin () + rangeMin - 1 , targetData.begin () + rangeMax,
5139
- [&](const auto & entry) { return entry.name == targetName; });
5134
+ if constexpr (std::is_same_v<T, Game_Event>) {
5135
+ return ToString (obj.GetName ());
5136
+ }
5137
+ else if constexpr (std::is_same_v<T, Game_Actor*>) {
5138
+ return ToString (obj->GetName ());
5139
+ }
5140
+ else {
5141
+ return ToString (obj.name );
5142
+ }
5143
+ };
5140
5144
5141
- if (it != targetData.end ()) {
5142
- const int id = std::distance (targetData.begin (), it) + 1 ;
5145
+ auto find_by_name = [&](const auto & vec) -> int {
5146
+ if (rangeMin <= 0 ) rangeMin = 1 ;
5147
+ if (rangeMin > static_cast <int >(vec.size ())) rangeMin = static_cast <int >(vec.size ());
5143
5148
5144
- if (id >= rangeMin && id <= rangeMax) {
5145
- Output::Debug ( " Variable \" {} \" found at ID: {}. Storing ID in variable {}. " , targetName, id, outputVar );
5149
+ if (rangeMax <= 0 || rangeMax >= static_cast < int >(vec. size ())) rangeMax = static_cast < int >(vec. size ());
5150
+ if (rangeMax < rangeMin) std::swap (rangeMin, rangeMax );
5146
5151
5147
- Main_Data::game_variables->Set (outputVar, id);
5148
- Game_Map::SetNeedRefresh (true );
5149
- return true ;
5152
+ for (int i = rangeMin - 1 ; i < rangeMax; ++i) {
5153
+ if (GetName (vec[i]) == targetName) {
5154
+ return i + 1 ;
5155
+ }
5150
5156
}
5157
+ return 0 ;
5158
+ };
5159
+
5160
+ std::string typeName = " Unknown" ;
5161
+ int id = 0 ;
5162
+ switch (dataType) {
5163
+ case 0 :
5164
+ typeName = " Actor" ;
5165
+ id = find_by_name (lcf::Data::actors);
5166
+ break ;
5167
+ case 1 :
5168
+ typeName = " Skill" ;
5169
+ id = find_by_name (lcf::Data::skills);
5170
+ break ;
5171
+ case 2 :
5172
+ typeName = " Item" ;
5173
+ id = find_by_name (lcf::Data::items);
5174
+ break ;
5175
+ case 3 :
5176
+ typeName = " Enemy" ;
5177
+ id = find_by_name (lcf::Data::enemies);
5178
+ break ;
5179
+ case 4 :
5180
+ typeName = " Troop" ;
5181
+ id = find_by_name (lcf::Data::troops);
5182
+ break ;
5183
+ case 5 :
5184
+ typeName = " Terrain" ;
5185
+ id = find_by_name (lcf::Data::terrains);
5186
+ break ;
5187
+ case 6 :
5188
+ typeName = " Attribute" ;
5189
+ id = find_by_name (lcf::Data::attributes);
5190
+ break ;
5191
+ case 7 :
5192
+ typeName = " State" ;
5193
+ id = find_by_name (lcf::Data::states);
5194
+ break ;
5195
+ case 8 :
5196
+ typeName = " Animation" ;
5197
+ id = find_by_name (lcf::Data::animations);
5198
+ break ;
5199
+ case 9 :
5200
+ typeName = " Tileset" ;
5201
+ id = find_by_name (lcf::Data::chipsets);
5202
+ break ;
5203
+ case 10 :
5204
+ typeName = " Switch" ;
5205
+ id = find_by_name (lcf::Data::switches);
5206
+ break ;
5207
+ case 11 :
5208
+ typeName = " Variable" ;
5209
+ id = find_by_name (lcf::Data::variables);
5210
+ break ;
5211
+ case 12 :
5212
+ typeName = " String Variable" ;
5213
+ Output::Warning (" {} names are not supported yet." , typeName); // FIXME: .t[a].name? - String variables don't support name yet
5214
+ return true ;
5215
+ // Main_Data::game_strings->GetLcfData();
5216
+ // break;
5217
+ case 13 :
5218
+ typeName = " Common Event" ;
5219
+ id = find_by_name (lcf::Data::commonevents);
5220
+ break ;
5221
+ case 14 :
5222
+ typeName = " Class" ;
5223
+ id = find_by_name (lcf::Data::classes);
5224
+ break ;
5225
+ case 15 :
5226
+ typeName = " Battler Animation" ;
5227
+ id = find_by_name (lcf::Data::battleranimations);
5228
+ break ;
5229
+ case 16 :
5230
+ typeName = " Map" ;
5231
+ id = find_by_name (lcf::Data::treemap.maps );
5232
+ break ;
5233
+ case 17 :
5234
+ typeName = " Map Event" ;
5235
+ id = find_by_name (Game_Map::GetEvents ());
5236
+ break ;
5237
+ case 18 :
5238
+ typeName = " Party Member" ;
5239
+ id = find_by_name (Main_Data::game_party.get ()->GetActors ());
5240
+ break ;
5241
+ default :
5242
+ Output::Warning (" Unsupported data type: {}({})" , typeName, dataType);
5243
+ return true ;
5244
+ }
5245
+
5246
+ if (id > 0 ) {
5247
+ Output::Debug (" {} \" {}\" found at ID: {}. Storing ID in variable {}." , typeName, targetName, id, outputVar);
5248
+ Main_Data::game_variables->Set (outputVar, id);
5249
+ Game_Map::SetNeedRefresh (true );
5250
+ }
5251
+ else {
5252
+ Output::Warning (" {} \" {}\" not found within the range {} to {}." , typeName, targetName, rangeMin, rangeMax);
5151
5253
}
5152
5254
5153
- Output::Warning (" Variable \" {}\" not found within the range of variables {} to {}." , targetName, rangeMin, rangeMax);
5154
5255
return true ;
5155
5256
}
5156
5257
0 commit comments