depot.cpp

Go to the documentation of this file.
00001 /* $Id: depot.cpp 11828 2008-01-13 01:21:35Z rubidium $ */
00002 
00005 #include "stdafx.h"
00006 #include "openttd.h"
00007 #include "depot.h"
00008 #include "landscape.h"
00009 #include "saveload.h"
00010 #include "order.h"
00011 #include "window_func.h"
00012 
00013 #include "table/strings.h"
00014 
00015 DEFINE_OLD_POOL_GENERIC(Depot, Depot)
00016 
00017 
00022 Depot *GetDepotByTile(TileIndex tile)
00023 {
00024   Depot *depot;
00025 
00026   FOR_ALL_DEPOTS(depot) {
00027     if (depot->xy == tile) return depot;
00028   }
00029 
00030   return NULL;
00031 }
00032 
00036 Depot::~Depot()
00037 {
00038   if (CleaningPool()) return;
00039 
00040   /* Clear the depot from all order-lists */
00041   RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
00042 
00043   /* Delete the depot-window */
00044   DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
00045   this->xy = 0;
00046 }
00047 
00048 void InitializeDepots()
00049 {
00050   _Depot_pool.CleanPool();
00051   _Depot_pool.AddBlockToPool();
00052 }
00053 
00054 
00055 static const SaveLoad _depot_desc[] = {
00056   SLE_CONDVAR(Depot, xy,         SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
00057   SLE_CONDVAR(Depot, xy,         SLE_UINT32,                 6, SL_MAX_VERSION),
00058       SLE_VAR(Depot, town_index, SLE_UINT16),
00059   SLE_END()
00060 };
00061 
00062 static void Save_DEPT()
00063 {
00064   Depot *depot;
00065 
00066   FOR_ALL_DEPOTS(depot) {
00067     SlSetArrayIndex(depot->index);
00068     SlObject(depot, _depot_desc);
00069   }
00070 }
00071 
00072 static void Load_DEPT()
00073 {
00074   int index;
00075 
00076   while ((index = SlIterateArray()) != -1) {
00077     Depot *depot = new (index) Depot();
00078     SlObject(depot, _depot_desc);
00079   }
00080 }
00081 
00082 extern const ChunkHandler _depot_chunk_handlers[] = {
00083   { 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST},
00084 };

Generated on Wed Oct 1 17:03:20 2008 for openttd by  doxygen 1.5.6