object_base.h

Go to the documentation of this file.
00001 /* $Id: object_base.h 23735 2012-01-03 20:26:05Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef OBJECT_BASE_H
00013 #define OBJECT_BASE_H
00014 
00015 #include "core/pool_type.hpp"
00016 #include "object_type.h"
00017 #include "tilearea_type.h"
00018 #include "town_type.h"
00019 #include "date_type.h"
00020 
00021 typedef Pool<Object, ObjectID, 64, 64000> ObjectPool;
00022 extern ObjectPool _object_pool;
00023 
00025 struct Object : ObjectPool::PoolItem<&_object_pool> {
00026   Town *town;         
00027   TileArea location;  
00028   Date build_date;    
00029   byte colour;        
00030   byte view;          
00031 
00033   Object() {}
00035   ~Object() {}
00036 
00037   static Object *GetByTile(TileIndex tile);
00038 
00044   static inline void IncTypeCount(ObjectType type)
00045   {
00046     assert(type < NUM_OBJECTS);
00047     counts[type]++;
00048   }
00049 
00055   static inline void DecTypeCount(ObjectType type)
00056   {
00057     assert(type < NUM_OBJECTS);
00058     counts[type]--;
00059   }
00060 
00066   static inline uint16 GetTypeCount(ObjectType type)
00067   {
00068     assert(type < NUM_OBJECTS);
00069     return counts[type];
00070   }
00071 
00073   static inline void ResetTypeCounts()
00074   {
00075     memset(&counts, 0, sizeof(counts));
00076   }
00077 
00078 protected:
00079   static uint16 counts[NUM_OBJECTS]; 
00080 };
00081 
00082 #define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
00083 #define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
00084 
00088 struct ClearedObjectArea {
00089   TileIndex first_tile;  
00090   TileArea area;         
00091 };
00092 
00093 ClearedObjectArea *FindClearedObject(TileIndex tile);
00094 extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
00095 
00096 #endif /* OBJECT_BASE_H */