2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/** @file depot.cpp */
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2007-04-12 13:07:15 +00:00
|
|
|
#include "landscape.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "saveload.h"
|
|
|
|
#include "order.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
|
2007-08-02 22:33:53 +00:00
|
|
|
DEFINE_OLD_POOL_GENERIC(Depot, Depot)
|
2005-02-06 10:18:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a depot from a tile
|
|
|
|
*
|
|
|
|
* @return Returns the depot if the tile had a depot, else it returns NULL
|
|
|
|
*/
|
2005-06-24 12:38:35 +00:00
|
|
|
Depot *GetDepotByTile(TileIndex tile)
|
2005-02-06 10:18:47 +00:00
|
|
|
{
|
|
|
|
Depot *depot;
|
|
|
|
|
|
|
|
FOR_ALL_DEPOTS(depot) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (depot->xy == tile) return depot;
|
2005-02-06 10:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-26 14:44:55 +00:00
|
|
|
* Clean up a depot
|
2005-02-06 10:18:47 +00:00
|
|
|
*/
|
2007-08-02 22:33:53 +00:00
|
|
|
Depot::~Depot()
|
2005-02-06 10:18:47 +00:00
|
|
|
{
|
2007-08-05 21:20:55 +00:00
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
/* Clear the depot from all order-lists */
|
2007-08-02 22:33:53 +00:00
|
|
|
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
|
2005-02-06 10:18:47 +00:00
|
|
|
|
|
|
|
/* Delete the depot-window */
|
2007-08-02 22:33:53 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
|
|
|
|
this->xy = 0;
|
2005-02-06 10:18:47 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeDepots()
|
2005-02-06 10:18:47 +00:00
|
|
|
{
|
2007-08-02 22:33:53 +00:00
|
|
|
_Depot_pool.CleanPool();
|
|
|
|
_Depot_pool.AddBlockToPool();
|
2005-02-06 10:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _depot_desc[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
|
|
|
|
SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLE_VAR(Depot, town_index, SLE_UINT16),
|
2005-02-06 10:18:47 +00:00
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_DEPT()
|
2005-02-06 10:18:47 +00:00
|
|
|
{
|
|
|
|
Depot *depot;
|
|
|
|
|
|
|
|
FOR_ALL_DEPOTS(depot) {
|
2006-08-22 15:33:35 +00:00
|
|
|
SlSetArrayIndex(depot->index);
|
|
|
|
SlObject(depot, _depot_desc);
|
2005-02-06 10:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_DEPT()
|
2005-02-06 10:18:47 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2007-08-02 22:33:53 +00:00
|
|
|
Depot *depot = new (index) Depot();
|
2005-02-06 10:18:47 +00:00
|
|
|
SlObject(depot, _depot_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const ChunkHandler _depot_chunk_handlers[] = {
|
2005-02-06 10:18:47 +00:00
|
|
|
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST},
|
|
|
|
};
|