diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 12a940e3355..f624ec344d2 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -3606,8 +3606,9 @@ bool Game_Interpreter::CommandConditionalBranch(lcf::rpg::EventCommand const& co int op = com.parameters[4] & 3; int ignoreCase = com.parameters[4] >> 8 & 1; - std::string str_l = static_cast(Main_Data::game_strings->GetWithMode(com.string, com.parameters[2], modes[0]+1)); - std::string str_r = static_cast(Main_Data::game_strings->GetWithMode(com.string, com.parameters[3], modes[1])); + std::string str_param = static_cast(com.string); + std::string str_l = Main_Data::game_strings->GetWithMode(str_param, com.parameters[2], modes[0]+1); + std::string str_r = Main_Data::game_strings->GetWithMode(str_param, com.parameters[3], modes[1]); result = ManiacCheckString(str_l, str_r, op, ignoreCase); } break; @@ -4730,6 +4731,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& (com.parameters[0] >> 16) & 15 }; + Game_Strings::Str_t str_param = static_cast(com.string); Game_Strings::Str_t result = ""; Game_Strings::Str_Params str_params = { string_id_0, @@ -4744,7 +4746,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& switch (fn) { case 0: //String - result = Main_Data::game_strings->GetWithMode(static_cast(com.string), args[0], modes[0]); + result = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); // min_size @@ -4754,79 +4756,23 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& args[0] = Main_Data::game_variables->GetWithMode(args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); - result = static_cast(std::to_string(args[0])); + result = std::to_string(args[0]); result = Main_Data::game_strings->PrependMin(result, args[1], '0'); break; case 3: //Database Names args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); - - switch (args[0]) - { - case 0: //.actor[a].name - if (args[2]) result = static_cast(Main_Data::game_actors->GetActor(args[1])->GetName()); - else result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::actors, args[1])->name); - break; - case 1: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::skills, args[1])->name); break; //.skill[a].name - case 2: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::items, args[1])->name); break; //.item[a].name - case 3: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::enemies, args[1])->name); break; //.enemy[a].name - case 4: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::troops, args[1])->name); break; //.troop[a].name - case 5: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::terrains, args[1])->name); break; //.terrain[a].name - case 6: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::attributes, args[1])->name); break; //.element[a].name - case 7: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::states, args[1])->name); break; //.state[a].name - case 8: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::animations, args[1])->name); break; //.anim[a].name - case 9: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::chipsets, args[1])->name); break; //.tileset[a].name - case 10: result = static_cast(Main_Data::game_switches->GetName(args[1])); break; //.s[a].name - case 11: result = static_cast(Main_Data::game_variables->GetName(args[1])); break; //.v[a].name - case 12: break; //.t[a].name -- not sure how to get this for now - case 13: //.cev[a].name - // assuming the vector of common events here is ordered by common event ID - if (Game_Map::GetCommonEvents().size() >= args[1]) { - result = (Game_Strings::Str_t)Game_Map::GetCommonEvents()[args[1]-1].GetName(); - } - break; - case 14: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::classes, args[1])->name); break; //.class[a].name - case 15: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::battleranimations, args[1])->name); break; //.anim2[a].name - case 16: result = static_cast(Game_Map::GetMapName(args[1])); break; //.map[a].name - case 17: result = static_cast(Game_Map::GetEvent(args[1])->GetName()); break; //.mev[a].name - case 18: //.member[a].name - if (args[2]) { - result = static_cast(Main_Data::game_party->GetActor(args[1])->GetName()); - } - else { - args[1] = Main_Data::game_party->GetActor(args[1])->GetId(); - result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::actors, args[1])->name); - } - break; - } + result = ManiacGetLcfDataName(args[0], args[1], (bool)args[2]); break; case 4: //Database Descriptions args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); - - switch (args[0]) - { - case 0: //.actor[a].desc - if (args[2]) result = static_cast(Main_Data::game_actors->GetActor(args[1])->GetTitle()); - else result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::actors, args[1])->title); - break; - case 1: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::skills, args[1])->description); break; //.skill[a].desc - case 2: result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::items, args[1])->description); break; //.item[a].desc - case 18: //.member[a].desc - if (args[2]) { - result = static_cast(Main_Data::game_party->GetActor(args[1])->GetTitle()); - } - else { - args[1] = Main_Data::game_party->GetActor(args[1])->GetId(); - result = static_cast(lcf::ReaderUtil::GetElement(lcf::Data::actors, args[1])->title); - } - break; - } + result = ManiacGetLcfDataDescription(args[0], args[1], (bool)args[2]); break; case 6: //Concatenate (cat) { int pos = 0; std::string op_string; for (int i = 0; i < 3; i++) { - op_string += static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[i], modes[i], &pos)); + op_string += Main_Data::game_strings->GetWithModeAndPos(str_param, args[i], modes[i], &pos); } result = (Game_Strings::Str_t)op_string; break; @@ -4837,8 +4783,8 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& std::string base, insert; args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); - base = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[0], modes[0], &pos)); - insert = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[2], modes[2], &pos)); + base = Main_Data::game_strings->GetWithModeAndPos(str_param, args[0], modes[0], &pos); + insert = Main_Data::game_strings->GetWithModeAndPos(str_param, args[2], modes[2], &pos); result = (Game_Strings::Str_t)base.insert(args[1], insert); break; @@ -4848,9 +4794,9 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& int pos = 0; std::string base, search, replacement; - base = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[0], modes[0], &pos)); - search = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[1], modes[1], &pos)); - replacement = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[2], modes[2], &pos)); + base = Main_Data::game_strings->GetWithModeAndPos(str_param, args[0], modes[0], &pos); + search = Main_Data::game_strings->GetWithModeAndPos(str_param, args[1], modes[1], &pos); + replacement = Main_Data::game_strings->GetWithModeAndPos(str_param, args[2], modes[2], &pos); std::size_t index = base.find(search); while (index != std::string::npos) { @@ -4864,12 +4810,12 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& case 9: //Substring (subs) args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); args[2] = Main_Data::game_variables->GetWithMode(args[2], modes[2]); - result = static_cast(static_cast(Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0])).substr(args[1], args[2])); + result = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]).substr(args[1], args[2]); break; case 10: //Join (join) { std::string op_string = ""; - std::string delimiter = (std::string)Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0]); + std::string delimiter = (std::string)Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); Output::Debug("args {} {} {}", args[0], args[1], args[2]); Output::Debug("modes {} {} {}", modes[0], modes[1], modes[2]); // args[1] & mode[1] relates to starting ID for strings to join @@ -4879,7 +4825,7 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& while (args[2] > 0) { if (modes[1] < 2) { - op_string += static_cast(Main_Data::game_strings->Get(args[1]++)); + op_string += Main_Data::game_strings->Get(args[1]++); } else { op_string += std::to_string(Main_Data::game_variables->Get(args[1]++)); } @@ -4887,20 +4833,20 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& if (--args[2] > 0) op_string += delimiter; } - result = static_cast(op_string); + result = op_string; break; } case 12: //File (file) { // maniacs does not like a file extension - Game_Strings::Str_t filename = Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0]); + Game_Strings::Str_t filename = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); // args[1] is the encoding... 0 for sjis, 1 for utf8 Filesystem_Stream::InputStream is = FileFinder::OpenText(StringView(filename)); if (is.good()) { std::stringstream buffer; buffer << is.rdbuf(); - result = static_cast(buffer.str()); + result = buffer.str(); } is.Close(); break; @@ -4908,21 +4854,21 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& case 13: //Remove (rem) args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); args[2] = Main_Data::game_variables->GetWithMode(args[2], modes[2]); - result = static_cast(static_cast(Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0])).erase(args[1], args[2])); + result = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]).erase(args[1], args[2]); break; case 14: //Replace Ex (exRep) , edge case: the arg "first" is at ((flags >> 19) & 1). Wtf BingShan { int pos = 0; std::string base, search, replacement; - base = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[0], modes[0], &pos)); - search = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[1], modes[1], &pos)); - replacement = static_cast(Main_Data::game_strings->GetWithModeAndPos(com.string, args[2], modes[2], &pos)); + base = Main_Data::game_strings->GetWithModeAndPos(str_param, args[0], modes[0], &pos); + search = Main_Data::game_strings->GetWithModeAndPos(str_param, args[1], modes[1], &pos); + replacement = Main_Data::game_strings->GetWithModeAndPos(str_param, args[2], modes[2], &pos); std::regex rexp(search); - if (first_flag) result = static_cast(std::regex_replace(base, rexp, replacement, std::regex_constants::format_first_only)); - else result = static_cast(std::regex_replace(base, rexp, replacement)); + if (first_flag) result = std::regex_replace(base, rexp, replacement, std::regex_constants::format_first_only); + else result = std::regex_replace(base, rexp, replacement); break; } default: @@ -4945,27 +4891,27 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& break; case 4: //inStr takes hex?????? { - Game_Strings::Str_t search = Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0]); + Game_Strings::Str_t search = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); // not sure this is necessary but better safe args[2] = Main_Data::game_variables->GetWithMode(args[2], modes[2]); if (is_range) Main_Data::game_strings->RangeOp(str_params, string_id_1, search, op, args); - else Main_Data::game_strings->InStr(str_params, static_cast(search), args[1], args[2]); + else Main_Data::game_strings->InStr(str_params, search, args[1], args[2]); break; } case 5: //split takes hex { - Game_Strings::Str_t delimiter = Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0]); + Game_Strings::Str_t delimiter = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); args[2] = Main_Data::game_variables->GetWithMode(args[2], modes[2]); if (is_range) Main_Data::game_strings->RangeOp(str_params, string_id_1, delimiter, op, args); - else Main_Data::game_strings->Split(str_params, static_cast(delimiter), args[1], args[2]); + else Main_Data::game_strings->Split(str_params, delimiter, args[1], args[2]); break; } case 7: //toFile takes hex { - std::string filename = static_cast(Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0])); + std::string filename = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); Main_Data::game_strings->ToFile(str_params, filename, args[1]); @@ -4985,12 +4931,12 @@ bool Game_Interpreter::CommandManiacControlStrings(lcf::rpg::EventCommand const& case 10: //exMatch , edge case: the only command that generates 8 parameters instead of 7 { // takes hex - std::string expr = static_cast(Main_Data::game_strings->GetWithMode(com.string, args[0], modes[0])); + std::string expr = Main_Data::game_strings->GetWithMode(str_param, args[0], modes[0]); args[1] = Main_Data::game_variables->GetWithMode(args[1], modes[1]); // output var args[2] = Main_Data::game_variables->GetWithMode(args[2], modes[2]); // beginning pos if (is_range) { - Main_Data::game_strings->RangeOp(str_params, string_id_1, static_cast(expr), op, args); + Main_Data::game_strings->RangeOp(str_params, string_id_1, expr, op, args); } else { if (op == 9) Main_Data::game_strings->ExMatch(str_params, expr, args[1], args[2]); @@ -5080,3 +5026,135 @@ bool Game_Interpreter::ManiacCheckString(std::string str_l, std::string str_r, i return false; } } + +Game_Strings::Str_t Game_Interpreter::ManiacGetLcfDataName(int data_type, int id, bool is_dynamic) const { + switch (data_type) + { + case 0: //.actor[a].name + if (is_dynamic) { + auto actor = Main_Data::game_actors->GetActor(id); + if (actor != nullptr) { + return static_cast(actor->GetName()); + } + } else { + return Game_Interpreter::ManiacGetNameSafely(lcf::Data::actors, id); + } + break; + case 1: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::skills, id); //.skill[a].name + case 2: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::items, id); //.item[a].name + case 3: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::enemies, id); //.enemy[a].name + case 4: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::troops, id); //.troop[a].name + case 5: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::terrains, id); //.terrain[a].name + case 6: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::attributes, id); //.element[a].name + case 7: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::states, id); //.state[a].name + case 8: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::animations, id); //.anim[a].name + case 9: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::chipsets, id); //.tileset[a].name + case 10: return static_cast(Main_Data::game_switches->GetName(id)); //.s[a].name + case 11: return static_cast(Main_Data::game_variables->GetName(id)); //.v[a].name + case 12: break; //.t[a].name -- not sure how to get this for now + case 13: //.cev[a].name + { + // assuming the vector of common events here is ordered by common event ID + if (Game_Map::GetCommonEvents().size() >= id) { + return (Game_Strings::Str_t)Game_Map::GetCommonEvents()[id - 1].GetName(); + } + break; + } + case 14: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::classes, id); //.class[a].name + case 15: return Game_Interpreter::ManiacGetNameSafely(lcf::Data::battleranimations, id); //.anim2[a].name + case 16: return static_cast(Game_Map::GetMapName(id)); //.map[a].name + case 17: //.mev[a].name + { + auto map = Game_Map::GetEvent(id); + if (map != nullptr) { + return static_cast(map->GetName()); + } + break; + } + case 18: //.member[a].name + { + auto actor = Main_Data::game_party->GetActor(id); + if (actor != nullptr) { + if (is_dynamic) { + return static_cast(actor->GetName()); + } + else { + id = actor->GetId(); + return Game_Interpreter::ManiacGetNameSafely(lcf::Data::actors, id); + } + } + break; + } + } + + Output::Warning("Unable to read name: {} {}", data_type, id); + return ""; +} + +Game_Strings::Str_t Game_Interpreter::ManiacGetLcfDataDescription(int data_type, int id, bool is_dynamic) const { + switch (data_type) + { + case 0: //.actor[a].desc + if (is_dynamic) { + auto actor = Main_Data::game_actors->GetActor(id); + if (actor != nullptr) { + return static_cast(actor->GetTitle()); + } + } else { + return Game_Interpreter::ManiacGetDescriptionSafely(lcf::Data::actors, id); + } + break; + case 1: return Game_Interpreter::ManiacGetDescriptionSafely(lcf::Data::skills, id); //.skill[a].desc + case 2: return Game_Interpreter::ManiacGetDescriptionSafely(lcf::Data::items, id); //.item[a].desc + case 18: //.member[a].desc + { + auto actor = Main_Data::game_party->GetActor(id); + if (actor != nullptr) { + if (is_dynamic) { + return static_cast(actor->GetTitle()); + } + else { + id = actor->GetId(); + return Game_Interpreter::ManiacGetDescriptionSafely(lcf::Data::actors, id); + } + } + break; + } + } + + Output::Warning("Unable to read description: {} {}", data_type, id); + return ""; +} + +template +Game_Strings::Str_t Game_Interpreter::ManiacGetNameSafely(std::vector vec, int id) const { + T* data = lcf::ReaderUtil::GetElement(vec, id); + if (data != nullptr) { + return static_cast(data->name); + } + + Output::Warning("Unable to read name: {}", id); + return ""; +} + +template +Game_Strings::Str_t Game_Interpreter::ManiacGetDescriptionSafely(std::vector vec, int id) const { + T* data = lcf::ReaderUtil::GetElement(vec, id); + if (data != nullptr) { + return static_cast(data->description); + } + + Output::Warning("Unable to read description: {}", id); + return ""; +} + +template <> +Game_Strings::Str_t Game_Interpreter::ManiacGetDescriptionSafely(std::vector vec, int id) const { + lcf::rpg::Actor* data = lcf::ReaderUtil::GetElement(vec, id); + if (data != nullptr) { + return static_cast(data->title); + } + + Output::Warning("Unable to read description: {}", id); + return ""; +} diff --git a/src/game_interpreter.h b/src/game_interpreter.h index e561dea1366..1c5754489a4 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -335,6 +335,15 @@ class Game_Interpreter lcf::rpg::SaveEventExecState _state; KeyInputState _keyinput; AsyncOp _async_op = {}; + + std::string ManiacGetLcfDataName(int data_type, int id, bool is_dynamic) const; + std::string ManiacGetLcfDataDescription(int data_type, int id, bool is_dynamic) const; + +private: + template std::string ManiacGetNameSafely(std::vector, int id) const; + template std::string ManiacGetDescriptionSafely(std::vector, int id) const; + template<> std::string ManiacGetDescriptionSafely(std::vector, int id) const; + }; inline const lcf::rpg::SaveEventExecFrame* Game_Interpreter::GetFramePtr() const { diff --git a/src/game_strings.cpp b/src/game_strings.cpp index 0e3bc7715dd..8102d37e49d 100644 --- a/src/game_strings.cpp +++ b/src/game_strings.cpp @@ -37,15 +37,15 @@ Game_Strings::Str_t Game_Strings::Cat(Str_Params params, Str_t string) { if (!ResizeWithId(params.string_id)) return ""; Str_t s = Get(params.string_id); - std::string op_string = static_cast(s); - op_string.append(static_cast(string)); - Set(params, static_cast(op_string)); + std::string op_string = s; + op_string.append(string); + Set(params, op_string); return s; } int Game_Strings::ToNum(Str_Params params, int var_id) { if (!ResizeWithId(params.string_id)) return -1; - std::string str = static_cast(Get(params.string_id)); + std::string str = Get(params.string_id); int num; if (params.hex) @@ -60,7 +60,7 @@ int Game_Strings::ToNum(Str_Params params, int var_id) { int Game_Strings::GetLen(Str_Params params, int var_id) { if (!ResizeWithId(params.string_id)) return -1; - int len = static_cast(Get(params.string_id)).length(); + int len = Get(params.string_id).length(); Main_Data::game_variables->Set(var_id, len); return len; } @@ -69,14 +69,14 @@ int Game_Strings::InStr(Str_Params params, std::string search, int var_id, int b if (!ResizeWithId(params.string_id)) return -1; if (params.extract) { - search = static_cast(Extract(static_cast(search), params.hex)); + search = Extract(search, params.hex); } - std::string str = static_cast(Get(params.string_id)); + std::string str = Get(params.string_id); Output::Debug("Searching for {} in {}", search, str); - int index = static_cast(Get(params.string_id)).find(search, begin); + int index = Get(params.string_id).find(search, begin); Main_Data::game_variables->Set(var_id, index); return index; } @@ -89,29 +89,29 @@ int Game_Strings::Split(Str_Params params, std::string delimiter, int string_out // always returns at least 1 int splits = 1; - std::string str = static_cast(Get(params.string_id)); + std::string str = Get(params.string_id); params.string_id = string_out_id; for (index = str.find(delimiter); index != std::string::npos; index = str.find(delimiter)) { token = str.substr(0, index); - Set(params, static_cast(token)); + Set(params, token); params.string_id++; splits++; str.erase(0, index + delimiter.length()); } // set the remaining string - Set(params, static_cast(str)); + Set(params, str); Main_Data::game_variables->Set(var_id, splits); return splits; } Game_Strings::Str_t Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) { - std::string str = static_cast(Get(params.string_id)); + std::string str = Get(params.string_id); if (params.extract) { - filename = static_cast(Extract(static_cast(filename), params.hex)); + filename = Extract(filename, params.hex); } // this sucks but it is what maniacs does @@ -127,7 +127,7 @@ Game_Strings::Str_t Game_Strings::ToFile(Str_Params params, std::string filename txt_out << str; txt_out.Close(); - return static_cast(str); + return str; } Game_Strings::Str_t Game_Strings::PopLine(Str_Params params, int offset, int string_out_id) { @@ -135,7 +135,7 @@ Game_Strings::Str_t Game_Strings::PopLine(Str_Params params, int offset, int str int index; std::string result; - std::string str = static_cast(Get(params.string_id)); + std::string str = Get(params.string_id); std::stringstream ss(str); @@ -143,9 +143,9 @@ Game_Strings::Str_t Game_Strings::PopLine(Str_Params params, int offset, int str offset = ss.rdbuf()->in_avail(); - Set(params, static_cast(ss.str().substr(str.length() - offset))); + Set(params, ss.str().substr(str.length() - offset)); params.string_id = string_out_id; - return Set(params, static_cast(result)); + return Set(params, result); } Game_Strings::Str_t Game_Strings::ExMatch(Str_Params params, std::string expr, int var_id, int begin, int string_out_id) { @@ -154,10 +154,10 @@ Game_Strings::Str_t Game_Strings::ExMatch(Str_Params params, std::string expr, i std::smatch match; if (params.extract) { - expr = static_cast(Extract(static_cast(expr), params.hex)); + expr = Extract(expr, params.hex); } - std::string base = static_cast(Get(params.string_id)).erase(0, begin); + std::string base = Get(params.string_id).erase(0, begin); std::regex r(expr); std::regex_search(base, match, r); @@ -165,7 +165,7 @@ Game_Strings::Str_t Game_Strings::ExMatch(Str_Params params, std::string expr, i var_result = match.position() + begin; Main_Data::game_variables->Set(var_id, var_result); - str_result = static_cast(match.str()); + str_result = match.str(); if (string_out_id > 0) { params.string_id = string_out_id; Set(params, str_result); @@ -203,11 +203,11 @@ const Game_Strings::Strings_t& Game_Strings::RangeOp(Str_Params params, int stri case 1: Cat(params, string); break; case 2: ToNum(params, args[0] + (params.string_id - start)); break; case 3: GetLen(params, args[0] + (params.string_id - start)); break; - case 4: InStr(params, static_cast(string), args[1], args[2]); break; - case 5: params.string_id += Split(params, static_cast(string), args[1], args[2]); break; + case 4: InStr(params, string, args[1], args[2]); break; + case 5: params.string_id += Split(params, string, args[1], args[2]); break; case 8: break; // range case not applicable for popLine; see case in game_interpreter.cpp - case 9: ExMatch(params, static_cast(string), args[1] + (params.string_id - start), args[2]); break; - case 10: ExMatch(params, static_cast(string), args[1] + (params.string_id - start), args[2], args[3]); break; + case 9: ExMatch(params, string, args[1] + (params.string_id - start), args[2]); break; + case 10: ExMatch(params, string, args[1] + (params.string_id - start), args[2], args[3]); break; } } return GetData(); @@ -217,7 +217,7 @@ Game_Strings::Str_t Game_Strings::PrependMin(Str_t string, int min_size, char c) if (string.size() < min_size) { int s = min_size - string.size(); std::string res = std::string(s, c) + (std::string)string; - return (Str_t)res; + return res; } return string; } diff --git a/src/game_strings.h b/src/game_strings.h index 98636a0d310..ba779537260 100644 --- a/src/game_strings.h +++ b/src/game_strings.h @@ -32,7 +32,7 @@ */ class Game_Strings { public: - using Str_t = lcf::DBString; + using Str_t = std::string; using Strings_t = std::vector; static constexpr int max_warnings = 10; @@ -44,7 +44,9 @@ class Game_Strings { Game_Strings(); void SetData(Strings_t s); + void SetData(std::vector s); const Strings_t& GetData() const; + std::vector GetLcfData(); Str_t Get(int id) const; Str_t GetIndirect(int id) const; @@ -92,10 +94,18 @@ inline void Game_Strings::SetData(Strings_t s) { _strings = std::move(s); } +inline void Game_Strings::SetData(std::vector s) { + _strings = std::vector(s.begin(), s.end()); +} + inline const Game_Strings::Strings_t& Game_Strings::GetData() const { return _strings; } +inline std::vector Game_Strings::GetLcfData() { + return std::vector(_strings.begin(), _strings.end()); +} + inline bool Game_Strings::ShouldWarn(int id) const { return id <= 0 && _warnings > 0; } @@ -144,7 +154,7 @@ inline Game_Strings::Str_t Game_Strings::GetWithModeAndPos(Str_t str_data, int a Str_t ret; switch (mode) { case 0: - ret = static_cast(static_cast(str_data).substr(*pos, arg)); + ret = str_data.substr(*pos, arg); *pos += arg; break; case 1: // direct string reference @@ -158,5 +168,5 @@ inline Game_Strings::Str_t Game_Strings::GetWithModeAndPos(Str_t str_data, int a } inline Game_Strings::Str_t Game_Strings::Extract(Str_t string, bool as_hex) { - return static_cast(PendingMessage::ApplyTextInsertingCommands(static_cast(string), Player::escape_char, true, as_hex)); + return PendingMessage::ApplyTextInsertingCommands(string, Player::escape_char, true, as_hex); } diff --git a/src/game_windows.cpp b/src/game_windows.cpp index b30cc8931e8..bf4f7cabd7d 100644 --- a/src/game_windows.cpp +++ b/src/game_windows.cpp @@ -204,7 +204,7 @@ void Game_Windows::Window_User::Refresh(bool& async_wait) { fonts.emplace_back(font); - std::string extracted_text = ToString(Main_Data::game_strings->Extract(text.text, false)); + std::string extracted_text = Main_Data::game_strings->Extract(ToString(text.text), false); std::stringstream ss(extracted_text); std::string out; PendingMessage pm; diff --git a/src/scene_save.cpp b/src/scene_save.cpp index 7a1e5eae91a..c9ee59c4b4d 100644 --- a/src/scene_save.cpp +++ b/src/scene_save.cpp @@ -138,7 +138,7 @@ bool Scene_Save::Save(std::ostream& os, int slot_id, bool prepare_save) { save.system = Main_Data::game_system->GetSaveData(); save.system.switches = Main_Data::game_switches->GetData(); save.system.variables = Main_Data::game_variables->GetData(); - save.system.maniac_strings = Main_Data::game_strings->GetData(); + save.system.maniac_strings = Main_Data::game_strings->GetLcfData(); save.inventory = Main_Data::game_party->GetSaveData(); save.actors = Main_Data::game_actors->GetSaveData(); save.screen = Main_Data::game_screen->GetSaveData();