diff --git a/src/command.cpp b/src/command.cpp index 34d97b8751..1718c65694 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -251,17 +251,17 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdWantEnginePreview, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_WANT_ENGINE_PREVIEW - DEF_CMD(CmdRenameVehicle, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE - DEF_CMD(CmdRenameEngine, CMD_STR_CTRL | CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE + DEF_CMD(CmdRenameVehicle, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_VEHICLE + DEF_CMD(CmdRenameEngine, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_ENGINE - DEF_CMD(CmdRenameCompany, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_COMPANY - DEF_CMD(CmdRenamePresident, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PRESIDENT + DEF_CMD(CmdRenameCompany, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_COMPANY + DEF_CMD(CmdRenamePresident, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PRESIDENT - DEF_CMD(CmdRenameStation, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION - DEF_CMD(CmdRenameDepot, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT + DEF_CMD(CmdRenameStation, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_STATION + DEF_CMD(CmdRenameDepot, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_DEPOT - DEF_CMD(CmdPlaceSign, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN - DEF_CMD(CmdRenameSign, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN + DEF_CMD(CmdPlaceSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_PLACE_SIGN + DEF_CMD(CmdRenameSign, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_SIGN DEF_CMD(CmdTurnRoadVeh, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_TURN_ROADVEH @@ -272,7 +272,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdBuyCompany, 0, CMDT_MONEY_MANAGEMENT ), // CMD_BUY_COMANY DEF_CMD(CmdFoundTown, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_FOUND_TOWN; founding random town can fail only in exec run - DEF_CMD(CmdRenameTown, CMD_STR_CTRL | CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN + DEF_CMD(CmdRenameTown, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN DEF_CMD(CmdDoTownAction, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DO_TOWN_ACTION DEF_CMD(CmdTownCargoGoal, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_CARGO_GOAL DEF_CMD(CmdTownGrowthRate, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_TOWN_GROWTH_RATE @@ -314,7 +314,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdDepotMassAutoReplace, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_DEPOT_MASS_AUTOREPLACE DEF_CMD(CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CREATE_GROUP DEF_CMD(CmdDeleteGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_DELETE_GROUP - DEF_CMD(CmdRenameGroup, CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_GROUP + DEF_CMD(CmdRenameGroup, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_GROUP DEF_CMD(CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_VEHICLE_GROUP DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 981ec2c31a..d46d717a0c 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -38,7 +38,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidBaseStation(station_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 8dea4c22e9..2f06fd69de 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -43,7 +43,7 @@ CCountedPtr counter(name); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -64,8 +64,9 @@ CCountedPtr counter(name); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, text); } diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index bd2ea3010a..01569d8241 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -53,7 +53,7 @@ EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 2852c4ae9e..f30159b398 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -265,6 +265,8 @@ ScriptObject::ActiveInstance::~ActiveInstance() return false; } + assert(StrEmpty(text) || (GetCommandFlags(cmd) & CMD_STR_CTRL) != 0 || StrValid(text, text + strlen(text))); + /* Set the default callback to return a true/false result of the DoCommand */ if (callback == NULL) callback = &ScriptInstance::DoCommandReturn; diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index 514dd4a21c..3373800b54 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -37,7 +37,7 @@ EnforcePrecondition(false, IsValidSign(sign_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -72,7 +72,7 @@ EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); EnforcePrecondition(INVALID_SIGN, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(INVALID_SIGN, text); EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp index 8507a176d0..577dd813e8 100644 --- a/src/script/api/script_text.cpp +++ b/src/script/api/script_text.cpp @@ -11,9 +11,12 @@ #include "../../stdafx.h" #include "../../string_func.h" +#include "../../strings_func.h" #include "script_text.hpp" #include "../../table/control_codes.h" +#include "table/strings.h" + ScriptText::ScriptText(HSQUIRRELVM vm) : ZeroedMemoryAllocator() { @@ -191,3 +194,14 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count) return p; } + +const char *Text::GetDecodedText() +{ + const char *encoded_text = this->GetEncodedText(); + if (encoded_text == NULL) return NULL; + + static char buf[1024]; + ::SetDParamStr(0, encoded_text); + ::GetString(buf, STR_JUST_RAW_STRING, lastof(buf)); + return buf; +} diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp index 6dd022bb76..9b75e21c52 100644 --- a/src/script/api/script_text.hpp +++ b/src/script/api/script_text.hpp @@ -27,6 +27,13 @@ public: * @api -all */ virtual const char *GetEncodedText() = 0; + + /** + * Convert a #ScriptText into a decoded normal string. + * @return A string (in a static buffer), or NULL. + * @api -all + */ + const char *GetDecodedText(); }; /** diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index fa4b9c0c77..cb8fb62d69 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -43,9 +43,10 @@ CCountedPtr counter(text); EnforcePrecondition(false, text != NULL); - const char *encoded_text = text->GetEncodedText(); + const char *encoded_text = text->GetDecodedText(); EnforcePreconditionEncodedText(false, encoded_text); EnforcePrecondition(false, IsValidTown(town_id)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(encoded_text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text); } diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 5bbcd543ac..d02b4e0510 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -219,7 +219,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id)); EnforcePrecondition(false, name != NULL); - const char *text = name->GetEncodedText(); + const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);