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/>.
8 /** @file object_base.h Base for all objects. */
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"
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 TimerGameCalendar::Date build_date
; ///< Date of construction
28 uint8_t colour
; ///< Colour of the object, for display purpose
29 uint8_t view
; ///< The view setting for this object
31 /** Make sure the object isn't zeroed. */
33 /** Make sure the right destructor is called as well! */
36 static Object
*GetByTile(TileIndex tile
);
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
);
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
);
61 * Get the count of objects for this type.
62 * @param type ObjectType to query
63 * @pre type < NUM_OBJECTS
65 static inline uint16_t GetTypeCount(ObjectType type
)
67 assert(type
< NUM_OBJECTS
);
71 /** Resets object counts. */
72 static inline void ResetTypeCounts()
74 memset(&counts
, 0, sizeof(counts
));
78 static uint16_t counts
[NUM_OBJECTS
]; ///< Number of objects per type ingame
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 */