Codechange: Template script command calls.

This commit is contained in:
Michael Lutz
2021-11-01 21:30:34 +01:00
parent eab18f06a4
commit 6691ee3b96
30 changed files with 310 additions and 185 deletions

View File

@@ -19,6 +19,7 @@
#include "../../goal_base.h"
#include "../../string_func.h"
#include "../../tile_map.h"
#include "../../story_cmd.h"
#include "../../safeguards.h"
@@ -47,12 +48,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
if (!ScriptObject::DoCommand(0,
if (!ScriptObject::Command<CMD_CREATE_STORY_PAGE>::Do(&ScriptInstance::DoCommandReturnStoryPageID,
0,
c,
0,
CMD_CREATE_STORY_PAGE,
title != nullptr? title->GetEncodedText() : nullptr,
&ScriptInstance::DoCommandReturnStoryPageID)) return STORY_PAGE_INVALID;
title != nullptr ? std::string{ title->GetEncodedText() } : std::string{})) return STORY_PAGE_INVALID;
/* In case of test-mode, we return StoryPageID 0 */
return (ScriptStoryPage::StoryPageID)0;
@@ -89,12 +89,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
NOT_REACHED();
}
if (!ScriptObject::DoCommand(reftile,
if (!ScriptObject::Command<CMD_CREATE_STORY_PAGE_ELEMENT>::Do(&ScriptInstance::DoCommandReturnStoryPageElementID,
reftile,
story_page_id + (type << 16),
refid,
CMD_CREATE_STORY_PAGE_ELEMENT,
StoryPageElementTypeRequiresText(btype) ? text->GetEncodedText() : nullptr,
&ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID;
StoryPageElementTypeRequiresText(btype) ? std::string{ text->GetEncodedText() } : std::string{})) return STORY_PAGE_ELEMENT_INVALID;
/* In case of test-mode, we return StoryPageElementID 0 */
return (ScriptStoryPage::StoryPageElementID)0;
@@ -134,11 +133,10 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
NOT_REACHED();
}
return ScriptObject::DoCommand(reftile,
return ScriptObject::Command<CMD_UPDATE_STORY_PAGE_ELEMENT>::Do(reftile,
story_page_element_id,
refid,
CMD_UPDATE_STORY_PAGE_ELEMENT,
StoryPageElementTypeRequiresText(type) ? text->GetEncodedText() : nullptr);
StoryPageElementTypeRequiresText(type) ? std::string{ text->GetEncodedText() } : std::string{});
}
/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
@@ -162,7 +160,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr? title->GetEncodedText() : nullptr);
return ScriptObject::Command<CMD_SET_STORY_PAGE_TITLE>::Do(0, story_page_id, 0, title != nullptr ? std::string{ title->GetEncodedText() } : std::string{});
}
/* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id)
@@ -188,7 +186,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, nullptr);
return ScriptObject::Command<CMD_SET_STORY_PAGE_DATE>::Do(0, story_page_id, date, {});
}
@@ -197,7 +195,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SHOW_STORY_PAGE);
return ScriptObject::Command<CMD_SHOW_STORY_PAGE>::Do(0, story_page_id, 0, {});
}
/* static */ bool ScriptStoryPage::Remove(StoryPageID story_page_id)
@@ -205,7 +203,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_REMOVE_STORY_PAGE);
return ScriptObject::Command<CMD_REMOVE_STORY_PAGE>::Do(0, story_page_id, 0, {});
}
/* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id)
@@ -213,7 +211,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
return ScriptObject::DoCommand(0, story_page_element_id, 0, CMD_REMOVE_STORY_PAGE_ELEMENT);
return ScriptObject::Command<CMD_REMOVE_STORY_PAGE_ELEMENT>::Do(0, story_page_element_id, 0, {});
}
/* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakePushButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags)