|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
28 static std::array<HouseClassMapping, HOUSE_CLASS_MAX> _class_mapping;
39 const HouseSpec *hs = HouseSpec::Get(house_id);
56 CallbackID callback, uint32_t param1, uint32_t param2,
57 bool not_yet_constructed, uint8_t 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 void ResetHouseClassIDs()
80 HouseClassID AllocateHouseClassID(
byte grf_class_id, uint32_t grfid)
83 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
94 return HOUSE_NO_CLASS;
97 void InitializeBuildingCounts()
99 memset(&_building_counts, 0,
sizeof(_building_counts));
102 memset(&t->cache.building_counts, 0,
sizeof(t->cache.building_counts));
117 _building_counts.id_count[house_id]++;
119 if (class_id == HOUSE_NO_CLASS)
return;
122 _building_counts.class_count[class_id]++;
136 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
138 if (class_id == HOUSE_NO_CLASS)
return;
141 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
158 static uint32_t GetNumHouses(
HouseID house_id,
const Town *town)
162 uint8_t map_id_count = ClampTo<uint8_t>(_building_counts.id_count[house_id]);
163 uint8_t map_class_count = ClampTo<uint8_t>(_building_counts.class_count[class_id]);
167 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
199 const HouseSpec *hs = HouseSpec::Get(house);
204 if (north_tile == nbhd->
north_tile)
return false;
223 const HouseSpec *hs = HouseSpec::Get(house);
228 if (north_tile == nbhd->
north_tile)
return false;
247 const HouseSpec *hs = HouseSpec::Get(house);
252 if (north_tile == nbhd->
north_tile)
return false;
278 uint8_t searchtype =
GB(parameter, 6, 2);
279 uint8_t searchradius =
GB(parameter, 0, 6);
280 if (searchtype >=
lengthof(search_procs))
return 0;
281 if (searchradius < 1)
return 0;
284 nbhd.
hs = HouseSpec::Get(house);
288 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
313 case 0x44:
return GetNumHouses(this->
house_id, this->
town);
333 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->
town);
381 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
384 if (hs->
class_id != HOUSE_NO_CLASS) {
386 houseclass |= _class_mapping[hs->
class_id].class_id;
389 uint local_houseid = 0;
391 local_houseid = nearby_house_id;
396 return houseclass << 16 | local_houseid;
411 Debug(grf, 1,
"Unhandled house variable 0x{:X}", variable);
418 bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers)
423 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
424 return object.ResolveCallback();
431 const HouseSpec *hs = HouseSpec::Get(house_id);
437 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
456 const HouseSpec *hs = HouseSpec::Get(house_id);
459 bool draw_old_one =
true;
472 if (group !=
nullptr && group->type == SGT_TILELAYOUT) {
481 uint16_t GetSimpleHouseCallback(
CallbackID callback, uint32_t param1, uint32_t param2,
const HouseSpec *spec,
Town *town,
TileIndex tile, CargoTypes extra_data)
483 return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
498 if (hs ==
nullptr)
return;
503 void AnimateNewHouseConstruction(
TileIndex tile)
530 static void AnimationControl(
TileIndex tile, uint16_t random_bits)
549 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
550 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
558 uint16_t random =
GB(Random(), 0, 16);
560 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
565 AnimationControl(tile, 0);
583 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger,
byte base_random,
bool first)
598 if (group ==
nullptr)
return;
604 byte new_random_bits = Random();
606 uint32_t reseed =
object.GetReseedSum();
607 random_bits &= ~reseed;
608 random_bits |= (first ? new_random_bits : base_random) & reseed;
612 case HOUSE_TRIGGER_TILE_LOOP:
616 case HOUSE_TRIGGER_TILE_LOOP_TOP:
630 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
632 DoTriggerHouse(t, trigger, 0,
true);
645 uint32_t cb_info = random << 16 | (uint8_t)diff.
y << 8 | (uint8_t)diff.
x;
659 const HouseSpec *hs = HouseSpec::Get(
id);
663 if (trigger_cargoes == 0)
return;
666 uint16_t r = Random();
670 hs = HouseSpec::Get(
id);
byte GetHouseRandomBits(Tile t)
Get the random bits for this house.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ MP_HOUSE
A house by a town.
Structure with user-data for SearchNearbyHouseXXX - functions.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
Callback function to search a house by its HouseID.
uint32_t GetGRFID(uint16_t entity_id) const
Gives the GRFID of the file the entity belongs to.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Town * town
Town of this house.
Structure contains cached list of stations nearby.
@ TO_HOUSES
town buildings
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
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
void SetHouseTriggers(Tile t, byte triggers)
Set the activated triggers bits for this house.
uint16_t initial_random_bits
Random bits during construction checks.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
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 TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
Interface for SpriteGroup-s to access the gamestate.
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16_t random)
Run the watched cargo accepted callback for a single house tile.
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
@ CALLBACK_1A_RANDOM_BITS
callback 1A needs random bits
uint16_t callback_mask
Bitmask of house callbacks that have to be called.
void SetHouseRandomBits(Tile t, byte random)
Set the random bits for this house.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
int y
Y position of the tile in unit coordinates.
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
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
byte GetHouseTriggers(Tile t)
Get the already activated triggers bits for this house.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_HOUSE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for house tile.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
uint32_t PaletteID
The number of the palette.
@ CBM_HOUSE_CONSTRUCTION_STATE_CHANGE
change animation when construction state changes
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
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_t GetRandomBits() const override
Get a few random bits.
PalSpriteID ground
Palette and sprite for the ground.
HouseExtraFlags extra_flags
some more flags
TimerGameCalendar::Year GetHouseAge(Tile t)
Get the age of the house.
@ 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.
@ CBID_HOUSE_DESTRUCTION
Called periodically to determine if a house should be destroyed.
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.
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.
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.
uint16_t HouseClassID
Classes of houses.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
@ CBM_HOUSE_COLOUR
decide the colour of the building
@ CBM_HOUSE_ANIMATION_SPEED
decides animation speed
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.
static void ChangeAnimationFrame(CallbackID cb, const HouseSpec *spec, Town *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, CargoTypes extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
@ CBID_HOUSE_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
byte CargoID
Cargo slots to indicate a cargo type within a game.
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ CBM_HOUSE_ANIMATION_START_STOP
periodically start/stop the animation
std::set< Station *, StationCompare > StationList
List of stations.
TileIndex north_tile
Northern tile of the house.
uint16_t local_id
id defined by the grf file for this entity
bool IsValidTile(Tile tile)
Checks if a tile is valid.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
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.
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
void SetHouseProcessingTime(Tile t, byte time)
Set the amount of time remaining before the tile loop processes this tile.
@ BUILDING_IS_PROTECTED
towns and AI will not remove this house, while human players will be able to
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
CompanyID _current_company
Company currently doing an action.
@ SYNCHRONISED_CALLBACK_1B
synchronized callback 1B will be performed, on multi tile houses
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
BuildingCounts< uint16_t > building_counts
The number of each type of building in the town.
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
Callback function to search a house by its classID.
byte GetHouseBuildingStage(Tile t)
House Construction Scheme.
byte GetHouseProcessingTime(Tile t)
Get the amount of time remaining before the tile loop processes this tile.
uint32_t grfid
The GRF ID of the file this class belongs to.
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.
@ 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.
CargoTypes watched_cargoes
Cargo types watched for acceptance.
TownCache cache
Container for all cacheable data.
HouseClassID class_id
defines the class this house has (not grf file based)
uint16_t HouseID
OpenTTD ID of house types.
static void AnimateTile(const HouseSpec *spec, Town *obj, TileIndex tile, bool random_animation, CargoTypes extra_data=0)
Animate a single tile.
byte processing_time
Periodic refresh multiplier.
#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.
int16_t y
The y value of the coordinate.
Helper class for a unified approach to NewGRF animation.
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
#define lengthof(x)
Return the length of an fixed size array.
byte GetAnimationFrame(Tile t)
Get the current animation frame.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
uint8_t class_id
The class id within the grf file.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
int x
X position of the tile in unit coordinates.
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).
Colours random_colour[4]
4 "random" colours
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
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
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
void DecHouseProcessingTime(Tile t)
Decrease the amount of time remaining before the tile loop processes this tile.
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.
TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
const DrawTileSprites * ProcessRegisters(uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
@ OWNER_WATER
The tile/execution is done by "water".
@ CBID_HOUSE_DENY_DESTRUCTION
Called to determine whether a town building can be destroyed.
int16_t x
The x value of the coordinate.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
uint32_t GetTriggers() const override
Get the triggers.
GRFFileProps grf_prop
Properties related the the grf file.
void ClearTownHouse(Town *t, TileIndex tile)
Clear a town house.
@ CBID_HOUSE_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
static uint32_t GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
Get information about a nearby tile.
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.
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town, CallbackID callback=CBID_NO_CALLBACK, uint32_t param1=0, uint32_t param2=0, bool not_yet_constructed=false, uint8_t initial_random_bits=0, CargoTypes watched_cargo_triggers=0)
Construct a resolver for a house.
Dynamic data of a loaded NewGRF.
Makes class IDs unique to each GRF file.
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
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 requ...
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.