Codechange: use GSCompanyMode::IsValid, IsDeity, and the precondition helpers

Direct 1:1 replacements in the code, and comments now refer to either
GSCompanyMode::IsValid or GSCompanyMode::IsDeity instead of several variations
on "company mode active" or "no company mode active".
This commit is contained in:
Rubidium
2023-03-02 19:44:13 +01:00
committed by rubidium42
parent cada2ca310
commit 83946ca31d
46 changed files with 227 additions and 226 deletions

View File

@@ -42,7 +42,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
{
CCountedPtr<Text> counter(title);
EnforcePrecondition(STORY_PAGE_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(STORY_PAGE_INVALID);
EnforcePrecondition(STORY_PAGE_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
uint8 c = company;
@@ -61,7 +61,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
::StoryPageElementType btype = static_cast<::StoryPageElementType>(type);
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(STORY_PAGE_ELEMENT_INVALID);
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPage(story_page_id));
std::string encoded_text;
if (StoryPageElementTypeRequiresText(btype)) {
@@ -105,7 +105,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
{
CCountedPtr<Text> counter(text);
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
StoryPageElement *pe = StoryPageElement::Get(story_page_element_id);
@@ -162,7 +162,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
CCountedPtr<Text> counter(title);
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
return ScriptObject::Command<CMD_SET_STORY_PAGE_TITLE>::Do(story_page_id, title != nullptr ? title->GetEncodedText() : std::string{});
}
@@ -180,7 +180,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
/* static */ ScriptDate::Date ScriptStoryPage::GetDate(StoryPageID story_page_id)
{
EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id));
EnforcePrecondition(ScriptDate::DATE_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(ScriptDate::DATE_INVALID);
return (ScriptDate::Date)StoryPage::Get(story_page_id)->date;
}
@@ -188,7 +188,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
return ScriptObject::Command<CMD_SET_STORY_PAGE_DATE>::Do(story_page_id, date);
}
@@ -197,14 +197,14 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
/* static */ bool ScriptStoryPage::Show(StoryPageID story_page_id)
{
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
return ScriptObject::Command<CMD_SHOW_STORY_PAGE>::Do(story_page_id);
}
/* static */ bool ScriptStoryPage::Remove(StoryPageID story_page_id)
{
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
return ScriptObject::Command<CMD_REMOVE_STORY_PAGE>::Do(story_page_id);
@@ -212,7 +212,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
/* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id)
{
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforceDeityMode(false);
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
return ScriptObject::Command<CMD_REMOVE_STORY_PAGE_ELEMENT>::Do(story_page_element_id);