OpenTTD Source 20260421-master-gc2fbc6fdeb
object_base.h
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
9
10#ifndef OBJECT_BASE_H
11#define OBJECT_BASE_H
12
13#include "core/pool_type.hpp"
14#include "gfx_type.h"
15#include "object_type.h"
16#include "tilearea_type.h"
17#include "town_type.h"
19
20using ObjectPool = Pool<Object, ObjectID, 64>;
21extern ObjectPool _object_pool;
22
24struct Object : ObjectPool::PoolItem<&_object_pool> {
26 Town *town = nullptr;
29 uint8_t recolour_offset = 0;
30 uint8_t view = 0;
31
32 Object(ObjectID index) : ObjectPool::PoolItem<&_object_pool>(index) {}
34 ObjectPool::PoolItem<&_object_pool>(index), type(type), town(town), location(location), build_date(build_date), view(view) {}
37
38 static Object *GetByTile(TileIndex tile);
39
45 static inline void IncTypeCount(ObjectType type)
46 {
47 assert(type < NUM_OBJECTS);
49 }
50
56 static inline void DecTypeCount(ObjectType type)
57 {
58 assert(type < NUM_OBJECTS);
60 }
61
68 static inline uint16_t GetTypeCount(ObjectType type)
69 {
70 assert(type < NUM_OBJECTS);
71 return Object::counts[type];
72 }
73
75 static inline void ResetTypeCounts()
76 {
77 Object::counts.fill(0);
78 }
79
80protected:
81 static std::array<uint16_t, NUM_OBJECTS> counts;
82};
83
91
93extern std::vector<ClearedObjectArea> _cleared_object_areas;
94
95#endif /* OBJECT_BASE_H */
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Types related to the graphics and/or input devices.
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Types related to object tiles.
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
PoolID< uint32_t, struct ObjectIDTag, 0xFF0000, 0xFFFFFFFF > ObjectID
Unique identifier for an object.
Definition object_type.h:30
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition object_type.h:27
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition object_type.h:25
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Keeps track of removed objects during execution/testruns of commands.
Definition object_base.h:87
TileArea area
The area of the object.
Definition object_base.h:89
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition object_base.h:88
An object, such as transmitter, on the map.
Definition object_base.h:24
ObjectType type
Type of the object.
Definition object_base.h:25
Town * town
Town the object is built in.
Definition object_base.h:26
static std::array< uint16_t, NUM_OBJECTS > counts
Number of objects per type ingame.
Definition object_base.h:81
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition object_base.h:68
uint8_t recolour_offset
Recolour offset of the object (basically the 2CC colour offset), for display purpose.
Definition object_base.h:29
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition object_base.h:45
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:28
uint8_t view
The view setting for this object.
Definition object_base.h:30
TileArea location
Location of the object.
Definition object_base.h:27
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition object_base.h:56
static void ResetTypeCounts()
Resets object counts.
Definition object_base.h:75
~Object()
Make sure the right destructor is called as well!
Definition object_base.h:36
Base class for all pools.
Town data structure.
Definition town.h:63
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
Type for storing the 'area' of something uses on the map.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition of the game-calendar-timer.
Types related to towns.