summaryrefslogtreecommitdiff
path: root/src/object_base.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-28 18:23:14 +0000
committerrubidium <rubidium@openttd.org>2010-08-28 18:23:14 +0000
commitbd488934787b3587ec5048db59a7dd14c164ca70 (patch)
tree548528641f87567720c66c780dddbd5a4ec7cfc0 /src/object_base.h
parentc481e3b110da20085a77f55625e564a7baa772a8 (diff)
downloadopenttd-bd488934787b3587ec5048db59a7dd14c164ca70.tar.xz
(svn r20656) -Codechange: implement counting of objects
Diffstat (limited to 'src/object_base.h')
-rw-r--r--src/object_base.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/object_base.h b/src/object_base.h
index a4e7eb0d7..d5f796191 100644
--- a/src/object_base.h
+++ b/src/object_base.h
@@ -38,6 +38,48 @@ struct Object : ObjectPool::PoolItem<&_object_pool> {
* @return The object.
*/
static Object *GetByTile(TileIndex tile);
+
+ /**
+ * Increment the count of objects for this type.
+ * @param type ObjectType to increment
+ * @pre type < NUM_OBJECTS
+ */
+ static inline void IncTypeCount(ObjectType type)
+ {
+ assert(type < NUM_OBJECTS);
+ counts[type]++;
+ }
+
+ /**
+ * Decrement the count of objects for this type.
+ * @param type ObjectType to decrement
+ * @pre type < NUM_OBJECTS
+ */
+ static inline void DecTypeCount(ObjectType type)
+ {
+ assert(type < NUM_OBJECTS);
+ counts[type]--;
+ }
+
+ /**
+ * Get the count of objects for this type.
+ * @param type ObjectType to query
+ * @pre type < NUM_OBJECTS
+ */
+ static inline uint16 GetTypeCount(ObjectType type)
+ {
+ assert(type < NUM_OBJECTS);
+ return counts[type];
+ }
+
+ /** Resets object counts. */
+ static inline void ResetTypeCounts()
+ {
+ memset(&counts, 0, sizeof(counts));
+ }
+
+protected:
+ static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame
};
#define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)