author | tron |
Mon, 25 Apr 2005 13:52:59 +0000 | |
changeset 1728 | ea7210a31593 |
parent 1718 | 96d76767ea93 |
child 1790 | 47963a0cfca3 |
permissions | -rw-r--r-- |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
1 |
#ifndef DEPOT_H |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
2 |
#define DEPOT_H |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
3 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
4 |
#include "pool.h" |
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
|
5 |
#include "tile.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
6 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
7 |
struct Depot { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
8 |
TileIndex xy; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
9 |
uint16 town_index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
10 |
uint16 index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
11 |
}; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
12 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
13 |
extern MemoryPool _depot_pool; |
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 |
* Get the pointer to the depot with index 'index' |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
17 |
*/ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
18 |
static inline Depot *GetDepot(uint index) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
19 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
20 |
return (Depot*)GetItemFromPool(&_depot_pool, index); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
21 |
} |
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 |
/** |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
24 |
* Get the current size of the DepotPool |
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 |
static inline uint16 GetDepotPoolSize(void) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
27 |
{ |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
28 |
return _depot_pool.total_items; |
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 |
|
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
31 |
static inline bool IsDepotIndex(uint index) |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
32 |
{ |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
33 |
return index < GetDepotPoolSize(); |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
34 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
35 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
36 |
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
37 |
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0) |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
38 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
39 |
#define MIN_SERVINT_PERCENT 5 |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
40 |
#define MAX_SERVINT_PERCENT 90 |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
41 |
#define MIN_SERVINT_DAYS 30 |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
42 |
#define MAX_SERVINT_DAYS 800 |
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 |
VARDEF TileIndex _last_built_train_depot_tile; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
45 |
VARDEF TileIndex _last_built_road_depot_tile; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
46 |
VARDEF TileIndex _last_built_aircraft_depot_tile; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
47 |
VARDEF TileIndex _last_built_ship_depot_tile; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
48 |
|
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
|
49 |
/** |
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
|
50 |
* Check if a depot really exists. |
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
|
51 |
*/ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1650
diff
changeset
|
52 |
static inline bool IsValidDepot(const Depot* 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
|
53 |
{ |
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
|
54 |
return depot->xy != 0; /* XXX: Replace by INVALID_TILE someday */ |
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
|
55 |
} |
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 |
|
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
|
57 |
/** |
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
|
58 |
* Check if a tile is a depot of the given type. |
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
|
59 |
*/ |
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
|
60 |
static inline bool IsTileDepotType(TileIndex tile, TransportType type) |
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
|
61 |
{ |
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
|
62 |
switch(type) |
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
|
63 |
{ |
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
|
64 |
case TRANSPORT_RAIL: |
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
|
65 |
return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0; |
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
|
66 |
break; |
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
|
67 |
case TRANSPORT_ROAD: |
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
|
68 |
return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20; |
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
|
69 |
break; |
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
|
70 |
case TRANSPORT_WATER: |
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
|
71 |
return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80; |
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
|
72 |
break; |
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
|
73 |
default: |
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
|
74 |
assert(0); |
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
|
75 |
return false; |
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
|
76 |
} |
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
|
77 |
} |
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
|
78 |
|
1650
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
79 |
/** |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
80 |
* Returns the direction the exit of the depot on the given tile is facing. |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
81 |
*/ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
82 |
static inline uint GetDepotDirection(TileIndex tile, TransportType type) |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
83 |
{ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
84 |
assert(IsTileDepotType(tile, type)); |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
85 |
|
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
86 |
switch (type) |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
87 |
{ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
88 |
case TRANSPORT_RAIL: |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
89 |
case TRANSPORT_ROAD: |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
90 |
/* Rail and road store a diagonal direction in bits 0 and 1 */ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
91 |
return _map5[tile] & 3; |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
92 |
case TRANSPORT_WATER: |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
93 |
/* Water is stubborn, it stores the directions in a different order. */ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
94 |
switch (_map5[tile] & 3) { |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
95 |
case 0: return 0; |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
96 |
case 1: return 2; |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
97 |
case 2: return 3; |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
98 |
case 3: return 1; |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
99 |
} |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
100 |
default: |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
101 |
return 0; /* Not reached */ |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
102 |
} |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
103 |
} |
4a5141e10b72
(svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents:
1330
diff
changeset
|
104 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
105 |
Depot *GetDepotByTile(uint tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
106 |
void InitializeDepot(void); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
107 |
Depot *AllocateDepot(void); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
108 |
void DoDeleteDepot(uint tile); |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
109 |
|
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff
changeset
|
110 |
#endif /* DEPOT_H */ |