src/depot.cpp
author rubidium
Tue, 22 Jan 2008 21:00:30 +0000
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6800 6c09e1e86fcb
child 10184 fcf5fb2548eb
permissions -rw-r--r--
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5838
diff changeset
     3
/** @file depot.cpp */
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5838
diff changeset
     4
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     7
#include "depot.h"
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
     8
#include "landscape.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     9
#include "saveload.h"
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    10
#include "order.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6800
diff changeset
    11
#include "window_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6800
diff changeset
    12
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6800
diff changeset
    13
#include "table/strings.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    14
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    15
DEFINE_OLD_POOL_GENERIC(Depot, Depot)
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    16
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    17
/**
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    18
 * Gets a depot from a tile
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    19
 *
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    20
 * @return Returns the depot if the tile had a depot, else it returns NULL
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    21
 */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    22
Depot *GetDepotByTile(TileIndex tile)
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    23
{
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    24
	Depot *depot;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    25
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    26
	FOR_ALL_DEPOTS(depot) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3585
diff changeset
    27
		if (depot->xy == tile) return depot;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    28
	}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    29
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    30
	return NULL;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    31
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    32
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    33
/**
4388
e5a166837162 (svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents: 4351
diff changeset
    34
 * Clean up a depot
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    35
 */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    36
Depot::~Depot()
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    37
{
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6743
diff changeset
    38
	if (CleaningPool()) return;
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6743
diff changeset
    39
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    40
	/* Clear the depot from all order-lists */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    41
	RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    42
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    43
	/* Delete the depot-window */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    44
	DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    45
	this->xy = 0;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    46
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    47
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6451
diff changeset
    48
void InitializeDepots()
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    49
{
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    50
	_Depot_pool.CleanPool();
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    51
	_Depot_pool.AddBlockToPool();
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    52
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    53
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    54
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1330
diff changeset
    55
static const SaveLoad _depot_desc[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    56
	SLE_CONDVAR(Depot, xy,         SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    57
	SLE_CONDVAR(Depot, xy,         SLE_UINT32,                 6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    58
	    SLE_VAR(Depot, town_index, SLE_UINT16),
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    59
	SLE_END()
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    60
};
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    61
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6451
diff changeset
    62
static void Save_DEPT()
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    63
{
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    64
	Depot *depot;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    65
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    66
	FOR_ALL_DEPOTS(depot) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    67
		SlSetArrayIndex(depot->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    68
		SlObject(depot, _depot_desc);
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    69
	}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    70
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    71
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6451
diff changeset
    72
static void Load_DEPT()
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    73
{
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    74
	int index;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    75
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    76
	while ((index = SlIterateArray()) != -1) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6719
diff changeset
    77
		Depot *depot = new (index) Depot();
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    78
		SlObject(depot, _depot_desc);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    79
	}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    80
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    81
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    82
extern const ChunkHandler _depot_chunk_handlers[] = {
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    83
	{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST},
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    84
};