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

Method UpdateElement

src/script/api/script_story_page.cpp:109–149  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

107}
108
109/* static */ bool ScriptStoryPage::UpdateElement(StoryPageElementID story_page_element_id, SQInteger reference, Text *text)
110{
111 ScriptObjectRef counter(text);
112
113 EnforceDeityMode(false);
114 EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
115
116 const StoryPageElement *pe = StoryPageElement::Get(story_page_element_id);
117 const StoryPage *p = StoryPage::Get(pe->page);
118 ::StoryPageElementType type = pe->type;
119
120 EncodedString encoded_text;
121 if (StoryPageElementTypeRequiresText(type)) {
122 EnforcePrecondition(false, text != nullptr);
123 encoded_text = text->GetEncodedText();
124 EnforcePreconditionEncodedText(false, encoded_text);
125 }
126 EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile((::TileIndex)reference));
127 EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference)));
128 EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid()));
129
130 uint32_t refid = 0;
131 TileIndex reftile{};
132 switch (type) {
133 case ::SPET_LOCATION:
134 reftile = TileIndex(reference);
135 break;
136 case ::SPET_GOAL:
137 case ::SPET_BUTTON_PUSH:
138 case ::SPET_BUTTON_TILE:
139 case ::SPET_BUTTON_VEHICLE:
140 refid = reference;
141 break;
142 case ::SPET_TEXT:
143 break;
144 default:
145 NOT_REACHED();
146 }
147
148 return ScriptObject::Command<CMD_UPDATE_STORY_PAGE_ELEMENT>::Do(reftile, story_page_element_id, refid, encoded_text);
149}
150
151/* static */ SQInteger ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
152{

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected