Update: Translations from eints
[openttd-github.git] / src / newgrf_house.h
blob954417b7a7e523c9ae3dfc1f0aaaa88bb217fb3a
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file newgrf_house.h Functions related to NewGRF houses. */
10 #ifndef NEWGRF_HOUSE_H
11 #define NEWGRF_HOUSE_H
13 #include "newgrf_callbacks.h"
14 #include "tile_cmd.h"
15 #include "house_type.h"
16 #include "newgrf_spritegroup.h"
17 #include "newgrf_town.h"
19 /** Scope resolver for houses. */
20 struct HouseScopeResolver : public ScopeResolver {
21 HouseID house_id; ///< Type of house being queried.
22 TileIndex tile; ///< Tile of this house.
23 Town *town; ///< Town of this house.
24 bool not_yet_constructed; ///< True for construction check.
25 uint16_t initial_random_bits; ///< Random bits during construction checks.
26 CargoTypes watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback.
27 int view; ///< View when house does yet exist.
29 /**
30 * Constructor of a house scope resolver.
31 * @param ro Surrounding resolver.
32 * @param house_id House type being queried.
33 * @param tile %Tile containing the house.
34 * @param town %Town containing the house.
35 * @param not_yet_constructed House is still under construction.
36 * @param initial_random_bits Random bits during construction checks.
37 * @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
39 HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
40 bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
41 : ScopeResolver(ro), house_id(house_id), tile(tile), town(town), not_yet_constructed(not_yet_constructed),
42 initial_random_bits(initial_random_bits), watched_cargo_triggers(watched_cargo_triggers), view(view)
46 uint32_t GetRandomBits() const override;
47 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
48 uint32_t GetTriggers() const override;
51 /** Resolver object to be used for houses (feature 07 spritegroups). */
52 struct HouseResolverObject : public ResolverObject {
53 HouseScopeResolver house_scope;
54 TownScopeResolver town_scope;
56 HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
57 CallbackID callback = CBID_NO_CALLBACK, uint32_t param1 = 0, uint32_t param2 = 0,
58 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0, int view = 0);
60 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
62 switch (scope) {
63 case VSG_SCOPE_SELF: return &this->house_scope;
64 case VSG_SCOPE_PARENT: return &this->town_scope;
65 default: return ResolverObject::GetScope(scope, relative);
69 GrfSpecFeature GetFeature() const override;
70 uint32_t GetDebugID() const override;
73 /**
74 * Makes class IDs unique to each GRF file.
75 * Houses can be assigned class IDs which are only comparable within the GRF
76 * file they were defined in. This mapping ensures that if two houses have the
77 * same class as defined by the GRF file, the classes are different within the
78 * game. An array of HouseClassMapping structs is created, and the array index
79 * of the struct that matches both the GRF ID and the class ID is the class ID
80 * used in the game.
82 * Although similar to the HouseIDMapping struct above, this serves a different
83 * purpose. Since the class ID is not saved anywhere, this mapping does not
84 * need to be persistent; it just needs to keep class ids unique.
86 struct HouseClassMapping {
87 uint32_t grfid; ///< The GRF ID of the file this class belongs to
88 uint8_t class_id; ///< The class id within the grf file
91 void ResetHouseClassIDs();
92 HouseClassID AllocateHouseClassID(uint8_t grf_class_id, uint32_t grfid);
94 void InitializeBuildingCounts();
95 void InitializeBuildingCounts(Town *t);
96 void IncreaseBuildingCount(Town *t, HouseID house_id);
97 void DecreaseBuildingCount(Town *t, HouseID house_id);
98 std::span<const uint> GetBuildingHouseIDCounts();
100 void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
101 void AnimateNewHouseTile(TileIndex tile);
102 void AnimateNewHouseConstruction(TileIndex tile);
104 uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile,
105 bool not_yet_constructed = false, uint8_t initial_random_bits = 0, CargoTypes watched_cargo_triggers = 0, int view = 0);
106 void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes);
108 bool CanDeleteHouse(TileIndex tile);
110 bool NewHouseTileLoop(TileIndex tile);
112 enum HouseTrigger {
113 /* The tile of the house has been triggered during the tileloop. */
114 HOUSE_TRIGGER_TILE_LOOP = 0x01,
116 * The top tile of a (multitile) building has been triggered during and all
117 * the tileloop other tiles of the same building get the same random value.
119 HOUSE_TRIGGER_TILE_LOOP_TOP = 0x02,
121 void TriggerHouse(TileIndex t, HouseTrigger trigger);
123 #endif /* NEWGRF_HOUSE_H */