OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
story.cpp File Reference

Handling of stories. More...

`#include "stdafx.h"`
`#include "story_base.h"`
`#include "core/pool_func.hpp"`
`#include "cmd_helper.h"`
`#include "command_func.h"`
`#include "company_base.h"`
`#include "company_func.h"`
`#include "string_func.h"`
`#include "date_func.h"`
`#include "tile_map.h"`
`#include "goal_type.h"`
`#include "goal_base.h"`
`#include "window_func.h"`
`#include "gui.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
static bool | VerifyElementContentParameters (StoryPageID page_id, StoryPageElementType type, TileIndex tile, uint32 reference, const char *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 reference, const char *text)
| This helper for Create/Update PageElement Cmd procedure updates a page element with new content data.
CommandCost | CmdCreateStoryPage (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Create a new story page.
CommandCost | CmdCreateStoryPageElement (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Create a new story page element.
CommandCost | CmdUpdateStoryPageElement (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Update a new story page element.
CommandCost | CmdSetStoryPageTitle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Update title of a story page.
CommandCost | CmdSetStoryPageDate (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Update date of a story page.
CommandCost | CmdShowStoryPage (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Display a story page for all clients that are allowed to view the story page.
CommandCost | CmdRemoveStoryPage (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Remove a story page and associated story page elements.
CommandCost | CmdRemoveStoryPageElement (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Remove a story page element.

## Variables
StoryPageElementID | _new_story_page_element_id
StoryPageID | _new_story_page_id
uint32 | _story_page_element_next_sort_value
uint32 | _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

CommandCost CmdCreateStoryPage | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Create a new story page.

Parameters

  tile | unused.
  flags | type of operation
  p1 | various bitstuffed elements p1 = (bit 0 - 7) - Company for which this story page belongs to.
  p2 | unused.
  text | Title of the story page. Null is allowed in wich case a generic page title is provided by OpenTTD.

Returns
  the cost of this operation or an error

Definition at line 107 of file story.cpp.

References _current_company, _date, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::CanAllocateItem(), CMD_ERROR, StoryPage::company, StoryPage::date, DC_EXEC, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_COMPANY, InvalidateWindowClassesData(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::items, OWNER_DEITY, StoryPage::sort_value, stredup(), StrEmpty(), StoryPage::title, WC_MAIN_TOOLBAR, and WC_STORY_BOOK.

CommandCost CmdCreateStoryPageElement | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Create a new story page element.

Parameters

  tile | Tile location if it is a location page element, otherwise unused.
  flags | type of operation
  p1 | various bitstuffed elements p1 = (bit 0 - 15) - The page which the element belongs to. (bit 16 - 23) - Page element type
  p2 | Id of referenced object
  text | Text content in case it is a text or location page element

Returns
  the cost of this operation or an error

Definition at line 153 of file story.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_element_pool >::CanAllocateItem(), CMD_ERROR, DC_EXEC, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::items, OWNER_DEITY, StoryPageElement::page, StoryPageElement::sort_value, StoryPageElement::type, UpdateElement(), VerifyElementContentParameters(), and WC_STORY_BOOK.

CommandCost CmdRemoveStoryPage | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Remove a story page and associated story page elements.

Parameters

  tile | unused.
  flags | type of operation
  p1 | = (bit 0 - 15) - StoryPageID to remove.
  p2 | unused.
  text | unused.

Returns
  the cost of this operation or an error

Definition at line 313 of file story.cpp.

References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::IsValidID(), OWNER_DEITY, StoryPageElement::page, WC_MAIN_TOOLBAR, and WC_STORY_BOOK.

CommandCost CmdRemoveStoryPageElement | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Remove a story page element.

Parameters

  tile | unused.
  flags | type of operation
  p1 | = (bit 0 - 15) - StoryPageElementID to remove.
  p2 | unused.
  text | unused.

Returns
  the cost of this operation or an error

Definition at line 347 of file story.cpp.

References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_element_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_element_pool >::IsValidID(), OWNER_DEITY, StoryPageElement::page, and WC_STORY_BOOK.

CommandCost CmdSetStoryPageDate | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Update date of a story page.

Parameters

  tile | unused.
  flags | type of operation
  p1 | = (bit 0 - 15) - StoryPageID to update.
  p2 | = (bit 0 - 31) - date
  text | unused

Returns
  the cost of this operation or an error

Definition at line 264 of file story.cpp.

References _current_company, CMD_ERROR, StoryPage::date, DC_EXEC, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::IsValidID(), OWNER_DEITY, and WC_STORY_BOOK.

CommandCost CmdSetStoryPageTitle | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Update title of a story page.

Parameters

  tile | unused.
  flags | type of operation
  p1 | = (bit 0 - 15) - StoryPageID to update.
  p2 | unused
  text | title text of the story page.

Returns
  the cost of this operation or an error

Definition at line 234 of file story.cpp.

References _current_company, CMD_ERROR, DC_EXEC, free(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::IsValidID(), OWNER_DEITY, stredup(), StrEmpty(), StoryPage::title, and WC_STORY_BOOK.

CommandCost CmdShowStoryPage | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Display a story page for all clients that are allowed to view the story page.

Parameters

  tile | unused.
  flags | type of operation
  p1 | = (bit 0 - 15) - StoryPageID to show.
  p2 | unused
  text | unused

Returns
  the cost of this operation or an error

Definition at line 291 of file story.cpp.

References _current_company, _local_company, CMD_ERROR, StoryPage::company, DC_EXEC, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::Get(), INVALID_COMPANY, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, and ShowStoryBook().

CommandCost CmdUpdateStoryPageElement | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text
| ) |  |

Update a new story page element.

Parameters

  tile | Tile location if it is a location page element, otherwise unused.
  flags | type of operation
  p1 | various bitstuffed elements p1 = (bit 0 - 15) - The page element to update. (bit 16 - 31) - unused
  p2 | Id of referenced object
  text | Text content in case it is a text or location page element

Returns
  the cost of this operation or an error

Definition at line 204 of file story.cpp.

References _current_company, CMD_ERROR, DC_EXEC, GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_element_pool >::Get(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_element_pool >::IsValidID(), OWNER_DEITY, StoryPageElement::page, StoryPageElement::type, UpdateElement(), VerifyElementContentParameters(), and WC_STORY_BOOK.

static void UpdateElement | ( | StoryPageElement & | pe,
|  | TileIndex | tile,
|  | uint32 | reference,
|  | const char * | text
| ) |  |
| static

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

Parameters

  pe | The page element to update
  tile | The tile parameter of the DoCommand proc
  reference | The reference parameter of the DoCommand proc (p2)
  text | The text parameter of the DoCommand proc

Definition at line 80 of file story.cpp.

References StoryPageElement::referenced_id, SPET_GOAL, SPET_LOCATION, SPET_TEXT, stredup(), StoryPageElement::text, and StoryPageElement::type.

Referenced by CmdCreateStoryPageElement(), and CmdUpdateStoryPageElement().

static bool VerifyElementContentParameters | ( | StoryPageID | page_id,
|  | StoryPageElementType | type,
|  | TileIndex | tile,
|  | uint32 | reference,
|  | const char * | 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_id | The page id of the page which the page element (will) belong to
  type | The type of the page element to create/update
  tile | The tile parameter of the DoCommand proc
  reference | The reference parameter of the DoCommand proc (p2)
  text | The text parameter of the DoCommand proc

Returns
  true, if and only if the given parameters are valid for the given page elment type and page id.

Definition at line 50 of file story.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_story_page_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_goal_pool >::Get(), INVALID_COMPANY, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_goal_pool >::IsValidID(), IsValidTile(), SPET_GOAL, SPET_LOCATION, SPET_TEXT, and StrEmpty().

Referenced by CmdCreateStoryPageElement(), and CmdUpdateStoryPageElement().