author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1330 | 5d76a0522a11 |
child 1881 | 435d39bd6ee0 |
permissions | -rw-r--r-- |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
1 |
#include "stdafx.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
2 |
#include "ttd.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
3 |
#include "depot.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
4 |
#include "tile.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
5 |
#include "map.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
6 |
#include "table/strings.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
7 |
#include "saveload.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
8 |
#include "order.h" |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
9 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
10 |
enum { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
11 |
/* Max depots: 64000 (8 * 8000) */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
12 |
DEPOT_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
13 |
DEPOT_POOL_MAX_BLOCKS = 8000, |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
14 |
}; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
15 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
16 |
/** |
f1013ec3d318
(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 |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
18 |
*/ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
19 |
static void DepotPoolNewBlock(uint start_item) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
20 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
21 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
22 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
23 |
FOR_ALL_DEPOTS_FROM(depot, start_item) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
24 |
depot->index = start_item++; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
25 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
26 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
27 |
/* Initialize the town-pool */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
28 |
MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZE_BITS, sizeof(Depot), &DepotPoolNewBlock, 0, 0, NULL }; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
29 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
30 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
31 |
/** |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
32 |
* Gets a depot from a tile |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
33 |
* |
f1013ec3d318
(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 |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
35 |
*/ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
36 |
Depot *GetDepotByTile(uint tile) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
37 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
38 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
39 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
40 |
FOR_ALL_DEPOTS(depot) { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
41 |
if (depot->xy == tile) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
42 |
return depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
43 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
44 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
45 |
return NULL; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
46 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
47 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
48 |
/** |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
49 |
* Allocate a new depot |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
50 |
*/ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
51 |
Depot *AllocateDepot(void) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
52 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
53 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
54 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
55 |
FOR_ALL_DEPOTS(depot) { |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
56 |
if (!IsValidDepot(depot)) { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
57 |
uint index = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
58 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
59 |
memset(depot, 0, sizeof(Depot)); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
60 |
depot->index = index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
61 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
62 |
return depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
63 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
64 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
65 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
66 |
/* Check if we can add a block to the pool */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
67 |
if (AddBlockToPool(&_depot_pool)) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
68 |
return AllocateDepot(); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
69 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
70 |
return NULL; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
71 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
72 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
73 |
/** |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
74 |
* Delete a depot |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
75 |
*/ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
76 |
void DoDeleteDepot(uint tile) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
77 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
78 |
Order order; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
79 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
80 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
81 |
/* Get the depot */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
82 |
depot = GetDepotByTile(tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
83 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
84 |
/* Clear the tile */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
85 |
DoClearSquare(tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
86 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
87 |
/* Clear the depot */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
88 |
depot->xy = 0; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
89 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
90 |
/* Clear the depot from all order-lists */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
91 |
order.type = OT_GOTO_DEPOT; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
92 |
order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
93 |
DeleteDestinationFromVehicleOrder(order); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
94 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
95 |
/* Delete the depot-window */ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
96 |
DeleteWindowById(WC_VEHICLE_DEPOT, tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
97 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
98 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
99 |
void InitializeDepot(void) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
100 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
101 |
CleanPool(&_depot_pool); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
102 |
AddBlockToPool(&_depot_pool); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
103 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
104 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
105 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
106 |
static const byte _depot_desc[] = { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
107 |
SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
108 |
SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, 255), |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
109 |
SLE_VAR(Depot,town_index, SLE_UINT16), |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
110 |
SLE_END() |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
111 |
}; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
112 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
113 |
static void Save_DEPT(void) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
114 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
115 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
116 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
117 |
FOR_ALL_DEPOTS(depot) { |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
118 |
if (IsValidDepot(depot)) { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
119 |
SlSetArrayIndex(depot->index); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
120 |
SlObject(depot, _depot_desc); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
121 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
122 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
123 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
124 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
125 |
static void Load_DEPT(void) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
126 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
127 |
int index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
128 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
129 |
while ((index = SlIterateArray()) != -1) { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
130 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
131 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
132 |
if (!AddBlockIfNeeded(&_depot_pool, index)) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
133 |
error("Depots: failed loading savegame: too many depots"); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
134 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
135 |
depot = GetDepot(index); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
136 |
SlObject(depot, _depot_desc); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
137 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
138 |
} |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
139 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
140 |
const ChunkHandler _depot_chunk_handlers[] = { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
141 |
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST}, |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
142 |
}; |