OpenTTD Source: src/newgrf_commons.cpp Source File

OpenTTD Source 15.0-RC2

newgrf_commons.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
13#include "stdafx.h"
14#include "debug.h"
15#include "landscape.h"
16#include "house.h"
17#include "industrytype.h"
18#include "newgrf_config.h"
19#include "company_func.h"
20#include "clear_map.h"
21#include "station_map.h"
22#include "tree_map.h"
23#include "tunnelbridge_map.h"
24#include "newgrf_object.h"
25#include "genworld.h"
26#include "newgrf_spritegroup.h"
27#include "newgrf_text.h"
28#include "company_base.h"
29#include "error.h"
30#include "strings_func.h"
31#include "string_func.h"
32
33#include "table/strings.h"
34
35#include "safeguards.h"
36
43OverrideManagerBase::OverrideManagerBase(uint16_t offset, uint16_t maximum, uint16_t invalid)
44{
45 this->max_offset = offset;
46 this->max_entities = maximum;
47 this->invalid_id = invalid;
48
49 this->mappings.resize(this->max_entities);
50 this->entity_overrides.resize(this->max_offset);
51 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
52 this->grfid_overrides.resize(this->max_offset);
53}
54
63 void OverrideManagerBase::Add(uint16_t local_id, uint32_t grfid, uint entity_type)
64{
65 assert(entity_type < this->max_offset);
66 /* An override can be set only once */
67 if (this->entity_overrides[entity_type] != this->invalid_id) return;
68 this->entity_overrides[entity_type] = local_id;
69 this->grfid_overrides[entity_type] = grfid;
70}
71
73 void OverrideManagerBase::ResetMapping()
74{
75 std::fill(this->mappings.begin(), this->mappings.end(), EntityIDMapping{});
76}
77
79 void OverrideManagerBase::ResetOverride()
80{
81 std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_id);
82 std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32_t());
83}
84
91uint16_t OverrideManagerBase::GetID(uint16_t grf_local_id, uint32_t grfid) const
92{
93 for (uint16_t id = 0; id < this->max_entities; id++) {
94 const EntityIDMapping *map = &this->mappings[id];
95 if (map->entity_id == grf_local_id && map->grfid == grfid) {
96 return id;
97 }
98 }
99
100 return this->invalid_id;
101}
102
110uint16_t OverrideManagerBase::AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
111{
112 uint16_t id = this->GetID(grf_local_id, grfid);
113
114 /* Look to see if this entity has already been added. This is done
115 * separately from the loop below in case a GRF has been deleted, and there
116 * are any gaps in the array.
117 */
118 if (id != this->invalid_id) return id;
119
120 /* This entity hasn't been defined before, so give it an ID now. */
121 for (id = this->max_offset; id < this->max_entities; id++) {
122 EntityIDMapping *map = &this->mappings[id];
123
124 if (CheckValidNewID(id) && map->entity_id == 0 && map->grfid == 0) {
125 map->entity_id = grf_local_id;
126 map->grfid = grfid;
127 map->substitute_id = substitute_id;
128 return id;
129 }
130 }
131
132 return this->invalid_id;
133}
134
140uint32_t OverrideManagerBase::GetGRFID(uint16_t entity_id) const
141{
142 return this->mappings[entity_id].grfid;
143}
144
150uint16_t OverrideManagerBase::GetSubstituteID(uint16_t entity_id) const
151{
152 return this->mappings[entity_id].substitute_id;
153}
154
160 void HouseOverrideManager::SetEntitySpec(HouseSpec &&hs)
161{
162 HouseID house_id = this->AddEntityID(hs.grf_prop.local_id, hs.grf_prop.grfid, hs.grf_prop.subst_id);
163
164 if (house_id == this->invalid_id) {
165 GrfMsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
166 return;
167 }
168
169 auto &house_specs = HouseSpec::Specs();
170
171 /* Now that we know we can use the given id, copy the spec to its final destination. */
172 if (house_id >= house_specs.size()) house_specs.resize(house_id + 1);
173 house_specs[house_id] = std::move(hs);
174
175 /* Now add the overrides. */
176 for (int i = 0; i < this->max_offset; i++) {
177 HouseSpec *overridden_hs = HouseSpec::Get(i);
178
179 if (this->entity_overrides[i] != house_specs[house_id].grf_prop.local_id || this->grfid_overrides[i] != house_specs[house_id].grf_prop.grfid) continue;
180
181 overridden_hs->grf_prop.override_id = house_id;
182 this->entity_overrides[i] = this->invalid_id;
183 this->grfid_overrides[i] = 0;
184 }
185}
186
193uint16_t IndustryOverrideManager::GetID(uint16_t grf_local_id, uint32_t grfid) const
194{
195 uint16_t id = OverrideManagerBase::GetID(grf_local_id, grfid);
196 if (id != this->invalid_id) return id;
197
198 /* No mapping found, try the overrides */
199 for (id = 0; id < this->max_offset; id++) {
200 if (this->entity_overrides[id] == grf_local_id && this->grfid_overrides[id] == grfid) return id;
201 }
202
203 return this->invalid_id;
204}
205
213uint16_t IndustryOverrideManager::AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
214{
215 /* This entity hasn't been defined before, so give it an ID now. */
216 for (uint16_t id = 0; id < this->max_entities; id++) {
217 /* Skip overridden industries */
218 if (id < this->max_offset && this->entity_overrides[id] != this->invalid_id) continue;
219
220 /* Get the real live industry */
221 const IndustrySpec *inds = GetIndustrySpec(id);
222
223 /* This industry must be one that is not available(enabled), mostly because of climate.
224 * And it must not already be used by a grf (grffile == nullptr).
225 * So reserve this slot here, as it is the chosen one */
226 if (!inds->enabled && !inds->grf_prop.HasGrfFile()) {
227 EntityIDMapping *map = &this->mappings[id];
228
229 if (map->entity_id == 0 && map->grfid == 0) {
230 /* winning slot, mark it as been used */
231 map->entity_id = grf_local_id;
232 map->grfid = grfid;
233 map->substitute_id = substitute_id;
234 return id;
235 }
236 }
237 }
238
239 return this->invalid_id;
240}
241
248 void IndustryOverrideManager::SetEntitySpec(IndustrySpec &&inds)
249{
250 /* First step : We need to find if this industry is already specified in the savegame data. */
251 IndustryType ind_id = this->GetID(inds.grf_prop.local_id, inds.grf_prop.grfid);
252
253 if (ind_id == this->invalid_id) {
254 /* Not found.
255 * Or it has already been overridden, so you've lost your place.
256 * Or it is a simple substitute.
257 * We need to find a free available slot */
258 ind_id = this->AddEntityID(inds.grf_prop.local_id, inds.grf_prop.grfid, inds.grf_prop.subst_id);
259 inds.grf_prop.override_id = this->invalid_id; // make sure it will not be detected as overridden
260 }
261
262 if (ind_id == this->invalid_id) {
263 GrfMsg(1, "Industry.SetEntitySpec: Too many industries allocated. Ignoring.");
264 return;
265 }
266
267 /* Now that we know we can use the given id, copy the spec to its final destination... */
268 _industry_specs[ind_id] = std::move(inds);
269 /* ... and mark it as usable*/
270 _industry_specs[ind_id].enabled = true;
271}
272
273void IndustryTileOverrideManager::SetEntitySpec(IndustryTileSpec &&its)
274{
275 IndustryGfx indt_id = this->AddEntityID(its.grf_prop.local_id, its.grf_prop.grfid, its.grf_prop.subst_id);
276
277 if (indt_id == this->invalid_id) {
278 GrfMsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
279 return;
280 }
281
282 _industry_tile_specs[indt_id] = std::move(its);
283
284 /* Now add the overrides. */
285 for (int i = 0; i < this->max_offset; i++) {
286 IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
287
288 if (this->entity_overrides[i] != _industry_tile_specs[indt_id].grf_prop.local_id || this->grfid_overrides[i] != _industry_tile_specs[indt_id].grf_prop.grfid) continue;
289
290 overridden_its->grf_prop.override_id = indt_id;
291 overridden_its->enabled = false;
292 this->entity_overrides[i] = this->invalid_id;
293 this->grfid_overrides[i] = 0;
294 }
295}
296
303 void ObjectOverrideManager::SetEntitySpec(ObjectSpec &&spec)
304{
305 /* First step : We need to find if this object is already specified in the savegame data. */
306 ObjectType type = this->GetID(spec.grf_prop.local_id, spec.grf_prop.grfid);
307
308 if (type == this->invalid_id) {
309 /* Not found.
310 * Or it has already been overridden, so you've lost your place.
311 * Or it is a simple substitute.
312 * We need to find a free available slot */
313 type = this->AddEntityID(spec.grf_prop.local_id, spec.grf_prop.grfid, OBJECT_TRANSMITTER);
314 }
315
316 if (type == this->invalid_id) {
317 GrfMsg(1, "Object.SetEntitySpec: Too many objects allocated. Ignoring.");
318 return;
319 }
320
321 extern std::vector<ObjectSpec> _object_specs;
322
323 /* Now that we know we can use the given id, copy the spec to its final destination. */
324 if (type >= _object_specs.size()) _object_specs.resize(type + 1);
325 _object_specs[type] = std::move(spec);
326}
327
336uint32_t GetTerrainType(TileIndex tile, TileContext context)
337{
338 switch (_settings_game.game_creation.landscape) {
339 case LandscapeType::Tropic: return GetTropicZone(tile);
340 case LandscapeType::Arctic: {
341 bool has_snow;
342 switch (GetTileType(tile)) {
343 case MP_CLEAR:
344 /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
345 if (_generating_world) goto genworld;
346 has_snow = IsSnowTile(tile) && GetClearDensity(tile) >= 2;
347 break;
348
349 case MP_RAILWAY: {
350 /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
351 if (_generating_world) goto genworld; // we do not care about foundations here
352 RailGroundType ground = GetRailGroundType(tile);
353 has_snow = (ground == RailGroundType::SnowOrDesert || (context == TCX_UPPER_HALFTILE && ground == RailGroundType::HalfTileSnow));
354 break;
355 }
356
357 case MP_ROAD:
358 /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
359 if (_generating_world) goto genworld; // we do not care about foundations here
360 has_snow = IsOnSnowOrDesert(tile);
361 break;
362
363 case MP_TREES: {
364 /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
365 if (_generating_world) goto genworld;
366 TreeGround ground = GetTreeGround(tile);
367 has_snow = (ground == TREE_GROUND_SNOW_DESERT || ground == TREE_GROUND_ROUGH_SNOW) && GetTreeDensity(tile) >= 2;
368 break;
369 }
370
371 case MP_TUNNELBRIDGE:
372 if (context == TCX_ON_BRIDGE) {
373 has_snow = (GetBridgeHeight(tile) > GetSnowLine());
374 } else {
375 /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
376 if (_generating_world) goto genworld; // we do not care about foundations here
377 has_snow = HasTunnelBridgeSnowOrDesert(tile);
378 }
379 break;
380
381 case MP_STATION:
382 case MP_HOUSE:
383 case MP_INDUSTRY:
384 case MP_OBJECT:
385 /* These tiles usually have a levelling foundation. So use max Z */
386 has_snow = (GetTileMaxZ(tile) > GetSnowLine());
387 break;
388
389 case MP_VOID:
390 case MP_WATER:
391 genworld:
392 has_snow = (GetTileZ(tile) > GetSnowLine());
393 break;
394
395 default: NOT_REACHED();
396 }
397 return has_snow ? 4 : 0;
398 }
399 default: return 0;
400 }
401}
402
411 TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
412{
413 int8_t x = GB(parameter, 0, 4);
414 int8_t y = GB(parameter, 4, 4);
415
416 if (signed_offsets && x >= 8) x -= 16;
417 if (signed_offsets && y >= 8) y -= 16;
418
419 /* Swap width and height depending on axis for railway stations */
420 if (axis == INVALID_AXIS && HasStationTileRail(tile)) axis = GetRailStationAxis(tile);
421 if (axis == AXIS_Y) std::swap(x, y);
422
423 /* Make sure we never roam outside of the map, better wrap in that case */
424 return Map::WrapToMap(tile + TileDiffXY(x, y));
425}
426
434uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
435{
436 TileType tile_type = GetTileType(tile);
437
438 /* Fake tile type for trees on shore */
439 if (IsTileType(tile, MP_TREES) && GetTreeGround(tile) == TREE_GROUND_SHORE) tile_type = MP_WATER;
440
441 /* Fake tile type for road waypoints */
442 if (IsRoadWaypointTile(tile)) tile_type = MP_ROAD;
443
444 auto [tileh, z] = GetTilePixelSlope(tile);
445 /* Return 0 if the tile is a land tile */
446 uint8_t terrain_type = (HasTileWaterClass(tile) ? (to_underlying(GetWaterClass(tile)) + 1) & 3 : 0) << 5 | GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
447 if (grf_version8) z /= TILE_HEIGHT;
448 return tile_type << 24 | ClampTo<uint8_t>(z) << 16 | terrain_type << 8 | tileh;
449}
450
457uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
458{
459 if (l == nullptr && Company::IsValidID(owner)) l = &Company::Get(owner)->livery[LS_DEFAULT];
460 return owner.base() | (Company::IsValidAiID(owner) ? 0x10000 : 0) | (l != nullptr ? (l->colour1 << 24) | (l->colour2 << 28) : 0);
461}
462
471 CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span<const int32_t> textstack, const GRFFile *grffile, StringID default_error)
472{
473 auto get_newgrf_text = [&grffile](GRFStringID text_id, std::span<const int32_t> textstack) {
474 CommandCost res = CommandCost(GetGRFStringID(grffile->grfid, text_id));
475
476 /* If this error isn't for the local player then it won't be seen, so don't bother encoding anything. */
477 if (IsLocalCompany()) {
478 StringID stringid = GetGRFStringID(grffile->grfid, text_id);
479 auto params = GetGRFStringTextStackParameters(grffile, stringid, textstack);
480 res.SetEncodedMessage(GetEncodedStringWithArgs(stringid, params));
481 }
482
483 return res;
484 };
485
486 CommandCost res;
487 if (cb_res < 0x400) {
488 res = get_newgrf_text(GRFSTR_MISC_GRF_TEXT + cb_res, textstack);
489 } else {
490 switch (cb_res) {
491 case 0x400: return res; // No error.
492
493 default: // unknown reason -> default error
494 case 0x401: res = CommandCost(default_error); break;
495
496 case 0x402: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST); break;
497 case 0x403: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT); break;
498 case 0x404: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE); break;
499 case 0x405: res = CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE); break;
500 case 0x406: res = CommandCost(STR_ERROR_CAN_T_BUILD_ON_SEA); break;
501 case 0x407: res = CommandCost(STR_ERROR_CAN_T_BUILD_ON_CANAL); break;
502 case 0x408: res = CommandCost(STR_ERROR_CAN_T_BUILD_ON_RIVER); break;
503 case 0x40F: res = get_newgrf_text(static_cast<GRFStringID>(textstack[0]), textstack.subspan(1)); break;
504 }
505 }
506
507 return res;
508}
509
517 void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
518{
519 GRFConfig *grfconfig = GetGRFConfig(grfid);
520
521 if (grfconfig->grf_bugs.Test(GRFBug::UnknownCbResult)) {
522 grfconfig->grf_bugs.Set(GRFBug::UnknownCbResult);
523 ShowErrorMessage(GetEncodedString(STR_NEWGRF_BUGGY, grfconfig->GetName()),
524 GetEncodedString(STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT, std::monostate{}, cbid, cb_res),
525 WL_CRITICAL);
526 }
527
528 /* debug output */
529 Debug(grf, 0, "{}", StrMakeValid(GetString(STR_NEWGRF_BUGGY, grfconfig->GetName())));
530
531 Debug(grf, 0, "{}", StrMakeValid(GetString(STR_NEWGRF_BUGGY_UNKNOWN_CALLBACK_RESULT, std::monostate{}, cbid, cb_res)));
532}
533
543 bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
544{
545 assert(cb_res != CALLBACK_FAILED); // We do not know what to return
546
547 if (grffile->grf_version < 8) return cb_res != 0;
548
549 if (cb_res > 1) ErrorUnknownCallbackResult(grffile->grfid, cbid, cb_res);
550 return cb_res != 0;
551}
552
562 bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
563{
564 assert(cb_res != CALLBACK_FAILED); // We do not know what to return
565
566 if (grffile->grf_version < 8) return GB(cb_res, 0, 8) != 0;
567
568 if (cb_res > 1) ErrorUnknownCallbackResult(grffile->grfid, cbid, cb_res);
569 return cb_res != 0;
570}
571
576 void NewGRFSpriteLayout::Allocate(uint num_sprites)
577{
578 assert(this->seq.empty());
579
580 this->seq.resize(num_sprites, {});
581}
582
586 void NewGRFSpriteLayout::AllocateRegisters()
587{
588 assert(this->registers.empty());
589
590 this->registers.resize(1 + this->seq.size(), {}); // 1 for the ground sprite
591}
592
603SpriteLayoutProcessor::SpriteLayoutProcessor(const NewGRFSpriteLayout &raw_layout, uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground) :
604 raw_layout(&raw_layout), separate_ground(separate_ground)
605{
606 this->result_seq.reserve(this->raw_layout->seq.size() + 1);
607
608 /* Create a copy of the spritelayout, so we can modify some values.
609 * Also include the groundsprite into the sequence for easier processing. */
610 DrawTileSeqStruct &copy = this->result_seq.emplace_back();
611 copy.image = this->raw_layout->ground;
612 copy.origin.z = static_cast<int8_t>(0x80);
613
614 this->result_seq.insert(this->result_seq.end(), this->raw_layout->seq.begin(), this->raw_layout->seq.end());
615
616 /* Determine the var10 values the action-1-2-3 chains needs to be resolved for,
617 * and apply the default sprite offsets (unless disabled). */
618 const TileLayoutRegisters *regs = this->raw_layout->registers.empty() ? nullptr : this->raw_layout->registers.data();
619 bool ground = true;
620 for (DrawTileSeqStruct &result : this->result_seq) {
621 TileLayoutFlags flags = TLF_NOTHING;
622 if (regs != nullptr) flags = regs->flags;
623
624 /* Record var10 value for the sprite */
625 if (HasBit(result.image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE) || (flags & TLF_SPRITE_REG_FLAGS)) {
626 uint8_t var10 = (flags & TLF_SPRITE_VAR10) ? regs->sprite_var10 : (ground && this->separate_ground ? 1 : 0);
627 SetBit(this->var10_values, var10);
628 }
629
630 /* Add default sprite offset, unless there is a custom one */
631 if (!(flags & TLF_SPRITE)) {
632 if (HasBit(result.image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
633 result.image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
634 if (constr_stage > 0 && regs != nullptr) result.image.sprite += GetConstructionStageOffset(constr_stage, regs->max_sprite_offset);
635 } else {
636 result.image.sprite += orig_offset;
637 }
638 }
639
640 /* Record var10 value for the palette */
641 if (HasBit(result.image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE) || (flags & TLF_PALETTE_REG_FLAGS)) {
642 uint8_t var10 = (flags & TLF_PALETTE_VAR10) ? regs->palette_var10 : (ground && this->separate_ground ? 1 : 0);
643 SetBit(this->var10_values, var10);
644 }
645
646 /* Add default palette offset, unless there is a custom one */
647 if (!(flags & TLF_PALETTE)) {
648 if (HasBit(result.image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
649 result.image.sprite += ground ? newgrf_ground_offset : newgrf_offset;
650 if (constr_stage > 0 && regs != nullptr) result.image.sprite += GetConstructionStageOffset(constr_stage, regs->max_palette_offset);
651 }
652 }
653
654 ground = false;
655 if (regs != nullptr) regs++;
656 }
657}
658
665 void SpriteLayoutProcessor::ProcessRegisters(const ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
666{
667 assert(this->raw_layout != nullptr);
668 const TileLayoutRegisters *regs = this->raw_layout->registers.empty() ? nullptr : this->raw_layout->registers.data();
669 bool ground = true;
670 for (DrawTileSeqStruct &result : this->result_seq) {
671 TileLayoutFlags flags = TLF_NOTHING;
672 if (regs != nullptr) flags = regs->flags;
673
674 /* Is the sprite or bounding box affected by an action-1-2-3 chain? */
675 if (HasBit(result.image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE) || (flags & TLF_SPRITE_REG_FLAGS)) {
676 /* Does the var10 value apply to this sprite? */
677 uint8_t var10 = (flags & TLF_SPRITE_VAR10) ? regs->sprite_var10 : (ground && this->separate_ground ? 1 : 0);
678 if (var10 == resolved_var10) {
679 /* Apply registers */
680 if ((flags & TLF_DODRAW) && object.GetRegister(regs->dodraw) == 0) {
681 result.image.sprite = 0;
682 } else {
683 if (HasBit(result.image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) result.image.sprite += resolved_sprite;
684 if (flags & TLF_SPRITE) {
685 int16_t offset = static_cast<int16_t>(object.GetRegister(regs->sprite)); // mask to 16 bits to avoid trouble
686 if (!HasBit(result.image.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE) || (offset >= 0 && offset < regs->max_sprite_offset)) {
687 result.image.sprite += offset;
688 } else {
689 result.image.sprite = SPR_IMG_QUERY;
690 }
691 }
692
693 if (result.IsParentSprite()) {
694 if (flags & TLF_BB_XY_OFFSET) {
695 result.origin.x += object.GetRegister(regs->delta.parent[0]);
696 result.origin.y += object.GetRegister(regs->delta.parent[1]);
697 }
698 if (flags & TLF_BB_Z_OFFSET) result.origin.z += object.GetRegister(regs->delta.parent[2]);
699 } else {
700 if (flags & TLF_CHILD_X_OFFSET) result.origin.x += object.GetRegister(regs->delta.child[0]);
701 if (flags & TLF_CHILD_Y_OFFSET) result.origin.y += object.GetRegister(regs->delta.child[1]);
702 }
703 }
704 }
705 }
706
707 /* Is the palette affected by an action-1-2-3 chain? */
708 if (result.image.sprite != 0 && (HasBit(result.image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE) || (flags & TLF_PALETTE_REG_FLAGS))) {
709 /* Does the var10 value apply to this sprite? */
710 uint8_t var10 = (flags & TLF_PALETTE_VAR10) ? regs->palette_var10 : (ground && this->separate_ground ? 1 : 0);
711 if (var10 == resolved_var10) {
712 /* Apply registers */
713 if (HasBit(result.image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) result.image.pal += resolved_sprite;
714 if (flags & TLF_PALETTE) {
715 int16_t offset = static_cast<int16_t>(object.GetRegister(regs->palette)); // mask to 16 bits to avoid trouble
716 if (!HasBit(result.image.pal, SPRITE_MODIFIER_CUSTOM_SPRITE) || (offset >= 0 && offset < regs->max_palette_offset)) {
717 result.image.pal += offset;
718 } else {
719 result.image.sprite = SPR_IMG_QUERY;
720 result.image.pal = PAL_NONE;
721 }
722 }
723 }
724 }
725
726 ground = false;
727 if (regs != nullptr) regs++;
728 }
729}
730
735 void GRFFilePropsBase::SetGRFFile(const struct GRFFile *grffile)
736{
737 this->grffile = grffile;
738 this->grfid = grffile == nullptr ? 0 : grffile->grfid;
739}
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
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition bridge_map.cpp:70
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::SetEncodedMessage
void SetEncodedMessage(EncodedString &&message)
Set the encoded message string.
Definition command_type.h:72
HouseOverrideManager::SetEntitySpec
void SetEntitySpec(HouseSpec &&hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go.
Definition newgrf_commons.cpp:160
IndustryOverrideManager::AddEntityID
uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id) override
Method to find an entity ID and to mark it as reserved for the Industry to be included.
Definition newgrf_commons.cpp:213
IndustryOverrideManager::GetID
uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override
Return the ID (if ever available) of a previously inserted entity.
Definition newgrf_commons.cpp:193
IndustryOverrideManager::SetEntitySpec
void SetEntitySpec(IndustrySpec &&inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
Definition newgrf_commons.cpp:248
ObjectOverrideManager::SetEntitySpec
void SetEntitySpec(ObjectSpec &&spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
Definition newgrf_commons.cpp:303
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::ResetMapping
void ResetMapping()
Resets the mapping, which is used while initializing game.
Definition newgrf_commons.cpp:73
OverrideManagerBase::max_entities
uint16_t max_entities
what is the amount of entities, old and new summed
Definition newgrf_commons.h:204
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::invalid_id
uint16_t invalid_id
ID used to detected invalid entities.
Definition newgrf_commons.h:206
OverrideManagerBase::Add
void Add(uint16_t local_id, uint32_t grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
Definition newgrf_commons.cpp:63
OverrideManagerBase::OverrideManagerBase
OverrideManagerBase(uint16_t offset, uint16_t maximum, uint16_t invalid)
Constructor of generic class.
Definition newgrf_commons.cpp:43
OverrideManagerBase::mappings
std::vector< EntityIDMapping > mappings
mapping of ids from grf files. Public out of convenience
Definition newgrf_commons.h:210
OverrideManagerBase::ResetOverride
void ResetOverride()
Resets the override, which is used while initializing game.
Definition newgrf_commons.cpp:79
OverrideManagerBase::GetSubstituteID
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
Definition newgrf_commons.cpp:150
OverrideManagerBase::max_offset
uint16_t max_offset
what is the length of the original entity's array of specs
Definition newgrf_commons.h:203
OverrideManagerBase::AddEntityID
virtual uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
Reserves a place in the mapping array for an entity to be installed.
Definition newgrf_commons.cpp:110
SpriteLayoutProcessor::ProcessRegisters
void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Definition newgrf_commons.cpp:665
clear_map.h
Map accessors for 'clear' tiles.
IsSnowTile
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
Definition clear_map.h:35
GetClearDensity
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition clear_map.h:71
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
company_func.h
Functions related to companies.
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition company_func.h:47
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition direction_type.h:127
AXIS_Y
@ AXIS_Y
The y axis.
Definition direction_type.h:125
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
error.h
Functions related to errors.
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition error.h:27
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
_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.
GetSnowLine
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition landscape.cpp:605
house.h
definition of HouseSpec and accessors
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition industry_cmd.cpp:126
industrytype.h
Industry type specs.
landscape.h
Functions related to OTTD's landscape.
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:517
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
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition newgrf_commons.cpp:471
GetCompanyInfo
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Definition newgrf_commons.cpp:457
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
TileContext
TileContext
Context for tile accesses.
Definition newgrf_commons.h:24
TCX_UPPER_HALFTILE
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
Definition newgrf_commons.h:26
TCX_ON_BRIDGE
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
Definition newgrf_commons.h:27
TileLayoutFlags
TileLayoutFlags
Flags to enable register usage in sprite layouts.
Definition newgrf_commons.h:33
TLF_BB_Z_OFFSET
@ TLF_BB_Z_OFFSET
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:42
TLF_SPRITE
@ TLF_SPRITE
Add signed offset to sprite from register TileLayoutRegisters::sprite.
Definition newgrf_commons.h:37
TLF_CHILD_X_OFFSET
@ TLF_CHILD_X_OFFSET
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:44
TLF_DODRAW
@ TLF_DODRAW
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
Definition newgrf_commons.h:36
TLF_PALETTE_REG_FLAGS
@ TLF_PALETTE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palet...
Definition newgrf_commons.h:65
TLF_BB_XY_OFFSET
@ TLF_BB_XY_OFFSET
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:41
TLF_SPRITE_REG_FLAGS
@ TLF_SPRITE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite...
Definition newgrf_commons.h:62
TLF_PALETTE_VAR10
@ TLF_PALETTE_VAR10
Resolve palette with a specific value in variable 10.
Definition newgrf_commons.h:48
TLF_SPRITE_VAR10
@ TLF_SPRITE_VAR10
Resolve sprite with a specific value in variable 10.
Definition newgrf_commons.h:47
TLF_PALETTE
@ TLF_PALETTE
Add signed offset to palette from register TileLayoutRegisters::palette.
Definition newgrf_commons.h:38
TLF_CHILD_Y_OFFSET
@ TLF_CHILD_Y_OFFSET
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:45
GetConstructionStageOffset
uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
Definition newgrf_commons.h:75
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition newgrf_config.cpp:622
newgrf_config.h
Functions to find and configure NewGRFs.
GRFBug::UnknownCbResult
@ UnknownCbResult
A callback returned an unknown/invalid result.
_object_specs
std::vector< ObjectSpec > _object_specs
All the object specifications.
Definition newgrf_object.cpp:37
newgrf_object.h
Functions related to NewGRF objects.
newgrf_spritegroup.h
Action 2 handling.
GetGRFStringTextStackParameters
std::vector< StringParameter > GetGRFStringTextStackParameters(const GRFFile *grffile, StringID stringid, std::span< const int32_t > textstack)
Process the text ref stack for a GRF String and return its parameters.
Definition newgrf_text.cpp:977
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
Definition newgrf_text.cpp:580
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
GRFSTR_MISC_GRF_TEXT
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Definition newgrf_text_type.h:18
ObjectType
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
OBJECT_TRANSMITTER
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition object_type.h:18
RailGroundType
RailGroundType
The ground 'under' the rail.
Definition rail_map.h:484
RailGroundType::HalfTileSnow
@ HalfTileSnow
Snow only on higher part of slope (steep or one corner raised)
RailGroundType::SnowOrDesert
@ SnowOrDesert
Icy or sandy.
IsOnSnowOrDesert
bool IsOnSnowOrDesert(Tile t)
Check if a road tile has snow/desert.
Definition road_map.h:441
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
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
station_map.h
Maps accessors for stations.
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition station_map.h:146
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition station_map.h:503
IsRoadWaypointTile
bool IsRoadWaypointTile(Tile t)
Is this tile a station tile and a road waypoint?
Definition station_map.h:212
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
StrMakeValid
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Definition string.cpp:119
string_func.h
Functions related to low-level strings.
GetEncodedStringWithArgs
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
Definition strings.cpp:102
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
Company::IsValidAiID
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition company_base.h:153
Coord3D::z
T z
Z coordinate.
Definition geometry_type.hpp:46
DrawTileSeqStruct
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:33
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
EntityIDMapping
Maps an entity id stored on the map to a GRF file.
Definition newgrf_commons.h:192
EntityIDMapping::substitute_id
uint16_t substitute_id
The (original) entity ID to use if this GRF is not available.
Definition newgrf_commons.h:195
EntityIDMapping::grfid
uint32_t grfid
The GRF ID of the file the entity belongs to.
Definition newgrf_commons.h:193
EntityIDMapping::entity_id
uint16_t entity_id
The entity ID within the GRF file.
Definition newgrf_commons.h:194
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:158
GRFConfig::grf_bugs
GRFBugs grf_bugs
NOSAVE: bugs in this GRF in this run,.
Definition newgrf_config.h:180
GRFConfig::GetName
std::string GetName() const
Get the name of this grf.
Definition newgrf_config.cpp:85
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::SetGRFFile
void SetGRFFile(const struct GRFFile *grffile)
Set the NewGRF file, and its grfid, associated with grf props.
Definition newgrf_commons.cpp:735
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
GameCreationSettings::landscape
LandscapeType landscape
the landscape we're currently in
Definition settings_type.h:395
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition settings_type.h:634
HouseSpec
Definition house.h:98
HouseSpec::grf_prop
SubstituteGRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:114
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:70
HouseSpec::Specs
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Definition newgrf_house.cpp:51
IndustrySpec
Defines the data structure for constructing industry.
Definition industrytype.h:103
IndustrySpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:134
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition industrytype.h:133
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition industrytype.h:152
IndustryTileSpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:168
IndustryTileSpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition industrytype.h:167
Livery
Information about a particular livery.
Definition livery.h:79
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:88
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition livery.h:87
Map::WrapToMap
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
Definition map_func.h:329
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition newgrf_commons.h:113
NewGRFSpriteLayout::Allocate
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
Definition newgrf_commons.cpp:576
NewGRFSpriteLayout::AllocateRegisters
void AllocateRegisters()
Allocate memory for register modifiers.
Definition newgrf_commons.cpp:586
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
SpriteBounds::origin
Coord3D< int8_t > origin
Position of northern corner within tile.
Definition sprite.h:19
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SubstituteGRFFileProps::override_id
uint16_t override_id
id of the entity been replaced by
Definition newgrf_commons.h:469
TileLayoutRegisters
Additional modifiers for items in sprite layouts.
Definition newgrf_commons.h:91
TileLayoutRegisters::parent
uint8_t parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
Definition newgrf_commons.h:99
TileLayoutRegisters::flags
TileLayoutFlags flags
Flags defining which members are valid and to be used.
Definition newgrf_commons.h:92
TileLayoutRegisters::dodraw
uint8_t dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
Definition newgrf_commons.h:93
TileLayoutRegisters::max_sprite_offset
uint16_t max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
Definition newgrf_commons.h:96
TileLayoutRegisters::palette
uint8_t palette
Register specifying a signed offset for the palette.
Definition newgrf_commons.h:95
TileLayoutRegisters::sprite_var10
uint8_t sprite_var10
Value for variable 10 when resolving the sprite.
Definition newgrf_commons.h:102
TileLayoutRegisters::max_palette_offset
uint16_t max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
Definition newgrf_commons.h:97
TileLayoutRegisters::palette_var10
uint8_t palette_var10
Value for variable 10 when resolving the palette.
Definition newgrf_commons.h:103
TileLayoutRegisters::child
uint8_t child[2]
Registers for signed offsets for the position of child sprites.
Definition newgrf_commons.h:100
TileLayoutRegisters::sprite
uint8_t sprite
Register specifying a signed offset for the sprite.
Definition newgrf_commons.h:94
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:136
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:116
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetTilePixelSlope
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
Definition tile_map.h:289
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition tile_map.h:238
GetTileType
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
TILE_HEIGHT
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
TileType
TileType
The different types of tiles.
Definition tile_type.h:47
MP_TREES
@ MP_TREES
Tile got trees.
Definition tile_type.h:52
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:48
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition tile_type.h:51
MP_WATER
@ MP_WATER
Water tile.
Definition tile_type.h:54
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition tile_type.h:56
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition tile_type.h:55
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
tree_map.h
Map accessors for tree tiles.
GetTreeGround
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition tree_map.h:102
TreeGround
TreeGround
Enumeration for ground types of tiles with trees.
Definition tree_map.h:52
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition tree_map.h:56
TREE_GROUND_ROUGH_SNOW
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
Definition tree_map.h:57
TREE_GROUND_SNOW_DESERT
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
Definition tree_map.h:55
GetTreeDensity
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
Definition tree_map.h:127
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
HasTunnelBridgeSnowOrDesert
bool HasTunnelBridgeSnowOrDesert(Tile t)
Tunnel: Is this tunnel entrance in a snowy or desert area? Bridge: Does the bridge ramp lie in a snow...
Definition tunnelbridge_map.h:52
HasTileWaterClass
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition water_map.h:103
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:114