MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / NewElement

Method NewElement

src/script/api/script_story_page.cpp:62–107  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

60}
61
62/* static */ StoryPageElementID ScriptStoryPage::NewElement(StoryPageID story_page_id, StoryPageElementType type, SQInteger reference, Text *text)
63{
64 ScriptObjectRef counter(text);
65
66 ::StoryPageElementType btype = static_cast<::StoryPageElementType>(type);
67
68 EnforceDeityMode(STORY_PAGE_ELEMENT_INVALID);
69 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPage(story_page_id));
70 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPageElementType(type));
71 EncodedString encoded_text;
72 if (StoryPageElementTypeRequiresText(btype)) {
73 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, text != nullptr);
74 encoded_text = text->GetEncodedText();
75 EnforcePreconditionEncodedText(STORY_PAGE_ELEMENT_INVALID, encoded_text);
76 }
77 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile((::TileIndex)reference));
78 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference)));
79 EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid()));
80
81 uint32_t refid = 0;
82 TileIndex reftile{};
83 switch (type) {
84 case SPET_LOCATION:
85 reftile = TileIndex(reference);
86 break;
87 case SPET_GOAL:
88 case SPET_BUTTON_PUSH:
89 case SPET_BUTTON_TILE:
90 case SPET_BUTTON_VEHICLE:
91 refid = reference;
92 break;
93 case SPET_TEXT:
94 break;
95 default:
96 NOT_REACHED();
97 }
98
99 if (!ScriptObject::Command<CMD_CREATE_STORY_PAGE_ELEMENT>::Do(&ScriptInstance::DoCommandReturnStoryPageElementID,
100 reftile,
101 (::StoryPageID)story_page_id, (::StoryPageElementType)type,
102 refid,
103 encoded_text)) return STORY_PAGE_ELEMENT_INVALID;
104
105 /* In case of test-mode, we return StoryPageElementID 0 */
106 return StoryPageElementID::Begin();
107}
108
109/* static */ bool ScriptStoryPage::UpdateElement(StoryPageElementID story_page_element_id, SQInteger reference, Text *text)
110{

Callers

nothing calls this directly

Calls 6

IsValidTileFunction · 0.85
InvalidFunction · 0.85
NOT_REACHEDFunction · 0.85
BeginFunction · 0.85
GetEncodedTextMethod · 0.80

Tested by

no test coverage detected