41 const HouseSpec *hs = HouseSpec::Get(house_id);
58 CallbackID callback, uint32 param1, uint32 param2,
59 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
61 house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
62 town_scope(*this, town, not_yet_constructed)
67 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
70 for (
int i = 1; i !=
lengthof(_class_mapping); i++) {
81 return HOUSE_NO_CLASS;
84 void InitializeBuildingCounts()
86 memset(&_building_counts, 0,
sizeof(_building_counts));
107 _building_counts.id_count[house_id]++;
109 if (class_id == HOUSE_NO_CLASS)
return;
112 _building_counts.class_count[class_id]++;
128 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
130 if (class_id == HOUSE_NO_CLASS)
return;
133 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
140 return this->not_yet_constructed ? this->initial_random_bits :
GetHouseRandomBits(this->tile);
150 static uint32 GetNumHouses(
HouseID house_id,
const Town *town)
152 uint8 map_id_count, town_id_count, map_class_count, town_class_count;
155 map_id_count =
ClampU(_building_counts.id_count[house_id], 0, 255);
156 map_class_count =
ClampU(_building_counts.class_count[class_id], 0, 255);
160 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
192 const HouseSpec *hs = HouseSpec::Get(house);
197 if (north_tile == nbhd->
north_tile)
return false;
216 const HouseSpec *hs = HouseSpec::Get(house);
221 if (north_tile == nbhd->
north_tile)
return false;
240 const HouseSpec *hs = HouseSpec::Get(house);
245 if (north_tile == nbhd->
north_tile)
return false;
271 uint8 searchtype =
GB(parameter, 6, 2);
272 uint8 searchradius =
GB(parameter, 0, 6);
273 if (searchtype >=
lengthof(search_procs))
return 0;
274 if (searchradius < 1)
return 0;
277 nbhd.
hs = HouseSpec::Get(house);
281 if (
CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &nbhd)) {
306 case 0x44:
return GetNumHouses(this->house_id, this->town);
315 case 0x47:
return TileY(this->tile) << 16 |
TileX(this->tile);
318 case 0x60:
return parameter <
NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0;
322 const HouseSpec *hs = HouseSpec::Get(this->house_id);
326 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town);
353 for (
Station *
const * st_iter = sl->
Begin(); st_iter != sl->
End(); st_iter++) {
362 if (
HasBit(this->watched_cargo_triggers, cid))
SetBit(res, 4);
375 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
378 if (hs->
class_id != HOUSE_NO_CLASS) {
383 uint local_houseid = 0;
385 local_houseid = nearby_house_id;
387 local_houseid = (hs->
grf_prop.
grffile == this->ro.grffile ? 1 : 2) << 8;
390 return houseclass << 16 | local_houseid;
401 return _house_mngr.
GetGRFID(house_id);
405 DEBUG(grf, 1,
"Unhandled house variable 0x%X", variable);
412 bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
417 not_yet_constructed, initial_random_bits, watched_cargo_triggers);
418 return object.ResolveCallback();
425 const HouseSpec *hs = HouseSpec::Get(house_id);
431 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE :
callback;
450 const HouseSpec *hs = HouseSpec::Get(house_id);
453 bool draw_old_one =
true;
466 if (group != NULL && group->type == SGT_TILELAYOUT) {
477 return GetHouseCallback(
callback, param1, param2, spec - HouseSpec::Get(0), town, tile,
false, 0, extra_data);
492 if (hs == NULL)
return;
497 void AnimateNewHouseConstruction(
TileIndex tile)
524 static void AnimationControl(
TileIndex tile, uint16 random_bits)
543 TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP);
544 if (hs->
building_flags & BUILDING_HAS_1_TILE) TriggerHouse(tile, HOUSE_TRIGGER_TILE_LOOP_TOP);
552 uint16 random =
GB(Random(), 0, 16);
554 if (hs->
building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
559 AnimationControl(tile, 0);
567 ClearTownHouse(Town::GetByTile(tile), tile);
577 static void DoTriggerHouse(
TileIndex tile, HouseTrigger trigger, byte base_random,
bool first)
592 if (group == NULL)
return;
598 byte new_random_bits = Random();
600 uint32
reseed =
object.GetReseedSum();
601 random_bits &= ~reseed;
602 random_bits |= (first ? new_random_bits : base_random) & reseed;
606 case HOUSE_TRIGGER_TILE_LOOP:
610 case HOUSE_TRIGGER_TILE_LOOP_TOP:
624 void TriggerHouse(
TileIndex t, HouseTrigger trigger)
626 DoTriggerHouse(t, trigger, 0,
true);
639 uint32 cb_info = random << 16 | (uint8)diff.
y << 8 | (uint8)diff.
x;
653 const HouseSpec *hs = HouseSpec::Get(
id);
657 if (trigger_cargoes == 0)
return;
664 hs = HouseSpec::Get(
id);
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.
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.
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, uint32 watched_cargo_triggers=0)
Construct a resolver for a house.
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.
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.
uint32 GetRandomBits() const
Get a few random bits.
static byte GetHouseRandomBits(TileIndex t)
Get the random bits for this house.
const T * Begin() const
Get the pointer to the first item (const)
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, uint32 trigger_cargoes, uint16 random)
Run the watched cargo accepted callback for a single house tile.
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, uint32 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.
const T * End() const
Get the pointer behind the last valid item (const)
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static const HouseID NUM_HOUSES
Total number of houses.
static void AnimateTile(const HouseSpec *spec, Town *obj, TileIndex tile, bool random_animation, uint32 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".
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 give 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
byte status
Status of this cargo, see GoodsEntryStatus.
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.
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.
uint32 GetTriggers() const
Get the triggers.
The tile has no ownership.
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.
uint32 watched_cargoes
Cargo types watched for acceptance.
#define DEBUG(name, level,...)
Output a line of debugging information.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
A pair-construct of a TileIndexDiff.
Set when a vehicle ever delivered cargo to the station for final delivery.
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.
HouseExtraFlags extra_flags
some more flags
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
CompanyByte _current_company
Company currently doing an action.
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.
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.
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.
The tile/execution is done by "water".
#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.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
static const GRFFile * GetHouseSpecGrf(HouseID house_id)
Retrieve the grf file associated with a house.
Dynamic data of a loaded NewGRF.
void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes)
Run watched cargo accepted callback for a house.
PaletteID pal
The palette (use PAL_NONE) if not needed)
HouseCallbackMask
Callback masks for houses.