author | Darkvater |
Tue, 05 Sep 2006 23:21:41 +0000 | |
changeset 4559 | aa0c13e39840 |
parent 4549 | 106ed18a7675 |
child 4619 | aa9747946f8e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
3 |
/** @file station_cmd.c */ |
2213
bab9abeaa644
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
7 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
8 |
#include "functions.h" |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
9 |
#include "station_map.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
10 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
11 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
595
diff
changeset
|
12 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1190
diff
changeset
|
13 |
#include "tile.h" |
0 | 14 |
#include "station.h" |
15 |
#include "gfx.h" |
|
16 |
#include "window.h" |
|
17 |
#include "viewport.h" |
|
18 |
#include "command.h" |
|
19 |
#include "town.h" |
|
20 |
#include "vehicle.h" |
|
21 |
#include "news.h" |
|
22 |
#include "saveload.h" |
|
23 |
#include "economy.h" |
|
24 |
#include "player.h" |
|
25 |
#include "airport.h" |
|
405
415546028e8d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
26 |
#include "sprite.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
27 |
#include "depot.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
28 |
#include "train.h" |
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
29 |
#include "water_map.h" |
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
30 |
#include "industry_map.h" |
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
31 |
#include "newgrf_callbacks.h" |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
32 |
#include "newgrf_station.h" |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
33 |
#include "yapf/yapf.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
34 |
#include "date.h" |
0 | 35 |
|
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
36 |
enum { |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
37 |
/* Max stations: 64000 (64 * 1000) */ |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
38 |
STATION_POOL_BLOCK_SIZE_BITS = 6, /* In bits, so (1 << 6) == 64 */ |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
39 |
STATION_POOL_MAX_BLOCKS = 1000, |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
40 |
|
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
41 |
/* Max roadstops: 64000 (32 * 2000) */ |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
42 |
ROADSTOP_POOL_BLOCK_SIZE_BITS = 5, /* In bits, so (1 << 5) == 32 */ |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
43 |
ROADSTOP_POOL_MAX_BLOCKS = 2000, |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
44 |
}; |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
45 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
46 |
/** |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
47 |
* Called if a new block is added to the station-pool |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
48 |
*/ |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
49 |
static void StationPoolNewBlock(uint start_item) |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
50 |
{ |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
51 |
Station *st; |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
52 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
53 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
4348
d9ddb0558a48
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
54 |
* TODO - This is just a temporary stage, this will be removed. */ |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
55 |
for (st = GetStation(start_item); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) st->index = start_item++; |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
56 |
} |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
57 |
|
3587 | 58 |
static void StationPoolCleanBlock(uint start_item, uint end_item) |
59 |
{ |
|
60 |
uint i; |
|
61 |
||
62 |
for (i = start_item; i <= end_item; i++) { |
|
63 |
Station *st = GetStation(i); |
|
64 |
free(st->speclist); |
|
65 |
st->speclist = NULL; |
|
66 |
} |
|
67 |
} |
|
68 |
||
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
69 |
/** |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
70 |
* Called if a new block is added to the roadstop-pool |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
71 |
*/ |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
72 |
static void RoadStopPoolNewBlock(uint start_item) |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
73 |
{ |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
74 |
RoadStop *rs; |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
75 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
76 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
77 |
* TODO - This is just a temporary stage, this will be removed. */ |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
78 |
for (rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) rs->index = start_item++; |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
79 |
} |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
80 |
|
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
81 |
/* Initialize the station-pool and roadstop-pool */ |
3587 | 82 |
MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, &StationPoolCleanBlock, 0, 0, NULL }; |
3585
43461f26b729
(svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up.
peter1138
parents:
3580
diff
changeset
|
83 |
MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL }; |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
84 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
85 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
86 |
void ShowAircraftDepotWindow(TileIndex tile); |
0 | 87 |
extern void UpdateAirplanesOnNewStation(Station *st); |
88 |
||
2549 | 89 |
static void MarkStationDirty(const Station* st) |
0 | 90 |
{ |
91 |
if (st->sign.width_1 != 0) { |
|
92 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1); |
|
93 |
||
94 |
MarkAllViewportsDirty( |
|
95 |
st->sign.left - 6, |
|
96 |
st->sign.top, |
|
97 |
st->sign.left + (st->sign.width_1 << 2) + 12, |
|
98 |
st->sign.top + 48); |
|
99 |
} |
|
100 |
} |
|
101 |
||
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
102 |
static void InitializeRoadStop(RoadStop *road_stop, RoadStop *previous, TileIndex tile, StationID index) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
103 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
104 |
road_stop->xy = tile; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
105 |
road_stop->used = true; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
106 |
road_stop->status = 3; //stop is free |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
107 |
road_stop->next = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
108 |
road_stop->prev = previous; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
109 |
road_stop->station = index; |
3431 | 110 |
road_stop->num_vehicles = 0; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
111 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
112 |
|
2639 | 113 |
RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
114 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
115 |
switch (type) { |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
116 |
case RS_BUS: return st->bus_stops; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
117 |
case RS_TRUCK: return st->truck_stops; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
118 |
default: NOT_REACHED(); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
119 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
120 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
121 |
return NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
122 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
123 |
|
2639 | 124 |
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
125 |
{ |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
126 |
const Station* st = GetStationByTile(tile); |
2639 | 127 |
RoadStop* rs; |
128 |
||
129 |
for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
130 |
assert(rs->next != NULL); |
2639 | 131 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
132 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
133 |
return rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
134 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
135 |
|
4399
960cf4a06027
(svn r6152) -Codechange: renamed GetNumRoadStops to GetNumRoadStopsInStation as it reflects its function more
truelight
parents:
4398
diff
changeset
|
136 |
uint GetNumRoadStopsInStation(const Station* st, RoadStopType type) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
137 |
{ |
2549 | 138 |
uint num = 0; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
139 |
const RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
140 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
141 |
assert(st != NULL); |
2549 | 142 |
for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) num++; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
143 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
144 |
return num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
145 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
146 |
|
2549 | 147 |
RoadStop *AllocateRoadStop(void) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
148 |
{ |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
149 |
RoadStop *rs; |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
150 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
151 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
152 |
* TODO - This is just a temporary stage, this will be removed. */ |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
153 |
for (rs = GetRoadStop(0); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
154 |
if (!IsValidRoadStop(rs)) { |
4397
4160539a3062
(svn r6150) -Codechange: introduced and used RoadStopID where needed
truelight
parents:
4393
diff
changeset
|
155 |
RoadStopID index = rs->index; |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
156 |
|
2549 | 157 |
memset(rs, 0, sizeof(*rs)); |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
158 |
rs->index = index; |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
159 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
160 |
return rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
161 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
162 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
163 |
|
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
164 |
/* Check if we can add a block to the pool */ |
2639 | 165 |
if (AddBlockToPool(&_roadstop_pool)) return AllocateRoadStop(); |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
166 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
167 |
return NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
168 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
169 |
|
703
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
170 |
/* Calculate the radius of the station. Basicly it is the biggest |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
171 |
* radius that is available within the station */ |
2643 | 172 |
static uint FindCatchmentRadius(const Station* st) |
703
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
173 |
{ |
2643 | 174 |
uint ret = 0; |
703
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
175 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
176 |
if (st->bus_stops != NULL) ret = max(ret, CA_BUS); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
177 |
if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK); |
703
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
178 |
if (st->train_tile) ret = max(ret, CA_TRAIN); |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
179 |
if (st->dock_tile) ret = max(ret, CA_DOCK); |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
180 |
|
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
181 |
if (st->airport_tile) { |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
182 |
switch (st->airport_type) { |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
183 |
case AT_OILRIG: ret = max(ret, CA_AIR_OILPAD); break; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
184 |
case AT_SMALL: ret = max(ret, CA_AIR_SMALL); break; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
185 |
case AT_HELIPORT: ret = max(ret, CA_AIR_HELIPORT); break; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
186 |
case AT_LARGE: ret = max(ret, CA_AIR_LARGE); break; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
187 |
case AT_METROPOLITAN: ret = max(ret, CA_AIR_METRO); break; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
188 |
case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER); break; |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
189 |
case AT_COMMUTER: ret = max(ret, CA_AIR_COMMUTER); break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
190 |
case AT_HELIDEPOT: ret = max(ret, CA_AIR_HELIDEPOT); break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
191 |
case AT_INTERCON: ret = max(ret, CA_AIR_INTERCON); break; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
192 |
case AT_HELISTATION: ret = max(ret, CA_AIR_HELISTATION); break; |
703
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
193 |
} |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
194 |
} |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
195 |
|
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
196 |
return ret; |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
197 |
} |
3f64a428fcbc
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
198 |
|
0 | 199 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
200 |
||
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
201 |
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station) |
0 | 202 |
{ |
203 |
// check around to see if there's any stations there |
|
1981 | 204 |
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1032
diff
changeset
|
205 |
if (IsTileType(tile_cur, MP_STATION)) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
206 |
StationID t = GetStationIndex(tile_cur); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
207 |
{ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
208 |
Station *st = GetStation(t); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
209 |
// you cannot take control of an oilrig!! |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
210 |
if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK)) |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
211 |
continue; |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
212 |
} |
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
213 |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
214 |
if (closest_station == INVALID_STATION) { |
0 | 215 |
closest_station = t; |
216 |
} else if (closest_station != t) { |
|
217 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
218 |
return CHECK_STATIONS_ERR; |
|
219 |
} |
|
220 |
} |
|
1981 | 221 |
END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
222 |
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station); |
0 | 223 |
} |
224 |
||
225 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
226 |
static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h) |
0 | 227 |
{ |
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
228 |
StationID station_index = st->index; |
0 | 229 |
uint i; |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
230 |
uint x1 = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
231 |
uint y1 = TileY(tile); |
0 | 232 |
uint x2 = x1 + w - 1; |
233 |
uint y2 = y1 + h - 1; |
|
234 |
uint t; |
|
235 |
||
863
6a1444534f62
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
856
diff
changeset
|
236 |
for (i = 0; i != MapSize(); i++) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
237 |
if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) { |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
238 |
t = TileX(i); |
0 | 239 |
if (t < x1) x1 = t; |
240 |
if (t > x2) x2 = t; |
|
241 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
242 |
t = TileY(i); |
0 | 243 |
if (t < y1) y1 = t; |
244 |
if (t > y2) y2 = t; |
|
245 |
} |
|
246 |
} |
|
247 |
||
2549 | 248 |
if (y2 - y1 >= _patches.station_spread || x2 - x1 >= _patches.station_spread) { |
0 | 249 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
return true; |
|
254 |
} |
|
255 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
256 |
static Station *AllocateStation(void) |
0 | 257 |
{ |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
258 |
Station *st = NULL; |
0 | 259 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
260 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
261 |
* TODO - This is just a temporary stage, this will be removed. */ |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
262 |
for (st = GetStation(0); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
263 |
if (!IsValidStation(st)) { |
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
264 |
StationID index = st->index; |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
265 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
266 |
memset(st, 0, sizeof(Station)); |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
267 |
st->index = index; |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
268 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
269 |
return st; |
0 | 270 |
} |
271 |
} |
|
272 |
||
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
273 |
/* Check if we can add a block to the pool */ |
2639 | 274 |
if (AddBlockToPool(&_station_pool)) return AllocateStation(); |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
275 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
276 |
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING; |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
277 |
return NULL; |
0 | 278 |
} |
279 |
||
280 |
||
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
281 |
/** |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
282 |
* Counts the numbers of tiles matching a specific type in the area around |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
283 |
* @param tile the center tile of the 'count area' |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
284 |
* @param type the type of tile searched for |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
285 |
* @param industry when type == MP_INDUSTRY, the type of the industry, |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
286 |
* in all other cases this parameter is ignored |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
287 |
* @result the noumber of matching tiles around |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
288 |
*/ |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
289 |
static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry) |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
290 |
{ |
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
291 |
TileIndex cur_tile; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
292 |
int dx, dy; |
0 | 293 |
int num = 0; |
294 |
||
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
295 |
for (dx = -3; dx <= 3; dx++) { |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
296 |
for (dy = -3; dy <= 3; dy++) { |
3682
e435df955cf6
(svn r4602) - Fix: an assertion triggered when building a station near the south corner of the map (appeared in r4367)
glx
parents:
3676
diff
changeset
|
297 |
cur_tile = TILE_MASK(tile + TileDiffXY(dx, dy)); |
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
298 |
|
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
299 |
if (IsTileType(cur_tile, type)) { |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
300 |
switch (type) { |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
301 |
case MP_INDUSTRY: |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
302 |
if (GetIndustryType(cur_tile) == industry) |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
303 |
num++; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
304 |
break; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
305 |
|
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
306 |
case MP_WATER: |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
307 |
if (!IsWater(cur_tile)) |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
308 |
break; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
309 |
/* FALL THROUGH WHEN WATER TILE */ |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
310 |
case MP_TREES: |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
311 |
num++; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
312 |
break; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
313 |
|
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
314 |
default: |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
315 |
break; |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
316 |
} |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
317 |
} |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
318 |
} |
0 | 319 |
} |
320 |
||
321 |
return num; |
|
322 |
} |
|
323 |
||
324 |
#define M(x) ((x) - STR_SV_STNAME) |
|
325 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
326 |
static bool GenerateStationName(Station *st, TileIndex tile, int flag) |
0 | 327 |
{ |
328 |
static const uint32 _gen_station_name_bits[] = { |
|
1454 | 329 |
0, /* 0 */ |
330 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
331 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
332 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
333 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
334 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
0 | 335 |
}; |
336 |
||
337 |
Town *t = st->town; |
|
338 |
uint32 free_names = (uint32)-1; |
|
339 |
int found; |
|
340 |
uint z,z2; |
|
341 |
unsigned long tmp; |
|
342 |
||
343 |
{ |
|
344 |
Station *s; |
|
345 |
||
346 |
FOR_ALL_STATIONS(s) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
347 |
if (s != st && s->town==t) { |
0 | 348 |
uint str = M(s->string_id); |
349 |
if (str <= 0x20) { |
|
350 |
if (str == M(STR_SV_STNAME_FOREST)) |
|
351 |
str = M(STR_SV_STNAME_WOODS); |
|
352 |
CLRBIT(free_names, str); |
|
353 |
} |
|
354 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
355 |
} |
0 | 356 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
357 |
|
0 | 358 |
/* check default names */ |
359 |
tmp = free_names & _gen_station_name_bits[flag]; |
|
360 |
if (tmp != 0) { |
|
361 |
found = FindFirstBit(tmp); |
|
362 |
goto done; |
|
363 |
} |
|
364 |
||
365 |
/* check mine? */ |
|
366 |
if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) { |
|
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
367 |
if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 || |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
368 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 || |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
369 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 || |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
370 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 || |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
371 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) { |
1454 | 372 |
found = M(STR_SV_STNAME_MINES); |
373 |
goto done; |
|
374 |
} |
|
0 | 375 |
} |
376 |
||
377 |
/* check close enough to town to get central as name? */ |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
378 |
if (DistanceMax(tile,t->xy) < 8) { |
0 | 379 |
found = M(STR_SV_STNAME); |
380 |
if (HASBIT(free_names, M(STR_SV_STNAME))) goto done; |
|
381 |
||
382 |
found = M(STR_SV_STNAME_CENTRAL); |
|
383 |
if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done; |
|
384 |
} |
|
385 |
||
386 |
/* Check lakeside */ |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
387 |
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
388 |
DistanceFromEdge(tile) < 20 && |
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
389 |
CountMapSquareAround(tile, MP_WATER, 0) >= 5) { |
1454 | 390 |
found = M(STR_SV_STNAME_LAKESIDE); |
391 |
goto done; |
|
392 |
} |
|
0 | 393 |
|
394 |
/* Check woods */ |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
395 |
if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && ( |
3515
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
396 |
CountMapSquareAround(tile, MP_TREES, 0) >= 8 || |
86dccaaef457
(svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents:
3503
diff
changeset
|
397 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2) |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
398 |
) { |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
399 |
found = _opt.landscape == LT_DESERT ? |
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
400 |
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS); |
1454 | 401 |
goto done; |
0 | 402 |
} |
403 |
||
404 |
/* check elevation compared to town */ |
|
405 |
z = GetTileZ(tile); |
|
406 |
z2 = GetTileZ(t->xy); |
|
407 |
if (z < z2) { |
|
408 |
found = M(STR_SV_STNAME_VALLEY); |
|
409 |
if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done; |
|
410 |
} else if (z > z2) { |
|
411 |
found = M(STR_SV_STNAME_HEIGHTS); |
|
412 |
if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done; |
|
413 |
} |
|
414 |
||
415 |
/* check direction compared to town */ |
|
416 |
{ |
|
417 |
static const int8 _direction_and_table[] = { |
|
418 |
~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
419 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
420 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ), |
|
421 |
~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ), |
|
422 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
423 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
424 |
free_names &= _direction_and_table[ |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
425 |
(TileX(tile) < TileX(t->xy)) + |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
426 |
(TileY(tile) < TileY(t->xy)) * 2]; |
0 | 427 |
} |
428 |
||
429 |
tmp = free_names & ((1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<6)|(1<<7)|(1<<12)|(1<<26)|(1<<27)|(1<<28)|(1<<29)|(1<<30)); |
|
430 |
if (tmp == 0) { |
|
431 |
_error_message = STR_3007_TOO_MANY_STATIONS_LOADING; |
|
432 |
return false; |
|
433 |
} |
|
434 |
found = FindFirstBit(tmp); |
|
435 |
||
436 |
done: |
|
437 |
st->string_id = found + STR_SV_STNAME; |
|
438 |
return true; |
|
439 |
} |
|
440 |
#undef M |
|
441 |
||
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
442 |
static Station* GetClosestStationFromTile(TileIndex tile, uint threshold, PlayerID owner) |
0 | 443 |
{ |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
444 |
Station* best_station = NULL; |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
445 |
Station* st; |
0 | 446 |
|
447 |
FOR_ALL_STATIONS(st) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
448 |
if ((owner == OWNER_SPECTATOR || st->owner == owner)) { |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
449 |
uint cur_dist = DistanceManhattan(tile, st->xy); |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
450 |
|
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
451 |
if (cur_dist < threshold) { |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
452 |
threshold = cur_dist; |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
453 |
best_station = st; |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
454 |
} |
0 | 455 |
} |
456 |
} |
|
457 |
||
458 |
return best_station; |
|
459 |
} |
|
460 |
||
461 |
static void StationInitialize(Station *st, TileIndex tile) |
|
462 |
{ |
|
463 |
GoodsEntry *ge; |
|
464 |
||
465 |
st->xy = tile; |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
466 |
st->airport_tile = st->dock_tile = st->train_tile = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
467 |
st->bus_stops = st->truck_stops = NULL; |
0 | 468 |
st->had_vehicle_of_type = 0; |
469 |
st->time_since_load = 255; |
|
470 |
st->time_since_unload = 255; |
|
471 |
st->delete_ctr = 0; |
|
472 |
st->facilities = 0; |
|
473 |
||
3580
14bf6e7715c8
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3576
diff
changeset
|
474 |
st->last_vehicle_type = VEH_Invalid; |
0 | 475 |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
476 |
for (ge = st->goods; ge != endof(st->goods); ge++) { |
0 | 477 |
ge->waiting_acceptance = 0; |
478 |
ge->days_since_pickup = 0; |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
479 |
ge->enroute_from = INVALID_STATION; |
0 | 480 |
ge->rating = 175; |
481 |
ge->last_speed = 0; |
|
482 |
ge->last_age = 0xFF; |
|
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1902
diff
changeset
|
483 |
ge->feeder_profit = 0; |
0 | 484 |
} |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
485 |
|
3687
f421ffcfeb00
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
486 |
st->random_bits = Random(); |
f421ffcfeb00
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
487 |
st->waiting_triggers = 0; |
f421ffcfeb00
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
488 |
|
0 | 489 |
} |
490 |
||
491 |
// Update the virtual coords needed to draw the station sign. |
|
492 |
// st = Station to update for. |
|
493 |
static void UpdateStationVirtCoord(Station *st) |
|
494 |
{ |
|
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
495 |
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
496 |
|
0 | 497 |
pt.y -= 32; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
498 |
if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16; |
0 | 499 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
500 |
SetDParam(0, st->index); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
501 |
SetDParam(1, st->facilities); |
0 | 502 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
503 |
} |
|
504 |
||
505 |
// Update the virtual coords needed to draw the station sign for all stations. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
506 |
void UpdateAllStationVirtCoord(void) |
0 | 507 |
{ |
2639 | 508 |
Station* st; |
509 |
||
0 | 510 |
FOR_ALL_STATIONS(st) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
511 |
UpdateStationVirtCoord(st); |
0 | 512 |
} |
513 |
} |
|
514 |
||
515 |
// Update the station virt coords while making the modified parts dirty. |
|
516 |
static void UpdateStationVirtCoordDirty(Station *st) |
|
517 |
{ |
|
518 |
MarkStationDirty(st); |
|
519 |
UpdateStationVirtCoord(st); |
|
520 |
MarkStationDirty(st); |
|
521 |
} |
|
522 |
||
523 |
// Get a mask of the cargo types that the station accepts. |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
524 |
static uint GetAcceptanceMask(const Station *st) |
0 | 525 |
{ |
526 |
uint mask = 0; |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
527 |
uint i; |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
528 |
|
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
529 |
for (i = 0; i != NUM_CARGO; i++) { |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
530 |
if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i; |
0 | 531 |
} |
532 |
return mask; |
|
533 |
} |
|
534 |
||
535 |
// Items contains the two cargo names that are to be accepted or rejected. |
|
536 |
// msg is the string id of the message to display. |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
537 |
static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg) |
0 | 538 |
{ |
539 |
if (items) { |
|
2549 | 540 |
SetDParam(2, GB(items, 16, 16)); |
541 |
SetDParam(1, GB(items, 0, 16)); |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
542 |
SetDParam(0, st->index); |
0 | 543 |
AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); |
544 |
} |
|
545 |
} |
|
546 |
||
547 |
// Get a list of the cargo types being produced around the tile. |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
548 |
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
549 |
int w, int h, int rad) |
0 | 550 |
{ |
551 |
int x,y; |
|
552 |
int x1,y1,x2,y2; |
|
553 |
int xc,yc; |
|
554 |
||
2133 | 555 |
memset(produced, 0, sizeof(AcceptedCargo)); |
0 | 556 |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
557 |
x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
558 |
y = TileY(tile); |
0 | 559 |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
560 |
// expand the region by rad tiles on each side |
0 | 561 |
// while making sure that we remain inside the board. |
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
562 |
x2 = min(x + w + rad, MapSizeX()); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
563 |
x1 = max(x - rad, 0); |
568
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
564 |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
565 |
y2 = min(y + h + rad, MapSizeY()); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
566 |
y1 = max(y - rad, 0); |
0 | 567 |
|
568 |
assert(x1 < x2); |
|
569 |
assert(y1 < y2); |
|
570 |
assert(w > 0); |
|
571 |
assert(h > 0); |
|
572 |
||
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
573 |
for (yc = y1; yc != y2; yc++) { |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
574 |
for (xc = x1; xc != x2; xc++) { |
0 | 575 |
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) { |
576 |
GetProducedCargoProc *gpc; |
|
1981 | 577 |
TileIndex tile = TileXY(xc, yc); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
578 |
|
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
579 |
gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc; |
0 | 580 |
if (gpc != NULL) { |
3344
fc86351d4641
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3334
diff
changeset
|
581 |
CargoID cargos[2] = { CT_INVALID, CT_INVALID }; |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
582 |
|
0 | 583 |
gpc(tile, cargos); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
584 |
if (cargos[0] != CT_INVALID) { |
0 | 585 |
produced[cargos[0]]++; |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
586 |
if (cargos[1] != CT_INVALID) { |
0 | 587 |
produced[cargos[1]]++; |
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
592 |
} |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
593 |
} |
0 | 594 |
} |
595 |
||
596 |
// Get a list of the cargo types that are accepted around the tile. |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
597 |
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
598 |
int w, int h, int rad) |
0 | 599 |
{ |
600 |
int x,y; |
|
601 |
int x1,y1,x2,y2; |
|
602 |
int xc,yc; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
603 |
|
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
604 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 605 |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
606 |
x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
607 |
y = TileY(tile); |
0 | 608 |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
609 |
// expand the region by rad tiles on each side |
0 | 610 |
// while making sure that we remain inside the board. |
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
611 |
x2 = min(x + w + rad, MapSizeX()); |
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
847
diff
changeset
|
612 |
y2 = min(y + h + rad, MapSizeY()); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
613 |
x1 = max(x - rad, 0); |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
614 |
y1 = max(y - rad, 0); |
0 | 615 |
|
616 |
assert(x1 < x2); |
|
617 |
assert(y1 < y2); |
|
618 |
assert(w > 0); |
|
619 |
assert(h > 0); |
|
620 |
||
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
621 |
for (yc = y1; yc != y2; yc++) { |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
622 |
for (xc = x1; xc != x2; xc++) { |
1981 | 623 |
TileIndex tile = TileXY(xc, yc); |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
624 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1032
diff
changeset
|
625 |
if (!IsTileType(tile, MP_STATION)) { |
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
626 |
AcceptedCargo ac; |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
627 |
uint i; |
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
628 |
|
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
629 |
GetAcceptedCargo(tile, ac); |
2639 | 630 |
for (i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; |
0 | 631 |
} |
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
632 |
} |
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
633 |
} |
0 | 634 |
} |
635 |
||
2793
a0d17504b599
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
636 |
typedef struct ottd_Rectangle { |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
637 |
uint min_x; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
638 |
uint min_y; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
639 |
uint max_x; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
640 |
uint max_y; |
2793
a0d17504b599
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
641 |
} ottd_Rectangle; |
a0d17504b599
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
642 |
|
a0d17504b599
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
643 |
static void MergePoint(ottd_Rectangle* rect, TileIndex tile) |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
644 |
{ |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
645 |
uint x = TileX(tile); |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
646 |
uint y = TileY(tile); |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
647 |
|
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
648 |
if (rect->min_x > x) rect->min_x = x; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
649 |
if (rect->min_y > y) rect->min_y = y; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
650 |
if (rect->max_x < x) rect->max_x = x; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
651 |
if (rect->max_y < y) rect->max_y = y; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
652 |
} |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
653 |
|
0 | 654 |
// Update the acceptance for a station. |
655 |
// show_msg controls whether to display a message that acceptance was changed. |
|
656 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
|
657 |
{ |
|
658 |
uint old_acc, new_acc; |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
659 |
const RoadStop *cur_rs; |
0 | 660 |
int i; |
2793
a0d17504b599
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
661 |
ottd_Rectangle rect; |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
662 |
int rad; |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
663 |
AcceptedCargo accepts; |
0 | 664 |
|
1507
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
665 |
rect.min_x = MapSizeX(); |
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
666 |
rect.min_y = MapSizeY(); |
18cb39ddddfd
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
667 |
rect.max_x = rect.max_y = 0; |
0 | 668 |
// Don't update acceptance for a buoy |
2639 | 669 |
if (IsBuoy(st)) return; |
0 | 670 |
|
671 |
/* old accepted goods types */ |
|
672 |
old_acc = GetAcceptanceMask(st); |
|
673 |
||
674 |
// Put all the tiles that span an area in the table. |
|
675 |
if (st->train_tile != 0) { |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
676 |
MergePoint(&rect, st->train_tile); |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
677 |
MergePoint(&rect, |
1981 | 678 |
st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1) |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
679 |
); |
0 | 680 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
681 |
|
0 | 682 |
if (st->airport_tile != 0) { |
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
683 |
const AirportFTAClass* afc = GetAirport(st->airport_type); |
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
684 |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
685 |
MergePoint(&rect, st->airport_tile); |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
686 |
MergePoint(&rect, |
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
687 |
st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1) |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
688 |
); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
689 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
690 |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
691 |
if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile); |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
692 |
|
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
693 |
for (cur_rs = st->bus_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
694 |
MergePoint(&rect, cur_rs->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
695 |
} |
0 | 696 |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
697 |
for (cur_rs = st->truck_stops; cur_rs != NULL; cur_rs = cur_rs->next) { |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
698 |
MergePoint(&rect, cur_rs->xy); |
0 | 699 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
700 |
|
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
701 |
rad = (_patches.modified_catchment) ? FindCatchmentRadius(st) : 4; |
0 | 702 |
|
703 |
// And retrieve the acceptance. |
|
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
704 |
if (rect.max_x >= rect.min_x) { |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
705 |
GetAcceptanceAroundTiles( |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
706 |
accepts, |
1981 | 707 |
TileXY(rect.min_x, rect.min_y), |
1423
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
708 |
rect.max_x - rect.min_x + 1, |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
709 |
rect.max_y - rect.min_y + 1, |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
710 |
rad |
11cd644bf8f8
(svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents:
1417
diff
changeset
|
711 |
); |
0 | 712 |
} else { |
713 |
memset(accepts, 0, sizeof(accepts)); |
|
714 |
} |
|
715 |
||
716 |
// Adjust in case our station only accepts fewer kinds of goods |
|
1424
38b76de179c9
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
717 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 718 |
uint amt = min(accepts[i], 15); |
719 |
||
720 |
// Make sure the station can accept the goods type. |
|
721 |
if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
|
722 |
(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) |
|
723 |
amt = 0; |
|
724 |
||
2504
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
725 |
SB(st->goods[i].waiting_acceptance, 12, 4, amt); |
0 | 726 |
} |
727 |
||
728 |
// Only show a message in case the acceptance was actually changed. |
|
729 |
new_acc = GetAcceptanceMask(st); |
|
730 |
if (old_acc == new_acc) |
|
731 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
732 |
|
0 | 733 |
// show a message to report that the acceptance was changed? |
734 |
if (show_msg && st->owner == _local_player && st->facilities) { |
|
735 |
uint32 accept=0, reject=0; /* these contain two string ids each */ |
|
736 |
const StringID *str = _cargoc.names_s; |
|
737 |
||
738 |
do { |
|
739 |
if (new_acc & 1) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
740 |
if (!(old_acc & 1)) accept = (accept << 16) | *str; |
0 | 741 |
} else { |
742 |
if (old_acc & 1) reject = (reject << 16) | *str; |
|
743 |
} |
|
744 |
} while (str++,(new_acc>>=1) != (old_acc>>=1)); |
|
745 |
||
746 |
ShowRejectOrAcceptNews(st, accept, STR_3040_NOW_ACCEPTS); |
|
747 |
ShowRejectOrAcceptNews(st, reject, STR_303E_NO_LONGER_ACCEPTS); |
|
748 |
} |
|
749 |
||
750 |
// redraw the station view since acceptance changed |
|
751 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); |
|
752 |
} |
|
753 |
||
754 |
// This is called right after a station was deleted. |
|
755 |
// It checks if the whole station is free of substations, and if so, the station will be |
|
756 |
// deleted after a little while. |
|
2639 | 757 |
static void DeleteStationIfEmpty(Station* st) |
758 |
{ |
|
0 | 759 |
if (st->facilities == 0) { |
760 |
st->delete_ctr = 0; |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
761 |
RebuildStationLists(); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
762 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
27
87c8058a69b5
(svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents:
22
diff
changeset
|
763 |
} |
0 | 764 |
} |
765 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
766 |
static int32 ClearTile_Station(TileIndex tile, byte flags); |
977
ab88e042b39d
(svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents:
972
diff
changeset
|
767 |
|
0 | 768 |
// Tries to clear the given area. Returns the cost in case of success. |
769 |
// Or an error code if it failed. |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
770 |
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station) |
0 | 771 |
{ |
772 |
int32 cost = 0, ret; |
|
773 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
774 |
Slope tileh; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
775 |
uint z; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
776 |
int allowed_z = -1; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
777 |
int flat_z; |
0 | 778 |
|
779 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
|
2639 | 780 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 781 |
|
782 |
tileh = GetTileSlope(tile_cur, &z); |
|
783 |
||
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
784 |
/* Prohibit building if |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
785 |
* 1) The tile is "steep" (i.e. stretches two height levels) |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
786 |
* -OR- |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
787 |
* 2) The tile is non-flat if |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
788 |
* a) the player building is an "old-school" AI |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
789 |
* -OR- |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
790 |
* b) the build_on_slopes switch is disabled |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
791 |
*/ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
792 |
if (IsSteepSlope(tileh) || |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
793 |
((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
794 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 795 |
} |
796 |
||
797 |
flat_z = z; |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
798 |
if (tileh != SLOPE_FLAT) { |
0 | 799 |
// need to check so the entrance to the station is not pointing at a slope. |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
800 |
if ((invalid_dirs&1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) || |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4399
diff
changeset
|
801 |
(invalid_dirs&2 && !(tileh & SLOPE_SE) && h_cur == 1) || |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
802 |
(invalid_dirs&4 && !(tileh & SLOPE_SW) && w_cur == 1) || |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
803 |
(invalid_dirs&8 && !(tileh & SLOPE_NW) && (uint)h_cur == h)) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
804 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 805 |
} |
806 |
cost += _price.terraform; |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
807 |
flat_z += TILE_HEIGHT; |
0 | 808 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
809 |
|
0 | 810 |
// get corresponding flat level and make sure that all parts of the station have the same level. |
811 |
if (allowed_z == -1) { |
|
812 |
// first tile |
|
813 |
allowed_z = flat_z; |
|
814 |
} else if (allowed_z != flat_z) { |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
815 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 816 |
} |
817 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
818 |
// if station is set, then we have special handling to allow building on top of already existing stations. |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
819 |
// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build |
0 | 820 |
// on exactly that station. |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1032
diff
changeset
|
821 |
if (station != NULL && IsTileType(tile_cur, MP_STATION)) { |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
822 |
if (!IsRailwayStation(tile_cur)) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
823 |
return ClearTile_Station(tile_cur, DC_AUTO); // get error message |
0 | 824 |
} else { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
825 |
StationID st = GetStationIndex(tile_cur); |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
826 |
if (*station == INVALID_STATION) { |
0 | 827 |
*station = st; |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
828 |
} else if (*station != st) { |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
829 |
return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING); |
0 | 830 |
} |
831 |
} |
|
832 |
} else { |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
833 |
ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
834 |
if (CmdFailed(ret)) return ret; |
0 | 835 |
cost += ret; |
836 |
} |
|
837 |
END_TILE_LOOP(tile_cur, w, h, tile) |
|
838 |
||
839 |
return cost; |
|
840 |
} |
|
841 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
842 |
static bool CanExpandRailroadStation(Station* st, uint* fin, Axis axis) |
0 | 843 |
{ |
844 |
uint curw = st->trainst_w, curh = st->trainst_h; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
845 |
TileIndex tile = fin[0]; |
0 | 846 |
uint w = fin[1]; |
847 |
uint h = fin[2]; |
|
848 |
||
849 |
if (_patches.nonuniform_stations) { |
|
850 |
// determine new size of train station region.. |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
851 |
int x = min(TileX(st->train_tile), TileX(tile)); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
852 |
int y = min(TileY(st->train_tile), TileY(tile)); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
853 |
curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
854 |
curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; |
1981 | 855 |
tile = TileXY(x, y); |
0 | 856 |
} else { |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
857 |
// check so the orientation is the same |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
858 |
if (GetRailStationAxis(st->train_tile) != axis) { |
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
859 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
860 |
return false; |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
861 |
} |
0 | 862 |
|
863 |
// check if the new station adjoins the old station in either direction |
|
1981 | 864 |
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { |
0 | 865 |
// above |
866 |
curh += h; |
|
1981 | 867 |
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { |
0 | 868 |
// below |
1981 | 869 |
tile -= TileDiffXY(0, curh); |
0 | 870 |
curh += h; |
1981 | 871 |
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { |
0 | 872 |
// to the left |
873 |
curw += w; |
|
1981 | 874 |
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { |
0 | 875 |
// to the right |
1981 | 876 |
tile -= TileDiffXY(curw, 0); |
0 | 877 |
curw += w; |
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
878 |
} else { |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
879 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
0 | 880 |
return false; |
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
881 |
} |
0 | 882 |
} |
883 |
// make sure the final size is not too big. |
|
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
884 |
if (curw > _patches.station_spread || curh > _patches.station_spread) { |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
885 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
886 |
return false; |
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
887 |
} |
0 | 888 |
|
889 |
// now tile contains the new value for st->train_tile |
|
890 |
// curw, curh contain the new value for width and height |
|
891 |
fin[0] = tile; |
|
892 |
fin[1] = curw; |
|
893 |
fin[2] = curh; |
|
894 |
return true; |
|
895 |
} |
|
896 |
||
536 | 897 |
static inline byte *CreateSingle(byte *layout, int n) |
0 | 898 |
{ |
899 |
int i = n; |
|
900 |
do *layout++ = 0; while (--i); |
|
901 |
layout[((n-1) >> 1)-n] = 2; |
|
902 |
return layout; |
|
903 |
} |
|
904 |
||
536 | 905 |
static inline byte *CreateMulti(byte *layout, int n, byte b) |
0 | 906 |
{ |
907 |
int i = n; |
|
908 |
do *layout++ = b; while (--i); |
|
909 |
if (n > 4) { |
|
910 |
layout[0-n] = 0; |
|
911 |
layout[n-1-n] = 0; |
|
912 |
} |
|
913 |
return layout; |
|
914 |
} |
|
915 |
||
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
916 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec) |
0 | 917 |
{ |
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
918 |
if (statspec != NULL && statspec->lengths >= plat_len && |
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
919 |
statspec->platforms[plat_len - 1] >= numtracks && |
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
920 |
statspec->layouts[plat_len - 1][numtracks - 1]) { |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
921 |
/* Custom layout defined, follow it. */ |
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
922 |
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1], |
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
923 |
plat_len * numtracks); |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
924 |
return; |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
925 |
} |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
926 |
|
0 | 927 |
if (plat_len == 1) { |
928 |
CreateSingle(layout, numtracks); |
|
929 |
} else { |
|
2639 | 930 |
if (numtracks & 1) layout = CreateSingle(layout, plat_len); |
931 |
numtracks >>= 1; |
|
0 | 932 |
|
933 |
while (--numtracks >= 0) { |
|
934 |
layout = CreateMulti(layout, plat_len, 4); |
|
935 |
layout = CreateMulti(layout, plat_len, 6); |
|
936 |
} |
|
937 |
} |
|
938 |
} |
|
939 |
||
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
940 |
/** Build railroad station |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
941 |
* @param tile_org starting position of station dragging/placement |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
942 |
* @param p1 various bitstuffed elements |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
943 |
* - p1 = (bit 0) - orientation (p1 & 1) |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
944 |
* - p1 = (bit 8-15) - number of tracks |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
945 |
* - p1 = (bit 16-23) - platform length |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
946 |
* @param p2 various bitstuffed elements |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
947 |
* - p2 = (bit 0- 3) - railtype (p2 & 0xF) |
3587 | 948 |
* - p2 = (bit 8-15) - custom station class |
949 |
* - p2 = (bit 16-23) - custom station id |
|
0 | 950 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
951 |
int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2) |
0 | 952 |
{ |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
953 |
Station *st; |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
954 |
int w_org, h_org; |
0 | 955 |
int32 cost, ret; |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
956 |
StationID est; |
0 | 957 |
int plat_len, numtracks; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
958 |
Axis axis; |
0 | 959 |
uint finalvalues[3]; |
3587 | 960 |
const StationSpec *statspec; |
961 |
int specindex; |
|
0 | 962 |
|
963 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
964 |
||
965 |
/* Does the authority allow this? */ |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
966 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR; |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
967 |
if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR; |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
968 |
|
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
969 |
/* unpack parameters */ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
970 |
axis = p1 & 1; |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
971 |
numtracks = GB(p1, 8, 8); |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
972 |
plat_len = GB(p1, 16, 8); |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
973 |
/* w = length, h = num_tracks */ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
974 |
if (axis == AXIS_X) { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
975 |
w_org = plat_len; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
976 |
h_org = numtracks; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
977 |
} else { |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
978 |
h_org = plat_len; |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
979 |
w_org = numtracks; |
0 | 980 |
} |
981 |
||
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
982 |
if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR; |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
983 |
|
0 | 984 |
// these values are those that will be stored in train_tile and station_platforms |
985 |
finalvalues[0] = tile_org; |
|
986 |
finalvalues[1] = w_org; |
|
987 |
finalvalues[2] = h_org; |
|
988 |
||
989 |
// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
990 |
est = INVALID_STATION; |
313
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
991 |
// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug |
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
992 |
// for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
993 |
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
994 |
if (CmdFailed(ret)) return ret; |
0 | 995 |
cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len; |
996 |
||
997 |
// Make sure there are no similar stations around us. |
|
998 |
st = GetStationAround(tile_org, w_org, h_org, est); |
|
999 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
|
1000 |
||
1001 |
// See if there is a deleted station close to us. |
|
1002 |
if (st == NULL) { |
|
1003 |
st = GetClosestStationFromTile(tile_org, 8, _current_player); |
|
1004 |
if (st != NULL && st->facilities) st = NULL; |
|
1005 |
} |
|
1006 |
||
1007 |
if (st != NULL) { |
|
1008 |
// Reuse an existing station. |
|
1009 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1010 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
1011 |
||
1012 |
if (st->train_tile != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
1013 |
// check if we want to expanding an already existing station? |
2422
897a01f7c624
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2395
diff
changeset
|
1014 |
if (_is_old_ai_player || !_patches.join_stations) |
0 | 1015 |
return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD); |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
1016 |
if (!CanExpandRailroadStation(st, finalvalues, axis)) |
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
1017 |
return CMD_ERROR; |
0 | 1018 |
} |
1019 |
||
1189
257509152c47
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
1020 |
//XXX can't we pack this in the "else" part of the if above? |
2639 | 1021 |
if (!CheckStationSpreadOut(st, tile_org, w_org, h_org)) return CMD_ERROR; |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4399
diff
changeset
|
1022 |
} else { |
0 | 1023 |
// Create a new station |
1024 |
st = AllocateStation(); |
|
2639 | 1025 |
if (st == NULL) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1026 |
|
0 | 1027 |
st->town = ClosestTownFromTile(tile_org, (uint)-1); |
2639 | 1028 |
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) |
0 | 1029 |
SETBIT(st->town->have_ratings, _current_player); |
1030 |
||
2639 | 1031 |
if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR; |
1032 |
||
1033 |
if (flags & DC_EXEC) StationInitialize(st, tile_org); |
|
0 | 1034 |
} |
1035 |
||
3587 | 1036 |
/* Check if the given station class is valid */ |
1037 |
if (GB(p2, 8, 8) >= STAT_CLASS_MAX) return CMD_ERROR; |
|
1038 |
||
1039 |
/* Check if we can allocate a custom stationspec to this station */ |
|
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
1040 |
statspec = GetCustomStationSpec(GB(p2, 8, 8), GB(p2, 16, 8)); |
3587 | 1041 |
specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC); |
1042 |
if (specindex == -1) return CMD_ERROR; |
|
1043 |
||
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1044 |
if (statspec != NULL) { |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1045 |
/* Perform NewStation checks */ |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1046 |
|
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1047 |
/* Check if the station size is permitted */ |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1048 |
if (HASBIT(statspec->disallowed_platforms, numtracks - 1) || HASBIT(statspec->disallowed_lengths, plat_len - 1)) { |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1049 |
return CMD_ERROR; |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1050 |
} |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1051 |
|
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1052 |
/* Check if the station is buildable */ |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1053 |
if (HASBIT(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1054 |
return CMD_ERROR; |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1055 |
} |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1056 |
} |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1057 |
|
0 | 1058 |
if (flags & DC_EXEC) { |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1059 |
TileIndexDiff tile_delta; |
0 | 1060 |
byte *layout_ptr; |
3769
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1061 |
byte numtracks_orig; |
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1062 |
Track track; |
0 | 1063 |
|
313
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1064 |
// Now really clear the land below the station |
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1065 |
// It should never return CMD_ERROR.. but you never know ;) |
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1066 |
// (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1067 |
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1068 |
if (CmdFailed(ret)) return ret; |
313
0c7cac001d1a
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
1069 |
|
0 | 1070 |
st->train_tile = finalvalues[0]; |
1071 |
if (!st->facilities) st->xy = finalvalues[0]; |
|
1072 |
st->facilities |= FACIL_TRAIN; |
|
1073 |
st->owner = _current_player; |
|
1074 |
||
1075 |
st->trainst_w = finalvalues[1]; |
|
1076 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1077 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1078 |
st->build_date = _date; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1079 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
1080 |
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
4158 | 1081 |
track = AxisToTrack(axis); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1082 |
|
0 | 1083 |
layout_ptr = alloca(numtracks * plat_len); |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1084 |
GetStationLayout(layout_ptr, numtracks, plat_len, statspec); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1085 |
|
3769
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1086 |
numtracks_orig = numtracks; |
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1087 |
|
0 | 1088 |
do { |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1774
diff
changeset
|
1089 |
TileIndex tile = tile_org; |
0 | 1090 |
int w = plat_len; |
1091 |
do { |
|
3769
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1092 |
byte layout = *layout_ptr++; |
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1093 |
MakeRailStation(tile, st->owner, st->index, axis, layout, GB(p2, 0, 4)); |
3587 | 1094 |
SetCustomStationSpecIndex(tile, specindex); |
3742
c5ef7a92daa5
(svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents:
3741
diff
changeset
|
1095 |
SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
0 | 1096 |
|
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1097 |
if (statspec != NULL) { |
3784
213a1a3f8697
(svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents:
3775
diff
changeset
|
1098 |
/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */ |
213a1a3f8697
(svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents:
3775
diff
changeset
|
1099 |
uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false); |
3769
7d3b35126fc1
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
1100 |
uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile); |
3784
213a1a3f8697
(svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents:
3775
diff
changeset
|
1101 |
if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, callback + axis); |
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1102 |
} |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
1103 |
|
0 | 1104 |
tile += tile_delta; |
1105 |
} while (--w); |
|
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1106 |
SetSignalsOnBothDir(tile_org, track); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1107 |
YapfNotifyTrackLayoutChange(tile_org, track); |
1981 | 1108 |
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta |
0 | 1109 |
} while (--numtracks); |
1110 |
||
1111 |
UpdateStationVirtCoordDirty(st); |
|
1112 |
UpdateStationAcceptance(st, false); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1113 |
RebuildStationLists(); |
0 | 1114 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
1115 |
} |
|
1116 |
||
1117 |
return cost; |
|
1118 |
} |
|
1119 |
||
2805
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1120 |
static bool TileBelongsToRailStation(const Station *st, TileIndex tile) |
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1121 |
{ |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1122 |
return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && IsRailwayStation(tile); |
2805
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1123 |
} |
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2793
diff
changeset
|
1124 |
|
0 | 1125 |
static void MakeRailwayStationAreaSmaller(Station *st) |
1126 |
{ |
|
1127 |
uint w = st->trainst_w; |
|
1128 |
uint h = st->trainst_h; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1129 |
TileIndex tile = st->train_tile; |
0 | 1130 |
uint i; |
1131 |
||
1132 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1133 |
|
0 | 1134 |
// too small? |
1135 |
if (w != 0 && h != 0) { |
|
1136 |
// check the left side, x = constant, y changes |
|
1981 | 1137 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(0, i));) { |
0 | 1138 |
// the left side is unused? |
1981 | 1139 |
if (++i == h) { |
1140 |
tile += TileDiffXY(1, 0); |
|
1141 |
w--; |
|
1142 |
goto restart; |
|
1143 |
} |
|
1144 |
} |
|
0 | 1145 |
|
1146 |
// check the right side, x = constant, y changes |
|
1981 | 1147 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(w - 1, i));) { |
0 | 1148 |
// the right side is unused? |
1981 | 1149 |
if (++i == h) { |
1150 |
w--; |
|
1151 |
goto restart; |
|
1152 |
} |
|
1153 |
} |
|
0 | 1154 |
|
1155 |
// check the upper side, y = constant, x changes |
|
1981 | 1156 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, 0));) { |
0 | 1157 |
// the left side is unused? |
1981 | 1158 |
if (++i == w) { |
1159 |
tile += TileDiffXY(0, 1); |
|
1160 |
h--; |
|
1161 |
goto restart; |
|
1162 |
} |
|
1163 |
} |
|
0 | 1164 |
|
1165 |
// check the lower side, y = constant, x changes |
|
1981 | 1166 |
for (i = 0; !TileBelongsToRailStation(st, tile + TileDiffXY(i, h - 1));) { |
0 | 1167 |
// the left side is unused? |
1981 | 1168 |
if (++i == w) { |
1169 |
h--; |
|
1170 |
goto restart; |
|
1171 |
} |
|
1172 |
} |
|
0 | 1173 |
} else { |
1174 |
tile = 0; |
|
1175 |
} |
|
1176 |
||
1177 |
st->trainst_w = w; |
|
1178 |
st->trainst_h = h; |
|
1179 |
st->train_tile = tile; |
|
1180 |
} |
|
1181 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1182 |
/** Remove a single tile from a railroad station. |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1183 |
* This allows for custom-built station with holes and weird layouts |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1184 |
* @param tile tile of station piece to remove |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1185 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1186 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1187 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1188 |
int32 CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1189 |
{ |
1190 |
Station *st; |
|
1191 |
||
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
1192 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
863
diff
changeset
|
1193 |
|
0 | 1194 |
// make sure the specified tile belongs to the current player, and that it is a railroad station. |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1195 |
if (!IsTileType(tile, MP_STATION) || !IsRailwayStation(tile) || !_patches.nonuniform_stations) return CMD_ERROR; |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1196 |
st = GetStationByTile(tile); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1197 |
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR; |
0 | 1198 |
|
1199 |
// if we reached here, it means we can actually delete it. do that. |
|
1200 |
if (flags & DC_EXEC) { |
|
3587 | 1201 |
uint specindex = GetCustomStationSpecIndex(tile); |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1202 |
Track track = GetRailStationTrack(tile); |
0 | 1203 |
DoClearSquare(tile); |
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1204 |
SetSignalsOnBothDir(tile, track); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1205 |
YapfNotifyTrackLayoutChange(tile, track); |
3587 | 1206 |
|
1207 |
DeallocateSpecFromStation(st, specindex); |
|
1208 |
||
0 | 1209 |
// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
1210 |
// we also need to adjust train_tile. |
|
1211 |
MakeRailwayStationAreaSmaller(st); |
|
1212 |
||
1213 |
// if we deleted the whole station, delete the train facility. |
|
1214 |
if (st->train_tile == 0) { |
|
1215 |
st->facilities &= ~FACIL_TRAIN; |
|
1216 |
UpdateStationVirtCoordDirty(st); |
|
1217 |
DeleteStationIfEmpty(st); |
|
1218 |
} |
|
1219 |
} |
|
1220 |
return _price.remove_rail_station; |
|
1221 |
} |
|
1222 |
||
1223 |
// determine the number of platforms for the station |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2427
diff
changeset
|
1224 |
uint GetStationPlatforms(const Station *st, TileIndex tile) |
0 | 1225 |
{ |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1226 |
TileIndex t; |
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1227 |
TileIndexDiff delta; |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1228 |
Axis axis; |
2639 | 1229 |
uint len; |
0 | 1230 |
assert(TileBelongsToRailStation(st, tile)); |
1231 |
||
1232 |
len = 0; |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1233 |
axis = GetRailStationAxis(tile); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1234 |
delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 1235 |
|
1236 |
// find starting tile.. |
|
1237 |
t = tile; |
|
2639 | 1238 |
do { |
1239 |
t -= delta; |
|
1240 |
len++; |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1241 |
} while (TileBelongsToRailStation(st, t) && GetRailStationAxis(t) == axis); |
0 | 1242 |
|
1243 |
// find ending tile |
|
1244 |
t = tile; |
|
2639 | 1245 |
do { |
1246 |
t += delta; |
|
1247 |
len++; |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1248 |
} while (TileBelongsToRailStation(st, t) && GetRailStationAxis(t) == axis); |
0 | 1249 |
|
1250 |
return len - 1; |
|
1251 |
} |
|
1252 |
||
3928
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1253 |
/** Determines the REMAINING length of a platform, starting at (and including) |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1254 |
* the given tile. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1255 |
* @param tile the tile from which to start searching. Must be a railway station tile |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1256 |
* @param dir The direction in which to search. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1257 |
* @return The platform length |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1258 |
*/ |
3928
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1259 |
uint GetPlatformLength(TileIndex tile, DiagDirection dir) |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1260 |
{ |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1261 |
TileIndex start_tile = tile; |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1262 |
uint length = 0; |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1263 |
assert(IsRailwayStationTile(tile)); |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1264 |
assert(dir < DIAGDIR_END); |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1265 |
|
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1266 |
do { |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1267 |
length ++; |
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1268 |
tile += TileOffsByDiagDir(dir); |
3928
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1269 |
} while (IsCompatibleTrainStationTile(tile, start_tile)); |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1270 |
|
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1271 |
return length; |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1272 |
} |
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1273 |
|
53fe96558353
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1274 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1275 |
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1276 |
{ |
1277 |
int w,h; |
|
1278 |
int32 cost; |
|
1279 |
||
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1280 |
/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1281 |
if (_current_player == OWNER_WATER && _patches.nonuniform_stations) |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1282 |
return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION); |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1283 |
|
0 | 1284 |
/* Current player owns the station? */ |
1285 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1286 |
return CMD_ERROR; |
|
1287 |
||
1288 |
/* determine width and height of platforms */ |
|
1289 |
tile = st->train_tile; |
|
1290 |
w = st->trainst_w; |
|
1291 |
h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1292 |
|
0 | 1293 |
assert(w != 0 && h != 0); |
1294 |
||
1295 |
/* cost is area * constant */ |
|
1296 |
cost = w*h*_price.remove_rail_station; |
|
1297 |
||
1298 |
/* clear all areas of the station */ |
|
1299 |
do { |
|
1300 |
int w_bak = w; |
|
1301 |
do { |
|
1302 |
// for nonuniform stations, only remove tiles that are actually train station tiles |
|
1303 |
if (TileBelongsToRailStation(st, tile)) { |
|
1304 |
if (!EnsureNoVehicle(tile)) |
|
1305 |
return CMD_ERROR; |
|
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1306 |
if (flags & DC_EXEC) { |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1307 |
Track track = GetRailStationTrack(tile); |
0 | 1308 |
DoClearSquare(tile); |
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1309 |
SetSignalsOnBothDir(tile, track); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1310 |
YapfNotifyTrackLayoutChange(tile, track); |
2824
4409cab99b02
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1311 |
} |
0 | 1312 |
} |
1981 | 1313 |
tile += TileDiffXY(1, 0); |
0 | 1314 |
} while (--w); |
1315 |
w = w_bak; |
|
1981 | 1316 |
tile += TileDiffXY(-w, 1); |
0 | 1317 |
} while (--h); |
1318 |
||
1319 |
if (flags & DC_EXEC) { |
|
1320 |
st->train_tile = 0; |
|
1321 |
st->facilities &= ~FACIL_TRAIN; |
|
1322 |
||
3587 | 1323 |
free(st->speclist); |
1324 |
st->num_specs = 0; |
|
1325 |
st->speclist = NULL; |
|
1326 |
||
0 | 1327 |
UpdateStationVirtCoordDirty(st); |
1328 |
DeleteStationIfEmpty(st); |
|
1329 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1330 |
|
0 | 1331 |
return cost; |
1332 |
} |
|
1333 |
||
3435
dfba5b1c7c2d
(svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents:
3431
diff
changeset
|
1334 |
int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec) |
0 | 1335 |
{ |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1336 |
const Station* st = GetStationByTile(tile); |
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1337 |
|
0 | 1338 |
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
1339 |
||
1340 |
// tile is not a railroad station? |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1341 |
if (!IsRailwayStation(tile)) return CMD_ERROR; |
0 | 1342 |
|
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1343 |
if (GetRailType(tile) == totype) return CMD_ERROR; |
0 | 1344 |
|
1345 |
if (exec) { |
|
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1346 |
SetRailType(tile, totype); |
0 | 1347 |
MarkTileDirtyByTile(tile); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1348 |
YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile)); |
0 | 1349 |
} |
1350 |
||
1351 |
return _price.build_rail >> 1; |
|
1352 |
} |
|
1353 |
||
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1354 |
/** Heavy wizardry used to add a roadstop to a station. |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1355 |
* To understand the function, lets first look at what is passed around, |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1356 |
* especially the last two parameters. CmdBuildRoadStop allocates a road |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1357 |
* stop and needs to put that stop into the linked list of road stops. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1358 |
* It (CmdBuildRoadStop) has a **currstop pointer which points to element |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1359 |
* in the linked list of stops (each element in this list being a pointer |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1360 |
* in itself, hence the double pointer). We (FindRoadStopSpot) need to |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1361 |
* modify this pointer (**currstop) thus we need to pass by reference, |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1362 |
* obtaining a triple pointer (***currstop). When finished, **currstop |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1363 |
* in CmdBuildRoadStop will contain the address of the pointer which will |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1364 |
* then point into the global roadstop array. *prev (in CmdBuildRoadStop) |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1365 |
* is the pointer tino the global roadstop array which has *currstop in |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1366 |
* its ->next element. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1367 |
* @param[in] truck_station Determines whether a stop is RS_BUS or RS_TRUCK |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1368 |
* @param[in] station The station to do the whole procedure for |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1369 |
* @param[out] currstop See the detailed function description |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1370 |
* @param prev See the detailed function description |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1371 |
*/ |
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1372 |
static void FindRoadStopSpot(bool truck_station, Station* st, RoadStop*** currstop, RoadStop** prev) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1373 |
{ |
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1374 |
RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops; |
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1375 |
assert(*prev == NULL); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1376 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1377 |
if (*primary_stop == NULL) { |
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1378 |
//we have no roadstop of the type yet, so write a "primary stop" |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1379 |
*currstop = primary_stop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1380 |
} else { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1381 |
//there are stops already, so append to the end of the list |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1382 |
*prev = *primary_stop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1383 |
*currstop = &(*primary_stop)->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1384 |
while (**currstop != NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1385 |
*prev = (*prev)->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1386 |
*currstop = &(**currstop)->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1387 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1388 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1389 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1390 |
|
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1391 |
/** Build a bus or truck stop |
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1392 |
* @param tile tile to build the stop at |
3333 | 1393 |
* @param p1 entrance direction (DiagDirection) |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1394 |
* @param p2 0 for Bus stops, 1 for truck stops |
0 | 1395 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1396 |
int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1397 |
{ |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1398 |
Station *st; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1399 |
RoadStop *road_stop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1400 |
RoadStop **currstop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1401 |
RoadStop *prev = NULL; |
0 | 1402 |
int32 cost; |
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1403 |
int32 ret; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1404 |
bool type = !!p2; |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1405 |
|
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1406 |
/* Saveguard the parameters */ |
3699
dfd1e4dec957
(svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents:
3691
diff
changeset
|
1407 |
if (!IsValidDiagDirection(p1)) return CMD_ERROR; |
0 | 1408 |
|
1409 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1410 |
||
1411 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1412 |
return CMD_ERROR; |
|
1413 |
||
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1414 |
ret = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1415 |
if (CmdFailed(ret)) return ret; |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1416 |
cost = ret; |
0 | 1417 |
|
1418 |
st = GetStationAround(tile, 1, 1, -1); |
|
2639 | 1419 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1420 |
|
1421 |
/* Find a station close to us */ |
|
1422 |
if (st == NULL) { |
|
1423 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
2989 | 1424 |
if (st != NULL && st->facilities != 0) st = NULL; |
0 | 1425 |
} |
1426 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1427 |
//give us a road stop in the list, and check if something went wrong |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
1428 |
road_stop = AllocateRoadStop(); |
2951 | 1429 |
if (road_stop == NULL) { |
1430 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
|
1431 |
} |
|
1432 |
||
2989 | 1433 |
if (st != NULL && |
4399
960cf4a06027
(svn r6152) -Codechange: renamed GetNumRoadStops to GetNumRoadStopsInStation as it reflects its function more
truelight
parents:
4398
diff
changeset
|
1434 |
GetNumRoadStopsInStation(st, RS_BUS) + GetNumRoadStopsInStation(st, RS_TRUCK) >= ROAD_STOP_LIMIT) { |
2951 | 1435 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
1436 |
} |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1437 |
|
0 | 1438 |
if (st != NULL) { |
2951 | 1439 |
if (st->owner != OWNER_NONE && st->owner != _current_player) { |
0 | 1440 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
2951 | 1441 |
} |
1442 |
||
1443 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) return CMD_ERROR; |
|
0 | 1444 |
|
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1445 |
FindRoadStopSpot(type, st, &currstop, &prev); |
0 | 1446 |
} else { |
1447 |
Town *t; |
|
1448 |
||
1449 |
st = AllocateStation(); |
|
2639 | 1450 |
if (st == NULL) return CMD_ERROR; |
0 | 1451 |
|
1452 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1453 |
||
3691
56dfcf599c3f
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1454 |
FindRoadStopSpot(type, st, &currstop, &prev); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1455 |
|
2951 | 1456 |
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) { |
0 | 1457 |
SETBIT(t->have_ratings, _current_player); |
2951 | 1458 |
} |
0 | 1459 |
|
1460 |
st->sign.width_1 = 0; |
|
1461 |
||
2639 | 1462 |
if (!GenerateStationName(st, tile, 0)) return CMD_ERROR; |
1463 |
||
1464 |
if (flags & DC_EXEC) StationInitialize(st, tile); |
|
0 | 1465 |
} |
1466 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1467 |
cost += (type) ? _price.build_truck_station : _price.build_bus_station; |
0 | 1468 |
|
1469 |
if (flags & DC_EXEC) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1470 |
//point to the correct item in the _busstops or _truckstops array |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1471 |
*currstop = road_stop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1472 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1473 |
//initialize an empty station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1474 |
InitializeRoadStop(road_stop, prev, tile, st->index); |
0 | 1475 |
if (!st->facilities) st->xy = tile; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1476 |
st->facilities |= (type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP; |
0 | 1477 |
st->owner = _current_player; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1478 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1479 |
st->build_date = _date; |
0 | 1480 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1481 |
MakeRoadStop(tile, st->owner, st->index, type, p1); |
0 | 1482 |
|
1483 |
UpdateStationVirtCoordDirty(st); |
|
1484 |
UpdateStationAcceptance(st, false); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1485 |
RebuildStationLists(); |
0 | 1486 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
1487 |
} |
|
1488 |
return cost; |
|
1489 |
} |
|
1490 |
||
1491 |
// Remove a bus station |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1492 |
static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) |
0 | 1493 |
{ |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1494 |
RoadStop **primary_stop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1495 |
RoadStop *cur_stop; |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1496 |
bool is_truck = IsTruckStop(tile); |
0 | 1497 |
|
2951 | 1498 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
0 | 1499 |
return CMD_ERROR; |
2951 | 1500 |
} |
0 | 1501 |
|
2639 | 1502 |
if (is_truck) { // truck stop |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1503 |
primary_stop = &st->truck_stops; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1504 |
cur_stop = GetRoadStopByTile(tile, RS_TRUCK); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1505 |
} else { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1506 |
primary_stop = &st->bus_stops; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1507 |
cur_stop = GetRoadStopByTile(tile, RS_BUS); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1508 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1509 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1510 |
assert(cur_stop != NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1511 |
|
2951 | 1512 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 1513 |
|
1514 |
if (flags & DC_EXEC) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1515 |
//we only had one stop left |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1516 |
if (cur_stop->next == NULL && cur_stop->prev == NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1517 |
//so we remove ALL stops |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1518 |
*primary_stop = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1519 |
st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1520 |
} else if (cur_stop == *primary_stop) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1521 |
//removed the first stop in the list |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1522 |
//need to set the primary element to the next stop |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1523 |
*primary_stop = (*primary_stop)->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1524 |
} |
0 | 1525 |
|
4398
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1526 |
DeleteRoadStop(cur_stop); |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1527 |
DoClearSquare(tile); |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1528 |
|
0 | 1529 |
UpdateStationVirtCoordDirty(st); |
1530 |
DeleteStationIfEmpty(st); |
|
1531 |
} |
|
1532 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1533 |
return (is_truck) ? _price.remove_truck_station : _price.remove_bus_station; |
0 | 1534 |
} |
1535 |
||
1536 |
||
1537 |
||
1538 |
// FIXME -- need to move to its corresponding Airport variable |
|
1539 |
// Country Airfield (small) |
|
3429
20b7bab277c1
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1540 |
static const byte _airport_sections_country[] = { |
0 | 1541 |
54, 53, 52, 65, |
1542 |
58, 57, 56, 55, |
|
1543 |
64, 63, 63, 62 |
|
1544 |
}; |
|
1545 |
||
1546 |
// City Airport (large) |
|
3429
20b7bab277c1
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1547 |
static const byte _airport_sections_town[] = { |
2549 | 1548 |
31, 9, 33, 9, 9, 32, |
1549 |
27, 36, 29, 34, 8, 10, |
|
0 | 1550 |
30, 11, 35, 13, 20, 21, |
1551 |
51, 12, 14, 17, 19, 28, |
|
1552 |
38, 13, 15, 16, 18, 39, |
|
1553 |
26, 22, 23, 24, 25, 26 |
|
1554 |
}; |
|
1555 |
||
1556 |
// Metropolitain Airport (large) - 2 runways |
|
3429
20b7bab277c1
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1557 |
static const byte _airport_sections_metropolitan[] = { |
2549 | 1558 |
31, 9, 33, 9, 9, 32, |
1559 |
27, 36, 29, 34, 8, 10, |
|
1560 |
30, 11, 35, 13, 20, 21, |
|
1561 |
102, 8, 8, 8, 8, 28, |
|
1562 |
83, 84, 84, 84, 84, 83, |
|
1563 |
26, 23, 23, 23, 23, 26 |
|
0 | 1564 |
}; |
1565 |
||
1566 |
// International Airport (large) - 2 runways |
|
3429
20b7bab277c1
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1567 |
static const byte _airport_sections_international[] = { |
3554
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
1568 |
88, 89, 89, 89, 89, 89, 88, |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
1569 |
51, 8, 8, 8, 8, 8, 32, |
2549 | 1570 |
30, 8, 11, 27, 11, 8, 10, |
0 | 1571 |
32, 8, 11, 27, 11, 8, 114, |
1572 |
87, 8, 11, 85, 11, 8, 114, |
|
2549 | 1573 |
87, 8, 8, 8, 8, 8, 90, |
1574 |
26, 23, 23, 23, 23, 23, 26 |
|
0 | 1575 |
}; |
1576 |
||
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1577 |
// Intercontinental Airport (vlarge) - 4 runways |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1578 |
static const byte _airport_sections_intercontinental[] = { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1579 |
102, 120, 89, 89, 89, 89, 89, 89, 118, |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1580 |
120, 22, 22, 22, 22, 22, 22, 119, 117, |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1581 |
87, 54, 87, 8, 8, 8, 8, 51, 117, |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1582 |
87, 162, 87, 85, 116, 116, 8, 9, 10, |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1583 |
87, 8, 8, 11, 31, 11, 8, 160, 32, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1584 |
32, 160, 8, 11, 27, 11, 8, 8, 10, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1585 |
87, 8, 8, 11, 30, 11, 8, 8, 10, |
4066
2d099b946f10
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
1586 |
87, 142, 8, 11, 29, 11, 10, 163, 10, |
2d099b946f10
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
1587 |
87, 164, 87, 8, 8, 8, 10, 37, 117, |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1588 |
87, 120, 89, 89, 89, 89, 89, 89, 119, |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
1589 |
121, 22, 22, 22, 22, 22, 22, 119, 37 |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1590 |
}; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1591 |
|
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1592 |
|
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1593 |
// Commuter Airfield (small) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1594 |
static const byte _airport_sections_commuter[] = { |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1595 |
85, 30, 115, 115, 32, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1596 |
87, 8, 8, 8, 10, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1597 |
87, 11, 11, 11, 10, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1598 |
26, 23, 23, 23, 26 |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1599 |
}; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1600 |
|
0 | 1601 |
// Heliport |
3429
20b7bab277c1
(svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents:
3422
diff
changeset
|
1602 |
static const byte _airport_sections_heliport[] = { |
0 | 1603 |
66, |
1604 |
}; |
|
1605 |
||
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1606 |
// Helidepot |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1607 |
static const byte _airport_sections_helidepot[] = { |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1608 |
124, 32, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1609 |
122, 123 |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1610 |
}; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1611 |
|
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1612 |
// Helistation |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1613 |
static const byte _airport_sections_helistation[] = { |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1614 |
32, 134, 159, 158, |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1615 |
161, 142, 142, 157 |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1616 |
}; |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1617 |
|
3471
e454e2c0c23e
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1618 |
static const byte * const _airport_sections[] = { |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1619 |
_airport_sections_country, // Country Airfield (small) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1620 |
_airport_sections_town, // City Airport (large) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1621 |
_airport_sections_heliport, // Heliport |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1622 |
_airport_sections_metropolitan, // Metropolitain Airport (large) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1623 |
_airport_sections_international, // International Airport (xlarge) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1624 |
_airport_sections_commuter, // Commuter Airport (small) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1625 |
_airport_sections_helidepot, // Helidepot |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1626 |
_airport_sections_intercontinental, // Intercontinental Airport (xxlarge) |
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1627 |
_airport_sections_helistation // Helistation |
0 | 1628 |
}; |
1629 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1630 |
/** Place an Airport. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1631 |
* @param tile tile where airport will be built |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1632 |
* @param p1 airport type, @see airport.h |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1633 |
* @param p2 unused |
0 | 1634 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1635 |
int32 CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1636 |
{ |
1637 |
Town *t; |
|
1638 |
Station *st; |
|
1639 |
int32 cost; |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1640 |
int32 ret; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1641 |
int w, h; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1642 |
bool airport_upgrade = true; |
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1643 |
const AirportFTAClass* afc; |
0 | 1644 |
|
1645 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1646 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1647 |
/* Check if a valid, buildable airport was chosen for construction */ |
3471
e454e2c0c23e
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1648 |
if (p1 > lengthof(_airport_sections) || !HASBIT(GetValidAirports(), p1)) return CMD_ERROR; |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1649 |
|
0 | 1650 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
1651 |
return CMD_ERROR; |
|
1652 |
||
1653 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
1654 |
||
1655 |
/* Check if local auth refuses a new airport */ |
|
1656 |
{ |
|
1657 |
uint num = 0; |
|
1658 |
FOR_ALL_STATIONS(st) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1659 |
if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG) |
0 | 1660 |
num++; |
1661 |
} |
|
1662 |
if (num >= 2) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1663 |
SetDParam(0, t->index); |
0 | 1664 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
1665 |
} |
|
1666 |
} |
|
1667 |
||
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1668 |
afc = GetAirport(p1); |
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1669 |
w = afc->size_x; |
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1670 |
h = afc->size_y; |
0 | 1671 |
|
3183
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1672 |
ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL); |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1673 |
if (CmdFailed(ret)) return ret; |
90c676e6a50d
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
1674 |
cost = ret; |
0 | 1675 |
|
1676 |
st = GetStationAround(tile, w, h, -1); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1677 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
0 | 1678 |
|
1679 |
/* Find a station close to us */ |
|
1680 |
if (st == NULL) { |
|
1681 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1682 |
if (st != NULL && st->facilities) st = NULL; |
0 | 1683 |
} |
1684 |
||
1685 |
if (st != NULL) { |
|
1686 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1687 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1688 |
|
0 | 1689 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) |
1690 |
return CMD_ERROR; |
|
1691 |
||
1692 |
if (st->airport_tile != 0) |
|
1693 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
|
1694 |
} else { |
|
1695 |
airport_upgrade = false; |
|
1696 |
||
1697 |
st = AllocateStation(); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1698 |
if (st == NULL) return CMD_ERROR; |
0 | 1699 |
|
1265
71ed55c20f6e
(svn r1769) Don't compute the same value twice, remove one function call
tron
parents:
1247
diff
changeset
|
1700 |
st->town = t; |
0 | 1701 |
|
2639 | 1702 |
if (_current_player < MAX_PLAYERS && flags & DC_EXEC) |
0 | 1703 |
SETBIT(t->have_ratings, _current_player); |
1704 |
||
1705 |
st->sign.width_1 = 0; |
|
1706 |
||
1707 |
// if airport type equals Heliport then generate |
|
1708 |
// type 5 name, which is heliport, otherwise airport names (1) |
|
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
1709 |
if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT)||(p1 == AT_HELIDEPOT)||(p1 == AT_HELISTATION) ? 5 : 1)) |
0 | 1710 |
return CMD_ERROR; |
1711 |
||
2951 | 1712 |
if (flags & DC_EXEC) StationInitialize(st, tile); |
0 | 1713 |
} |
1714 |
||
1715 |
cost += _price.build_airport * w * h; |
|
1716 |
||
1717 |
if (flags & DC_EXEC) { |
|
1718 |
st->owner = _current_player; |
|
1719 |
st->airport_tile = tile; |
|
1720 |
if (!st->facilities) st->xy = tile; |
|
1721 |
st->facilities |= FACIL_AIRPORT; |
|
1722 |
st->airport_type = (byte)p1; |
|
1723 |
st->airport_flags = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1724 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1725 |
st->build_date = _date; |
0 | 1726 |
|
2639 | 1727 |
/* if airport was demolished while planes were en-route to it, the |
1728 |
* positions can no longer be the same (v->u.air.pos), since different |
|
1729 |
* airports have different indexes. So update all planes en-route to this |
|
1730 |
* airport. Only update if |
|
1731 |
* 1. airport is upgraded |
|
1732 |
* 2. airport is added to existing station (unfortunately unavoideable) |
|
1733 |
*/ |
|
2549 | 1734 |
if (airport_upgrade) UpdateAirplanesOnNewStation(st); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1735 |
|
0 | 1736 |
{ |
3471
e454e2c0c23e
(svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents:
3435
diff
changeset
|
1737 |
const byte *b = _airport_sections[p1]; |
2549 | 1738 |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1739 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1740 |
MakeAirport(tile_cur, st->owner, st->index, *b++); |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1741 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 1742 |
} |
1743 |
||
1744 |
UpdateStationVirtCoordDirty(st); |
|
1745 |
UpdateStationAcceptance(st, false); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1746 |
RebuildStationLists(); |
0 | 1747 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
1748 |
} |
|
1749 |
||
1750 |
return cost; |
|
1751 |
} |
|
1752 |
||
1753 |
static int32 RemoveAirport(Station *st, uint32 flags) |
|
1754 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1755 |
TileIndex tile; |
0 | 1756 |
int w,h; |
1757 |
int32 cost; |
|
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1758 |
const AirportFTAClass* afc; |
0 | 1759 |
|
1760 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1761 |
return CMD_ERROR; |
|
1762 |
||
1763 |
tile = st->airport_tile; |
|
1764 |
||
3876
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1765 |
afc = GetAirport(st->airport_type); |
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1766 |
w = afc->size_x; |
468642825a10
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3873
diff
changeset
|
1767 |
h = afc->size_y; |
0 | 1768 |
|
1769 |
cost = w * h * _price.remove_airport; |
|
1770 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1771 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1772 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 1773 |
|
1774 |
if (flags & DC_EXEC) { |
|
1775 |
DeleteAnimatedTile(tile_cur); |
|
1776 |
DoClearSquare(tile_cur); |
|
1777 |
} |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1778 |
} END_TILE_LOOP(tile_cur, w,h,tile) |
0 | 1779 |
|
1780 |
if (flags & DC_EXEC) { |
|
700 | 1781 |
uint i; |
1782 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1783 |
for (i = 0; i < afc->nof_depots; ++i) { |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1784 |
DeleteWindowById( |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1785 |
WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]) |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1786 |
); |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1787 |
} |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
709
diff
changeset
|
1788 |
|
0 | 1789 |
st->airport_tile = 0; |
1790 |
st->facilities &= ~FACIL_AIRPORT; |
|
1791 |
||
1792 |
UpdateStationVirtCoordDirty(st); |
|
1793 |
DeleteStationIfEmpty(st); |
|
1794 |
} |
|
1795 |
||
1796 |
return cost; |
|
1797 |
} |
|
1798 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1799 |
/** Build a buoy. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1800 |
* @param tile tile where to place the bouy |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1801 |
* @param p1 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1802 |
* @param p2 unused |
0 | 1803 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1804 |
int32 CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1805 |
{ |
1806 |
Station *st; |
|
1807 |
||
1808 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1809 |
||
3374
faff80c38bcc
(svn r4173) -Codechange: Use IsClearWaterTile for buoy construction
celestar
parents:
3362
diff
changeset
|
1810 |
if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
0 | 1811 |
|
1812 |
st = AllocateStation(); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1813 |
if (st == NULL) return CMD_ERROR; |
0 | 1814 |
|
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1815 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
0 | 1816 |
st->sign.width_1 = 0; |
1817 |
||
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1818 |
if (!GenerateStationName(st, tile, 4)) return CMD_ERROR; |
0 | 1819 |
|
1820 |
if (flags & DC_EXEC) { |
|
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1821 |
StationInitialize(st, tile); |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1822 |
st->dock_tile = tile; |
0 | 1823 |
st->facilities |= FACIL_DOCK; |
1751
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1824 |
/* Buoys are marked in the Station struct by this flag. Yes, it is this |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1825 |
* braindead.. */ |
0 | 1826 |
st->had_vehicle_of_type |= HVOT_BUOY; |
1827 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1828 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1829 |
st->build_date = _date; |
0 | 1830 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1831 |
MakeBuoy(tile, st->index); |
0 | 1832 |
|
1833 |
UpdateStationVirtCoordDirty(st); |
|
1834 |
UpdateStationAcceptance(st, false); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1835 |
RebuildStationLists(); |
0 | 1836 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
1837 |
} |
|
1838 |
||
1839 |
return _price.build_dock; |
|
1840 |
} |
|
1841 |
||
1078
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1842 |
/* Checks if any ship is servicing the buoy specified. Returns yes or no */ |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1843 |
static bool CheckShipsOnBuoy(Station *st) |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1844 |
{ |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1845 |
const Vehicle *v; |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1846 |
FOR_ALL_VEHICLES(v) { |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1847 |
if (v->type == VEH_Ship) { |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1848 |
const Order *order; |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1849 |
FOR_VEHICLE_ORDERS(v, order) { |
4527
fa30d19685c2
(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:
4467
diff
changeset
|
1850 |
if (order->type == OT_GOTO_STATION && order->dest == st->index) { |
1078
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1851 |
return true; |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1852 |
} |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1853 |
} |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1854 |
} |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1855 |
} |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1856 |
return false; |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1857 |
} |
1b9163f2e7eb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1858 |
|
0 | 1859 |
static int32 RemoveBuoy(Station *st, uint32 flags) |
1860 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1861 |
TileIndex tile; |
0 | 1862 |
|
1863 |
if (_current_player >= MAX_PLAYERS) { |
|
1864 |
/* XXX: strange stuff */ |
|
1865 |
return_cmd_error(INVALID_STRING_ID); |
|
1866 |
} |
|
1867 |
||
1868 |
tile = st->dock_tile; |
|
1869 |
||
2639 | 1870 |
if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE); |
1871 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 1872 |
|
1873 |
if (flags & DC_EXEC) { |
|
1874 |
st->dock_tile = 0; |
|
1751
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1875 |
/* Buoys are marked in the Station struct by this flag. Yes, it is this |
009a240d035a
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1876 |
* braindead.. */ |
0 | 1877 |
st->facilities &= ~FACIL_DOCK; |
1878 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1879 |
||
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1880 |
MakeWater(tile); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1881 |
MarkTileDirtyByTile(tile); |
0 | 1882 |
|
1883 |
UpdateStationVirtCoordDirty(st); |
|
1884 |
DeleteStationIfEmpty(st); |
|
1885 |
} |
|
1886 |
||
1887 |
return _price.remove_truck_station; |
|
1888 |
} |
|
1889 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1890 |
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1891 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1892 |
{ 0, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1893 |
{ 0, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1894 |
{ 0, -1} |
0 | 1895 |
}; |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
1896 |
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 }; |
7e123fec5b0b
(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:
4326
diff
changeset
|
1897 |
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; |
0 | 1898 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1899 |
/** Build a dock/haven. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1900 |
* @param tile tile where dock will be built |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1901 |
* @param p1 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1902 |
* @param p2 unused |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1903 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1904 |
int32 CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1905 |
{ |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1906 |
TileIndex tile_cur; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
1907 |
DiagDirection direction; |
0 | 1908 |
int32 cost; |
1909 |
Station *st; |
|
1910 |
||
1911 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1912 |
||
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1913 |
switch (GetTileSlope(tile, NULL)) { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1914 |
case SLOPE_SW: direction = DIAGDIR_NE; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1915 |
case SLOPE_SE: direction = DIAGDIR_NW; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1916 |
case SLOPE_NW: direction = DIAGDIR_SE; break; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1917 |
case SLOPE_NE: direction = DIAGDIR_SW; break; |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1918 |
default: return_cmd_error(STR_304B_SITE_UNSUITABLE); |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1919 |
} |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1920 |
|
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1921 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1922 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1923 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1924 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1925 |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1926 |
tile_cur = tile + TileOffsByDiagDir(direction); |
0 | 1927 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1928 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
0 | 1929 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1930 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1931 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1932 |
} |
0 | 1933 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
1934 |
cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1935 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1936 |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1937 |
tile_cur += TileOffsByDiagDir(direction); |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1938 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
0 | 1939 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
1940 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1941 |
|
0 | 1942 |
/* middle */ |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1943 |
st = GetStationAround( |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1944 |
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), |
0 | 1945 |
_dock_w_chk[direction], _dock_h_chk[direction], -1); |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1946 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1947 |
|
0 | 1948 |
/* Find a station close to us */ |
1949 |
if (st == NULL) { |
|
1950 |
st = GetClosestStationFromTile(tile, 8, _current_player); |
|
1951 |
if (st!=NULL && st->facilities) st = NULL; |
|
1952 |
} |
|
1953 |
||
1954 |
if (st != NULL) { |
|
1955 |
if (st->owner != OWNER_NONE && st->owner != _current_player) |
|
1956 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1957 |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1958 |
if (!CheckStationSpreadOut(st, tile, 1, 1)) return CMD_ERROR; |
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1959 |
|
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1960 |
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
0 | 1961 |
} else { |
1962 |
Town *t; |
|
1963 |
||
1964 |
st = AllocateStation(); |
|
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1965 |
if (st == NULL) return CMD_ERROR; |
0 | 1966 |
|
1967 |
st->town = t = ClosestTownFromTile(tile, (uint)-1); |
|
1968 |
||
1969 |
if (_current_player < MAX_PLAYERS && flags&DC_EXEC) |
|
1970 |
SETBIT(t->have_ratings, _current_player); |
|
1971 |
||
1972 |
st->sign.width_1 = 0; |
|
1973 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1974 |
if (!GenerateStationName(st, tile, 3)) return CMD_ERROR; |
0 | 1975 |
|
2639 | 1976 |
if (flags & DC_EXEC) StationInitialize(st, tile); |
0 | 1977 |
} |
1978 |
||
1979 |
if (flags & DC_EXEC) { |
|
1980 |
st->dock_tile = tile; |
|
1981 |
if (!st->facilities) st->xy = tile; |
|
1982 |
st->facilities |= FACIL_DOCK; |
|
1983 |
st->owner = _current_player; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1984 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1985 |
st->build_date = _date; |
0 | 1986 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1987 |
MakeDock(tile, st->owner, st->index, direction); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1988 |
|
0 | 1989 |
UpdateStationVirtCoordDirty(st); |
1990 |
UpdateStationAcceptance(st, false); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1991 |
RebuildStationLists(); |
0 | 1992 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
1993 |
} |
|
1994 |
return _price.build_dock; |
|
1995 |
} |
|
1996 |
||
1997 |
static int32 RemoveDock(Station *st, uint32 flags) |
|
1998 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1999 |
TileIndex tile1; |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2000 |
TileIndex tile2; |
0 | 2001 |
|
2639 | 2002 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 2003 |
|
2004 |
tile1 = st->dock_tile; |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2005 |
tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1)); |
0 | 2006 |
|
2639 | 2007 |
if (!EnsureNoVehicle(tile1)) return CMD_ERROR; |
2008 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
|
0 | 2009 |
|
2010 |
if (flags & DC_EXEC) { |
|
2011 |
DoClearSquare(tile1); |
|
2012 |
||
3111
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
2013 |
MakeWater(tile2); |
750f37699a13
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
2014 |
MarkTileDirtyByTile(tile2); |
0 | 2015 |
|
2016 |
st->dock_tile = 0; |
|
2017 |
st->facilities &= ~FACIL_DOCK; |
|
2018 |
||
2019 |
UpdateStationVirtCoordDirty(st); |
|
2020 |
DeleteStationIfEmpty(st); |
|
2021 |
} |
|
2022 |
||
2023 |
return _price.remove_dock; |
|
2024 |
} |
|
2025 |
||
2026 |
#include "table/station_land.h" |
|
2027 |
||
3763
7098c393c172
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2028 |
const DrawTileSprites *GetStationTileLayout(byte gfx) |
7098c393c172
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2029 |
{ |
7098c393c172
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2030 |
return &_station_display_datas[gfx]; |
7098c393c172
(svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents:
3754
diff
changeset
|
2031 |
} |
0 | 2032 |
|
2033 |
static void DrawTile_Station(TileInfo *ti) |
|
2034 |
{ |
|
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2035 |
uint32 image; |
0 | 2036 |
const DrawTileSeqStruct *dtss; |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2037 |
const DrawTileSprites *t = NULL; |
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
2038 |
RailType railtype = GetRailType(ti->tile); |
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2039 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2040 |
uint32 relocation = 0; |
3775
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2041 |
const Station *st = NULL; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2042 |
const StationSpec *statspec = NULL; |
4227
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2043 |
PlayerID owner = GetTileOwner(ti->tile); |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2044 |
uint32 palette; |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2045 |
|
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2046 |
if (owner < MAX_PLAYERS) { |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2047 |
palette = PLAYER_SPRITE_COLOR(owner); |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2048 |
} else { |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2049 |
// Some stations are not owner by a player, namely oil rigs |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2050 |
palette = PALETTE_TO_GREY; |
0 | 2051 |
} |
2052 |
||
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2053 |
// don't show foundation for docks |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2054 |
if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) |
0 | 2055 |
DrawFoundation(ti, ti->tileh); |
2056 |
||
3568
c60d7aceed1a
(svn r4450) - NewStations, rename *CustomStationSprite() to *CustomStationSpecIndex() to reflect their use, and alter the test for determining if a station has customised graphics.
peter1138
parents:
3554
diff
changeset
|
2057 |
if (IsCustomStationSpecIndex(ti->tile)) { |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2058 |
// look for customization |
3775
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2059 |
st = GetStationByTile(ti->tile); |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2060 |
statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec; |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2061 |
|
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2062 |
//debug("Cust-o-mized %p", statspec); |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2063 |
|
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2064 |
if (statspec != NULL) { |
3576
18fb92480771
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2065 |
uint tile = GetStationGfx(ti->tile); |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2066 |
|
3751
ce6408fdb788
(svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents:
3742
diff
changeset
|
2067 |
relocation = GetCustomStationRelocation(statspec, st, ti->tile); |
3576
18fb92480771
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2068 |
|
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2069 |
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2070 |
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile); |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2071 |
if (callback != CALLBACK_FAILED) tile = callback + GetRailStationAxis(ti->tile); |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2072 |
} |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2073 |
|
3576
18fb92480771
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2074 |
/* Ensure the chosen tile layout is valid for this custom station */ |
3754
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2075 |
if (statspec->renderdata != NULL) { |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2076 |
t = &statspec->renderdata[tile < statspec->tiles ? tile : GetRailStationAxis(ti->tile)]; |
4c8cbaaa0bbe
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2077 |
} |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2078 |
} |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2079 |
} |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2080 |
|
3737
1e4df4eb9298
(svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents:
3699
diff
changeset
|
2081 |
if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationGfx(ti->tile)]; |
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2082 |
|
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2083 |
image = t->ground_sprite; |
3775
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2084 |
if (HASBIT(image, 31)) { |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2085 |
CLRBIT(image, 31); |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2086 |
image += GetCustomStationGroundRelocation(statspec, st, ti->tile); |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2087 |
image += rti->custom_ground_offset; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2088 |
} else { |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2089 |
image += rti->total_offset; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2090 |
} |
4227
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2091 |
if (image & PALETTE_MODIFIER_COLOR) image |= palette; |
449
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2092 |
|
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2093 |
// station_land array has been increased from 82 elements to 114 |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2094 |
// but this is something else. If AI builds station with 114 it looks all weird |
2856e9ce0754
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2095 |
DrawGroundSprite(image); |
0 | 2096 |
|
3789
c50647c927e4
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3784
diff
changeset
|
2097 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti); |
3355
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3344
diff
changeset
|
2098 |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2099 |
foreach_draw_tile_seq(dtss, t->seq) { |
3775
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2100 |
image = dtss->image; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2101 |
if (HASBIT(image, 30)) { |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2102 |
CLRBIT(image, 30); |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2103 |
image += rti->total_offset; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2104 |
} else { |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2105 |
image += relocation; |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2106 |
} |
0fb5118536c3
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2107 |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2108 |
if (_display_opt & DO_TRANS_BUILDINGS) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
2109 |
MAKE_TRANSPARENT(image); |
4227
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2110 |
} else if (image & PALETTE_MODIFIER_COLOR) { |
3ff996bf3f28
(svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents:
4177
diff
changeset
|
2111 |
image |= palette; |
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2112 |
} |
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2113 |
|
0 | 2114 |
if ((byte)dtss->delta_z != 0x80) { |
4230
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2115 |
AddSortableSpriteToDraw( |
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2116 |
image, |
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2117 |
ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2118 |
dtss->size_x, dtss->size_y, |
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2119 |
dtss->size_z, ti->z + dtss->delta_z |
f4e93251e2f6
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2120 |
); |
0 | 2121 |
} else { |
2122 |
AddChildSpriteScreen(image, dtss->delta_x, dtss->delta_y); |
|
2123 |
} |
|
2124 |
} |
|
2125 |
} |
|
2126 |
||
2520
8a52362c4ada
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2517
diff
changeset
|
2127 |
void StationPickerDrawSprite(int x, int y, RailType railtype, int image) |
0 | 2128 |
{ |
2129 |
uint32 ormod, img; |
|
2130 |
const DrawTileSeqStruct *dtss; |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2131 |
const DrawTileSprites *t; |
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2132 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
0 | 2133 |
|
2134 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
2135 |
||
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2136 |
t = &_station_display_datas[image]; |
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2137 |
|
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2138 |
img = t->ground_sprite; |
2639 | 2139 |
if (img & PALETTE_MODIFIER_COLOR) img |= ormod; |
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2140 |
DrawSprite(img + rti->total_offset, x, y); |
0 | 2141 |
|
384
809833b4068d
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2142 |
foreach_draw_tile_seq(dtss, t->seq) { |
0 | 2143 |
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); |
2254
99de94953104
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2144 |
DrawSprite((dtss->image | ormod) + rti->total_offset, x + pt.x, y + pt.y); |
0 | 2145 |
} |
2146 |
} |
|
2147 |
||
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2148 |
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y) |
0 | 2149 |
{ |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4230
diff
changeset
|
2150 |
return GetTileMaxZ(tile); |
0 | 2151 |
} |
2152 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2153 |
static Slope GetSlopeTileh_Station(TileIndex tile, Slope tileh) |
39 | 2154 |
{ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2155 |
return SLOPE_FLAT; |
39 | 2156 |
} |
2157 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2158 |
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac) |
0 | 2159 |
{ |
2160 |
/* not used */ |
|
2161 |
} |
|
2162 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2163 |
static void GetTileDesc_Station(TileIndex tile, TileDesc *td) |
0 | 2164 |
{ |
2165 |
StringID str; |
|
2166 |
||
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
2167 |
td->owner = GetTileOwner(tile); |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2168 |
td->build_date = GetStationByTile(tile)->build_date; |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
2169 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2170 |
switch (GetStationType(tile)) { |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2171 |
default: NOT_REACHED(); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2172 |
case STATION_RAIL: str = STR_305E_RAILROAD_STATION; break; |
3882
c2e3e12e71d6
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2173 |
case STATION_AIRPORT: |
c2e3e12e71d6
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2174 |
str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT); |
c2e3e12e71d6
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2175 |
break; |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2176 |
case STATION_TRUCK: str = STR_3061_TRUCK_LOADING_AREA; break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2177 |
case STATION_BUS: str = STR_3062_BUS_STATION; break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2178 |
case STATION_OILRIG: str = STR_4807_OIL_RIG; break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2179 |
case STATION_DOCK: str = STR_3063_SHIP_DOCK; break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2180 |
case STATION_BUOY: str = STR_3069_BUOY; break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2181 |
} |
0 | 2182 |
td->str = str; |
2183 |
} |
|
2184 |
||
2185 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2186 |
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2187 |
{ |
1032
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2188 |
switch (mode) { |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2189 |
case TRANSPORT_RAIL: |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2190 |
if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) { |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2191 |
return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101; |
1032
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2192 |
} |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2193 |
break; |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2194 |
|
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2195 |
case TRANSPORT_WATER: |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2196 |
// buoy is coded as a station, it is always on open water |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2197 |
if (IsBuoy_(tile)) return TRACK_BIT_ALL * 0x101; |
1032
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2198 |
break; |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2199 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2200 |
case TRANSPORT_ROAD: |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2201 |
if (IsRoadStopTile(tile)) { |
4158 | 2202 |
return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2203 |
} |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2204 |
break; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2205 |
|
1032
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2206 |
default: |
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2207 |
break; |
0 | 2208 |
} |
1032
b8094fcab4bc
(svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents:
1024
diff
changeset
|
2209 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2210 |
return 0; |
0 | 2211 |
} |
2212 |
||
2660 | 2213 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2214 |
static void TileLoop_Station(TileIndex tile) |
0 | 2215 |
{ |
2660 | 2216 |
// FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
2217 |
// hardcoded.....not good |
|
3540
3bcf5348842b
(svn r4403) CodeChange : Add GetStationGfx and make use of [G|S]etStationGfx accessors. Also, use GetStationGfx instead of directly accessing the map for functions in station_map.h
belugas
parents:
3527
diff
changeset
|
2218 |
switch (GetStationGfx(tile)) { |
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2219 |
case GFX_RADAR_LARGE_FIRST: |
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2220 |
case GFX_WINDSACK_FIRST : // for small airport |
3554
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2221 |
case GFX_RADAR_INTERNATIONAL_FIRST: |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2222 |
case GFX_RADAR_METROPOLITAN_FIRST: |
4059
b1e1c1193f0a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
4000
diff
changeset
|
2223 |
case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport |
4066
2d099b946f10
(svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents:
4059
diff
changeset
|
2224 |
case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport |
2660 | 2225 |
AddAnimatedTile(tile); |
2226 |
break; |
|
2227 |
||
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2228 |
case GFX_OILRIG_BASE: //(station part) |
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2229 |
case GFX_BUOY_BASE: |
2660 | 2230 |
TileLoop_Water(tile); |
2231 |
break; |
|
2232 |
||
2233 |
default: break; |
|
2234 |
} |
|
0 | 2235 |
} |
2236 |
||
2237 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2238 |
static void AnimateTile_Station(TileIndex tile) |
0 | 2239 |
{ |
4467
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2240 |
typedef struct AnimData { |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2241 |
StationGfx from; // first sprite |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2242 |
StationGfx to; // last sprite |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2243 |
byte delay; |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2244 |
} AnimData; |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2245 |
|
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2246 |
static const AnimData data[] = { |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2247 |
{ GFX_RADAR_LARGE_FIRST, GFX_RADAR_LARGE_LAST, 3 }, |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2248 |
{ GFX_WINDSACK_FIRST, GFX_WINDSACK_LAST, 1 }, |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2249 |
{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 }, |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2250 |
{ GFX_RADAR_METROPOLITAN_FIRST, GFX_RADAR_METROPOLITAN_LAST, 3 }, |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2251 |
{ GFX_RADAR_DISTRICTWE_FIRST, GFX_RADAR_DISTRICTWE_LAST, 3 }, |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2252 |
{ GFX_WINDSACK_INTERCON_FIRST, GFX_WINDSACK_INTERCON_LAST, 1 } |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2253 |
}; |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2254 |
|
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2255 |
StationGfx gfx = GetStationGfx(tile); |
4467
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2256 |
const AnimData* i; |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2257 |
|
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2258 |
for (i = data; i != endof(data); i++) { |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2259 |
if (i->from <= gfx && gfx <= i->to) { |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2260 |
if ((_tick_counter & i->delay) == 0) { |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2261 |
SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from); |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2262 |
MarkTileDirtyByTile(tile); |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2263 |
} |
156585f085d2
(svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents:
4434
diff
changeset
|
2264 |
break; |
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2265 |
} |
0 | 2266 |
} |
2267 |
} |
|
2268 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2269 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2270 |
static void ClickTile_Station(TileIndex tile) |
0 | 2271 |
{ |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2272 |
if (IsHangar(tile)) { |
0 | 2273 |
ShowAircraftDepotWindow(tile); |
2274 |
} else { |
|
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2275 |
ShowStationViewWindow(GetStationIndex(tile)); |
0 | 2276 |
} |
2277 |
} |
|
2278 |
||
2279 |
static const byte _enter_station_speedtable[12] = { |
|
2280 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2281 |
}; |
|
2282 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2283 |
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2284 |
{ |
2285 |
if (v->type == VEH_Train) { |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2286 |
if (IsRailwayStation(tile) && IsFrontEngine(v) && |
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2287 |
!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2288 |
StationID station_id = GetStationIndex(tile); |
2989 | 2289 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2290 |
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) || |
4527
fa30d19685c2
(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:
4467
diff
changeset
|
2291 |
(v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2292 |
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2293 |
v->current_order.type != OT_LEAVESTATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2294 |
v->last_station_visited != station_id) { |
3482
54b144f07963
(svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents:
3480
diff
changeset
|
2295 |
DiagDirection dir = DirToDiagDir(v->direction); |
2989 | 2296 |
|
0 | 2297 |
x &= 0xF; |
2298 |
y &= 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2299 |
|
3482
54b144f07963
(svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents:
3480
diff
changeset
|
2300 |
if (DiagDirToAxis(dir) != AXIS_X) intswap(x, y); |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2301 |
if (y == TILE_SIZE / 2) { |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2302 |
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; |
0 | 2303 |
if (x == 12) return 2 | (station_id << 8); /* enter station */ |
2304 |
if (x < 12) { |
|
2639 | 2305 |
uint16 spd; |
2306 |
||
0 | 2307 |
v->vehstatus |= VS_TRAIN_SLOWING; |
2308 |
spd = _enter_station_speedtable[x]; |
|
2639 | 2309 |
if (spd < v->cur_speed) v->cur_speed = spd; |
0 | 2310 |
} |
2311 |
} |
|
2312 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2313 |
} |
0 | 2314 |
} |
2315 |
} else if (v->type == VEH_Road) { |
|
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2316 |
if (v->u.road.state < 16 && !HASBIT(v->u.road.state, 2) && v->u.road.frame == 0) { |
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2317 |
if (IsRoadStop(tile)) { |
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2318 |
/* Attempt to allocate a parking bay in a road stop */ |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2319 |
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2320 |
|
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2321 |
/* rs->status bits 0 and 1 describe current the two parking spots. |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2322 |
* 0 means occupied, 1 means free. */ |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2323 |
|
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2324 |
// Check if station is busy or if there are no free bays. |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2325 |
if (HASBIT(rs->status, 7) || GB(rs->status, 0, 2) == 0) |
0 | 2326 |
return 8; |
2327 |
||
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2328 |
v->u.road.state += 32; |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2329 |
|
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2330 |
// if the first bay is free, allocate that, else the second bay must be free. |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2331 |
if (HASBIT(rs->status, 0)) { |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2332 |
CLRBIT(rs->status, 0); |
0 | 2333 |
} else { |
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2334 |
CLRBIT(rs->status, 1); |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2335 |
v->u.road.state += 2; |
0 | 2336 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2337 |
|
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2338 |
// mark the station as busy |
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2339 |
SETBIT(rs->status, 7); |
0 | 2340 |
} |
2341 |
} |
|
2342 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2343 |
|
0 | 2344 |
return 0; |
2345 |
} |
|
2346 |
||
4398
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2347 |
/** |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2348 |
* Cleanup a RoadStop. Make sure no vehicles try to go to this roadstop. |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2349 |
*/ |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2350 |
void DestroyRoadStop(RoadStop* rs) |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2351 |
{ |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2352 |
Vehicle *v; |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2353 |
|
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2354 |
/* Clear the slot assignment of all vehicles heading for this road stop */ |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2355 |
if (rs->num_vehicles != 0) { |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2356 |
FOR_ALL_VEHICLES(v) { |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2357 |
if (v->type == VEH_Road && v->u.road.slot == rs) { |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2358 |
ClearSlot(v); |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2359 |
} |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2360 |
} |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2361 |
} |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2362 |
assert(rs->num_vehicles == 0); |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2363 |
|
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2364 |
if (rs->prev != NULL) rs->prev->next = rs->next; |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2365 |
if (rs->next != NULL) rs->next->prev = rs->prev; |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2366 |
} |
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2367 |
|
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2368 |
/** |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2369 |
* Clean up a station by clearing vehicle orders and invalidating windows. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2370 |
* Aircraft-Hangar orders need special treatment here, as the hangars are |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2371 |
* actually part of a station (tiletype is STATION), but the order type |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2372 |
* is OT_GOTO_DEPOT. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2373 |
* @param st Station to be deleted |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
2374 |
*/ |
4398
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2375 |
void DestroyStation(Station *st) |
0 | 2376 |
{ |
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2377 |
StationID index; |
4398
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2378 |
|
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2379 |
index = st->index; |
0 | 2380 |
|
2381 |
DeleteName(st->string_id); |
|
2382 |
MarkStationDirty(st); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
2383 |
RebuildStationLists(); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2384 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2385 |
|
2386 |
DeleteWindowById(WC_STATION_VIEW, index); |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
2387 |
|
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4348
diff
changeset
|
2388 |
/* Now delete all orders that go to the station */ |
4527
fa30d19685c2
(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:
4467
diff
changeset
|
2389 |
RemoveOrderFromAllVehicles(OT_GOTO_STATION, index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1012
diff
changeset
|
2390 |
|
2213
bab9abeaa644
(svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents:
2187
diff
changeset
|
2391 |
//Subsidies need removal as well |
0 | 2392 |
DeleteSubsidyWithStation(index); |
4398
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2393 |
|
9232bcc7422a
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
2394 |
free(st->speclist); |
0 | 2395 |
} |
2396 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2397 |
void DeleteAllPlayerStations(void) |
0 | 2398 |
{ |
2399 |
Station *st; |
|
2400 |
||
2401 |
FOR_ALL_STATIONS(st) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2402 |
if (st->owner < MAX_PLAYERS) DeleteStation(st); |
0 | 2403 |
} |
2404 |
} |
|
2405 |
||
2406 |
/* this function is called for one station each tick */ |
|
2407 |
static void StationHandleBigTick(Station *st) |
|
2408 |
{ |
|
2409 |
UpdateStationAcceptance(st, true); |
|
2410 |
||
2639 | 2411 |
if (st->facilities == 0 && ++st->delete_ctr >= 8) DeleteStation(st); |
1239
133586622b78
(svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents:
1231
diff
changeset
|
2412 |
|
0 | 2413 |
} |
2414 |
||
500
8e52f7797b48
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2415 |
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } |
0 | 2416 |
|
2417 |
static void UpdateStationRating(Station *st) |
|
2418 |
{ |
|
2419 |
GoodsEntry *ge; |
|
1551
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2420 |
int rating; |
b1c7df6daa63
(svn r2055) -CodeChange: Begun introducting StationID
celestar
parents:
1527
diff
changeset
|
2421 |
StationID index; |
0 | 2422 |
int waiting; |
2423 |
bool waiting_changed = false; |
|
2424 |
||
2425 |
byte_inc_sat(&st->time_since_load); |
|
2426 |
byte_inc_sat(&st->time_since_unload); |
|
2427 |
||
2428 |
ge = st->goods; |
|
2429 |
do { |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2430 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2431 |
byte_inc_sat(&ge->enroute_time); |
2432 |
byte_inc_sat(&ge->days_since_pickup); |
|
2433 |
||
2434 |
rating = 0; |
|
2435 |
||
2436 |
{ |
|
2437 |
int b = ge->last_speed; |
|
2438 |
if ((b-=85) >= 0) |
|
2439 |
rating += b >> 2; |
|
2440 |
} |
|
2441 |
||
2442 |
{ |
|
2443 |
byte age = ge->last_age; |
|
2444 |
(age >= 3) || |
|
2445 |
(rating += 10, age >= 2) || |
|
2446 |
(rating += 10, age >= 1) || |
|
2447 |
(rating += 13, true); |
|
2448 |
} |
|
2449 |
||
1457
ace44a69238d
(svn r1961) - Fix: [ 1158618 ] Segmentation fault when loading savegame, out of bounds array check.
Darkvater
parents:
1454
diff
changeset
|
2450 |
if (st->owner < MAX_PLAYERS && HASBIT(st->town->statues, st->owner)) |
0 | 2451 |
rating += 26; |
2452 |
||
2453 |
{ |
|
2454 |
byte days = ge->days_since_pickup; |
|
3580
14bf6e7715c8
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3576
diff
changeset
|
2455 |
if (st->last_vehicle_type == VEH_Ship) |
0 | 2456 |
days >>= 2; |
2457 |
(days > 21) || |
|
2458 |
(rating += 25, days > 12) || |
|
2459 |
(rating += 25, days > 6) || |
|
2460 |
(rating += 45, days > 3) || |
|
2461 |
(rating += 35, true); |
|
2462 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2463 |
|
0 | 2464 |
{ |
2504
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2465 |
waiting = GB(ge->waiting_acceptance, 0, 12); |
0 | 2466 |
(rating -= 90, waiting > 1500) || |
2467 |
(rating += 55, waiting > 1000) || |
|
2468 |
(rating += 35, waiting > 600) || |
|
2469 |
(rating += 10, waiting > 300) || |
|
2470 |
(rating += 20, waiting > 100) || |
|
2471 |
(rating += 10, true); |
|
2472 |
} |
|
2473 |
||
2474 |
{ |
|
2475 |
int or = ge->rating; // old rating |
|
2476 |
||
2477 |
// only modify rating in steps of -2, -1, 0, 1 or 2 |
|
2478 |
ge->rating = rating = or + clamp(clamp(rating, 0, 255) - or, -2, 2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2479 |
|
0 | 2480 |
// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station |
2481 |
if (rating <= 64 && waiting >= 200) { |
|
2482 |
int dec = Random() & 0x1F; |
|
2483 |
if (waiting < 400) dec &= 7; |
|
2484 |
waiting -= dec + 1; |
|
2485 |
waiting_changed = true; |
|
2486 |
} |
|
2487 |
||
2488 |
// if rating is <= 127 and there are any items waiting, maybe remove some goods. |
|
2489 |
if (rating <= 127 && waiting != 0) { |
|
2490 |
uint32 r = Random(); |
|
2491 |
if ( (uint)rating <= (r & 0x7F) ) { |
|
2492 |
waiting = max(waiting - ((r >> 8)&3) - 1, 0); |
|
2493 |
waiting_changed = true; |
|
2494 |
} |
|
2495 |
} |
|
2496 |
||
2504
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2497 |
if (waiting_changed) SB(ge->waiting_acceptance, 0, 12, waiting); |
0 | 2498 |
} |
2499 |
} |
|
2500 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2501 |
|
0 | 2502 |
index = st->index; |
2503 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2504 |
if (waiting_changed) { |
0 | 2505 |
InvalidateWindow(WC_STATION_VIEW, index); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2506 |
} else { |
0 | 2507 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 5); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2508 |
} |
0 | 2509 |
} |
2510 |
||
2511 |
/* called for every station each tick */ |
|
2512 |
static void StationHandleSmallTick(Station *st) |
|
2513 |
{ |
|
2514 |
byte b; |
|
2515 |
||
2639 | 2516 |
if (st->facilities == 0) return; |
0 | 2517 |
|
2518 |
b = st->delete_ctr + 1; |
|
2519 |
if (b >= 185) b = 0; |
|
2520 |
st->delete_ctr = b; |
|
2521 |
||
2639 | 2522 |
if (b == 0) UpdateStationRating(st); |
0 | 2523 |
} |
2524 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2525 |
void OnTick_Station(void) |
0 | 2526 |
{ |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2527 |
uint i; |
0 | 2528 |
Station *st; |
2529 |
||
2639 | 2530 |
if (_game_mode == GM_EDITOR) return; |
0 | 2531 |
|
2532 |
i = _station_tick_ctr; |
|
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
2533 |
if (++_station_tick_ctr == GetStationArraySize()) _station_tick_ctr = 0; |
0 | 2534 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2535 |
if (IsValidStationID(i)) StationHandleBigTick(GetStation(i)); |
0 | 2536 |
|
2537 |
FOR_ALL_STATIONS(st) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2538 |
StationHandleSmallTick(st); |
0 | 2539 |
} |
2540 |
} |
|
2541 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2542 |
void StationMonthlyLoop(void) |
0 | 2543 |
{ |
2544 |
} |
|
2545 |
||
2546 |
||
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
2547 |
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) |
0 | 2548 |
{ |
2549 |
Station *st; |
|
2550 |
||
2551 |
FOR_ALL_STATIONS(st) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2552 |
if (st->owner == owner && |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
2553 |
DistanceManhattan(tile, st->xy) <= radius) { |
2549 | 2554 |
uint i; |
2555 |
||
2556 |
for (i = 0; i != NUM_CARGO; i++) { |
|
2557 |
GoodsEntry* ge = &st->goods[i]; |
|
2558 |
||
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
2559 |
if (ge->enroute_from != INVALID_STATION) { |
0 | 2560 |
ge->rating = clamp(ge->rating + amount, 0, 255); |
2561 |
} |
|
2562 |
} |
|
2563 |
} |
|
2564 |
} |
|
2565 |
} |
|
2566 |
||
2567 |
static void UpdateStationWaiting(Station *st, int type, uint amount) |
|
2568 |
{ |
|
2504
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2569 |
SB(st->goods[type].waiting_acceptance, 0, 12, |
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2570 |
min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount) |
5ae89f643cdc
(svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents:
2502
diff
changeset
|
2571 |
); |
0 | 2572 |
|
2573 |
st->goods[type].enroute_time = 0; |
|
2574 |
st->goods[type].enroute_from = st->index; |
|
2575 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
|
2576 |
} |
|
2577 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2578 |
/** Rename a station |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
2579 |
* @param tile unused |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2580 |
* @param p1 station ID that is to be renamed |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2581 |
* @param p2 unused |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2582 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
2583 |
int32 CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2584 |
{ |
2639 | 2585 |
StringID str; |
0 | 2586 |
Station *st; |
2587 |
||
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2588 |
if (!IsValidStationID(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1774
907db1b7a445
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2589 |
st = GetStation(p1); |
907db1b7a445
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2590 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2591 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
1774
907db1b7a445
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2592 |
|
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1786
diff
changeset
|
2593 |
str = AllocateNameUnique(_cmd_text, 6); |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1784
diff
changeset
|
2594 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2595 |
|
0 | 2596 |
if (flags & DC_EXEC) { |
2639 | 2597 |
StringID old_str = st->string_id; |
2598 |
||
0 | 2599 |
st->string_id = str; |
2600 |
UpdateStationVirtCoord(st); |
|
2601 |
DeleteName(old_str); |
|
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
2602 |
ResortStationLists(); |
0 | 2603 |
MarkWholeScreenDirty(); |
2604 |
} else { |
|
2605 |
DeleteName(str); |
|
2606 |
} |
|
2607 |
||
2608 |
return 0; |
|
2609 |
} |
|
2610 |
||
2611 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2612 |
uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) |
0 | 2613 |
{ |
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2614 |
Station* around[8]; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2615 |
uint i; |
0 | 2616 |
uint moved; |
2617 |
uint best_rating, best_rating2; |
|
2618 |
Station *st1, *st2; |
|
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2619 |
uint t; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2620 |
int rad = 0; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2621 |
int w_prod; //width and height of the "producer" of the cargo |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2622 |
int h_prod; |
568
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2623 |
int max_rad; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2624 |
|
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2625 |
for (i = 0; i < lengthof(around); i++) around[i] = NULL; |
0 | 2626 |
|
568
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2627 |
if (_patches.modified_catchment) { |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2628 |
w_prod = w; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2629 |
h_prod = h; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2630 |
w += 16; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2631 |
h += 16; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2632 |
max_rad = 8; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2633 |
} else { |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2634 |
w_prod = 0; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2635 |
h_prod = 0; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2636 |
w += 8; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2637 |
h += 8; |
568
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2638 |
max_rad = 4; |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2639 |
} |
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2640 |
|
1981 | 2641 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2642 |
Station* st; |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2643 |
|
0 | 2644 |
cur_tile = TILE_MASK(cur_tile); |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2645 |
if (!IsTileType(cur_tile, MP_STATION)) continue; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2646 |
|
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2647 |
st = GetStationByTile(cur_tile); |
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2648 |
|
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2649 |
for (i = 0; i != lengthof(around); i++) { |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2650 |
if (around[i] == NULL) { |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2651 |
if (!IsBuoy(st) && |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2652 |
(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2653 |
st->goods[type].rating != 0 && |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2654 |
(!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there. |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2655 |
((st->facilities & ~FACIL_BUS_STOP) != 0 || type == CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2656 |
((st->facilities & ~FACIL_TRUCK_STOP) != 0 || type != CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers |
3001
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2657 |
int x_dist; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2658 |
int y_dist; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2659 |
|
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2660 |
if (_patches.modified_catchment) { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2661 |
// min and max coordinates of the producer relative |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2662 |
const int x_min_prod = 9; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2663 |
const int x_max_prod = 8 + w_prod; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2664 |
const int y_min_prod = 9; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2665 |
const int y_max_prod = 8 + h_prod; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2666 |
|
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2667 |
rad = FindCatchmentRadius(st); |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2668 |
|
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2669 |
x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2670 |
if (w_cur < x_min_prod) { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2671 |
x_dist = x_min_prod - w_cur; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2672 |
} else if (w_cur > x_max_prod) { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2673 |
x_dist = w_cur - x_max_prod; |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2674 |
} |
3001
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2675 |
|
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2676 |
y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2677 |
if (h_cur < y_min_prod) { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2678 |
y_dist = y_min_prod - h_cur; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2679 |
} else if (h_cur > y_max_prod) { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2680 |
y_dist = h_cur - y_max_prod; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2681 |
} |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2682 |
} else { |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2683 |
x_dist = 0; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2684 |
y_dist = 0; |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2685 |
} |
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2686 |
|
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2687 |
if (x_dist <= rad && y_dist <= rad) around[i] = st; |
3001
f7944d55b88d
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2688 |
} |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2689 |
break; |
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2690 |
} else if (around[i] == st) { |
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2691 |
break; |
0 | 2692 |
} |
2693 |
} |
|
1981 | 2694 |
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2695 |
|
2696 |
/* no stations around at all? */ |
|
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2697 |
if (around[0] == NULL) return 0; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2698 |
|
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2699 |
if (around[1] == NULL) { |
0 | 2700 |
/* only one station around */ |
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2701 |
moved = (amount * around[0]->goods[type].rating >> 8) + 1; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2702 |
UpdateStationWaiting(around[0], type, moved); |
0 | 2703 |
return moved; |
2704 |
} |
|
2705 |
||
2706 |
/* several stations around, find the two with the highest rating */ |
|
2707 |
st2 = st1 = NULL; |
|
2708 |
best_rating = best_rating2 = 0; |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2709 |
|
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2710 |
for (i = 0; i != lengthof(around) && around[i] != NULL; i++) { |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2711 |
if (around[i]->goods[type].rating >= best_rating) { |
0 | 2712 |
best_rating2 = best_rating; |
2713 |
st2 = st1; |
|
2714 |
||
3002
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2715 |
best_rating = around[i]->goods[type].rating; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2716 |
st1 = around[i]; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2717 |
} else if (around[i]->goods[type].rating >= best_rating2) { |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2718 |
best_rating2 = around[i]->goods[type].rating; |
0651b917cd92
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2719 |
st2 = around[i]; |
0 | 2720 |
} |
2721 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2722 |
|
0 | 2723 |
assert(st1 != NULL); |
2724 |
assert(st2 != NULL); |
|
2725 |
assert(best_rating != 0 || best_rating2 != 0); |
|
2726 |
||
2727 |
/* the 2nd highest one gets a penalty */ |
|
2728 |
best_rating2 >>= 1; |
|
2729 |
||
2730 |
/* amount given to station 1 */ |
|
2731 |
t = (best_rating * (amount + 1)) / (best_rating + best_rating2); |
|
2732 |
||
2733 |
moved = 0; |
|
2734 |
if (t != 0) { |
|
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2735 |
moved = t * best_rating / 256 + 1; |
0 | 2736 |
amount -= t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2737 |
UpdateStationWaiting(st1, type, moved); |
0 | 2738 |
} |
2739 |
||
2740 |
if (amount != 0) { |
|
3000
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2741 |
amount = amount * best_rating2 / 256 + 1; |
692dd5ed9fca
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2742 |
moved += amount; |
0 | 2743 |
UpdateStationWaiting(st2, type, amount); |
2744 |
} |
|
2745 |
||
2746 |
return moved; |
|
2747 |
} |
|
2748 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2749 |
void BuildOilRig(TileIndex tile) |
0 | 2750 |
{ |
2639 | 2751 |
uint j; |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2752 |
Station *st = AllocateStation(); |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2753 |
|
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2754 |
if (st == NULL) { |
3630
13278b8ed023
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3587
diff
changeset
|
2755 |
DEBUG(misc, 0) ("Couldn't allocate station for oilrig at 0x%X, reverting to oilrig only...", tile); |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2756 |
return; |
0 | 2757 |
} |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2758 |
if (!GenerateStationName(st, tile, 2)) { |
3630
13278b8ed023
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3587
diff
changeset
|
2759 |
DEBUG(misc, 0) ("Couldn't allocate station-name for oilrig at 0x%X, reverting to oilrig only...", tile); |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2760 |
return; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2761 |
} |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2762 |
|
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2763 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2764 |
st->sign.width_1 = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2765 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2766 |
MakeOilrig(tile, st->index); |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2767 |
|
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2768 |
st->owner = OWNER_NONE; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2769 |
st->airport_flags = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2770 |
st->airport_type = AT_OILRIG; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2771 |
st->xy = tile; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2772 |
st->bus_stops = NULL; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2773 |
st->truck_stops = NULL; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2774 |
st->airport_tile = tile; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2775 |
st->dock_tile = tile; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2776 |
st->train_tile = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2777 |
st->had_vehicle_of_type = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2778 |
st->time_since_load = 255; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2779 |
st->time_since_unload = 255; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2780 |
st->delete_ctr = 0; |
3580
14bf6e7715c8
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3576
diff
changeset
|
2781 |
st->last_vehicle_type = VEH_Invalid; |
2427
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2782 |
st->facilities = FACIL_AIRPORT | FACIL_DOCK; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2783 |
st->build_date = _date; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2784 |
|
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2785 |
for (j = 0; j != NUM_CARGO; j++) { |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2786 |
st->goods[j].waiting_acceptance = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2787 |
st->goods[j].days_since_pickup = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2788 |
st->goods[j].enroute_from = INVALID_STATION; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2789 |
st->goods[j].rating = 175; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2790 |
st->goods[j].last_speed = 0; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2791 |
st->goods[j].last_age = 255; |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2792 |
} |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2793 |
|
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2794 |
UpdateStationVirtCoordDirty(st); |
5312305eecdd
(svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents:
2425
diff
changeset
|
2795 |
UpdateStationAcceptance(st, false); |
0 | 2796 |
} |
2797 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2798 |
void DeleteOilRig(TileIndex tile) |
0 | 2799 |
{ |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2800 |
Station* st = GetStationByTile(tile); |
0 | 2801 |
|
2802 |
DoClearSquare(tile); |
|
2803 |
||
2804 |
st->dock_tile = 0; |
|
2805 |
st->airport_tile = 0; |
|
2806 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
2807 |
st->airport_flags = 0; |
|
2808 |
UpdateStationVirtCoordDirty(st); |
|
2809 |
DeleteStation(st); |
|
2810 |
} |
|
2811 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2427
diff
changeset
|
2812 |
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 2813 |
{ |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
2814 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 2815 |
|
2502 | 2816 |
if (new_player != OWNER_SPECTATOR) { |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2817 |
Station* st = GetStationByTile(tile); |
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2818 |
|
1902 | 2819 |
SetTileOwner(tile, new_player); |
0 | 2820 |
st->owner = new_player; |
3812
e6fc916c17ab
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
2821 |
RebuildStationLists(); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2822 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2823 |
} else { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3482
diff
changeset
|
2824 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 2825 |
} |
2826 |
} |
|
2827 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2828 |
static int32 ClearTile_Station(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2829 |
{ |
0 | 2830 |
Station *st; |
2831 |
||
2832 |
if (flags & DC_AUTO) { |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2833 |
switch (GetStationType(tile)) { |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2834 |
case STATION_RAIL: return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2835 |
case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2836 |
case STATION_TRUCK: return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2837 |
case STATION_BUS: return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2838 |
case STATION_BUOY: return_cmd_error(STR_306A_BUOY_IN_THE_WAY); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2839 |
case STATION_DOCK: return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2840 |
case STATION_OILRIG: |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2841 |
SetDParam(0, STR_4807_OIL_RIG); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2842 |
return_cmd_error(STR_4800_IN_THE_WAY); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2843 |
} |
0 | 2844 |
} |
2845 |
||
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2846 |
st = GetStationByTile(tile); |
0 | 2847 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2848 |
switch (GetStationType(tile)) { |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2849 |
case STATION_RAIL: return RemoveRailroadStation(st, tile, flags); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2850 |
case STATION_AIRPORT: return RemoveAirport(st, flags); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2851 |
case STATION_TRUCK: |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2852 |
case STATION_BUS: return RemoveRoadStop(st, flags, tile); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2853 |
case STATION_BUOY: return RemoveBuoy(st, flags); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2854 |
case STATION_DOCK: return RemoveDock(st, flags); |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2855 |
default: break; |
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2856 |
} |
0 | 2857 |
|
2858 |
return CMD_ERROR; |
|
2859 |
} |
|
2860 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
2861 |
void InitializeStations(void) |
0 | 2862 |
{ |
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2863 |
/* Clean the station pool and create 1 block in it */ |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2864 |
CleanPool(&_station_pool); |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2865 |
AddBlockToPool(&_station_pool); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2866 |
|
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2867 |
/* Clean the roadstop pool and create 1 block in it */ |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2868 |
CleanPool(&_roadstop_pool); |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2869 |
AddBlockToPool(&_roadstop_pool); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2870 |
|
0 | 2871 |
_station_tick_ctr = 0; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2872 |
|
0 | 2873 |
} |
2874 |
||
2875 |
||
3765
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2876 |
void AfterLoadStations(void) |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2877 |
{ |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2878 |
Station *st; |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2879 |
uint i; |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2880 |
|
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2881 |
/* Update the speclists of all stations to point to the currently loaded custom stations. */ |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2882 |
FOR_ALL_STATIONS(st) { |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2883 |
for (i = 0; i < st->num_specs; i++) { |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2884 |
if (st->speclist[i].grfid == 0) continue; |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2885 |
|
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2886 |
st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx); |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2887 |
} |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2888 |
} |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2889 |
} |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2890 |
|
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2891 |
|
0 | 2892 |
const TileTypeProcs _tile_type_station_procs = { |
3554
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2893 |
DrawTile_Station, /* draw_tile_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2894 |
GetSlopeZ_Station, /* get_slope_z_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2895 |
ClearTile_Station, /* clear_tile_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2896 |
GetAcceptedCargo_Station, /* get_accepted_cargo_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2897 |
GetTileDesc_Station, /* get_tile_desc_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2898 |
GetTileTrackStatus_Station, /* get_tile_track_status_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2899 |
ClickTile_Station, /* click_tile_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2900 |
AnimateTile_Station, /* animate_tile_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2901 |
TileLoop_Station, /* tile_loop_clear */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2902 |
ChangeTileOwner_Station, /* change_tile_owner_clear */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2903 |
NULL, /* get_produced_cargo_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2904 |
VehicleEnter_Station, /* vehicle_enter_tile_proc */ |
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2905 |
GetSlopeTileh_Station, /* get_slope_tileh_proc */ |
0 | 2906 |
}; |
2907 |
||
1881
435d39bd6ee0
(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:
1876
diff
changeset
|
2908 |
static const SaveLoad _roadstop_desc[] = { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2909 |
SLE_VAR(RoadStop,xy, SLE_UINT32), |
3873
20861d17b162
(svn r4915) - Fix: SLE_UINT8 replaced by SLE_BOOL for bool variables (found by Celestar)
KUDr
parents:
3812
diff
changeset
|
2910 |
SLE_VAR(RoadStop,used, SLE_BOOL), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2911 |
SLE_VAR(RoadStop,status, SLE_UINT8), |
1285
4bda5c927b45
(svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents:
1284
diff
changeset
|
2912 |
/* Index was saved in some versions, but this is not needed */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2913 |
SLE_CONDNULL(4, 0, 8), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2914 |
SLE_VAR(RoadStop,station, SLE_UINT16), |
3479
3655a074a380
(svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents:
3478
diff
changeset
|
2915 |
SLE_CONDNULL(1, 0, 25), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2916 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2917 |
SLE_REF(RoadStop,next, REF_ROADSTOPS), |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2918 |
SLE_REF(RoadStop,prev, REF_ROADSTOPS), |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2919 |
|
3431 | 2920 |
SLE_CONDNULL(4, 0, 24), |
3475
150d89779e96
(svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents:
3474
diff
changeset
|
2921 |
SLE_CONDNULL(1, 25, 25), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2922 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2923 |
SLE_END() |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2924 |
}; |
0 | 2925 |
|
1881
435d39bd6ee0
(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:
1876
diff
changeset
|
2926 |
static const SaveLoad _station_desc[] = { |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2927 |
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2928 |
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2929 |
SLE_CONDVAR(Station, bus_tile_obsolete, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2930 |
SLE_CONDVAR(Station, lorry_tile_obsolete, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2931 |
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2932 |
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2933 |
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2934 |
SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2935 |
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2936 |
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2937 |
SLE_REF(Station, town, REF_TOWN), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2938 |
SLE_VAR(Station, trainst_w, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2939 |
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2940 |
|
2941 |
// alpha_order was stored here in savegame format 0 - 3 |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2942 |
SLE_CONDNULL(1, 0, 3), |
0 | 2943 |
|
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2944 |
SLE_VAR(Station, string_id, SLE_STRINGID), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2945 |
SLE_VAR(Station, had_vehicle_of_type, SLE_UINT16), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2946 |
|
7e123fec5b0b
(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:
4326
diff
changeset
|
2947 |
SLE_VAR(Station, time_since_load, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2948 |
SLE_VAR(Station, time_since_unload, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2949 |
SLE_VAR(Station, delete_ctr, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2950 |
SLE_VAR(Station, owner, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2951 |
SLE_VAR(Station, facilities, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2952 |
SLE_VAR(Station, airport_type, SLE_UINT8), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2953 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2954 |
// truck/bus_stop_status was stored here in savegame format 0 - 6 |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2955 |
SLE_CONDVAR(Station, truck_stop_status_obsolete, SLE_UINT8, 0, 5), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2956 |
SLE_CONDVAR(Station, bus_stop_status_obsolete, SLE_UINT8, 0, 5), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2957 |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
2958 |
// blocked_months was stored here in savegame format 0 - 4.0 |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2959 |
SLE_CONDVAR(Station, blocked_months_obsolete, SLE_UINT8, 0, 4), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2960 |
|
7e123fec5b0b
(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:
4326
diff
changeset
|
2961 |
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U32 | SLE_FILE_U16, 0, 2), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2962 |
SLE_CONDVAR(Station, airport_flags, SLE_UINT32, 3, SL_MAX_VERSION), |
3554
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2963 |
|
3580
14bf6e7715c8
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3576
diff
changeset
|
2964 |
SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */ |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2965 |
SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION), |
3554
86230061c3e7
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2966 |
|
3574
280e134ce515
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2967 |
// Was custom station class and id |
280e134ce515
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2968 |
SLE_CONDNULL(2, 3, 25), |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2969 |
SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2970 |
SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2971 |
|
7e123fec5b0b
(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:
4326
diff
changeset
|
2972 |
SLE_CONDREF(Station, bus_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2973 |
SLE_CONDREF(Station, truck_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION), |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2974 |
|
3687
f421ffcfeb00
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2975 |
/* Used by newstations for graphic variations */ |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2976 |
SLE_CONDVAR(Station, random_bits, SLE_UINT16, 27, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2977 |
SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2978 |
SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION), |
3687
f421ffcfeb00
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2979 |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2980 |
// reserve extra space in savegame here. (currently 32 bytes) |
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2981 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 2982 |
|
2983 |
SLE_END() |
|
2984 |
}; |
|
2985 |
||
1881
435d39bd6ee0
(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:
1876
diff
changeset
|
2986 |
static const SaveLoad _goods_desc[] = { |
4344
7e123fec5b0b
(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:
4326
diff
changeset
|
2987 |
SLE_VAR(GoodsEntry, waiting_acceptance, SLE_UINT16), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2988 |
SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2989 |
SLE_VAR(GoodsEntry, rating, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2990 |
SLE_CONDVAR(GoodsEntry, enroute_from, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2991 |
SLE_CONDVAR(GoodsEntry, enroute_from, SLE_UINT16, 7, SL_MAX_VERSION), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2992 |
SLE_VAR(GoodsEntry, enroute_time, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2993 |
SLE_VAR(GoodsEntry, last_speed, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2994 |
SLE_VAR(GoodsEntry, last_age, SLE_UINT8), |
7e123fec5b0b
(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:
4326
diff
changeset
|
2995 |
SLE_CONDVAR(GoodsEntry, feeder_profit, SLE_INT32, 14, SL_MAX_VERSION), |
0 | 2996 |
|
2997 |
SLE_END() |
|
2998 |
}; |
|
2999 |
||
3765
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3000 |
static const SaveLoad _station_speclist_desc[] = { |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3001 |
SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, 27, SL_MAX_VERSION), |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3002 |
SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8, 27, SL_MAX_VERSION), |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3003 |
|
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3004 |
SLE_END() |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3005 |
}; |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3006 |
|
0 | 3007 |
|
3008 |
static void SaveLoad_STNS(Station *st) |
|
3009 |
{ |
|
3765
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3010 |
uint i; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3011 |
|
0 | 3012 |
SlObject(st, _station_desc); |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3013 |
for (i = 0; i != NUM_CARGO; i++) { |
0 | 3014 |
SlObject(&st->goods[i], _goods_desc); |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3015 |
|
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3016 |
/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3017 |
if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) { |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
3018 |
st->goods[i].enroute_from = INVALID_STATION; |
2639 | 3019 |
} |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3020 |
} |
3765
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3021 |
|
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3022 |
if (st->num_specs != 0) { |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3023 |
/* Allocate speclist memory when loading a game */ |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3024 |
if (st->speclist == NULL) st->speclist = calloc(st->num_specs, sizeof(*st->speclist)); |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3025 |
for (i = 0; i < st->num_specs; i++) SlObject(&st->speclist[i], _station_speclist_desc); |
a4ddbff73f9f
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3026 |
} |
0 | 3027 |
} |
3028 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
3029 |
static void Save_STNS(void) |
0 | 3030 |
{ |
3031 |
Station *st; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3032 |
// Write the stations |
0 | 3033 |
FOR_ALL_STATIONS(st) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3034 |
SlSetArrayIndex(st->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3035 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
0 | 3036 |
} |
3037 |
} |
|
3038 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1078
diff
changeset
|
3039 |
static void Load_STNS(void) |
0 | 3040 |
{ |
3041 |
int index; |
|
3042 |
while ((index = SlIterateArray()) != -1) { |
|
1272
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3043 |
Station *st; |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3044 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3045 |
if (!AddBlockIfNeeded(&_station_pool, index)) |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3046 |
error("Stations: failed loading savegame: too many stations"); |
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3047 |
|
9aa073c64fc7
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
3048 |
st = GetStation(index); |
0 | 3049 |
SaveLoad_STNS(st); |
3050 |
||
3051 |
// this means it's an oldstyle savegame without support for nonuniform stations |
|
2639 | 3052 |
if (st->train_tile != 0 && st->trainst_h == 0) { |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3053 |
uint w = GB(st->trainst_w, 4, 4); |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3054 |
uint h = GB(st->trainst_w, 0, 4); |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3055 |
|
3334
2999d2ddc0f9
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
3056 |
if (GetRailStationAxis(st->train_tile) == AXIS_Y) uintswap(w, h); |
0 | 3057 |
st->trainst_w = w; |
3058 |
st->trainst_h = h; |
|
3059 |
} |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3060 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3061 |
/* In older versions, we had just 1 tile for a bus/lorry, now we have more.. |
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3062 |
* convert, if needed */ |
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2676
diff
changeset
|
3063 |
if (CheckSavegameVersion(6)) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3064 |
if (st->bus_tile_obsolete != 0) { |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3065 |
st->bus_stops = AllocateRoadStop(); |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3066 |
if (st->bus_stops == NULL) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3067 |
error("Station: too many busstations in savegame"); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3068 |
|
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3069 |
InitializeRoadStop(st->bus_stops, NULL, st->bus_tile_obsolete, st->index); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3070 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3071 |
if (st->lorry_tile_obsolete != 0) { |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3072 |
st->truck_stops = AllocateRoadStop(); |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3073 |
if (st->truck_stops == NULL) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3074 |
error("Station: too many truckstations in savegame"); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3075 |
|
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3076 |
InitializeRoadStop(st->truck_stops, NULL, st->lorry_tile_obsolete, st->index); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3077 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3078 |
} |
0 | 3079 |
} |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3080 |
|
1472
a2abe3b9d7a7
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
3081 |
/* This is to ensure all pointers are within the limits of _stations_size */ |
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4352
diff
changeset
|
3082 |
if (_station_tick_ctr > GetStationArraySize()) _station_tick_ctr = 0; |
0 | 3083 |
} |
3084 |
||
2549 | 3085 |
static void Save_ROADSTOP(void) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3086 |
{ |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3087 |
RoadStop *rs; |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3088 |
|
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3089 |
FOR_ALL_ROADSTOPS(rs) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3090 |
SlSetArrayIndex(rs->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3091 |
SlObject(rs, _roadstop_desc); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3092 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3093 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3094 |
|
2549 | 3095 |
static void Load_ROADSTOP(void) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3096 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3097 |
int index; |
3475
150d89779e96
(svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents:
3474
diff
changeset
|
3098 |
Vehicle *v; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3099 |
|
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3100 |
while ((index = SlIterateArray()) != -1) { |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3101 |
RoadStop *rs; |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3102 |
|
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3103 |
if (!AddBlockIfNeeded(&_roadstop_pool, index)) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
3104 |
error("RoadStops: failed loading savegame: too many RoadStops"); |
1284
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3105 |
|
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3106 |
rs = GetRoadStop(index); |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3107 |
SlObject(rs, _roadstop_desc); |
e1969eb0227b
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3108 |
} |
3475
150d89779e96
(svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents:
3474
diff
changeset
|
3109 |
|
150d89779e96
(svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents:
3474
diff
changeset
|
3110 |
FOR_ALL_VEHICLES(v) { |
3480
dbbc5e1ad694
(svn r4325) When updating the vehicle count for road stops after load use the slot pointer of the vehicle instead of recalculating the road stop using the destination tile of the vehicle. Apart from being more simple this could prevent a inconsistency of slot information in the edge case when the destination tile isn't the tile of the assigned slot.
tron
parents:
3479
diff
changeset
|
3111 |
if (v->type == VEH_Road && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++; |
3475
150d89779e96
(svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents:
3474
diff
changeset
|
3112 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3113 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3114 |
|
0 | 3115 |
const ChunkHandler _station_chunk_handlers[] = { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3116 |
{ 'STNS', Save_STNS, Load_STNS, CH_ARRAY }, |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3117 |
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST}, |
0 | 3118 |
}; |