OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
39 const HouseSpec *hs = HouseSpec::Get(house_id);
56 CallbackID callback, uint32 param1, uint32 param2,
57 bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
59 house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
60 town_scope(*this, town, not_yet_constructed)
75 HouseClassID AllocateHouseClassID(
byte grf_class_id, uint32 grfid)
78 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
89 return HOUSE_NO_CLASS;
92 void InitializeBuildingCounts()
94 memset(&_building_counts, 0,
sizeof(_building_counts));
97 memset(&t->cache.building_counts, 0,
sizeof(t->cache.building_counts));
112 _building_counts.id_count[house_id]++;
114 if (class_id == HOUSE_NO_CLASS)
return;
117 _building_counts.class_count[class_id]++;
131 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
133 if (class_id == HOUSE_NO_CLASS)
return;
136 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
153 static uint32 GetNumHouses(
HouseID house_id,
const Town *town)
155 uint8 map_id_count, town_id_count, map_class_count, town_class_count;
158 map_id_count =
ClampU(_building_counts.id_count[house_id], 0, 255);
159 map_class_count =
ClampU(_building_counts.class_count[class_id], 0, 255);
163 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
195 const HouseSpec *hs = HouseSpec::Get(house);
200 if (north_tile == nbhd->
north_tile)
return false;
219 const HouseSpec *hs = HouseSpec::Get(house);
224 if (north_tile == nbhd->
north_tile)
return false;
243 const HouseSpec *hs = HouseSpec::Get(house);
248 if (north_tile == nbhd->
north_tile)
return false;
274 uint8 searchtype =
GB(parameter, 6, 2);
275 uint8 searchradius =
GB(parameter, 0, 6);
276 if (searchtype >=
lengthof(search_procs))
return 0;
277 if (searchradius < 1)
return 0;
280 nbhd.
hs = HouseSpec::Get(house);
284 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
309 case 0x44:
return GetNumHouses(this->
house_id, this->
town);
329 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->
town);
377 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
380 if (hs->
class_id != HOUSE_NO_CLASS) {
385 uint local_houseid = 0;
387 local_houseid = nearby_house_id;
392 return houseclass << 16 | local_houseid;
407 Debug(grf, 1,
"Unhandled house variable 0x{:X}", variable);
414 bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
419 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
420 return object.ResolveCallback();
427 const HouseSpec *hs = HouseSpec::Get(house_id);
433 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
452 const HouseSpec *hs = HouseSpec::Get(house_id);
455 bool draw_old_one =
true;
468 if (group !=
nullptr && group->type == SGT_TILELAYOUT) {
479 return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
494 if (hs ==
nullptr)
return;
499 void AnimateNewHouseConstruction(
TileIndex tile)
526 static void AnimationControl(
TileIndex tile, uint16 random_bits)
545 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
546 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
554 uint16 random =
GB(Random(), 0, 16);
556 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
561 AnimationControl(tile, 0);
569 ClearTownHouse(Town::GetByTile(tile), tile);
579 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger,
byte base_random,
bool first)
594 if (group ==
nullptr)
return;
600 byte new_random_bits = Random();
602 uint32 reseed =
object.GetReseedSum();
603 random_bits &= ~reseed;
604 random_bits |= (first ? new_random_bits : base_random) & reseed;
608 case HOUSE_TRIGGER_TILE_LOOP:
612 case HOUSE_TRIGGER_TILE_LOOP_TOP:
626 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
628 DoTriggerHouse(t, trigger, 0,
true);
641 uint32 cb_info = random << 16 | (uint8)diff.
y << 8 | (uint8)diff.
x;
655 const HouseSpec *hs = HouseSpec::Get(
id);
659 if (trigger_cargoes == 0)
return;
666 hs = HouseSpec::Get(
id);
@ MP_HOUSE
A house by a town.
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Structure with user-data for SearchNearbyHouseXXX - functions.
uint32 TileIndex
The index/ID of a Tile.
uint32 GetTriggers() const override
Get the triggers.
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
Callback function to search a house by its HouseID.
Town * town
Town of this house.
Structure contains cached list of stations nearby.
@ TO_HOUSES
town buildings
static Year GetHouseAge(TileIndex t)
Get the age of the house.
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
byte random_colour[4]
4 "random" colours
uint x
X position of the tile in unit coordinates.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
Tile information, used while rendering the tile.
@ CBID_HOUSE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
@ SPRITE_WIDTH
number of bits for the sprite number
static void ChangeAnimationFrame(CallbackID cb, const HouseSpec *spec, Town *obj, TileIndex tile, uint32 random_bits, uint32 trigger, CargoTypes extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
static byte GetHouseProcessingTime(TileIndex t)
Get the amount of time remaining before the tile loop processes this tile.
Resolver object to be used for houses (feature 07 spritegroups).
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
@ CBID_HOUSE_WATCHED_CARGO_ACCEPTED
Called when a cargo type specified in property 20 is accepted.
SpriteID sprite
The 'real' sprite.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Interface for SpriteGroup-s to access the gamestate.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
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 requ...
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
@ CALLBACK_1A_RANDOM_BITS
callback 1A needs random bits
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
uint y
Y position of the tile in unit coordinates.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
static void AnimateTile(const HouseSpec *spec, Town *obj, TileIndex tile, bool random_animation, CargoTypes extra_data=0)
Animate a single tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static const GRFFile * GetHouseSpecGrf(HouseID house_id)
Retrieve the grf file associated with a house.
const HouseSpec * hs
Specs of the house that started the search.
@ CBM_HOUSE_DESTRUCTION
trigger destruction of building
CallbackID
List of implemented NewGRF callbacks.
static const uint HOUSE_CLASS_MAX
There can only be as many classes as there are new houses, plus one for NO_CLASS, as the original hou...
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
@ CBID_HOUSE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for house tile.
static TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
@ CBM_HOUSE_CONSTRUCTION_STATE_CHANGE
change animation when construction state changes
uint32 grfid
The GRF ID of the file this class belongs to.
uint32 GetRandomBits() const override
Get a few random bits.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
Callback function to search a house by its grfID.
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Slope tileh
Slope of the tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
BuildingCounts< uint16 > building_counts
The number of each type of building in the town.
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
PalSpriteID ground
Palette and sprite for the ground.
HouseExtraFlags extra_flags
some more flags
@ CBM_HOUSE_ANIMATION_NEXT_FRAME
decides next animation frame
@ CBID_HOUSE_COLOUR
Called to determine the colour of a town building.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
int16 y
The y value of the coordinate.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
@ CBID_HOUSE_DESTRUCTION
Called periodically to determine if a house should be destroyed.
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
HouseID house_id
Type of house being queried.
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
static const HouseID NUM_HOUSES
Total number of houses.
@ GES_EVER_ACCEPTED
Set when a vehicle ever delivered cargo to the station for final delivery.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
bool not_yet_constructed
True for construction check.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
@ GES_ACCEPTED_BIGTICK
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
@ CBID_HOUSE_CONSTRUCTION_STATE_CHANGE
Called whenever the construction state of a house changes.
uint8 class_id
The class id within the grf file.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
HouseCallbackMask
Callback masks for houses.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
@ CBM_HOUSE_COLOUR
decide the colour of the building
@ CBM_HOUSE_ANIMATION_SPEED
decides animation speed
uint16 callback_mask
Bitmask of house callbacks that have to be called.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Helper class for animation control.
@ SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
Ground palette sprite of a tile, together with its sprite layout.
@ CBID_HOUSE_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
@ CBM_HOUSE_ANIMATION_START_STOP
periodically start/stop the animation
std::set< Station *, StationCompare > StationList
List of stations.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
TileIndex north_tile
Northern tile of the house.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
A pair-construct of a TileIndexDiff.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
bool _generating_world
Whether we are generating the map or not.
@ BUILDING_IS_PROTECTED
towns and AI will not remove this house, while human players will be able to
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
uint16 HouseID
OpenTTD ID of house types.
CompanyID _current_company
Company currently doing an action.
@ SYNCHRONISED_CALLBACK_1B
synchronized callback 1B will be performed, on multi tile houses
uint16 initial_random_bits
Random bits during construction checks.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
Callback function to search a house by its classID.
static void SetHouseTriggers(TileIndex t, byte triggers)
Set the activated triggers bits for this house.
static byte GetHouseBuildingStage(TileIndex t)
House Construction Scheme.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
uint32 PaletteID
The number of the palette.
@ CBM_HOUSE_DENY_DESTRUCTION
conditional protection
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ OWNER_NONE
The tile has no ownership.
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
CargoTypes watched_cargoes
Cargo types watched for acceptance.
TownCache cache
Container for all cacheable data.
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
HouseClassID class_id
defines the class this house has (not grf file based)
static uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town, CallbackID callback=CBID_NO_CALLBACK, uint32 param1=0, uint32 param2=0, bool not_yet_constructed=false, uint8 initial_random_bits=0, CargoTypes watched_cargo_triggers=0)
Construct a resolver for a house.
byte processing_time
Periodic refresh multiplier.
uint16 HouseClassID
Classes of houses.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
TileIndex tile
Tile of this house.
Helper class for a unified approach to NewGRF animation.
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16 random)
Run the watched cargo accepted callback for a single house tile.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#define lengthof(x)
Return the length of an fixed size array.
static void SetHouseRandomBits(TileIndex t, byte random)
Set the random bits for this house.
byte CargoID
Cargo slots to indicate a cargo type within a game.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
uint32 GetGRFID(uint16 entity_id) const
Gives the GRFID of the file the entity belongs to.
uint16 local_id
id defined by the grf file for this entity
PaletteID pal
The palette (use PAL_NONE) if not needed)
TileIndex tile
Tile index.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
static void DecHouseProcessingTime(TileIndex t)
Decrease the amount of time remaining before the tile loop processes this tile.
ResolverObject & ro
Surrounding resolver object.
@ CBM_HOUSE_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
const struct GRFFile * grffile
grf file that introduced this entity
void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
static void SetHouseProcessingTime(TileIndex t, byte time)
Set the amount of time remaining before the tile loop processes this tile.
static byte GetHouseTriggers(TileIndex t)
Get the already activated triggers bits for this house.
@ CT_INVALID
Invalid cargo type.
@ OWNER_WATER
The tile/execution is done by "water".
@ CBID_HOUSE_DENY_DESTRUCTION
Called to determine whether a town building can be destroyed.
static uint32 GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
Get information about a nearby tile.
GRFFileProps grf_prop
Properties related the the grf file.
@ CBID_HOUSE_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
Dynamic data of a loaded NewGRF.
Makes class IDs unique to each GRF file.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
static byte GetHouseRandomBits(TileIndex t)
Get the random bits for this house.
int16 x
The x value of the coordinate.