OpenTTD
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 GRFFileGetHouseSpecGrf (HouseID house_id)
 Retrieve the grf file associated with a house. More...
 
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. More...
 
void DecreaseBuildingCount (Town *t, HouseID house_id)
 DecreaseBuildingCount() Decrease the number of a building when it is deleted. More...
 
static uint32 GetNumHouses (HouseID house_id, const Town *town)
 
static uint32 GetNearbyTileInformation (byte parameter, TileIndex tile, bool grf_version8)
 Get information about a nearby tile. More...
 
static bool SearchNearbyHouseID (TileIndex tile, void *user_data)
 Callback function to search a house by its HouseID. More...
 
static bool SearchNearbyHouseClass (TileIndex tile, void *user_data)
 Callback function to search a house by its classID. More...
 
static bool SearchNearbyHouseGRFID (TileIndex tile, void *user_data)
 Callback function to search a house by its grfID. More...
 
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. More...
 
uint16 GetHouseCallback (CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile, bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
 
static void DrawTileLayout (const TileInfo *ti, const TileLayoutSpriteGroup *group, byte stage, HouseID house_id)
 
void DrawNewHouseTile (TileInfo *ti, HouseID house_id)
 
uint16 GetSimpleHouseCallback (CallbackID callback, uint32 param1, uint32 param2, const HouseSpec *spec, Town *town, TileIndex tile, uint32 extra_data)
 
void AnimateNewHouseTile (TileIndex tile)
 
void AnimateNewHouseConstruction (TileIndex tile)
 
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)
 
void DoWatchedCargoCallback (TileIndex tile, TileIndex origin, uint32 trigger_cargoes, uint16 random)
 Run the watched cargo accepted callback for a single house tile. More...
 
void WatchedCargoCallback (TileIndex tile, uint32 trigger_cargoes)
 Run watched cargo accepted callback for a house. More...
 

Variables

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

Detailed Description

Implementation of NewGRF houses.

Definition in file newgrf_house.cpp.

Function Documentation

◆ DecreaseBuildingCount()

void DecreaseBuildingCount ( Town t,
HouseID  house_id 
)

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

Parameters
tThe town that the building was built in
house_idThe id of the house being removed

Definition at line 121 of file newgrf_house.cpp.

References _loaded_newgrf_features, TownCache::building_counts, Town::cache, HouseSpec::class_id, and GRFLoadedFeatures::has_newhouses.

◆ DoWatchedCargoCallback()

void DoWatchedCargoCallback ( TileIndex  tile,
TileIndex  origin,
uint32  trigger_cargoes,
uint16  random 
)

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

Parameters
tileThe house tile.
originThe triggering tile.
trigger_cargoesCargo types that triggered the callback.
randomRandom bits.

Definition at line 636 of file newgrf_house.cpp.

References TileIndexToTileIndexDiffC().

◆ GetDistanceFromNearbyHouse()

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
parameterthat 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
tileTileIndex from which to start the search
housethe 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 263 of file newgrf_house.cpp.

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

◆ GetHouseSpecGrf()

static const GRFFile* GetHouseSpecGrf ( HouseID  house_id)
static

Retrieve the grf file associated with a house.

Parameters
house_idHouse to query.
Returns
The associated GRF file (may be NULL).

Definition at line 39 of file newgrf_house.cpp.

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

◆ GetNearbyTileInformation()

static uint32 GetNearbyTileInformation ( byte  parameter,
TileIndex  tile,
bool  grf_version8 
)
static

Get information about a nearby tile.

Parameters
parameterfrom callback. It's in fact a pair of coordinates
tileTileIndex from which the callback was initiated
grf_version8True, 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 170 of file newgrf_house.cpp.

References GetNearbyTile().

◆ IncreaseBuildingCount()

void IncreaseBuildingCount ( Town t,
HouseID  house_id 
)

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

Parameters
tThe town that the building is being built in
house_idThe id of the house being added

Definition at line 100 of file newgrf_house.cpp.

References _loaded_newgrf_features, TownCache::building_counts, Town::cache, HouseSpec::class_id, and GRFLoadedFeatures::has_newhouses.

◆ SearchNearbyHouseClass()

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

Callback function to search a house by its classID.

Parameters
tileTileIndex to be examined
user_dataSearchNearbyHouseData
Returns
true or false, if found or not

Definition at line 212 of file newgrf_house.cpp.

References HouseSpec::class_id, GetHouseNorthPart(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, 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
tileTileIndex to be examined
user_dataSearchNearbyHouseData
Returns
true or false, if found or not

Definition at line 236 of file newgrf_house.cpp.

References GetHouseNorthPart(), GetHouseType(), HouseSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, 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
tileTileIndex to be examined
user_dataSearchNearbyHouseData
Returns
true or false, if found or not

Definition at line 188 of file newgrf_house.cpp.

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

Referenced by GetDistanceFromNearbyHouse().

◆ WatchedCargoCallback()

void WatchedCargoCallback ( TileIndex  tile,
uint32  trigger_cargoes 
)

Run watched cargo accepted callback for a house.

Parameters
tileHouse tile.
trigger_cargoesTriggering cargo types.
Precondition
IsTileType(t, MP_HOUSE)

Definition at line 649 of file newgrf_house.cpp.

Referenced by TriggerWatchedCargoCallbacks().