object_base.h

Go to the documentation of this file.
00001 /* $Id: object_base.h 21453 2010-12-10 21:32:04Z 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 #include "core/smallvec_type.hpp"
00021 
00022 typedef Pool<Object, ObjectID, 64, 64000> ObjectPool;
00023 extern ObjectPool _object_pool;
00024 
00026 struct Object : ObjectPool::PoolItem<&_object_pool> {
00027   Town *town;         
00028   TileArea location;  
00029   Date build_date;    
00030   byte colour;        
00031   byte view;          
00032 
00034   Object() {}
00036   ~Object() {}
00037 
00043   static Object *GetByTile(TileIndex tile);
00044 
00050   static inline void IncTypeCount(ObjectType type)
00051   {
00052     assert(type < NUM_OBJECTS);
00053     counts[type]++;
00054   }
00055 
00061   static inline void DecTypeCount(ObjectType type)
00062   {
00063     assert(type < NUM_OBJECTS);
00064     counts[type]--;
00065   }
00066 
00072   static inline uint16 GetTypeCount(ObjectType type)
00073   {
00074     assert(type < NUM_OBJECTS);
00075     return counts[type];
00076   }
00077 
00079   static inline void ResetTypeCounts()
00080   {
00081     memset(&counts, 0, sizeof(counts));
00082   }
00083 
00084 protected:
00085   static uint16 counts[NUM_OBJECTS]; 
00086 };
00087 
00088 #define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
00089 #define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
00090 
00094 struct ClearedObjectArea {
00095   TileIndex first_tile;  
00096   TileArea area;         
00097 };
00098 
00099 ClearedObjectArea *FindClearedObject(TileIndex tile);
00100 extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
00101 
00102 #endif /* OBJECT_BASE_H */

Generated on Sun Jan 9 16:01:58 2011 for OpenTTD by  doxygen 1.6.1