OpenTTD Source: src/newgrf_house.cpp File Reference

OpenTTD Source 15.0-beta1

Data Structures | Functions | Variables
newgrf_house.cpp File Reference

Implementation of NewGRF houses. More...

`#include "stdafx.h"`
`#include "debug.h"`
`#include "landscape.h"`
`#include "newgrf_house.h"`
`#include "newgrf_spritegroup.h"`
`#include "newgrf_town.h"`
`#include "newgrf_sound.h"`
`#include "company_func.h"`
`#include "company_base.h"`
`#include "town.h"`
`#include "genworld.h"`
`#include "newgrf_animation_base.h"`
`#include "newgrf_cargo.h"`
`#include "station_base.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | SearchNearbyHouseData
| Structure with user-data for SearchNearbyHouseXXX - functions. More...
struct | HouseAnimationBase
| Helper class for animation control. More...

## Functions
static const GRFFile * | GetHouseSpecGrf (HouseID house_id)
| Retrieve the grf file associated with a house.
void | ResetHouses ()
void | ResetHouseClassIDs ()
HouseClassID | AllocateHouseClassID (uint8_t grf_class_id, uint32_t grfid)
void | InitializeBuildingCounts (Town *t)
| Initialise building counts for a town.
void | InitializeBuildingCounts ()
| Initialise global building counts and all town building counts.
std::span< const uint > | GetBuildingHouseIDCounts ()
| Get read-only span of total HouseID building counts.
void | IncreaseBuildingCount (Town *t, HouseID house_id)
| IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
void | DecreaseBuildingCount (Town *t, HouseID house_id)
| DecreaseBuildingCount() Decrease the number of a building when it is deleted.
static uint32_t | GetNumHouses (HouseID house_id, const Town *town)
static uint32_t | GetNearbyTileInformation (uint8_t parameter, TileIndex tile, bool grf_version8)
| Get information about a nearby tile.
static bool | SearchNearbyHouseID (TileIndex tile, void *user_data)
| Callback function to search a house by its HouseID.
static bool | SearchNearbyHouseClass (TileIndex tile, void *user_data)
| Callback function to search a house by its classID.
static bool | SearchNearbyHouseGRFID (TileIndex tile, void *user_data)
| Callback function to search a house by its grfID.
static uint32_t | GetDistanceFromNearbyHouse (uint8_t parameter, TileIndex tile, HouseID house)
| This function will activate a search around a central tile, looking for some houses that fit the requested characteristics.
uint16_t | GetHouseCallback (CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile, bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
static void | DrawTileLayout (const TileInfo *ti, const TileLayoutSpriteGroup *group, uint8_t stage, HouseID house_id)
void | DrawNewHouseTile (TileInfo *ti, HouseID house_id)
uint16_t | GetSimpleHouseCallback (CallbackID callback, uint32_t param1, uint32_t param2, const HouseSpec *spec, Town *town, TileIndex tile, CargoTypes extra_data)
void | AnimateNewHouseTile (TileIndex tile)
void | AnimateNewHouseConstruction (TileIndex tile)
bool | CanDeleteHouse (TileIndex tile)
static void | AnimationControl (TileIndex tile, uint16_t random_bits)
bool | NewHouseTileLoop (TileIndex tile)
static void | DoTriggerHouse (TileIndex tile, HouseTrigger trigger, uint8_t base_random, bool first)
void | TriggerHouse (TileIndex t, HouseTrigger trigger)
void | DoWatchedCargoCallback (TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16_t random)
| Run the watched cargo accepted callback for a single house tile.
void | WatchedCargoCallback (TileIndex tile, CargoTypes trigger_cargoes)
| Run watched cargo accepted callback for a house.

## Variables
static BuildingCounts< uint32_t > | _building_counts {}
static std::vector< HouseClassMapping > | _class_mapping {}
HouseOverrideManager | _house_mngr (NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID)
const HouseSpec | _original_house_specs [NEW_HOUSE_OFFSET]
std::vector< HouseSpec > | _house_specs

## Detailed Description

Implementation of NewGRF houses.

Definition in file newgrf_house.cpp.

## Function Documentation

## ◆ AllocateHouseClassID()

HouseClassID AllocateHouseClassID | ( | uint8_t | grf_class_id,
|  | uint32_t | grfid
| ) |  |

Definition at line 137 of file newgrf_house.cpp.

## ◆ AnimateNewHouseConstruction()

void AnimateNewHouseConstruction | ( | TileIndex | tile | ) |

Definition at line 602 of file newgrf_house.cpp.

## ◆ AnimateNewHouseTile()

void AnimateNewHouseTile | ( | TileIndex | tile | ) |

Definition at line 594 of file newgrf_house.cpp.

## ◆ AnimationControl()

static void AnimationControl | ( | TileIndex | tile,
|  | uint16_t | random_bits
| ) |  |
| static

Definition at line 629 of file newgrf_house.cpp.

## ◆ CanDeleteHouse()

bool CanDeleteHouse | ( | TileIndex | tile | ) |

Definition at line 611 of file newgrf_house.cpp.

## ◆ DecreaseBuildingCount()

void DecreaseBuildingCount | ( | Town * | t,
|  | HouseID | house_id
| ) |  |

DecreaseBuildingCount() Decrease the number of a building when it is deleted.

Parameters

  t | The town that the building was built in
  house_id | The id of the house being removed

Definition at line 209 of file newgrf_house.cpp.

References TownCache::building_counts, Town::cache, HouseSpec::class_id, and HouseSpec::Get().

Referenced by DoClearTownHouseHelper().

## ◆ DoTriggerHouse()

static void DoTriggerHouse | ( | TileIndex | tile,
|  | HouseTrigger | trigger,
|  | uint8_t | base_random,
|  | bool | first
| ) |  |
| static

Definition at line 682 of file newgrf_house.cpp.

## ◆ DoWatchedCargoCallback()

void DoWatchedCargoCallback | ( | TileIndex | tile,
|  | TileIndex | origin,
|  | CargoTypes | trigger_cargoes,
|  | uint16_t | random
| ) |  |

Run the watched cargo accepted callback for a single house tile.

Parameters

  tile | The house tile.
  origin | The triggering tile.
  trigger_cargoes | Cargo types that triggered the callback.
  random | Random bits.

Definition at line 741 of file newgrf_house.cpp.

References CBID_HOUSE_WATCHED_CARGO_ACCEPTED, AnimationBase< HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback, TileAnimationFrameAnimationHelper< Town > >::ChangeAnimationFrame(), HouseSpec::Get(), GetHouseType(), TileIndexToTileIndexDiffC(), TileIndexDiffC::x, and TileIndexDiffC::y.

Referenced by WatchedCargoCallback().

## ◆ DrawNewHouseTile()

void DrawNewHouseTile | ( | TileInfo * | ti,
|  | HouseID | house_id
| ) |  |

Definition at line 553 of file newgrf_house.cpp.

## ◆ DrawTileLayout()

static void DrawTileLayout | ( | const TileInfo * | ti,
|  | const TileLayoutSpriteGroup * | group,
|  | uint8_t | stage,
|  | HouseID | house_id
| ) |  |
| static

Definition at line 526 of file newgrf_house.cpp.

## ◆ GetBuildingHouseIDCounts()

std::span< const uint > GetBuildingHouseIDCounts | ( |  | ) |

Get read-only span of total HouseID building counts.

Returns
  span of HouseID building counts.

Definition at line 179 of file newgrf_house.cpp.

Referenced by HousePickerCallbacks::FillUsedItems().

## ◆ GetDistanceFromNearbyHouse()

static uint32_t GetDistanceFromNearbyHouse | ( | uint8_t | parameter,
|  | TileIndex | tile,
|  | HouseID | house
| ) |  |
| static

This function will activate a search around a central tile, looking for some houses that fit the requested characteristics.

Parameters

  parameter | that is given by the callback. bits 0..6 radius of the search bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID
  tile | TileIndex from which to start the search
  house | the HouseID that is associated to the house, the callback is called for

Returns
  the Manhattan distance from the center tile, if any, and 0 if failure

Definition at line 346 of file newgrf_house.cpp.

References CircularTileSearch(), DistanceManhattan(), GB(), HouseSpec::Get(), GetHouseNorthPart(), SearchNearbyHouseData::hs, lengthof, SearchNearbyHouseData::north_tile, SearchNearbyHouseClass(), SearchNearbyHouseGRFID(), and SearchNearbyHouseID().

Referenced by HouseScopeResolver::GetVariable().

## ◆ GetHouseCallback()

uint16_t GetHouseCallback | ( | CallbackID | callback,
|  | uint32_t | param1,
|  | uint32_t | param2,
|  | HouseID | house_id,
|  | Town * | town,
|  | TileIndex | tile,
|  | bool | not_yet_constructed,
|  | uint8_t | initial_random_bits,
|  | CargoTypes | watched_cargo_triggers,
|  | int | view
| ) |  |

Definition at line 518 of file newgrf_house.cpp.

## ◆ GetHouseSpecGrf()

static const GRFFile * GetHouseSpecGrf | ( | HouseID | house_id | ) |
| static

Retrieve the grf file associated with a house.

Parameters

  house_id | House to query.

Returns
  The associated GRF file (may be `nullptr`).

Definition at line 37 of file newgrf_house.cpp.

References HouseSpec::Get(), HouseSpec::grf_prop, and GRFFilePropsBase< Tcnt >::grffile.

## ◆ GetNearbyTileInformation()

static uint32_t GetNearbyTileInformation | ( | uint8_t | parameter,
|  | TileIndex | tile,
|  | bool | grf_version8
| ) |  |
| static

Get information about a nearby tile.

Parameters

  parameter | from callback. It's in fact a pair of coordinates
  tile | TileIndex from which the callback was initiated
  grf_version8 | True, if we are dealing with a new NewGRF which uses GRF version >= 8.

Returns
  a construction of bits obeying the newgrf format

Definition at line 253 of file newgrf_house.cpp.

References GetNearbyTile(), and GetNearbyTileInformation().

Referenced by GetNearbyTileInformation().

## ◆ GetNumHouses()

static uint32_t GetNumHouses | ( | HouseID | house_id,
|  | const Town * | town
| ) |  |
| static

Definition at line 234 of file newgrf_house.cpp.

## ◆ GetSimpleHouseCallback()

uint16_t GetSimpleHouseCallback | ( | CallbackID | callback,
|  | uint32_t | param1,
|  | uint32_t | param2,
|  | const HouseSpec * | spec,
|  | Town * | town,
|  | TileIndex | tile,
|  | CargoTypes | extra_data
| ) |  |

Definition at line 580 of file newgrf_house.cpp.

## ◆ IncreaseBuildingCount()

void IncreaseBuildingCount | ( | Town * | t,
|  | HouseID | house_id
| ) |  |

IncreaseBuildingCount() Increase the count of a building when it has been added by a town.

Parameters

  t | The town that the building is being built in
  house_id | The id of the house being added

Definition at line 190 of file newgrf_house.cpp.

References TownCache::building_counts, Town::cache, HouseSpec::class_id, and HouseSpec::Get().

Referenced by ClearMakeHouseTile(), and RebuildTownCaches().

## ◆ InitializeBuildingCounts() [1/2]

void InitializeBuildingCounts | ( |  | ) |

Initialise global building counts and all town building counts.

Definition at line 163 of file newgrf_house.cpp.

References InitializeBuildingCounts(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Iterate(), and HouseSpec::Specs().

Referenced by DoCreateTown(), GenerateWorld(), InitializeBuildingCounts(), and RebuildTownCaches().

## ◆ InitializeBuildingCounts() [2/2]

void InitializeBuildingCounts | ( | Town * | t | ) |

Initialise building counts for a town.

Parameters

  t | Town cache to initialise.

Definition at line 152 of file newgrf_house.cpp.

References TownCache::building_counts, Town::cache, and HouseSpec::Specs().

## ◆ NewHouseTileLoop()

bool NewHouseTileLoop | ( | TileIndex | tile | ) |

Definition at line 639 of file newgrf_house.cpp.

## ◆ ResetHouseClassIDs()

void ResetHouseClassIDs | ( |  | ) |

Definition at line 129 of file newgrf_house.cpp.

## ◆ ResetHouses()

void ResetHouses | ( |  | ) |

Definition at line 80 of file newgrf_house.cpp.

## ◆ SearchNearbyHouseClass()

static bool SearchNearbyHouseClass | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

Callback function to search a house by its classID.

Parameters

  tile | TileIndex to be examined
  user_data | SearchNearbyHouseData

Returns
  true or false, if found or not

Definition at line 295 of file newgrf_house.cpp.

References HouseSpec::class_id, HouseSpec::Get(), GetHouseNorthPart(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase< Tcnt >::grfid, GRFFilePropsBase< Tcnt >::HasGrfFile(), SearchNearbyHouseData::hs, IsTileType(), MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().

## ◆ SearchNearbyHouseGRFID()

static bool SearchNearbyHouseGRFID | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

Callback function to search a house by its grfID.

Parameters

  tile | TileIndex to be examined
  user_data | SearchNearbyHouseData

Returns
  true or false, if found or not

Definition at line 319 of file newgrf_house.cpp.

References HouseSpec::Get(), GetHouseNorthPart(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase< Tcnt >::grfid, GRFFilePropsBase< Tcnt >::HasGrfFile(), SearchNearbyHouseData::hs, IsTileType(), MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().

## ◆ SearchNearbyHouseID()

static bool SearchNearbyHouseID | ( | TileIndex | tile,
|  | void * | user_data
| ) |  |
| static

Callback function to search a house by its HouseID.

Parameters

  tile | TileIndex to be examined
  user_data | SearchNearbyHouseData

Returns
  true or false, if found or not

Definition at line 271 of file newgrf_house.cpp.

References HouseSpec::Get(), GetHouseNorthPart(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase< Tcnt >::grfid, GRFFilePropsBase< Tcnt >::HasGrfFile(), SearchNearbyHouseData::hs, IsTileType(), GRFFilePropsBase< Tcnt >::local_id, MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().

## ◆ TriggerHouse()

void TriggerHouse | ( | TileIndex | t,
|  | HouseTrigger | trigger
| ) |  |

Definition at line 729 of file newgrf_house.cpp.

## ◆ WatchedCargoCallback()

void WatchedCargoCallback | ( | TileIndex | tile,
|  | CargoTypes | trigger_cargoes
| ) |  |

Run watched cargo accepted callback for a house.

Parameters

  tile | House tile.
  trigger_cargoes | Triggering cargo types.

Precondition
  IsTileType(t, MP_HOUSE)

Definition at line 754 of file newgrf_house.cpp.

References HouseSpec::building_flags, DoWatchedCargoCallback(), HouseSpec::Get(), GetHouseNorthPart(), GetHouseType(), IsTileType(), MP_HOUSE, TileAddXY(), and HouseSpec::watched_cargoes.

Referenced by TriggerWatchedCargoCallbacks().

## Variable Documentation

## ◆ _building_counts

BuildingCounts<uint32_t> _building_counts {}
| static

Definition at line 27 of file newgrf_house.cpp.

## ◆ _class_mapping

std::vector<HouseClassMapping> _class_mapping {}
| static

Definition at line 28 of file newgrf_house.cpp.

## ◆ _house_specs

std::vector<HouseSpec> _house_specs

Definition at line 44 of file newgrf_house.cpp.