OpenTTD Source 20250312-master-gcdcc6b491d
story.cpp File Reference

Handling of stories. More...

#include "stdafx.h"
#include "story_base.h"
#include "core/pool_func.hpp"
#include "command_func.h"
#include "company_base.h"
#include "company_func.h"
#include "string_func.h"
#include "timer/timer_game_calendar.h"
#include "tile_map.h"
#include "goal_type.h"
#include "goal_base.h"
#include "window_func.h"
#include "gui.h"
#include "vehicle_base.h"
#include "game/game.hpp"
#include "script/api/script_story_page.hpp"
#include "script/api/script_event_types.hpp"
#include "story_cmd.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

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 correct for the given page element type.
 
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.
 
std::tuple< CommandCost, StoryPageIDCmdCreateStoryPage (DoCommandFlags flags, CompanyID company, const EncodedString &text)
 Create a new story page.
 
std::tuple< CommandCost, StoryPageElementIDCmdCreateStoryPageElement (DoCommandFlags flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32_t reference, const EncodedString &text)
 Create a new story page element.
 
CommandCost CmdUpdateStoryPageElement (DoCommandFlags flags, TileIndex tile, StoryPageElementID page_element_id, uint32_t reference, const EncodedString &text)
 Update a new story page element.
 
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.
 
CommandCost CmdRemoveStoryPage (DoCommandFlags flags, StoryPageID page_id)
 Remove a story page and associated story page elements.
 
CommandCost CmdRemoveStoryPageElement (DoCommandFlags flags, StoryPageElementID page_element_id)
 Remove a story page element.
 
CommandCost CmdStoryPageButton (DoCommandFlags flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference)
 Clicked/used a button on a story page.
 

Variables

uint32_t _story_page_element_next_sort_value
 
uint32_t _story_page_next_sort_value
 
StoryPageElementPool _story_page_element_pool ("StoryPageElement")
 
StoryPagePool _story_page_pool ("StoryPage")
 

Detailed Description

Handling of stories.

Definition in file story.cpp.

Function Documentation

◆ CmdCreateStoryPage()

◆ CmdCreateStoryPageElement()

std::tuple< CommandCost, StoryPageElementID > CmdCreateStoryPageElement ( DoCommandFlags  flags,
TileIndex  tile,
StoryPageID  page_id,
StoryPageElementType  type,
uint32_t  reference,
const EncodedString text 
)

◆ CmdRemoveStoryPage()

◆ CmdRemoveStoryPageElement()

◆ CmdSetStoryPageDate()

CommandCost CmdSetStoryPageDate ( DoCommandFlags  flags,
StoryPageID  page_id,
TimerGameCalendar::Date  date 
)

◆ CmdSetStoryPageTitle()

CommandCost CmdSetStoryPageTitle ( DoCommandFlags  flags,
StoryPageID  page_id,
const EncodedString text 
)

Update title of a story page.

Parameters
flagstype of operation
page_idStoryPageID to update.
texttitle text of the story page.
Returns
the cost of this operation or an error

Definition at line 322 of file story.cpp.

References _current_company, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_pool >::IsValidID(), OWNER_DEITY, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), StoryPage::title, and WC_STORY_BOOK.

◆ CmdShowStoryPage()

◆ CmdStoryPageButton()

CommandCost CmdStoryPageButton ( DoCommandFlags  flags,
TileIndex  tile,
StoryPageElementID  page_element_id,
VehicleID  reference 
)

◆ CmdUpdateStoryPageElement()

CommandCost CmdUpdateStoryPageElement ( DoCommandFlags  flags,
TileIndex  tile,
StoryPageElementID  page_element_id,
uint32_t  reference,
const EncodedString text 
)

Update a new story page element.

Parameters
flagstype of operation
tileTile location if it is a location page element, otherwise unused.
page_element_idThe page element to update.
referenceId of referenced object
textText content in case it is a text or location page element
Returns
the cost of this operation or an error

Definition at line 296 of file story.cpp.

References _current_company, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_element_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_element_pool >::IsValidID(), OWNER_DEITY, StoryPageElement::page, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), StoryPageElement::type, UpdateElement(), VerifyElementContentParameters(), and WC_STORY_BOOK.

◆ UpdateElement()

static void UpdateElement ( StoryPageElement pe,
TileIndex  tile,
uint32_t  reference,
const EncodedString text 
)
static

This helper for Create/Update PageElement Cmd procedure updates a page element with new content data.

Parameters
peThe page element to update
tileThe tile parameter of the DoCommand proc
referenceThe reference parameter of the DoCommand proc (p2)
textThe text parameter of the DoCommand proc

Definition at line 106 of file story.cpp.

References StoryPageElement::referenced_id, SPET_BUTTON_PUSH, SPET_BUTTON_TILE, SPET_BUTTON_VEHICLE, SPET_GOAL, SPET_LOCATION, SPET_TEXT, StoryPageElement::text, and StoryPageElement::type.

Referenced by CmdCreateStoryPageElement(), and CmdUpdateStoryPageElement().

◆ VerifyElementContentParameters()

static bool VerifyElementContentParameters ( StoryPageID  page_id,
StoryPageElementType  type,
TileIndex  tile,
uint32_t  reference,
const EncodedString text 
)
static

This helper for Create/Update PageElement Cmd procedure verifies if the page element parameters are correct for the given page element type.

Parameters
page_idThe page id of the page which the page element (will) belong to
typeThe type of the page element to create/update
tileThe tile parameter of the DoCommand proc
referenceThe reference parameter of the DoCommand proc (p2)
textThe text parameter of the DoCommand proc
Returns
true, if and only if the given parameters are valid for the given page element type and page id.

Definition at line 59 of file story.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_goal_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_goal_pool >::IsValidID(), IsValidTile(), SPET_BUTTON_PUSH, SPET_BUTTON_TILE, SPET_BUTTON_VEHICLE, SPET_GOAL, SPET_LOCATION, and SPET_TEXT.

Referenced by CmdCreateStoryPageElement(), and CmdUpdateStoryPageElement().

Variable Documentation

◆ _story_page_element_next_sort_value

uint32_t _story_page_element_next_sort_value

Definition at line 32 of file story.cpp.

◆ _story_page_next_sort_value

uint32_t _story_page_next_sort_value

Definition at line 33 of file story.cpp.