Update to 1.11.0-beta1

This commit is contained in:
dP
2021-01-23 17:31:11 +03:00
parent d3c06c25c8
commit 5e4506f493
1045 changed files with 23534 additions and 60345 deletions

View File

@@ -22,6 +22,11 @@
#include "../../safeguards.h"
static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
{
return type == SPET_TEXT || type == SPET_LOCATION || type == SPET_BUTTON_PUSH || type == SPET_BUTTON_TILE || type == SPET_BUTTON_VEHICLE;
}
/* static */ bool ScriptStoryPage::IsValidStoryPage(StoryPageID story_page_id)
{
return ::StoryPage::IsValidID(story_page_id);
@@ -57,18 +62,38 @@
{
CCountedPtr<Text> counter(text);
::StoryPageElementType btype = static_cast<::StoryPageElementType>(type);
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPage(story_page_id));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, (type != SPET_TEXT && type != SPET_LOCATION) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, !StoryPageElementTypeRequiresText(btype) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile(reference));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference));
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
if (!ScriptObject::DoCommand(type == SPET_LOCATION ? reference : 0,
uint32 refid = 0;
TileIndex reftile = 0;
switch (type) {
case SPET_LOCATION:
reftile = reference;
break;
case SPET_GOAL:
case SPET_BUTTON_PUSH:
case SPET_BUTTON_TILE:
case SPET_BUTTON_VEHICLE:
refid = reference;
break;
case SPET_TEXT:
break;
default:
NOT_REACHED();
}
if (!ScriptObject::DoCommand(reftile,
story_page_id + (type << 16),
type == SPET_GOAL ? reference : 0,
refid,
CMD_CREATE_STORY_PAGE_ELEMENT,
type == SPET_TEXT || type == SPET_LOCATION ? text->GetEncodedText() : nullptr,
StoryPageElementTypeRequiresText(btype) ? text->GetEncodedText() : nullptr,
&ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID;
/* In case of test-mode, we return StoryPageElementID 0 */
@@ -86,16 +111,34 @@
StoryPage *p = StoryPage::Get(pe->page);
::StoryPageElementType type = pe->type;
EnforcePrecondition(false, (type != ::SPET_TEXT && type != ::SPET_LOCATION) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
EnforcePrecondition(false, !StoryPageElementTypeRequiresText(type) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile(reference));
EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference));
EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
return ScriptObject::DoCommand(type == ::SPET_LOCATION ? reference : 0,
uint32 refid = 0;
TileIndex reftile = 0;
switch (type) {
case ::SPET_LOCATION:
reftile = reference;
break;
case ::SPET_GOAL:
case ::SPET_BUTTON_PUSH:
case ::SPET_BUTTON_TILE:
case ::SPET_BUTTON_VEHICLE:
refid = reference;
break;
case ::SPET_TEXT:
break;
default:
NOT_REACHED();
}
return ScriptObject::DoCommand(reftile,
story_page_element_id,
type == ::SPET_GOAL ? reference : 0,
refid,
CMD_UPDATE_STORY_PAGE_ELEMENT,
type == ::SPET_TEXT || type == ::SPET_LOCATION ? text->GetEncodedText() : nullptr);
StoryPageElementTypeRequiresText(type) ? text->GetEncodedText() : nullptr);
}
/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
@@ -173,3 +216,39 @@
return ScriptObject::DoCommand(0, story_page_element_id, 0, CMD_REMOVE_STORY_PAGE_ELEMENT);
}
/* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakePushButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags)
{
StoryPageButtonData data;
data.SetColour((Colours)colour);
data.SetFlags((::StoryPageButtonFlags)flags);
if (!data.ValidateColour()) return UINT32_MAX;
if (!data.ValidateFlags()) return UINT32_MAX;
return data.referenced_id;
}
/* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakeTileButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor)
{
StoryPageButtonData data;
data.SetColour((Colours)colour);
data.SetFlags((::StoryPageButtonFlags)flags);
data.SetCursor((::StoryPageButtonCursor)cursor);
if (!data.ValidateColour()) return UINT32_MAX;
if (!data.ValidateFlags()) return UINT32_MAX;
if (!data.ValidateCursor()) return UINT32_MAX;
return data.referenced_id;
}
/* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakeVehicleButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor, ScriptVehicle::VehicleType vehtype)
{
StoryPageButtonData data;
data.SetColour((Colours)colour);
data.SetFlags((::StoryPageButtonFlags)flags);
data.SetCursor((::StoryPageButtonCursor)cursor);
data.SetVehicleType((::VehicleType)vehtype);
if (!data.ValidateColour()) return UINT32_MAX;
if (!data.ValidateFlags()) return UINT32_MAX;
if (!data.ValidateCursor()) return UINT32_MAX;
if (!data.ValidateVehicleType()) return UINT32_MAX;
return data.referenced_id;
}