4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file newgrf_house.h Functions related to NewGRF houses. */
12 #ifndef NEWGRF_HOUSE_H
13 #define NEWGRF_HOUSE_H
15 #include "newgrf_callbacks.h"
17 #include "house_type.h"
18 #include "newgrf_spritegroup.h"
19 #include "newgrf_town.h"
21 /** Scope resolver for houses. */
22 struct HouseScopeResolver
: public ScopeResolver
{
23 HouseID house_id
; ///< Type of house being queried.
24 TileIndex tile
; ///< Tile of this house.
25 Town
*town
; ///< Town of this house.
26 bool not_yet_constructed
; ///< True for construction check.
27 uint16 initial_random_bits
; ///< Random bits during construction checks.
28 uint32 watched_cargo_triggers
; ///< Cargo types that triggered the watched cargo callback.
30 HouseScopeResolver(ResolverObject
&ro
, HouseID house_id
, TileIndex tile
, Town
*town
,
31 bool not_yet_constructed
, uint8 initial_random_bits
, uint32 watched_cargo_triggers
);
33 /* virtual */ uint32
GetRandomBits() const;
34 /* virtual */ uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
35 /* virtual */ uint32
GetTriggers() const;
38 /** Resolver object to be used for houses (feature 07 spritegroups). */
39 struct HouseResolverObject
: public ResolverObject
{
40 HouseScopeResolver house_scope
;
41 TownScopeResolver town_scope
;
43 HouseResolverObject(HouseID house_id
, TileIndex tile
, Town
*town
,
44 CallbackID callback
= CBID_NO_CALLBACK
, uint32 param1
= 0, uint32 param2
= 0,
45 bool not_yet_constructed
= false, uint8 initial_random_bits
= 0, uint32 watched_cargo_triggers
= 0);
47 /* virtual */ ScopeResolver
*GetScope(VarSpriteGroupScope scope
= VSG_SCOPE_SELF
, byte relative
= 0)
50 case VSG_SCOPE_SELF
: return &this->house_scope
;
51 case VSG_SCOPE_PARENT
: return &this->town_scope
;
52 default: return ResolverObject::GetScope(scope
, relative
);
58 * Makes class IDs unique to each GRF file.
59 * Houses can be assigned class IDs which are only comparable within the GRF
60 * file they were defined in. This mapping ensures that if two houses have the
61 * same class as defined by the GRF file, the classes are different within the
62 * game. An array of HouseClassMapping structs is created, and the array index
63 * of the struct that matches both the GRF ID and the class ID is the class ID
66 * Although similar to the HouseIDMapping struct above, this serves a different
67 * purpose. Since the class ID is not saved anywhere, this mapping does not
68 * need to be persistent; it just needs to keep class ids unique.
70 struct HouseClassMapping
{
71 uint32 grfid
; ///< The GRF ID of the file this class belongs to
72 uint8 class_id
; ///< The class id within the grf file
75 HouseClassID
AllocateHouseClassID(byte grf_class_id
, uint32 grfid
);
77 void InitializeBuildingCounts();
78 void IncreaseBuildingCount(Town
*t
, HouseID house_id
);
79 void DecreaseBuildingCount(Town
*t
, HouseID house_id
);
81 void DrawNewHouseTile(TileInfo
*ti
, HouseID house_id
);
82 void AnimateNewHouseTile(TileIndex tile
);
83 void AnimateNewHouseConstruction(TileIndex tile
);
85 uint16
GetHouseCallback(CallbackID callback
, uint32 param1
, uint32 param2
, HouseID house_id
, Town
*town
, TileIndex tile
,
86 bool not_yet_constructed
= false, uint8 initial_random_bits
= 0, uint32 watched_cargo_triggers
= 0);
87 void WatchedCargoCallback(TileIndex tile
, uint32 trigger_cargoes
);
89 bool CanDeleteHouse(TileIndex tile
);
91 bool NewHouseTileLoop(TileIndex tile
);
94 /* The tile of the house has been triggered during the tileloop. */
95 HOUSE_TRIGGER_TILE_LOOP
= 0x01,
97 * The top tile of a (multitile) building has been triggered during and all
98 * the tileloop other tiles of the same building get the same random value.
100 HOUSE_TRIGGER_TILE_LOOP_TOP
= 0x02,
102 void TriggerHouse(TileIndex t
, HouseTrigger trigger
);
104 #endif /* NEWGRF_HOUSE_H */