summaryrefslogtreecommitdiff
path: root/src/object_base.h
diff options
context:
space:
mode:
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)