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