author | belugas |
Fri, 23 Feb 2007 18:55:07 +0000 | |
changeset 6451 | 7baba06b4b85 |
parent 5838 | 9c3129cb019b |
child 6298 | c30fe89622df |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
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" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
1977
diff
changeset
|
8 |
#include "functions.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
9 |
#include "tile.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
10 |
#include "map.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
11 |
#include "table/strings.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
12 |
#include "saveload.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
13 |
#include "order.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
14 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
15 |
|
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 |
* Called if a new block is added to the depot-pool |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
18 |
*/ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
19 |
static void DepotPoolNewBlock(uint start_item) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
20 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
21 |
Depot *d; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
22 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
23 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
24 |
* TODO - This is just a temporary stage, this will be removed. */ |
4973 | 25 |
for (d = GetDepot(start_item); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) d->index = start_item++; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
26 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
27 |
|
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4973
diff
changeset
|
28 |
DEFINE_OLD_POOL(Depot, Depot, DepotPoolNewBlock, NULL) |
1313
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 |
|
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 |
* Gets a depot from a tile |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
33 |
* |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
34 |
* @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
|
35 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
36 |
Depot *GetDepotByTile(TileIndex tile) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
37 |
{ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
38 |
Depot *depot; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
39 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
40 |
FOR_ALL_DEPOTS(depot) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3585
diff
changeset
|
41 |
if (depot->xy == tile) return depot; |
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 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
44 |
return NULL; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
45 |
} |
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 |
/** |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
48 |
* Allocate a new depot |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
49 |
*/ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
50 |
Depot *AllocateDepot(void) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
51 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
52 |
Depot *d; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
53 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
54 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
55 |
* TODO - This is just a temporary stage, this will be removed. */ |
4973 | 56 |
for (d = GetDepot(0); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
57 |
if (!IsValidDepot(d)) { |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
58 |
DepotID index = d->index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
59 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
60 |
memset(d, 0, sizeof(Depot)); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
61 |
d->index = index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
62 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
63 |
return d; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
64 |
} |
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 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
67 |
/* Check if we can add a block to the pool */ |
4973 | 68 |
if (AddBlockToPool(&_Depot_pool)) return AllocateDepot(); |
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 |
return NULL; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
71 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
72 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
73 |
/** |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
74 |
* Clean up a depot |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
75 |
*/ |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
76 |
void DestroyDepot(Depot *depot) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
77 |
{ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
78 |
/* Clear the tile */ |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
79 |
DoClearSquare(depot->xy); |
1313
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 |
/* Clear the depot from all order-lists */ |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4393
diff
changeset
|
82 |
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, depot->index); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
83 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
84 |
/* Delete the depot-window */ |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
85 |
DeleteWindowById(WC_VEHICLE_DEPOT, depot->xy); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
86 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
87 |
|
4347
79b04c2cef95
(svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
truelight
parents:
4346
diff
changeset
|
88 |
void InitializeDepots(void) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
89 |
{ |
4973 | 90 |
CleanPool(&_Depot_pool); |
91 |
AddBlockToPool(&_Depot_pool); |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
92 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
93 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
94 |
|
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
SLE_VAR(Depot, town_index, SLE_UINT16), |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
99 |
SLE_END() |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
100 |
}; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
101 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
102 |
static void Save_DEPT(void) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
103 |
{ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
104 |
Depot *depot; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
105 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
106 |
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
|
107 |
SlSetArrayIndex(depot->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
108 |
SlObject(depot, _depot_desc); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
109 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
110 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
111 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
112 |
static void Load_DEPT(void) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
113 |
{ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
114 |
int index; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
115 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
116 |
while ((index = SlIterateArray()) != -1) { |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
117 |
Depot *depot; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
118 |
|
4973 | 119 |
if (!AddBlockIfNeeded(&_Depot_pool, index)) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
120 |
error("Depots: failed loading savegame: too many depots"); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
121 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
122 |
depot = GetDepot(index); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
123 |
SlObject(depot, _depot_desc); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
124 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
125 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
126 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
127 |
extern const ChunkHandler _depot_chunk_handlers[] = { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
128 |
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST}, |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
129 |
}; |