25#include "script/api/script_story_page.hpp"
26#include "script/api/script_event_types.hpp"
32uint32_t _story_page_element_next_sort_value;
33uint32_t _story_page_next_sort_value;
40StoryPage::~StoryPage()
44 if (spe->page == this->index)
delete spe;
65 if (text.empty())
return false;
68 if (text.empty())
return false;
77 if (!button_data.ValidateColour())
return false;
78 if (!button_data.ValidateFlags())
return false;
81 if (!button_data.ValidateColour())
return false;
82 if (!button_data.ValidateFlags())
return false;
83 if (!button_data.ValidateCursor())
return false;
86 if (!button_data.ValidateColour())
return false;
87 if (!button_data.ValidateFlags())
return false;
88 if (!button_data.ValidateCursor())
return false;
89 if (!button_data.ValidateVehicleType())
return false;
125 default: NOT_REACHED();
132 assert(button_colour < COLOUR_END);
133 SB(this->referenced_id, 0, 8, button_colour);
138 SB(this->referenced_id, 24, 8, flags);
144 assert(cursor < SPBC_END);
145 SB(this->referenced_id, 8, 8, cursor);
152 SB(this->referenced_id, 16, 8, vehtype);
158 Colours colour =
static_cast<Colours
>(
GB(this->referenced_id, 0, 8));
185 return GB(this->referenced_id, 0, 8) < COLOUR_END;
188bool StoryPageButtonData::ValidateFlags()
const
190 uint8_t flags =
GB(this->referenced_id, 24, 8);
192 if ((flags & SPBF_FLOAT_LEFT) && (flags & SPBF_FLOAT_RIGHT))
return false;
194 if (flags & ~(SPBF_FLOAT_LEFT | SPBF_FLOAT_RIGHT))
return false;
201 return GB(this->referenced_id, 8, 8) < SPBC_END;
207 uint8_t vehtype =
GB(this->referenced_id, 16, 8);
228 _story_page_next_sort_value = 0;
236 _story_page_next_sort_value++;
258 uint16_t element_count = 0;
260 if (iter->page == page_id) element_count++;
262 if (element_count >= 128)
return {
CMD_ERROR, StoryPageElementID::Invalid() };
272 _story_page_element_next_sort_value = 0;
280 _story_page_element_next_sort_value++;
284 return {
CommandCost(), StoryPageElementID::Invalid() };
393 if (pe->page == p->
index) {
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
Container for an encoded string, created by GetEncodedString.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
static Date date
Current date in days (day counter).
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Execute
execute the given command
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Base functions for all Games.
basic types related to goals
GUI functions that shouldn't be here.
void ShowStoryBook(CompanyID company, StoryPageID page_id=StoryPageID::Invalid(), bool centered=false)
Raise or create the story book window for company, at page page_id.
bool IsValidColours(Colours colours)
Checks if a Colours value is valid.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
std::tuple< CommandCost, StoryPageElementID > CmdCreateStoryPageElement(DoCommandFlags flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32_t reference, const EncodedString &text)
Create a new story page element.
static bool VerifyElementContentParameters(StoryPageID page_id, StoryPageElementType type, TileIndex tile, uint32_t reference, const EncodedString &text)
This helper for Create/Update PageElement Cmd procedure verifies if the page element parameters are c...
std::tuple< CommandCost, StoryPageID > CmdCreateStoryPage(DoCommandFlags flags, CompanyID company, const EncodedString &text)
Create a new story page.
CommandCost CmdUpdateStoryPageElement(DoCommandFlags flags, TileIndex tile, StoryPageElementID page_element_id, uint32_t reference, const EncodedString &text)
Update a new story page element.
static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32_t reference, const EncodedString &text)
This helper for Create/Update PageElement Cmd procedure updates a page element with new content data.
CommandCost CmdRemoveStoryPageElement(DoCommandFlags flags, StoryPageElementID page_element_id)
Remove a story page element.
CommandCost CmdRemoveStoryPage(DoCommandFlags flags, StoryPageID page_id)
Remove a story page and associated story page elements.
CommandCost CmdStoryPageButton(DoCommandFlags flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference)
Clicked/used a button on a story page.
CommandCost CmdSetStoryPageTitle(DoCommandFlags flags, StoryPageID page_id, const EncodedString &text)
Update title of a story page.
CommandCost CmdSetStoryPageDate(DoCommandFlags flags, StoryPageID page_id, TimerGameCalendar::Date date)
Update date of a story page.
CommandCost CmdShowStoryPage(DoCommandFlags flags, StoryPageID page_id)
Display a story page for all clients that are allowed to view the story page.
StoryPageButtonFlags
Flags available for buttons.
@ SPET_LOCATION
An element that references a tile along with a one-line text.
@ SPET_GOAL
An element that references a goal.
@ SPET_BUTTON_PUSH
A push button that triggers an immediate event.
@ SPET_BUTTON_TILE
A button that allows the player to select a tile, and triggers an event with the tile.
@ SPET_TEXT
A text element.
@ SPET_BUTTON_VEHICLE
A button that allows the player to select a vehicle, and triggers an event with the vehicle.
StoryPageButtonCursor
Mouse cursors usable by story page buttons.
bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
Checks if a StoryPageButtonCursor value is valid.
Command definitions related to stories.
Functions related to low-level strings.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
static size_t GetNumItems()
Returns number of valid items in the pool.
Tindex index
Index of this pool item.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Base class for all pools.
Helper to construct packed "id" values for button-type StoryPageElement.
Colours GetColour() const
Get the button background colour.
VehicleType GetVehicleType() const
Get the type of vehicles that are accepted by the button.
void SetColour(Colours button_colour)
Set the button background colour.
bool ValidateVehicleType() const
Verity that the data stored a valid VehicleType value.
bool ValidateColour() const
Verify that the data stored a valid Colour value.
void SetVehicleType(VehicleType vehtype)
Set the type of vehicles that are accepted by the button.
StoryPageButtonCursor GetCursor() const
Get the mouse cursor used while waiting for input for the button.
bool ValidateCursor() const
Verify that the data stores a valid StoryPageButtonCursor value.
void SetCursor(StoryPageButtonCursor cursor)
Set the mouse cursor used while waiting for input for the button.
Struct about story page elements.
uint32_t referenced_id
Id of referenced object (location, goal etc.)
EncodedString text
Static content text of page element.
StoryPageElementType type
Type of page element.
StoryPageID page
Id of the page which the page element belongs to.
Struct about stories, current and completed.
EncodedString title
Title of story page.
CompanyID company
StoryPage is for a specific company; CompanyID::Invalid() if it is global.
TimerGameCalendar::Date date
Date when the page was created.
Map writing/reading functions for tiles.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition of the game-calendar-timer.
Base class for all vehicles.
VehicleType
Available vehicle types.
@ VEH_INVALID
Non-existing type of vehicle.
@ VEH_COMPANY_END
Last company-ownable type.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Window functions not directly related to making/drawing windows.
@ WC_STORY_BOOK
Story book; Window numbers:
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers: