depot.cpp

Go to the documentation of this file.
00001 /* $Id: depot.cpp 17456 2009-09-07 14:09:45Z rubidium $ */
00002 
00005 #include "stdafx.h"
00006 #include "depot_base.h"
00007 #include "order_func.h"
00008 #include "window_func.h"
00009 #include "oldpool_func.h"
00010 #include "core/bitmath_func.hpp"
00011 #include "tile_map.h"
00012 #include "water_map.h"
00013 #include "vehicle_gui.h"
00014 
00015 DEFINE_OLD_POOL_GENERIC(Depot, Depot)
00016 
00017 
00022 Depot *GetDepotByTile(TileIndex tile)
00023 {
00024   /* A ship depot is multiple tiles. The north most tile is
00025    * always the ->xy tile, so make sure we always look for
00026    * the nothern tile and not the southern one. */
00027   if (IsShipDepotTile(tile)) {
00028     tile = min(tile, GetOtherShipDepotTile(tile));
00029   }
00030 
00031   Depot *depot;
00032 
00033   FOR_ALL_DEPOTS(depot) {
00034     if (depot->xy == tile) return depot;
00035   }
00036 
00037   return NULL;
00038 }
00039 
00043 Depot::~Depot()
00044 {
00045   if (CleaningPool()) return;
00046 
00047   /* Clear the depot from all order-lists */
00048   RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
00049 
00050   /* Delete the depot-window */
00051   DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
00052 
00053   /* Delete the depot list */
00054   WindowNumber wno = (this->index << 16) | VLW_DEPOT_LIST | GetTileOwner(this->xy);
00055   switch (GetTileType(this->xy)) {
00056     default: break; // It can happen there is no depot here anymore (TTO/TTD savegames)
00057     case MP_RAILWAY: DeleteWindowById(WC_TRAINS_LIST,  wno | (VEH_TRAIN << 11)); break;
00058     case MP_ROAD:    DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD  << 11)); break;
00059     case MP_WATER:   DeleteWindowById(WC_SHIPS_LIST,   wno | (VEH_SHIP  << 11)); break;
00060   }
00061 
00062   this->xy = INVALID_TILE;
00063 }
00064 
00065 void InitializeDepots()
00066 {
00067   _Depot_pool.CleanPool();
00068   _Depot_pool.AddBlockToPool();
00069 }

Generated on Sun Sep 13 08:19:15 2009 for OpenTTD by  doxygen 1.5.6