1
0
Fork 0

Add: GSCompanyMode::IsValid and IsDeity, and precondition enforcement helpers

pull/10552/head
Rubidium 2023-03-02 19:44:13 +01:00 committed by rubidium42
parent 665a73b3c7
commit cada2ca310
4 changed files with 43 additions and 0 deletions

View File

@ -18,6 +18,8 @@
* This version is not yet released. The following changes are not set in stone yet.
*
* API additions:
* \li GSCompanyMode::IsValid
* \li GSCompanyMode::IsDeity
* \li GSTown::ROAD_LAYOUT_RANDOM
* \li GSVehicle::IsPrimaryVehicle
*

View File

@ -26,3 +26,13 @@ ScriptCompanyMode::~ScriptCompanyMode()
{
ScriptObject::SetCompany(this->last_company);
}
/* static */ bool ScriptCompanyMode::IsValid()
{
return ScriptObject::GetCompany() != OWNER_DEITY;
}
/* static */ bool ScriptCompanyMode::IsDeity()
{
return ScriptObject::GetCompany() == OWNER_DEITY;
}

View File

@ -47,6 +47,22 @@ public:
* in when the instance was created.
*/
~ScriptCompanyMode();
/**
* Check whether a company mode is valid. In other words, are commands
* being executed under some company.
* @return true When a company mode is valid.
* @post !ScriptCompanyMode::IsDeity().
*/
static bool IsValid();
/**
* Check whether the company mode is not active, i.e. whether we are a deity.
* In other words, are commands are not being executed under some company.
* @return true When we are a deity, i.e. company mode is not active.
* @post !ScriptCompanyMode::IsValid().
*/
static bool IsDeity();
};
#endif /* SCRIPT_COMPANYMODE_HPP */

View File

@ -11,6 +11,7 @@
#define SCRIPT_ERROR_HPP
#include "script_object.hpp"
#include "script_companymode.hpp"
#include <map>
/**
@ -47,6 +48,20 @@
return returnval; \
}
/**
* Helper to enforce the precondition that the company mode is valid.
* @param returnval The value to return on failure.
*/
#define EnforceCompanyModeValid(returnval) \
EnforcePrecondition(returnval, ScriptCompanyMode::IsValid())
/**
* Helper to enforce the precondition that we are in a deity mode.
* @param returnval The value to return on failure.
*/
#define EnforceDeityMode(returnval) \
EnforcePrecondition(returnval, ScriptCompanyMode::IsDeity())
/**
* Class that handles all error related functions.
* @api ai game