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)
65 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
68 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
79 return HOUSE_NO_CLASS;
82 void InitializeBuildingCounts()
84 memset(&_building_counts, 0,
sizeof(_building_counts));
87 memset(&t->cache.building_counts, 0,
sizeof(t->cache.building_counts));
104 _building_counts.id_count[house_id]++;
106 if (class_id == HOUSE_NO_CLASS)
return;
109 _building_counts.class_count[class_id]++;
125 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
127 if (class_id == HOUSE_NO_CLASS)
return;
130 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
137 return this->not_yet_constructed ? this->initial_random_bits :
GetHouseRandomBits(this->tile);
147 static uint32 GetNumHouses(
HouseID house_id,
const Town *town)
149 uint8 map_id_count, town_id_count, map_class_count, town_class_count;
152 map_id_count =
ClampU(_building_counts.id_count[house_id], 0, 255);
153 map_class_count =
ClampU(_building_counts.class_count[class_id], 0, 255);
157 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
189 const HouseSpec *hs = HouseSpec::Get(house);
194 if (north_tile == nbhd->
north_tile)
return false;
213 const HouseSpec *hs = HouseSpec::Get(house);
218 if (north_tile == nbhd->
north_tile)
return false;
237 const HouseSpec *hs = HouseSpec::Get(house);
242 if (north_tile == nbhd->
north_tile)
return false;
268 uint8 searchtype =
GB(parameter, 6, 2);
269 uint8 searchradius =
GB(parameter, 0, 6);
270 if (searchtype >=
lengthof(search_procs))
return 0;
271 if (searchradius < 1)
return 0;
274 nbhd.
hs = HouseSpec::Get(house);
278 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
303 case 0x44:
return GetNumHouses(this->house_id, this->town);
312 case 0x47:
return TileY(this->tile) << 16 |
TileX(this->tile);
315 case 0x60:
return parameter <
NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0;
319 const HouseSpec *hs = HouseSpec::Get(this->house_id);
323 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town);
358 if (
HasBit(this->watched_cargo_triggers, cid))
SetBit(res, 4);
371 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
374 if (hs->
class_id != HOUSE_NO_CLASS) {
379 uint local_houseid = 0;
381 local_houseid = nearby_house_id;
383 local_houseid = (hs->
grf_prop.
grffile == this->ro.grffile ? 1 : 2) << 8;
386 return houseclass << 16 | local_houseid;
397 return _house_mngr.
GetGRFID(house_id);
401 DEBUG(grf, 1,
"Unhandled house variable 0x%X", variable);
408 bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
413 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
414 return object.ResolveCallback();
421 const HouseSpec *hs = HouseSpec::Get(house_id);
427 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE :
callback;
446 const HouseSpec *hs = HouseSpec::Get(house_id);
449 bool draw_old_one =
true;
462 if (group !=
nullptr && group->type == SGT_TILELAYOUT) {
473 return GetHouseCallback(
callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
488 if (hs ==
nullptr)
return;
493 void AnimateNewHouseConstruction(
TileIndex tile)
520 static void AnimationControl(
TileIndex tile, uint16 random_bits)
539 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
540 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
548 uint16 random =
GB(Random(), 0, 16);
550 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
555 AnimationControl(tile, 0);
563 ClearTownHouse(Town::GetByTile(tile), tile);
573 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger, byte base_random,
bool first)
588 if (group ==
nullptr)
return;
594 byte new_random_bits = Random();
596 uint32
reseed =
object.GetReseedSum();
597 random_bits &= ~reseed;
598 random_bits |= (first ? new_random_bits : base_random) & reseed;
602 case HOUSE_TRIGGER_TILE_LOOP:
606 case HOUSE_TRIGGER_TILE_LOOP_TOP:
620 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
622 DoTriggerHouse(t, trigger, 0,
true);
635 uint32 cb_info = random << 16 | (uint8)diff.
y << 8 | (uint8)diff.
x;
649 const HouseSpec *hs = HouseSpec::Get(
id);
653 if (trigger_cargoes == 0)
return;
660 hs = HouseSpec::Get(
id);
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16 random)
Run the watched cargo accepted callback for a single house tile.
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.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
uint32 PaletteID
The number of the palette.
static Year GetHouseAge(TileIndex t)
Get the age of the house.
Definition of stuff that is very close to a company, like the company struct itself.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Tile information, used while rendering the tile.
static uint32 GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
Get information about a nearby tile.
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Structure with user-data for SearchNearbyHouseXXX - functions.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
synchronized callback 1B will be performed, on multi tile houses
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
Interface for SpriteGroup-s to access the gamestate.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
uint32 GetGRFID(uint16 entity_id) const
Gives the GRFID of the file the entity belongs to.
Slope tileh
Slope of the tile.
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval...
Called periodically to determine if a house should be destroyed.
Called to indicate how long the current animation frame should last.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
Callback function to search a house by its grfID.
Set when cargo was delivered for final delivery this month.
uint16 HouseClassID
Classes of houses.
Makes class IDs unique to each GRF file.
static uint TileX(TileIndex tile)
Get the X component of a tile.
static byte GetHouseRandomBits(TileIndex t)
Get the random bits for this house.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
change animation when construction state changes
Resolver object to be used for houses (feature 07 spritegroups).
Called to determine whether a town building can be destroyed.
Functions related to world/map generation.
uint32 reseed[VSG_END]
Collects bits to rerandomise while triggering triggers.
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.
uint16 callback_mask
Bitmask of house callbacks that have to be called.
uint16 HouseID
OpenTTD ID of house types.
std::set< Station *, StationCompare > StationList
List of stations.
static const HouseID NUM_HOUSES
Total number of houses.
static void AnimateTile(const HouseSpec *spec, Town *obj, TileIndex tile, bool random_animation, CargoTypes extra_data=0)
Animate a single tile.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
const HouseSpec * hs
Specs of the house that started the search.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Called to determine the type (if any) of foundation to draw for house tile.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
static byte GetHouseBuildingStage(TileIndex t)
House Construction Scheme.
int16 y
The y value of the coordinate.
Set when cargo was delivered for final delivery last month.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
Called to determine the colour of a town building.
static uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
uint x
X position of the tile in unit coordinates.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
The tile has no ownership.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
Called when a cargo type specified in property 20 is accepted.
TileIndex tile
Tile index.
The tile is leveled up to a flat slope.
HouseClassID class_id
defines the class this house has (not grf file based)
Ground palette sprite of a tile, together with its sprite layout.
static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
Callback function to search a house by its classID.
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
Functions related to NewGRF houses.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
trigger destruction of building
Definition of base types and functions in a cross-platform compatible way.
Function implementations related to NewGRF animation.
static void DecHouseProcessingTime(TileIndex t)
Decrease the amount of time remaining before the tile loop processes this tile.
byte processing_time
Periodic refresh multiplier.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
A number of safeguards to prevent using unsafe methods.
int16 x
The x value of the coordinate.
void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
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.
uint32 waiting_triggers
Waiting triggers to be used by any rerandomisation. (scope independent)
static void SetHouseRandomBits(TileIndex t, byte random)
Set the random bits for this house.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
uint y
Y position of the tile in unit coordinates.
decide the colour of the building
byte random_colour[4]
4 "random" colours
static byte GetHouseProcessingTime(TileIndex t)
Get the amount of time remaining before the tile loop processes this tile.
BuildingCounts< uint16 > building_counts
The number of each type of building in the town.
static void SetHouseProcessingTime(TileIndex t, byte time)
Set the amount of time remaining before the tile loop processes this tile.
TileIndex north_tile
Northern tile of the house.
Set when a sprite originates from an Action 1.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
decides next animation frame
#define lengthof(x)
Return the length of an fixed size array.
periodically start/stop the animation
number of bits for the sprite number
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Called whenever the construction state of a house changes.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
uint8 class_id
The class id within the grf file.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
bool has_newhouses
Set if there are any newhouses loaded.
#define DEBUG(name, level,...)
Output a line of debugging information.
A pair-construct of a TileIndexDiff.
Set when a vehicle ever delivered cargo to the station for final delivery.
The tile/execution is done by "water".
Functions related to companies.
PalSpriteID ground
Palette and sprite for the ground.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
bool _generating_world
Whether we are generating the map or not.
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
static byte GetHouseTriggers(TileIndex t)
Get the already activated triggers bits for this house.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
HouseExtraFlags extra_flags
some more flags
uint32 GetRandomBits() const override
Get a few random bits.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32 TileIndex
The index/ID of a Tile.
Helper class for a unified approach to NewGRF animation.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Cargo support for NewGRFs.
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...
uint32 GetRemainingTriggers() const
Returns the waiting triggers that did not trigger any rerandomisation.
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
Called for periodically starting or stopping the animation.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
towns and AI will not remove this house, while human players will be able to
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...
CallbackID callback
Callback being resolved.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
callback 1A needs random bits
TownCache cache
Container for all cacheable data.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Functions related to OTTD's landscape.
bool TestTileOnSearchProc(TileIndex tile, void *user_data)
A callback function type for searching tiles.
CompanyID _current_company
Company currently doing an action.
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 GetTriggers() const override
Get the triggers.
uint16 local_id
id defined by the grf file for this entity
decides if default foundations need to be drawn
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
GRFFileProps grf_prop
Properties related the the grf file.
Helper class for animation control.
const struct GRFFile * grffile
grf file that introduced this entity
CallbackID
List of implemented NewGRF callbacks.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Functions related to NewGRF provided sounds.
Set when calling a randomizing trigger (almost undocumented).
Functions to handle the town part of NewGRF towns.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
Callback function to search a house by its HouseID.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town...
Determine the next animation frame for a house.
static void SetHouseTriggers(TileIndex t, byte triggers)
Set the activated triggers bits for this house.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
SpriteID sprite
The 'real' sprite.
Structure contains cached list of stations nearby.
Base classes/functions for stations.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
uint32 grfid
The GRF ID of the file this class belongs to.
static TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
static const GRFFile * GetHouseSpecGrf(HouseID house_id)
Retrieve the grf file associated with a house.
Dynamic data of a loaded NewGRF.
PaletteID pal
The palette (use PAL_NONE) if not needed)
HouseCallbackMask
Callback masks for houses.