OpenTTD Source: src/newgrf_house.cpp Source File

OpenTTD Source 15.3

newgrf_house.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "debug.h"
12#include "landscape.h"
13#include "newgrf_badge.h"
14#include "newgrf_house.h"
15#include "newgrf_spritegroup.h"
16#include "newgrf_town.h"
17#include "newgrf_sound.h"
18#include "company_func.h"
19#include "company_base.h"
20#include "town.h"
21#include "genworld.h"
22#include "newgrf_animation_base.h"
23#include "newgrf_cargo.h"
24#include "station_base.h"
25
26#include "safeguards.h"
27
28static BuildingCounts<uint32_t> _building_counts{};
29static std::vector<HouseClassMapping> _class_mapping{};
30
31 HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID);
32
38 static const GRFFile *GetHouseSpecGrf(HouseID house_id)
39{
40 const HouseSpec *hs = HouseSpec::Get(house_id);
41 return (hs != nullptr) ? hs->grf_prop.grffile : nullptr;
42}
43
44extern const HouseSpec _original_house_specs[NEW_HOUSE_OFFSET];
45std::vector<HouseSpec> _house_specs;
46
51std::vector<HouseSpec> &HouseSpec::Specs()
52{
53 return _house_specs;
54}
55
60 HouseID HouseSpec::Index() const
61{
62 return static_cast<HouseID>(this - _house_specs.data());
63}
64
70 HouseSpec *HouseSpec::Get(size_t house_id)
71{
72 /* Empty house if index is out of range -- this might happen if NewGRFs are changed. */
73 static HouseSpec empty = {};
74
75 assert(house_id < NUM_HOUSES);
76 if (house_id >= _house_specs.size()) return &empty;
77 return &_house_specs[house_id];
78}
79
80/* Reset and initialise house specs. */
81void ResetHouses()
82{
83 _house_specs.clear();
84 _house_specs.reserve(std::size(_original_house_specs));
85
86 ResetHouseClassIDs();
87
88 /* Copy default houses. */
89 _house_specs.insert(std::end(_house_specs), std::begin(_original_house_specs), std::end(_original_house_specs));
90
91 /* Reset any overrides that have been set. */
92 _house_mngr.ResetOverride();
93}
94
107HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
108 CallbackID callback, uint32_t param1, uint32_t param2,
109 bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
110 : SpecializedResolverObject<HouseRandomTriggers>(GetHouseSpecGrf(house_id), callback, param1, param2),
111 house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers, view),
112 town_scope(*this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
113{
114 /* Tile must be valid and a house tile, unless not yet constructed in which case it may also be INVALID_TILE. */
115 assert((IsValidTile(tile) && (not_yet_constructed || IsTileType(tile, MP_HOUSE))) || (not_yet_constructed && tile == INVALID_TILE));
116
117 this->root_spritegroup = HouseSpec::Get(house_id)->grf_prop.GetSpriteGroup(!not_yet_constructed);
118}
119
120 GrfSpecFeature HouseResolverObject::GetFeature() const
121{
122 return GSF_HOUSES;
123}
124
125uint32_t HouseResolverObject::GetDebugID() const
126{
127 return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
128}
129
130void ResetHouseClassIDs()
131{
132 _class_mapping.clear();
133
134 /* Add initial entry for HOUSE_NO_CLASS. */
135 _class_mapping.emplace_back();
136}
137
138 HouseClassID AllocateHouseClassID(uint8_t grf_class_id, uint32_t grfid)
139{
140 /* Start from 1 because 0 means that no class has been assigned. */
141 auto it = std::find_if(std::next(std::begin(_class_mapping)), std::end(_class_mapping), [grf_class_id, grfid](const HouseClassMapping &map) { return map.class_id == grf_class_id && map.grfid == grfid; });
142
143 /* HouseClass not found, allocate a new one. */
144 if (it == std::end(_class_mapping)) it = _class_mapping.insert(it, {.grfid = grfid, .class_id = grf_class_id});
145
146 return static_cast<HouseClassID>(std::distance(std::begin(_class_mapping), it));
147}
148
153 void InitializeBuildingCounts(Town *t)
154{
155 t->cache.building_counts.id_count.clear();
156 t->cache.building_counts.class_count.clear();
157 t->cache.building_counts.id_count.resize(HouseSpec::Specs().size());
158 t->cache.building_counts.class_count.resize(_class_mapping.size());
159}
160
164 void InitializeBuildingCounts()
165{
166 _building_counts.id_count.clear();
167 _building_counts.class_count.clear();
168 _building_counts.id_count.resize(HouseSpec::Specs().size());
169 _building_counts.class_count.resize(_class_mapping.size());
170
171 for (Town *t : Town::Iterate()) {
172 InitializeBuildingCounts(t);
173 }
174}
175
180std::span<const uint> GetBuildingHouseIDCounts()
181{
182 return _building_counts.id_count;
183}
184
191 void IncreaseBuildingCount(Town *t, HouseID house_id)
192{
193 HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
194
195 t->cache.building_counts.id_count[house_id]++;
196 _building_counts.id_count[house_id]++;
197
198 if (class_id == HOUSE_NO_CLASS) return;
199
200 t->cache.building_counts.class_count[class_id]++;
201 _building_counts.class_count[class_id]++;
202}
203
210 void DecreaseBuildingCount(Town *t, HouseID house_id)
211{
212 HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
213
214 if (t->cache.building_counts.id_count[house_id] > 0) t->cache.building_counts.id_count[house_id]--;
215 if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
216
217 if (class_id == HOUSE_NO_CLASS) return;
218
219 if (t->cache.building_counts.class_count[class_id] > 0) t->cache.building_counts.class_count[class_id]--;
220 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
221}
222
223/* virtual */ uint32_t HouseScopeResolver::GetRandomBits() const
224{
225 /* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
226 return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile);
227}
228
229/* virtual */ uint32_t HouseScopeResolver::GetRandomTriggers() const
230{
231 /* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
232 return this->not_yet_constructed ? 0 : GetHouseRandomTriggers(this->tile).base();
233}
234
235static uint32_t GetNumHouses(HouseID house_id, const Town *town)
236{
237 HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
238
239 uint8_t map_id_count = ClampTo<uint8_t>(_building_counts.id_count[house_id]);
240 uint8_t map_class_count = ClampTo<uint8_t>(_building_counts.class_count[class_id]);
241 uint8_t town_id_count = ClampTo<uint8_t>(town->cache.building_counts.id_count[house_id]);
242 uint8_t town_class_count = ClampTo<uint8_t>(town->cache.building_counts.class_count[class_id]);
243
244 return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
245}
246
254 static uint32_t GetNearbyTileInformation(uint8_t parameter, TileIndex tile, bool grf_version8)
255{
256 tile = GetNearbyTile(parameter, tile);
257 return GetNearbyTileInformation(tile, grf_version8);
258}
259
270 static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex start_tile, HouseID start_house)
271{
272 uint8_t searchtype = GB(parameter, 6, 2);
273 uint8_t searchradius = GB(parameter, 0, 6);
274 if (searchradius < 1) return 0; // do not use a too low radius
275
276 const auto *start_hs = HouseSpec::Get(start_house);
277 const auto start_north_tile = start_tile + GetHouseNorthPart(start_house); // modifies 'start_house'!
278
279 for (auto tile : SpiralTileSequence(start_tile, 2 * searchradius + 1)) {
280 if (!IsTileType(tile, MP_HOUSE)) continue;
281 HouseID house = GetHouseType(tile);
282 const HouseSpec *hs = HouseSpec::Get(house);
283 if (!hs->grf_prop.HasGrfFile()) continue; // must be one from a grf file
284 if (start_north_tile == tile + GetHouseNorthPart(house)) continue; // Always ignore origin house
285
286 bool match;
287 switch (searchtype) {
288 case 0:
289 match = hs->grf_prop.local_id == start_hs->grf_prop.local_id && // same local id as the one requested
290 hs->grf_prop.grfid == start_hs->grf_prop.grfid; // from the same grf
291 break;
292 case 1:
293 match = hs->class_id == start_hs->class_id && // same classid as the one requested
294 hs->grf_prop.grfid == start_hs->grf_prop.grfid; // from the same grf
295 break;
296 case 2:
297 match = hs->grf_prop.grfid == start_hs->grf_prop.grfid; // from the same grf
298 break;
299 default:
300 return 0;
301 }
302 if (match) return DistanceManhattan(tile, start_tile);
303 }
304 return 0;
305}
306
310/* virtual */ uint32_t HouseScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
311{
312 if (this->tile == INVALID_TILE) {
313 /* House does not yet exist, nor is it being planned to exist. Provide some default values instead. */
314 switch (variable) {
315 case 0x40: return TOWN_HOUSE_COMPLETED | this->view << 2; /* Construction stage. */
316 case 0x41: return 0;
317 case 0x42: return 0;
318 case 0x43: return 0;
319 case 0x44: return 0;
320 case 0x45: return _generating_world ? 1 : 0;
321 case 0x46: return 0;
322 case 0x47: return 0;
323 case 0x60: return 0;
324 case 0x61: return 0;
325 case 0x62: return 0;
326 case 0x63: return 0;
327 case 0x64: return 0;
328 case 0x65: return 0;
329 case 0x66: return 0xFFFFFFFF; /* Class and ID of nearby house. */
330 case 0x67: return 0;
331
332 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter);
333 }
334
335 Debug(grf, 1, "Unhandled house variable 0x{:X}", variable);
336 available = false;
337 return UINT_MAX;
338 }
339
340 switch (variable) {
341 /* Construction stage. */
342 case 0x40: return (IsTileType(this->tile, MP_HOUSE) ? GetHouseBuildingStage(this->tile) : 0) | TileHash2Bit(TileX(this->tile), TileY(this->tile)) << 2;
343
344 /* Building age. */
345 case 0x41: return IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile).base() : 0;
346
347 /* Town zone */
348 case 0x42: return to_underlying(GetTownRadiusGroup(this->town, this->tile));
349
350 /* Terrain type */
351 case 0x43: return GetTerrainType(this->tile);
352
353 /* Number of this type of building on the map. */
354 case 0x44: return GetNumHouses(this->house_id, this->town);
355
356 /* Whether the town is being created or just expanded. */
357 case 0x45: return _generating_world ? 1 : 0;
358
359 /* Current animation frame. */
360 case 0x46: return IsTileType(this->tile, MP_HOUSE) ? GetAnimationFrame(this->tile) : 0;
361
362 /* Position of the house */
363 case 0x47: return TileY(this->tile) << 16 | TileX(this->tile);
364
365 /* Building counts for old houses with id = parameter. */
366 case 0x60: return parameter < NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0;
367
368 /* Building counts for new houses with id = parameter. */
369 case 0x61: {
370 const HouseSpec *hs = HouseSpec::Get(this->house_id);
371 if (!hs->grf_prop.HasGrfFile()) return 0;
372
373 HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grfid);
374 return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town);
375 }
376
377 /* Land info for nearby tiles. */
378 case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro.grffile->grf_version >= 8);
379
380 /* Current animation frame of nearby house tiles */
381 case 0x63: {
382 TileIndex testtile = GetNearbyTile(parameter, this->tile);
383 return IsTileType(testtile, MP_HOUSE) ? GetAnimationFrame(testtile) : 0;
384 }
385
386 /* Cargo acceptance history of nearby stations */
387 case 0x64: {
388 CargoType cargo_type = GetCargoTranslation(parameter, this->ro.grffile);
389 if (!IsValidCargoType(cargo_type)) return 0;
390
391 /* Extract tile offset. */
392 int8_t x_offs = GB(this->ro.GetRegister(0x100), 0, 8);
393 int8_t y_offs = GB(this->ro.GetRegister(0x100), 8, 8);
394 TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs));
395
396 StationFinder stations(TileArea(testtile, 1, 1));
397
398 /* Collect acceptance stats. */
399 uint32_t res = 0;
400 for (Station *st : stations.GetStations()) {
401 res |= st->goods[cargo_type].ConvertState();
402 }
403
404 /* Cargo triggered CB 148? */
405 if (HasBit(this->watched_cargo_triggers, cargo_type)) SetBit(res, 4);
406
407 return res;
408 }
409
410 /* Distance test for some house types */
411 case 0x65: return GetDistanceFromNearbyHouse(parameter, this->tile, this->house_id);
412
413 /* Class and ID of nearby house tile */
414 case 0x66: {
415 TileIndex testtile = GetNearbyTile(parameter, this->tile);
416 if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF;
417 HouseID nearby_house_id = GetHouseType(testtile);
418 HouseSpec *hs = HouseSpec::Get(nearby_house_id);
419 /* Information about the grf local classid if the house has a class */
420 uint houseclass = 0;
421 if (hs->class_id != HOUSE_NO_CLASS) {
422 houseclass = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
423 houseclass |= _class_mapping[hs->class_id].class_id;
424 }
425 /* old house type or grf-local houseid */
426 uint local_houseid = 0;
427 if (nearby_house_id < NEW_HOUSE_OFFSET) {
428 local_houseid = nearby_house_id;
429 } else {
430 local_houseid = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
431 local_houseid |= ClampTo<uint8_t>(hs->grf_prop.local_id); // Spec only allows 8 bits, so all local-ids above 254 are clamped.
432 }
433 return houseclass << 16 | local_houseid;
434 }
435
436 /* GRFID of nearby house tile */
437 case 0x67: {
438 TileIndex testtile = GetNearbyTile(parameter, this->tile);
439 if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF;
440 HouseID house_id = GetHouseType(testtile);
441 if (house_id < NEW_HOUSE_OFFSET) return 0;
442 /* Checking the grffile information via HouseSpec doesn't work
443 * in case the newgrf was removed. */
444 return _house_mngr.GetGRFID(house_id);
445 }
446
447 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter);
448 }
449
450 Debug(grf, 1, "Unhandled house variable 0x{:X}", variable);
451
452 available = false;
453 return UINT_MAX;
454}
455
456uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile, std::span<int32_t> regs100,
457 bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers, int view)
458{
459 HouseResolverObject object(house_id, tile, town, callback, param1, param2,
460 not_yet_constructed, initial_random_bits, watched_cargo_triggers, view);
461 return object.ResolveCallback(regs100);
462}
463
464static void DrawTileLayout(const TileInfo *ti, const DrawTileSpriteSpan &dts, uint8_t stage, HouseID house_id)
465{
466 const HouseSpec *hs = HouseSpec::Get(house_id);
467 PaletteID palette = GetColourPalette(hs->random_colour[TileHash2Bit(ti->x, ti->y)]);
468 if (hs->callback_mask.Test(HouseCallbackMask::Colour)) {
469 uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
470 if (callback != CALLBACK_FAILED) {
471 /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
472 palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
473 }
474 }
475
476 SpriteID image = dts.ground.sprite;
477 PaletteID pal = dts.ground.pal;
478
479 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
480 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
481
482 if (GB(image, 0, SPRITE_WIDTH) != 0) {
483 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
484 }
485
486 DrawNewGRFTileSeq(ti, &dts, TO_HOUSES, stage, palette);
487}
488
489void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
490{
491 const HouseSpec *hs = HouseSpec::Get(house_id);
492
493 if (ti->tileh != SLOPE_FLAT) {
494 bool draw_old_one = true;
495 if (hs->callback_mask.Test(HouseCallbackMask::DrawFoundations)) {
496 /* Called to determine the type (if any) of foundation to draw for the house tile */
497 uint32_t callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
498 if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res);
499 }
500
501 if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
502 }
503
504 HouseResolverObject object(house_id, ti->tile, Town::GetByTile(ti->tile));
505
506 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
507 if (group != nullptr) {
508 /* Limit the building stage to the number of stages supplied. */
509 uint8_t stage = GetHouseBuildingStage(ti->tile);
510 auto processor = group->ProcessRegisters(object, &stage);
511 auto dts = processor.GetLayout();
512 DrawTileLayout(ti, dts, stage, house_id);
513 }
514}
515
524 void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
525{
526 HouseResolverObject object(house_id, INVALID_TILE, nullptr, CBID_NO_CALLBACK, 0, 0, true, view);
527 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
528 if (group == nullptr) return;
529
530 uint8_t stage = TOWN_HOUSE_COMPLETED;
531 auto processor = group->ProcessRegisters(object, &stage);
532 auto dts = processor.GetLayout();
533
534 PaletteID palette = GetColourPalette(spec->random_colour[0]);
535 if (spec->callback_mask.Test(HouseCallbackMask::Colour)) {
536 uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, nullptr, INVALID_TILE, {}, true, view);
537 if (callback != CALLBACK_FAILED) {
538 /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
539 palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
540 }
541 }
542
543 SpriteID image = dts.ground.sprite;
544 PaletteID pal = dts.ground.pal;
545
546 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
547 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
548
549 if (GB(image, 0, SPRITE_WIDTH) != 0) {
550 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
551 }
552
553 DrawNewGRFTileSeqInGUI(x, y, &dts, stage, palette);
554}
555
556/* Simple wrapper for GetHouseCallback to keep the animation unified. */
557static uint16_t GetSimpleHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, const HouseSpec *spec, Town *town, TileIndex tile, CargoTypes extra_data)
558{
559 return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile, {}, false, 0, extra_data);
560}
561
563 struct HouseAnimationBase : public AnimationBase<HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback, TileAnimationFrameAnimationHelper<Town> > {
564 static constexpr CallbackID cb_animation_speed = CBID_HOUSE_ANIMATION_SPEED;
565 static constexpr CallbackID cb_animation_next_frame = CBID_HOUSE_ANIMATION_NEXT_FRAME;
566
567 static constexpr HouseCallbackMask cbm_animation_speed = HouseCallbackMask::AnimationSpeed;
568 static constexpr HouseCallbackMask cbm_animation_next_frame = HouseCallbackMask::AnimationNextFrame;
569};
570
571void AnimateNewHouseTile(TileIndex tile)
572{
573 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
574 if (hs == nullptr) return;
575
576 HouseAnimationBase::AnimateTile(hs, Town::GetByTile(tile), tile, hs->extra_flags.Test(HouseExtraFlag::Callback1ARandomBits));
577}
578
579void TriggerHouseAnimation_ConstructionStageChanged(TileIndex tile, bool first_call)
580{
581 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
582
583 if (hs->callback_mask.Test(HouseCallbackMask::AnimationTriggerConstructionStageChanged)) {
584 HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_TRIGGER_CONSTRUCTION_STAGE_CHANGED, hs, Town::GetByTile(tile), tile, Random(), first_call ? 1 : 0);
585 }
586}
587
588bool CanDeleteHouse(TileIndex tile)
589{
590 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
591
592 /* Humans are always allowed to remove buildings, as is water and disasters and
593 * anyone using the scenario editor. */
594 if (Company::IsValidHumanID(_current_company) || _current_company == OWNER_WATER || _current_company == OWNER_NONE || _game_mode == GM_EDITOR || _generating_world) {
595 return true;
596 }
597
598 if (hs->callback_mask.Test(HouseCallbackMask::DenyDestruction)) {
599 uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
600 return (callback_res == CALLBACK_FAILED || !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DENY_DESTRUCTION, callback_res));
601 } else {
602 return !IsHouseProtected(tile);
603 }
604}
605
612 static void TriggerHouseAnimation_TileLoop(TileIndex tile, bool sync, uint16_t random_bits)
613{
614 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
615
616 /* Check whether the matching trigger is enabled */
617 if (hs->callback_mask.Test(HouseCallbackMask::AnimationTriggerTileLoop) &&
618 hs->extra_flags.Test(HouseExtraFlag::SynchronisedCallback1B) == sync) {
619 uint32_t param = sync ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
620 HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_TRIGGER_TILE_LOOP, hs, Town::GetByTile(tile), tile, param, 0);
621 }
622}
623
624bool NewHouseTileLoop(TileIndex tile)
625{
626 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
627
628 if (GetHouseProcessingTime(tile) > 0) {
629 DecHouseProcessingTime(tile);
630 return true;
631 }
632
633 TriggerHouseRandomisation(tile, HouseRandomTrigger::TileLoop);
634 if (hs->building_flags.Any(BUILDING_HAS_1_TILE)) TriggerHouseRandomisation(tile, HouseRandomTrigger::TileLoopNorth);
635
636 /* Call the unsynchronized tile loop trigger */
637 TriggerHouseAnimation_TileLoop(tile, false, 0);
638
639 /* Call the synchronized tile loop trigger, if this is the north tile */
640 if (hs->building_flags.Any(BUILDING_HAS_1_TILE)) {
641 uint16_t random = GB(Random(), 0, 16);
642 TriggerHouseAnimation_TileLoop(tile, true, random);
643 if (hs->building_flags.Any(BUILDING_2_TILES_Y)) TriggerHouseAnimation_TileLoop(TileAddXY(tile, 0, 1), true, random);
644 if (hs->building_flags.Any(BUILDING_2_TILES_X)) TriggerHouseAnimation_TileLoop(TileAddXY(tile, 1, 0), true, random);
645 if (hs->building_flags.Any(BUILDING_HAS_4_TILES)) TriggerHouseAnimation_TileLoop(TileAddXY(tile, 1, 1), true, random);
646 }
647
648 /* Check callback 21, which determines if a house should be destroyed. */
649 if (hs->callback_mask.Test(HouseCallbackMask::Destruction)) {
650 uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
651 if (callback_res != CALLBACK_FAILED && Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DESTRUCTION, callback_res)) {
652 ClearTownHouse(Town::GetByTile(tile), tile);
653 return false;
654 }
655 }
656
657 SetHouseProcessingTime(tile, hs->processing_time);
658 MarkTileDirtyByTile(tile);
659 return true;
660}
661
662static void DoTriggerHouseRandomisation(TileIndex tile, HouseRandomTrigger trigger, uint8_t base_random, bool first)
663{
664 /* We can't trigger a non-existent building... */
665 assert(IsTileType(tile, MP_HOUSE));
666
667 HouseID hid = GetHouseType(tile);
668 HouseSpec *hs = HouseSpec::Get(hid);
669
670 if (!hs->grf_prop.HasSpriteGroups()) return;
671
672 HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
673 auto waiting_random_triggers = GetHouseRandomTriggers(tile);
674 waiting_random_triggers.Set(trigger);
675 SetHouseRandomTriggers(tile, waiting_random_triggers); // store now for var 5F
676 object.SetWaitingRandomTriggers(waiting_random_triggers);
677
678 object.ResolveRerandomisation();
679
680 /* Store remaining triggers. */
681 waiting_random_triggers.Reset(object.GetUsedRandomTriggers());
682 SetHouseRandomTriggers(tile, waiting_random_triggers);
683
684 /* Rerandomise bits. Scopes other than SELF are invalid for houses. For bug-to-bug-compatibility with TTDP we ignore the scope. */
685 uint8_t new_random_bits = Random();
686 uint8_t random_bits = GetHouseRandomBits(tile);
687 uint32_t reseed = object.GetReseedSum();
688 random_bits &= ~reseed;
689 random_bits |= (first ? new_random_bits : base_random) & reseed;
690 SetHouseRandomBits(tile, random_bits);
691
692 switch (trigger) {
693 case HouseRandomTrigger::TileLoop:
694 /* Random value already set. */
695 break;
696
697 case HouseRandomTrigger::TileLoopNorth:
698 if (!first) {
699 /* The top tile is marked dirty by the usual TileLoop */
700 MarkTileDirtyByTile(tile);
701 break;
702 }
703 /* Random value of first tile already set. */
704 if (hs->building_flags.Any(BUILDING_2_TILES_Y)) DoTriggerHouseRandomisation(TileAddXY(tile, 0, 1), trigger, random_bits, false);
705 if (hs->building_flags.Any(BUILDING_2_TILES_X)) DoTriggerHouseRandomisation(TileAddXY(tile, 1, 0), trigger, random_bits, false);
706 if (hs->building_flags.Any(BUILDING_HAS_4_TILES)) DoTriggerHouseRandomisation(TileAddXY(tile, 1, 1), trigger, random_bits, false);
707 break;
708 }
709}
710
711void TriggerHouseRandomisation(TileIndex t, HouseRandomTrigger trigger)
712{
713 DoTriggerHouseRandomisation(t, trigger, 0, true);
714}
715
723 static void DoTriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16_t random)
724{
725 TileIndexDiffC diff = TileIndexToTileIndexDiffC(origin, tile);
726 uint32_t cb_info = random << 16 | (uint8_t)diff.y << 8 | (uint8_t)diff.x;
727 HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_TRIGGER_WATCHED_CARGO_ACCEPTED, HouseSpec::Get(GetHouseType(tile)), Town::GetByTile(tile), tile, 0, cb_info, trigger_cargoes);
728}
729
736 void TriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, CargoTypes trigger_cargoes)
737{
738 assert(IsTileType(tile, MP_HOUSE));
739 HouseID id = GetHouseType(tile);
740 const HouseSpec *hs = HouseSpec::Get(id);
741
742 trigger_cargoes &= hs->watched_cargoes;
743 /* None of the trigger cargoes is watched? */
744 if (trigger_cargoes == 0) return;
745
746 /* Same random value for all tiles of a multi-tile house. */
747 uint16_t r = Random();
748
749 /* Do the callback, start at northern tile. */
750 TileIndex north = tile + GetHouseNorthPart(id);
751 hs = HouseSpec::Get(id);
752
753 DoTriggerHouseAnimation_WatchedCargoAccepted(north, tile, trigger_cargoes, r);
754 if (hs->building_flags.Any(BUILDING_2_TILES_Y)) DoTriggerHouseAnimation_WatchedCargoAccepted(TileAddXY(north, 0, 1), tile, trigger_cargoes, r);
755 if (hs->building_flags.Any(BUILDING_2_TILES_X)) DoTriggerHouseAnimation_WatchedCargoAccepted(TileAddXY(north, 1, 0), tile, trigger_cargoes, r);
756 if (hs->building_flags.Any(BUILDING_HAS_4_TILES)) DoTriggerHouseAnimation_WatchedCargoAccepted(TileAddXY(north, 1, 1), tile, trigger_cargoes, r);
757}
758
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::base
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
Definition base_bitset_type.hpp:219
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
HouseOverrideManager
Definition newgrf_commons.h:231
OverrideManagerBase::GetGRFID
uint32_t GetGRFID(uint16_t entity_id) const
Gives the GRFID of the file the entity belongs to.
Definition newgrf_commons.cpp:140
OverrideManagerBase::GetID
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
Definition newgrf_commons.cpp:91
OverrideManagerBase::ResetOverride
void ResetOverride()
Resets the override, which is used while initializing game.
Definition newgrf_commons.cpp:79
SpiralTileSequence
Generate TileIndices around a center tile or tile area, with increasing distance.
Definition tilearea_type.h:316
StationFinder
Structure contains cached list of stations nearby.
Definition station_type.h:137
StationFinder::GetStations
const StationList & GetStations()
Run a tile loop to find stations around a tile, on demand.
Definition station_cmd.cpp:4559
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
OWNER_WATER
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Definition company_type.h:27
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:74
genworld.h
Functions related to world/map generation.
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1034
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition viewport.cpp:2128
HouseExtraFlag::SynchronisedCallback1B
@ SynchronisedCallback1B
synchronized callback 1B will be performed, on multi tile houses
HouseExtraFlag::Callback1ARandomBits
@ Callback1ARandomBits
callback 1A needs random bits
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition house.h:29
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
TOWN_HOUSE_COMPLETED
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:25
HouseRandomTrigger
HouseRandomTrigger
Randomisation triggers for houses.
Definition house_type.h:21
HouseClassID
uint16_t HouseClassID
Classes of houses.
Definition house_type.h:16
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition landscape.cpp:429
landscape.h
Functions related to OTTD's landscape.
BorderFlag::Random
@ Random
Randomise borders.
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:169
TileAddXY
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:483
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:438
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:428
TileIndexToTileIndexDiffC
TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
Definition map_func.h:544
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_animation_base.h
Function implementations related to NewGRF animation.
GetBadgeVariableResult
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Definition newgrf_badge.cpp:225
newgrf_badge.h
Functions related to NewGRF badges.
StationCallbackMask::DrawTileLayout
@ DrawTileLayout
Use callback to select a tile layout to use when drawing.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_HOUSE_ANIMATION_TRIGGER_WATCHED_CARGO_ACCEPTED
@ CBID_HOUSE_ANIMATION_TRIGGER_WATCHED_CARGO_ACCEPTED
Called when a cargo type specified in property 20 is accepted.
Definition newgrf_callbacks.h:211
CBID_HOUSE_ANIMATION_TRIGGER_TILE_LOOP
@ CBID_HOUSE_ANIMATION_TRIGGER_TILE_LOOP
Called for periodically starting or stopping the animation.
Definition newgrf_callbacks.h:68
CBID_HOUSE_COLOUR
@ CBID_HOUSE_COLOUR
Called to determine the colour of a town building.
Definition newgrf_callbacks.h:77
CBID_HOUSE_DRAW_FOUNDATIONS
@ CBID_HOUSE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for house tile.
Definition newgrf_callbacks.h:229
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:24
CBID_HOUSE_ANIMATION_SPEED
@ CBID_HOUSE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition newgrf_callbacks.h:83
CBID_HOUSE_ANIMATION_NEXT_FRAME
@ CBID_HOUSE_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
Definition newgrf_callbacks.h:65
CBID_HOUSE_DENY_DESTRUCTION
@ CBID_HOUSE_DENY_DESTRUCTION
Called to determine whether a town building can be destroyed.
Definition newgrf_callbacks.h:196
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition newgrf_callbacks.h:27
CBID_HOUSE_ANIMATION_TRIGGER_CONSTRUCTION_STAGE_CHANGED
@ CBID_HOUSE_ANIMATION_TRIGGER_CONSTRUCTION_STAGE_CHANGED
Called whenever the construction stage of a house changes.
Definition newgrf_callbacks.h:71
CBID_HOUSE_DESTRUCTION
@ CBID_HOUSE_DESTRUCTION
Called periodically to determine if a house should be destroyed.
Definition newgrf_callbacks.h:86
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
HouseCallbackMask
HouseCallbackMask
Callback masks for houses.
Definition newgrf_callbacks.h:341
HouseCallbackMask::Destruction
@ Destruction
trigger destruction of building
HouseCallbackMask::DrawFoundations
@ DrawFoundations
decides if default foundations need to be drawn
HouseCallbackMask::AnimationNextFrame
@ AnimationNextFrame
decides next animation frame
HouseCallbackMask::DenyDestruction
@ DenyDestruction
conditional protection
HouseCallbackMask::AnimationSpeed
@ AnimationSpeed
decides animation speed
HouseCallbackMask::Colour
@ Colour
decide the colour of the building
HouseCallbackMask::AnimationTriggerConstructionStageChanged
@ AnimationTriggerConstructionStageChanged
change animation when construction stage changes
HouseCallbackMask::AnimationTriggerTileLoop
@ AnimationTriggerTileLoop
periodically start/stop the animation
GetCargoTranslation
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Definition newgrf_cargo.cpp:80
newgrf_cargo.h
Cargo support for NewGRFs.
Convert8bitBooleanCallback
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:562
GetNearbyTileInformation
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
Definition newgrf_commons.cpp:434
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:543
GetTerrainType
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 ...
Definition newgrf_commons.cpp:336
GetNearbyTile
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition newgrf_commons.cpp:411
DecreaseBuildingCount
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
Definition newgrf_house.cpp:210
IncreaseBuildingCount
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
Definition newgrf_house.cpp:191
DoTriggerHouseAnimation_WatchedCargoAccepted
static void DoTriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16_t random)
Run the watched cargo accepted callback for a single house tile.
Definition newgrf_house.cpp:723
TriggerHouseAnimation_TileLoop
static void TriggerHouseAnimation_TileLoop(TileIndex tile, bool sync, uint16_t random_bits)
Call the tile loop animation trigger for houses, if enabled.
Definition newgrf_house.cpp:612
GetBuildingHouseIDCounts
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
Definition newgrf_house.cpp:180
DrawNewHouseTileInGUI
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
Draw representation of a house tile for GUI purposes.
Definition newgrf_house.cpp:524
GetDistanceFromNearbyHouse
static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex start_tile, HouseID start_house)
This function will activate a search around a central tile, looking for some houses that fit the requ...
Definition newgrf_house.cpp:270
InitializeBuildingCounts
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
Definition newgrf_house.cpp:164
TriggerHouseAnimation_WatchedCargoAccepted
void TriggerHouseAnimation_WatchedCargoAccepted(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
Definition newgrf_house.cpp:736
GetHouseSpecGrf
static const GRFFile * GetHouseSpecGrf(HouseID house_id)
Retrieve the grf file associated with a house.
Definition newgrf_house.cpp:38
GetNearbyTileInformation
static uint32_t GetNearbyTileInformation(uint8_t parameter, TileIndex tile, bool grf_version8)
Get information about a nearby tile.
Definition newgrf_house.cpp:254
newgrf_house.h
Functions related to NewGRF houses.
newgrf_sound.h
Functions related to NewGRF provided sounds.
newgrf_spritegroup.h
Action 2 handling.
newgrf_town.h
Functions to handle the town part of NewGRF towns.
safeguards.h
A number of safeguards to prevent using unsafe methods.
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition slope_type.h:95
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
DrawNewGRFTileSeq
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition sprite.h:130
DrawNewGRFTileSeqInGUI
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:139
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:174
SPRITE_MODIFIER_CUSTOM_SPRITE
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Definition sprites.h:1559
SPRITE_WIDTH
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition sprites.h:1549
station_base.h
Base classes/functions for stations.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition newgrf_animation_base.h:43
AnimationBase< HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback, TileAnimationFrameAnimationHelper< Town > >::AnimateTile
static void AnimateTile(const HouseSpec *spec, Town *obj, TileIndex tile, bool random_animation, CargoTypes extra_data=0)
Animate a single tile.
Definition newgrf_animation_base.h:52
AnimationBase< HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback, TileAnimationFrameAnimationHelper< Town > >::ChangeAnimationFrame
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.
Definition newgrf_animation_base.h:131
BuildingCounts
Definition town.h:22
Company::IsValidHumanID
static bool IsValidHumanID(auto index)
Is this company a valid company, not controlled by a NoAI program?
Definition company_base.h:165
Coord3D::x
T x
X coordinate.
Definition geometry_type.hpp:44
Coord3D::y
T y
Y coordinate.
Definition geometry_type.hpp:45
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:326
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
HouseAnimationBase
Helper class for animation control.
Definition newgrf_house.cpp:563
HouseClassMapping
Makes class IDs unique to each GRF file.
Definition newgrf_house.h:86
HouseClassMapping::class_id
uint8_t class_id
The class id within the grf file.
Definition newgrf_house.h:88
HouseClassMapping::grfid
uint32_t grfid
The GRF ID of the file this class belongs to.
Definition newgrf_house.h:87
HouseResolverObject
Resolver object to be used for houses (feature 07 spritegroups).
Definition newgrf_house.h:52
HouseResolverObject::HouseResolverObject
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, int view=0)
Construct a resolver for a house.
Definition newgrf_house.cpp:107
HouseResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_house.cpp:125
HouseResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_house.cpp:120
HouseScopeResolver::view
int view
View when house does yet exist.
Definition newgrf_house.h:27
HouseScopeResolver::town
Town * town
Town of this house.
Definition newgrf_house.h:23
HouseScopeResolver::tile
TileIndex tile
Tile of this house.
Definition newgrf_house.h:22
HouseScopeResolver::watched_cargo_triggers
CargoTypes watched_cargo_triggers
Cargo types that triggered the watched cargo callback.
Definition newgrf_house.h:26
HouseScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Definition newgrf_house.cpp:310
HouseScopeResolver::initial_random_bits
uint16_t initial_random_bits
Random bits during construction checks.
Definition newgrf_house.h:25
HouseScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_house.cpp:223
HouseScopeResolver::house_id
HouseID house_id
Type of house being queried.
Definition newgrf_house.h:21
HouseScopeResolver::GetRandomTriggers
uint32_t GetRandomTriggers() const override
Get the triggers.
Definition newgrf_house.cpp:229
HouseScopeResolver::not_yet_constructed
bool not_yet_constructed
True for construction check.
Definition newgrf_house.h:24
HouseSpec
Definition house.h:98
HouseSpec::grf_prop
SubstituteGRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:114
HouseSpec::watched_cargoes
CargoTypes watched_cargoes
Cargo types watched for acceptance.
Definition house.h:123
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:70
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:109
HouseSpec::processing_time
uint8_t processing_time
Periodic refresh multiplier.
Definition house.h:121
HouseSpec::callback_mask
HouseCallbackMasks callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:115
HouseSpec::extra_flags
HouseExtraFlags extra_flags
some more flags
Definition house.h:118
HouseSpec::Index
HouseID Index() const
Gets the index of this spec.
Definition newgrf_house.cpp:60
HouseSpec::class_id
HouseClassID class_id
defines the class this house has (not grf file based)
Definition house.h:119
HouseSpec::random_colour
Colours random_colour[4]
4 "random" colours
Definition house.h:116
HouseSpec::Specs
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Definition newgrf_house.cpp:51
Map::WrapToMap
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
Definition map_func.h:329
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
Pool::PoolItem<&_town_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition newgrf_spritegroup.h:352
ResolverObject::GetRegister
int32_t GetRegister(uint i) const
Gets the value of a so-called newgrf "register".
Definition newgrf_spritegroup.h:324
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition newgrf_spritegroup.h:353
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
SpecializedResolverObject
Specialization of ResolverObject with type-safe access to RandomTriggers.
Definition newgrf_spritegroup.h:450
StandardGRFFileProps::GetSpriteGroup
const struct SpriteGroup * GetSpriteGroup(bool entity_exists) const
Get the standard sprite group.
Definition newgrf_commons.h:394
StandardGRFFileProps::HasSpriteGroups
bool HasSpriteGroups() const
Check whether the entity has sprite groups.
Definition newgrf_commons.h:385
Station
Station data structure.
Definition station_base.h:520
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
TileIndexDiffC::x
int16_t x
The x value of the coordinate.
Definition map_type.h:32
TileIndexDiffC::y
int16_t y
The y value of the coordinate.
Definition map_type.h:33
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:31
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition newgrf_spritegroup.h:236
TileLayoutSpriteGroup::ProcessRegisters
SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Definition newgrf_spritegroup.cpp:290
TownCache::building_counts
BuildingCounts< uint16_t > building_counts
The number of each type of building in the town.
Definition town.h:57
Town
Town data structure.
Definition town.h:63
Town::cache
TownCache cache
Container for all cacheable data.
Definition town.h:66
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
TileHash2Bit
uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
Definition tile_map.h:342
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition tile_type.h:51
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition tilearea_type.h:102
town.h
Base of the town class.
GetHouseNorthPart
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
Definition town_cmd.cpp:3025
ClearTownHouse
void ClearTownHouse(Town *t, TileIndex tile)
Clear a town house.
Definition town_cmd.cpp:3050
GetTownRadiusGroup
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition town_cmd.cpp:2516
GetHouseType
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
Definition town_map.h:60
SetHouseRandomBits
void SetHouseRandomBits(Tile t, uint8_t random)
Set the random bits for this house.
Definition town_map.h:284
GetHouseRandomBits
uint8_t GetHouseRandomBits(Tile t)
Get the random bits for this house.
Definition town_map.h:297
GetHouseAge
TimerGameCalendar::Year GetHouseAge(Tile t)
Get the age of the house.
Definition town_map.h:271
DecHouseProcessingTime
void DecHouseProcessingTime(Tile t)
Decrease the amount of time remaining before the tile loop processes this tile.
Definition town_map.h:358
GetHouseBuildingStage
uint8_t GetHouseBuildingStage(Tile t)
House Construction Scheme.
Definition town_map.h:205
SetHouseRandomTriggers
void SetHouseRandomTriggers(Tile t, HouseRandomTriggers triggers)
Set the activated triggers bits for this house.
Definition town_map.h:310
GetHouseRandomTriggers
HouseRandomTriggers GetHouseRandomTriggers(Tile t)
Get the already activated triggers bits for this house.
Definition town_map.h:323
SetHouseProcessingTime
void SetHouseProcessingTime(Tile t, uint8_t time)
Set the amount of time remaining before the tile loop processes this tile.
Definition town_map.h:347
IsHouseProtected
bool IsHouseProtected(Tile t)
Check if the house is protected from removal by towns.
Definition town_map.h:82
GetHouseProcessingTime
uint8_t GetHouseProcessingTime(Tile t)
Get the amount of time remaining before the tile loop processes this tile.
Definition town_map.h:335
TO_HOUSES
@ TO_HOUSES
town buildings
Definition transparency.h:26
DrawGroundSprite
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.
Definition viewport.cpp:579