Add: precondition checks to functions that work with both valid company and deity

These are functions that either use ScriptObject::Command or ScriptObject::GetCompany.
This is a bit over-protective, but having the check everywhere makes it easier to
validate that no check is missing automatically instead of by review.

At this moment these checks will not do anything useful, as either IsValid or
IsDeity from ScriptCompanyMode returns true, but that will change later.
This commit is contained in:
Rubidium
2023-03-02 21:22:37 +01:00
committed by rubidium42
parent 2fffde0891
commit 534f2419ad
27 changed files with 65 additions and 1 deletions

View File

@@ -62,6 +62,23 @@
#define EnforceDeityMode(returnval) \
EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsDeity(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY)
/**
* 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)
/**
* Helper to enforce the precondition that the company mode is valid or that we are a deity.
*/
#define EnforceDeityOrCompanyModeValid_Void() \
if (!(ScriptCompanyMode::IsDeity() || ScriptCompanyMode::IsValid())) { \
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_INVALID_COMPANY); \
return; \
}
/**
* Class that handles all error related functions.
* @api ai game