diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 7aff814c6a..3627be6811 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -44,7 +44,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); if (::Station::IsValidID(station_id)) { return ScriptObject::Command::Do(station_id, text); diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 340b31918b..50d418769b 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -52,7 +52,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); return ScriptObject::Command::Do(text); } @@ -74,7 +74,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); return ScriptObject::Command::Do(text); } diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index 11e046b32f..b98e863824 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -30,11 +30,12 @@ * @param returnval The value to return on failure. * @param condition The condition that must be obeyed. * @param error_code The error code passed to ScriptObject::SetLastError. + * @param extra_error_code The extra error code passed to ScriptObject::SetExtraLastError. */ -#define EnforcePreconditionCustomError(returnval, condition, error_code) \ +#define EnforcePreconditionCustomError(returnval, condition, error_code, extra_error_code) \ if (!(condition)) { \ ScriptObject::SetLastError(error_code); \ - ScriptObject::SetExtraLastError(ScriptError::ERR_UNKNOWN); \ + ScriptObject::SetExtraLastError(extra_error_code); \ return returnval; \ } @@ -55,7 +56,7 @@ * @param returnval The value to return on failure. */ #define EnforceCompanyModeValid(returnval) \ - EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY) + EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY, ScriptError::ERR_UNKNOWN) /** * Helper to enforce the precondition that the company mode is valid. @@ -72,14 +73,14 @@ * @param returnval The value to return on failure. */ #define EnforceDeityMode(returnval) \ - EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY) + EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY, ScriptError::ERR_UNKNOWN) /** * Helper to enforce the precondition that the company mode is valid or that we are a deity. * @param returnval The value to return on failure. */ #define EnforceDeityOrCompanyModeValid(returnval) \ - EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity() || ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY) + EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity() || ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY, ScriptError::ERR_UNKNOWN) /** * Helper to enforce the precondition that the company mode is valid or that we are a deity. diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index f75b41a30e..729c468881 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -63,7 +63,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); return ScriptObject::Command::Do(AlterGroupMode::Rename, group_id, 0, text); } diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index 19fcd04abb..6d7f333d2c 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -42,7 +42,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); return ScriptObject::Command::Do(sign_id, text); } @@ -79,7 +79,7 @@ EnforcePrecondition(INVALID_SIGN, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(INVALID_SIGN, text); - EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return INVALID_SIGN; diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index d8c286932f..9084b91009 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -49,7 +49,7 @@ std::string text; if (name != nullptr) { text = name->GetDecodedText(); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); } return ScriptObject::Command::Do(town_id, text); @@ -300,7 +300,7 @@ std::string text; if (name != nullptr) { text = name->GetDecodedText(); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); } uint32_t townnameparts; if (!GenerateTownName(ScriptObject::GetRandomizer(), &townnameparts)) { diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index c73ddee05c..7a885af41b 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -79,7 +79,7 @@ ::VehicleType type = ::Engine::Get(engine_id)->type; - EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED); + EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED, ScriptError::ERR_UNKNOWN); if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, engine_id, true, cargo, INVALID_CLIENT_ID)) return VEHICLE_INVALID; @@ -254,7 +254,7 @@ EnforcePrecondition(false, name != nullptr); const std::string &text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG, ScriptError::ERR_UNKNOWN); return ScriptObject::Command::Do(vehicle_id, text); }