# object_base.h

Go to the documentation of this file.

    00001 /* $Id: object_base.h 25844 2013-10-12 16:35:50Z frosch $ */
    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, 0xFF0000> ObjectPool;
    00022 extern ObjectPool _object_pool;
    00023
    00025 struct Object : ObjectPool::PoolItem<&_object_pool> {
    00026   ObjectType type;
    00027   Town *town;
    00028   TileArea location;
    00029   Date build_date;
    00030   byte colour;
    00031   byte view;
    00032
    00034   Object() {}
    00036   ~Object() {}
    00037
    00038   static Object *GetByTile(TileIndex tile);
    00039
    00045   static inline void IncTypeCount(ObjectType type)
    00046   {
    00047     assert(type < NUM_OBJECTS);
    00048     counts[type]++;
    00049   }
    00050
    00056   static inline void DecTypeCount(ObjectType type)
    00057   {
    00058     assert(type < NUM_OBJECTS);
    00059     counts[type]--;
    00060   }
    00061
    00067   static inline uint16 GetTypeCount(ObjectType type)
    00068   {
    00069     assert(type < NUM_OBJECTS);
    00070     return counts[type];
    00071   }
    00072
    00074   static inline void ResetTypeCounts()
    00075   {
    00076     memset(&counts, 0, sizeof(counts));
    00077   }
    00078
    00079 protected:
    00080   static uint16 counts[NUM_OBJECTS];
    00081 };
    00082
    00083 #define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
    00084 #define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
    00085
    00089 struct ClearedObjectArea {
    00090   TileIndex first_tile;
    00091   TileArea area;
    00092 };
    00093
    00094 ClearedObjectArea *FindClearedObject(TileIndex tile);
    00095 extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
    00096
    00097 #endif /* OBJECT_BASE_H */