Add a method in NewGRFInspectWindow to resolve FeatureIndex
[openttd/fttd.git] / src / object_base.h
bloba4bac5dc45da3e763c482ef8d361c2def34ab12d
1 /* $Id$ */
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 */
10 /** @file object_base.h Base for all objects. */
12 #ifndef OBJECT_BASE_H
13 #define OBJECT_BASE_H
15 #include "core/pool_type.hpp"
16 #include "object_type.h"
17 #include "map/tilearea.h"
18 #include "town_type.h"
19 #include "date_type.h"
21 typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
22 extern ObjectPool _object_pool;
24 /** An object, such as transmitter, on the map. */
25 struct Object : ObjectPool::PoolItem<&_object_pool> {
26 ObjectType type; ///< Type of the object
27 Town *town; ///< Town the object is built in
28 TileArea location; ///< Location of the object
29 Date build_date; ///< Date of construction
30 byte colour; ///< Colour of the object, for display purpose
31 byte view; ///< The view setting for this object
33 /** Make sure the object isn't zeroed. */
34 Object() {}
35 /** Make sure the right destructor is called as well! */
36 ~Object() {}
38 static Object *GetByTile(TileIndex tile);
40 /**
41 * Increment the count of objects for this type.
42 * @param type ObjectType to increment
43 * @pre type < NUM_OBJECTS
45 static inline void IncTypeCount(ObjectType type)
47 assert(type < NUM_OBJECTS);
48 counts[type]++;
51 /**
52 * Decrement the count of objects for this type.
53 * @param type ObjectType to decrement
54 * @pre type < NUM_OBJECTS
56 static inline void DecTypeCount(ObjectType type)
58 assert(type < NUM_OBJECTS);
59 counts[type]--;
62 /**
63 * Get the count of objects for this type.
64 * @param type ObjectType to query
65 * @pre type < NUM_OBJECTS
67 static inline uint16 GetTypeCount(ObjectType type)
69 assert(type < NUM_OBJECTS);
70 return counts[type];
73 /** Resets object counts. */
74 static inline void ResetTypeCounts()
76 memset(&counts, 0, sizeof(counts));
79 protected:
80 static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
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)
86 /**
87 * Keeps track of removed objects during execution/testruns of commands.
89 struct ClearedObjectArea {
90 TileIndex first_tile; ///< The first tile being cleared, which then causes the whole object to be cleared.
91 TileArea area; ///< The area of the object.
94 ClearedObjectArea *FindClearedObject(TileIndex tile);
95 extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
97 #endif /* OBJECT_BASE_H */