OpenTTD

object_base.h
Go to the documentation of this file.
1 /* $Id: object_base.h 25844 2013-10-12 16:35:50Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef OBJECT_BASE_H
13 #define OBJECT_BASE_H
14
15 #include "core/pool_type.hpp"
16 #include "object_type.h"
17 #include "tilearea_type.h"
18 #include "town_type.h"
19 #include "date_type.h"
20
21 typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
22 extern ObjectPool _object_pool;
23
25 struct Object : ObjectPool::PoolItem<&_object_pool> {
26 ObjectType type;
27 Town *town;
28 TileArea location;
29 Date build_date;
30 byte colour;
31 byte view;
32
34 Object() {}
36 ~Object() {}
37
38 static Object *GetByTile(TileIndex tile);
39
45 static inline void IncTypeCount(ObjectType type)
46 {
47 assert(type < NUM_OBJECTS);
48 counts[type]++;
49 }
50
56 static inline void DecTypeCount(ObjectType type)
57 {
58 assert(type < NUM_OBJECTS);
59 counts[type]--;
60 }
61
67 static inline uint16 GetTypeCount(ObjectType type)
68 {
69 assert(type < NUM_OBJECTS);
70 return counts[type];
71 }
72
74 static inline void ResetTypeCounts()
75 {
76 memset(&counts, 0, sizeof(counts));
77 }
78
79 protected:
80 static uint16 counts[NUM_OBJECTS];
81 };
82
83 #define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
84 #define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
85
89 struct ClearedObjectArea {
90 TileIndex first_tile;
91 TileArea area;
92 };
93
94 ClearedObjectArea *FindClearedObject(TileIndex tile);
95 extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
96
97 #endif /* OBJECT_BASE_H */
ClearedObjectArea::first_tile
TileIndex first_tile
The first tile being cleared, which then causes the whole object to be cleared.
Definition: object_base.h:90
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:27
town_type.h
Types related to towns.
Object::town
Town * town
Town the object is built in.
Definition: object_base.h:27
Object::build_date
Date build_date
Date of construction.
Definition: object_base.h:29
Object::colour
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:30
Object::Object
Object()
Make sure the object isn&#39;t zeroed.
Definition: object_base.h:34
SmallVector
Simple vector template class.
Definition: smallvec_type.hpp:29
pool_type.hpp
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
object_type.h
Types related to object tiles.
Object::counts
static uint16 counts[NUM_OBJECTS]
Number of objects per type ingame.
Definition: object_base.h:80
Object::~Object
~Object()
Make sure the right destructor is called as well!
Definition: object_base.h:36
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:89
ClearedObjectArea::area
TileArea area
The area of the object.
Definition: object_base.h:91
Object
An object, such as transmitter, on the map.
Definition: object_base.h:25
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
ObjectType
uint16 ObjectType
Types of objects.
Definition: object_type.h:16
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:453
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
Pool
Base class for all pools.
Definition: pool_type.hpp:83
Object::GetTypeCount
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition: object_base.h:67
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Object::ResetTypeCounts
static void ResetTypeCounts()
Resets object counts.
Definition: object_base.h:74
Object::IncTypeCount
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition: object_base.h:45
Object::location
TileArea location
Location of the object.
Definition: object_base.h:28
Object::type
ObjectType type
Type of the object.
Definition: object_base.h:26
Town
Town data structure.
Definition: town.h:55
tilearea_type.h
Type for storing the &#39;area&#39; of something uses on the map.
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:52
date_type.h
Types related to the dates in OpenTTD.
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
Object::DecTypeCount
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition: object_base.h:56
Object::view
byte view
The view setting for this object.
Definition: object_base.h:31