Fix 03cc0d6: Mark level crossings dirty when removing road from them, not from bridge...
[openttd-github.git] / src / object_base.h
bloba468a01ee9fa25ff0035725b3df7f499b291378e
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 */
8 /** @file object_base.h Base for all objects. */
10 #ifndef OBJECT_BASE_H
11 #define OBJECT_BASE_H
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"
19 typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
20 extern ObjectPool _object_pool;
22 /** An object, such as transmitter, on the map. */
23 struct Object : ObjectPool::PoolItem<&_object_pool> {
24 ObjectType type; ///< Type of the object
25 Town *town; ///< Town the object is built in
26 TileArea location; ///< Location of the object
27 Date build_date; ///< Date of construction
28 byte colour; ///< Colour of the object, for display purpose
29 byte view; ///< The view setting for this object
31 /** Make sure the object isn't zeroed. */
32 Object() {}
33 /** Make sure the right destructor is called as well! */
34 ~Object() {}
36 static Object *GetByTile(TileIndex tile);
38 /**
39 * Increment the count of objects for this type.
40 * @param type ObjectType to increment
41 * @pre type < NUM_OBJECTS
43 static inline void IncTypeCount(ObjectType type)
45 assert(type < NUM_OBJECTS);
46 counts[type]++;
49 /**
50 * Decrement the count of objects for this type.
51 * @param type ObjectType to decrement
52 * @pre type < NUM_OBJECTS
54 static inline void DecTypeCount(ObjectType type)
56 assert(type < NUM_OBJECTS);
57 counts[type]--;
60 /**
61 * Get the count of objects for this type.
62 * @param type ObjectType to query
63 * @pre type < NUM_OBJECTS
65 static inline uint16 GetTypeCount(ObjectType type)
67 assert(type < NUM_OBJECTS);
68 return counts[type];
71 /** Resets object counts. */
72 static inline void ResetTypeCounts()
74 memset(&counts, 0, sizeof(counts));
77 protected:
78 static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
81 /**
82 * Keeps track of removed objects during execution/testruns of commands.
84 struct ClearedObjectArea {
85 TileIndex first_tile; ///< The first tile being cleared, which then causes the whole object to be cleared.
86 TileArea area; ///< The area of the object.
89 ClearedObjectArea *FindClearedObject(TileIndex tile);
90 extern std::vector<ClearedObjectArea> _cleared_object_areas;
92 #endif /* OBJECT_BASE_H */