# newgrf_house.cpp File Reference

Implementation of NewGRF houses. More...

`#include "stdafx.h"`
`#include "variables.h"`
`#include "debug.h"`
`#include "viewport_func.h"`
`#include "landscape.h"`
`#include "newgrf.h"`
`#include "newgrf_house.h"`
`#include "newgrf_spritegroup.h"`
`#include "newgrf_town.h"`
`#include "newgrf_sound.h"`
`#include "newgrf_commons.h"`
`#include "functions.h"`
`#include "company_func.h"`
`#include "animated_tile_func.h"`
`#include "company_base.h"`
`#include "town.h"`
`#include "core/random_func.hpp"`
`#include "sprite.h"`

Go to the source code of this file.

## Data Structures

struct | SearchNearbyHouseData
| Structure with user-data for SearchNearbyHouseXXX - functions. More...

## Functions

HouseClassID | AllocateHouseClassID (byte grf_class_id, uint32 grfid)
void | InitializeBuildingCounts ()
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 | HouseGetRandomBits (const ResolverObject *object)
static uint32 | HouseGetTriggers (const ResolverObject *object)
static void | HouseSetTriggers (const ResolverObject *object, int triggers)
static uint32 | GetNumHouses (HouseID house_id, const Town *town)
uint32 | GetNearbyTileInformation (byte parameter, TileIndex 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 | GetDistanceFromNearbyHouse (uint8 parameter, TileIndex tile, HouseID house)
| This function will activate a search around a central tile, looking for some houses that fit the requested characteristics.
static uint32 | HouseGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
| HouseGetVariable():.
static const SpriteGroup * | HouseResolveReal (const ResolverObject *object, const RealSpriteGroup *group)
static void | NewHouseResolver (ResolverObject *res, HouseID house_id, TileIndex tile, Town *town)
| NewHouseResolver():.
uint16 | GetHouseCallback (CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)
static void | DrawTileLayout (const TileInfo *ti, const TileLayoutSpriteGroup *group, byte stage, HouseID house_id)
void | DrawNewHouseTile (TileInfo *ti, HouseID house_id)
void | AnimateNewHouseTile (TileIndex tile)
void | ChangeHouseAnimationFrame (const GRFFile *file, TileIndex tile, uint16 callback_result)
bool | CanDeleteHouse (TileIndex tile)
static void | AnimationControl (TileIndex tile, uint16 random_bits)
bool | NewHouseTileLoop (TileIndex tile)
static void | DoTriggerHouse (TileIndex tile, HouseTrigger trigger, byte base_random, bool first)
void | TriggerHouse (TileIndex t, HouseTrigger trigger)

## Variables

static BuildingCounts< uint32 > | _building_counts
static HouseClassMapping | _class_mapping [HOUSE_CLASS_MAX]
HouseOverrideManager | _house_mngr (NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID)

## Detailed Description

Implementation of NewGRF houses.

Definition in file newgrf_house.cpp.

## Function Documentation

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 85 of file newgrf_house.cpp.

References HouseSpec::class_id, and GRFLoadedFeatures::has_newhouses.

Referenced by DoClearTownHouseHelper().

static uint32 GetDistanceFromNearbyHouse | ( | uint8 | 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 220 of file newgrf_house.cpp.

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

Referenced by HouseGetVariable().

static uint32 HouseGetVariable | ( | const ResolverObject * | object,
|  | byte | variable,
|  | byte | parameter,
|  | bool * | available |
| ) |  |  | `[static]`

HouseGetVariable():.

Used by the resolver to get values for feature 07 deterministic spritegroups.

Definition at line 249 of file newgrf_house.cpp.

References HouseSpec::class_id, GetDistanceFromNearbyHouse(), GetHouseAge(), GetHouseAnimationFrame(), GetHouseBuildingStage(), GetHouseType(), OverrideManagerBase::GetID(), GetNearbyTileInformation(), GetTerrainType(), GetTownRadiusGroup(), HouseSpec::grffile, EntityIDMapping::grfid, IsTileType(), HouseSpec::local_id, OverrideManagerBase::mapping_ID, MP_HOUSE, ResolverObject::scope, TileHash2Bit(), TileX(), TileY(), and TownGetVariable().

Referenced by NewHouseResolver().

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 64 of file newgrf_house.cpp.

References HouseSpec::class_id, and GRFLoadedFeatures::has_newhouses.

Referenced by ClearMakeHouseTile(), and UpdateHousesAndTowns().

static void NewHouseResolver | ( | ResolverObject * | res,
|  | HouseID | house_id,
|  | TileIndex | tile,
|  | Town * | town |
| ) |  |  | `[static]`

NewHouseResolver():.

Returns a resolver object to be used with feature 07 spritegroups.

Definition at line 362 of file newgrf_house.cpp.

References CBID_NO_CALLBACK, ResolverObject::count, HouseSpec::grffile, ResolverObject::grffile, HouseGetVariable(), ResolverObject::last_value, and ResolverObject::reseed.

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 171 of file newgrf_house.cpp.

References HouseSpec::class_id, GetHouseNorthPart(), GetHouseType(), HouseSpec::grffile, SearchNearbyHouseData::hs, IsTileType(), MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().

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 194 of file newgrf_house.cpp.

References GetHouseNorthPart(), GetHouseType(), HouseSpec::grffile, SearchNearbyHouseData::hs, IsTileType(), MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().

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 148 of file newgrf_house.cpp.

References GetHouseNorthPart(), GetHouseType(), HouseSpec::grffile, SearchNearbyHouseData::hs, IsTileType(), HouseSpec::local_id, MP_HOUSE, and SearchNearbyHouseData::north_tile.

Referenced by GetDistanceFromNearbyHouse().