OpenTTD Source: src/object_base.h Source File

OpenTTD Source 13.1

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 <http://www.gnu.org/licenses/>.
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 "date_type.h"
18
19 typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
20 extern ObjectPool _object_pool;
21
23 struct Object : ObjectPool::PoolItem<&_object_pool> {
24 ObjectType type;
25 Town *town;
26 TileArea location;
27 Date build_date;
28 byte colour;
29 byte view;
30
32 Object() {}
34 ~Object() {}
35
36 static Object *GetByTile(TileIndex tile);
37
43 static inline void IncTypeCount(ObjectType type)
44 {
45 assert(type < NUM_OBJECTS);
46 counts[type]++;
47 }
48
54 static inline void DecTypeCount(ObjectType type)
55 {
56 assert(type < NUM_OBJECTS);
57 counts[type]--;
58 }
59
65 static inline uint16 GetTypeCount(ObjectType type)
66 {
67 assert(type < NUM_OBJECTS);
68 return counts[type];
69 }
70
72 static inline void ResetTypeCounts()
73 {
74 memset(&counts, 0, sizeof(counts));
75 }
76
77 protected:
78 static uint16 counts[NUM_OBJECTS];
79 };
80
84 struct ClearedObjectArea {
85 TileIndex first_tile;
86 TileArea area;
87 };
88
89 ClearedObjectArea *FindClearedObject(TileIndex tile);
90 extern std::vector<ClearedObjectArea> _cleared_object_areas;
91
92 #endif /* OBJECT_BASE_H */
Object::colour
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:28
Object::location
TileArea location
Location of the object.
Definition: object_base.h:26
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:53
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:25
Object::IncTypeCount
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition: object_base.h:43
Object::Object
Object()
Make sure the object isn't zeroed.
Definition: object_base.h:32
ObjectType
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition: object_base.h:85
Object::view
byte view
The view setting for this object.
Definition: object_base.h:29
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
Object
An object, such as transmitter, on the map.
Definition: object_base.h:23
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Object::type
ObjectType type
Type of the object.
Definition: object_base.h:24
date_type.h
tilearea_type.h
Pool
Base class for all pools.
Definition: pool_type.hpp:81
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:529
ClearedObjectArea::area
TileArea area
The area of the object.
Definition: object_base.h:86
Object::DecTypeCount
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition: object_base.h:54
Object::ResetTypeCounts
static void ResetTypeCounts()
Resets object counts.
Definition: object_base.h:72
Town
Town data structure.
Definition: town.h:50
pool_type.hpp
town_type.h
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:84
Object::~Object
~Object()
Make sure the right destructor is called as well!
Definition: object_base.h:34
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:234
Object::counts
static uint16 counts[NUM_OBJECTS]
Number of objects per type ingame.
Definition: object_base.h:78
Object::build_date
Date build_date
Date of construction.
Definition: object_base.h:27
Object::town
Town * town
Town the object is built in.
Definition: object_base.h:25
Object::GetTypeCount
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition: object_base.h:65
object_type.h