author | miham |
Wed, 13 Dec 2006 18:45:23 +0000 | |
changeset 5330 | 478fa9dc5a2e |
parent 5216 | d581e4db95b6 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
5 |
#include "depot.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
1977
diff
changeset
|
6 |
#include "functions.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
7 |
#include "tile.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
8 |
#include "map.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
9 |
#include "table/strings.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
10 |
#include "saveload.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
11 |
#include "order.h" |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
12 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
13 |
|
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 |
* 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
|
16 |
*/ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
17 |
static void DepotPoolNewBlock(uint start_item) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
18 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
19 |
Depot *d; |
1313
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 |
/* 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
|
22 |
* TODO - This is just a temporary stage, this will be removed. */ |
4973 | 23 |
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
|
24 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
25 |
|
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
|
26 |
DEFINE_OLD_POOL(Depot, Depot, DepotPoolNewBlock, NULL) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
27 |
|
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 |
* Gets a depot from a tile |
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 |
* @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
|
33 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
34 |
Depot *GetDepotByTile(TileIndex tile) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
35 |
{ |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
36 |
Depot *depot; |
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 |
FOR_ALL_DEPOTS(depot) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3585
diff
changeset
|
39 |
if (depot->xy == tile) return depot; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
40 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
41 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
42 |
return NULL; |
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 |
|
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 |
* Allocate a new depot |
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 |
Depot *AllocateDepot(void) |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
49 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
50 |
Depot *d; |
1313
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 |
/* 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
|
53 |
* TODO - This is just a temporary stage, this will be removed. */ |
4973 | 54 |
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
|
55 |
if (!IsValidDepot(d)) { |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
56 |
DepotID index = d->index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
57 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
58 |
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
|
59 |
d->index = index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
60 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
61 |
return d; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
62 |
} |
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 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
65 |
/* Check if we can add a block to the pool */ |
4973 | 66 |
if (AddBlockToPool(&_Depot_pool)) return AllocateDepot(); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
67 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
68 |
return NULL; |
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 |
/** |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
72 |
* Clean up a depot |
1313
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 |
void DestroyDepot(Depot *depot) |
1313
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 |
/* Clear the tile */ |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
77 |
DoClearSquare(depot->xy); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
78 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
79 |
/* 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
|
80 |
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, depot->index); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
81 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
82 |
/* Delete the depot-window */ |
4388
e5a166837162
(svn r6141) -Codechange: introduced DepotID and used it as much as possible
truelight
parents:
4351
diff
changeset
|
83 |
DeleteWindowById(WC_VEHICLE_DEPOT, depot->xy); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
84 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
85 |
|
4347
79b04c2cef95
(svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
truelight
parents:
4346
diff
changeset
|
86 |
void InitializeDepots(void) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
87 |
{ |
4973 | 88 |
CleanPool(&_Depot_pool); |
89 |
AddBlockToPool(&_Depot_pool); |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
90 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
91 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
92 |
|
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
SLE_VAR(Depot, town_index, SLE_UINT16), |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
97 |
SLE_END() |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
98 |
}; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
99 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
100 |
static void Save_DEPT(void) |
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 |
Depot *depot; |
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 |
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
|
105 |
SlSetArrayIndex(depot->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
106 |
SlObject(depot, _depot_desc); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
107 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
108 |
} |
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 |
static void Load_DEPT(void) |
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 |
int index; |
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 |
while ((index = SlIterateArray()) != -1) { |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
115 |
Depot *depot; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
116 |
|
4973 | 117 |
if (!AddBlockIfNeeded(&_Depot_pool, index)) |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
118 |
error("Depots: failed loading savegame: too many depots"); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
119 |
|
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
120 |
depot = GetDepot(index); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
121 |
SlObject(depot, _depot_desc); |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
122 |
} |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
123 |
} |
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 |
const ChunkHandler _depot_chunk_handlers[] = { |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
126 |
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST}, |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
127 |
}; |