OpenTTD Source: src/object_base.h Source File

OpenTTD Source 15.3

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
10#ifndef OBJECT_BASE_H
11#define OBJECT_BASE_H
12
13#include "core/pool_type.hpp"
14#include "object_type.h"
15#include "tilearea_type.h"
16#include "town_type.h"
17#include "timer/timer_game_calendar.h"
18
19using ObjectPool = Pool<Object, ObjectID, 64>;
20extern ObjectPool _object_pool;
21
23 struct Object : ObjectPool::PoolItem<&_object_pool> {
24 ObjectType type = INVALID_OBJECT_TYPE;
25 Town *town = nullptr;
26 TileArea location{INVALID_TILE, 0, 0};
27 TimerGameCalendar::Date build_date{};
28 uint8_t colour = 0;
29 uint8_t view = 0;
30
32 Object() {}
33 Object(ObjectType type, Town *town, TileArea location, TimerGameCalendar::Date build_date, uint8_t view) :
34 type(type), town(town), location(location), build_date(build_date), view(view) {}
36 ~Object() {}
37
38 static Object *GetByTile(TileIndex tile);
39
45 static inline void IncTypeCount(ObjectType type)
46 {
47 assert(type < NUM_OBJECTS);
48 Object::counts[type]++;
49 }
50
56 static inline void DecTypeCount(ObjectType type)
57 {
58 assert(type < NUM_OBJECTS);
59 Object::counts[type]--;
60 }
61
67 static inline uint16_t GetTypeCount(ObjectType type)
68 {
69 assert(type < NUM_OBJECTS);
70 return Object::counts[type];
71 }
72
74 static inline void ResetTypeCounts()
75 {
76 Object::counts.fill(0);
77 }
78
79protected:
80 static std::array<uint16_t, NUM_OBJECTS> counts;
81};
82
86 struct ClearedObjectArea {
87 TileIndex first_tile;
88 TileArea area;
89};
90
91 ClearedObjectArea *FindClearedObject(TileIndex tile);
92extern std::vector<ClearedObjectArea> _cleared_object_areas;
93
94#endif /* OBJECT_BASE_H */
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition object_cmd.cpp:531
object_type.h
Types related to object tiles.
ObjectType
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
INVALID_OBJECT_TYPE
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition object_type.h:27
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition object_type.h:25
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition object_base.h:86
ClearedObjectArea::area
TileArea area
The area of the object.
Definition object_base.h:88
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition object_base.h:87
Object
An object, such as transmitter, on the map.
Definition object_base.h:23
Object::type
ObjectType type
Type of the object.
Definition object_base.h:24
Object::town
Town * town
Town the object is built in.
Definition object_base.h:25
Object::counts
static std::array< uint16_t, NUM_OBJECTS > counts
Number of objects per type ingame.
Definition object_base.h:80
Object::GetTypeCount
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition object_base.h:67
Object::Object
Object()
Make sure the object isn't zeroed.
Definition object_base.h:32
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition object_cmd.cpp:55
Object::IncTypeCount
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition object_base.h:45
Object::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:27
Object::view
uint8_t view
The view setting for this object.
Definition object_base.h:29
Object::location
TileArea location
Location of the object.
Definition object_base.h:26
Object::colour
uint8_t colour
Colour of the object, for display purpose.
Definition object_base.h:28
Object::DecTypeCount
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition object_base.h:56
Object::ResetTypeCounts
static void ResetTypeCounts()
Resets object counts.
Definition object_base.h:74
Object::~Object
~Object()
Make sure the right destructor is called as well!
Definition object_base.h:36
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
Pool::PoolItem
Base class for all PoolItems.
Definition pool_type.hpp:285
Pool
Base class for all pools.
Definition pool_type.hpp:133
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
Town
Town data structure.
Definition town.h:63
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
tilearea_type.h
Type for storing the 'area' of something uses on the map.
timer_game_calendar.h
Definition of the game-calendar-timer.
town_type.h
Types related to towns.