mirror of https://github.com/OpenTTD/OpenTTD
Change: [Script] Allow EnforcePreconditionCustomError to set an additional extra error code parameter
parent
ebe5c114dd
commit
f8ab1bdb87
|
@ -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<CMD_RENAME_STATION>::Do(station_id, text);
|
||||
|
|
|
@ -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<CMD_RENAME_COMPANY>::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<CMD_RENAME_PRESIDENT>::Do(text);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<CMD_ALTER_GROUP>::Do(AlterGroupMode::Rename, group_id, 0, text);
|
||||
}
|
||||
|
|
|
@ -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<CMD_RENAME_SIGN>::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<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return INVALID_SIGN;
|
||||
|
||||
|
|
|
@ -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<CMD_RENAME_TOWN>::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)) {
|
||||
|
|
|
@ -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<CMD_BUILD_VEHICLE>::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<CMD_RENAME_VEHICLE>::Do(vehicle_id, text);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue