author | richk |
Tue, 31 Jul 2007 00:36:55 +0000 | |
branch | NewGRF_ports |
changeset 6739 | 3f2ca4d0abda |
parent 6738 | 72d1a2997952 |
child 6743 | cabfaa4a0295 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6442
diff
changeset
|
3 |
/** @file station_cmd.cpp */ |
2213
cb78ae22fe58
(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
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
6413 | 7 |
#include "aircraft.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
8 |
#include "bridge_map.h" |
6460 | 9 |
#include "cmd_helper.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
10 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
11 |
#include "functions.h" |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
12 |
#include "landscape.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
13 |
#include "station_map.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
14 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
15 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
595
diff
changeset
|
16 |
#include "map.h" |
1209
a1ac96655b79
(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
|
17 |
#include "tile.h" |
0 | 18 |
#include "station.h" |
19 |
#include "gfx.h" |
|
20 |
#include "window.h" |
|
21 |
#include "viewport.h" |
|
22 |
#include "command.h" |
|
23 |
#include "town.h" |
|
24 |
#include "vehicle.h" |
|
25 |
#include "news.h" |
|
26 |
#include "saveload.h" |
|
27 |
#include "economy.h" |
|
28 |
#include "player.h" |
|
29 |
#include "airport.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
403
diff
changeset
|
30 |
#include "sprite.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
31 |
#include "depot.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2671
diff
changeset
|
32 |
#include "train.h" |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
33 |
#include "roadveh.h" |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
34 |
#include "water_map.h" |
3515
b14c49efef1e
(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
|
35 |
#include "industry_map.h" |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
36 |
#include "newgrf_callbacks.h" |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
37 |
#include "newgrf_station.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
38 |
#include "yapf/yapf.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
39 |
#include "date.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
40 |
#include "helpers.hpp" |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
41 |
#include "misc/autoptr.hpp" |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
42 |
#include "road.h" |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6413
diff
changeset
|
43 |
#include "cargotype.h" |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
44 |
#include "strings.h" |
6717
b25cf31294e9
(svn r9510) [NewGRF_ports] -Codechange: Moved airport layouts from station_cmd.cpp into table/station_air.h. Ultimately, these layouts should be provided by a newgrf.
richk
parents:
6694
diff
changeset
|
45 |
#include "table/station_air.h" |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
46 |
#include "airport_states.h" |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
47 |
#include "newgrf_fsmports.h" |
5917
e0d30aba24a3
(svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents:
5916
diff
changeset
|
48 |
|
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
49 |
/** |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
50 |
* Called if a new block is added to the station-pool |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
51 |
*/ |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
52 |
static void StationPoolNewBlock(uint start_item) |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
53 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
54 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
55 |
* TODO - This is just a temporary stage, this will be removed. */ |
6395 | 56 |
for (Station *st = GetStation(start_item); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) st->index = start_item++; |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
57 |
} |
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
58 |
|
3587 | 59 |
static void StationPoolCleanBlock(uint start_item, uint end_item) |
60 |
{ |
|
6395 | 61 |
for (uint i = start_item; i <= end_item; i++) { |
3587 | 62 |
Station *st = GetStation(i); |
6322
3d191e6e89bc
(svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents:
6321
diff
changeset
|
63 |
if (st->IsValid()) st->~Station(); |
3587 | 64 |
} |
65 |
} |
|
66 |
||
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
67 |
/** |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
68 |
* Called if a new block is added to the roadstop-pool |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
69 |
*/ |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
70 |
static void RoadStopPoolNewBlock(uint start_item) |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
71 |
{ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
72 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
73 |
* TODO - This is just a temporary stage, this will be removed. */ |
6395 | 74 |
for (RoadStop *rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) { |
5969 | 75 |
rs->xy = INVALID_TILE; |
76 |
rs->index = start_item++; |
|
77 |
} |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
78 |
} |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
79 |
|
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5116
diff
changeset
|
80 |
DEFINE_OLD_POOL(Station, Station, StationPoolNewBlock, StationPoolCleanBlock) |
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5116
diff
changeset
|
81 |
DEFINE_OLD_POOL(RoadStop, RoadStop, RoadStopPoolNewBlock, NULL) |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
82 |
|
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
83 |
|
6087
b56c54f79335
(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents:
6085
diff
changeset
|
84 |
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
85 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
86 |
const Station* st = GetStationByTile(tile); |
6395 | 87 |
|
88 |
for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) { |
|
89 |
if (rs->xy == tile) return rs; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
90 |
assert(rs->next != NULL); |
2639 | 91 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
92 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
93 |
|
6164 | 94 |
|
95 |
static uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type) |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
96 |
{ |
2549 | 97 |
uint num = 0; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
98 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
99 |
assert(st != NULL); |
6395 | 100 |
for (const RoadStop *rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) { |
101 |
num++; |
|
102 |
} |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
103 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
104 |
return num; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
105 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
106 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
107 |
|
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
108 |
/* Calculate the radius of the station. Basicly it is the biggest |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
109 |
* radius that is available within the station */ |
2643 | 110 |
static uint FindCatchmentRadius(const Station* st) |
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
111 |
{ |
6367 | 112 |
uint ret = CA_NONE; |
113 |
||
114 |
if (st->bus_stops != NULL) ret = max<uint>(ret, CA_BUS); |
|
115 |
if (st->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK); |
|
116 |
if (st->train_tile != 0) ret = max<uint>(ret, CA_TRAIN); |
|
117 |
if (st->dock_tile != 0) ret = max<uint>(ret, CA_DOCK); |
|
118 |
if (st->airport_tile) ret = max<uint>(ret, st->Airport()->catchment); |
|
703
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
119 |
|
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
120 |
return ret; |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
121 |
} |
c917d7d9aced
(svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents:
701
diff
changeset
|
122 |
|
0 | 123 |
#define CHECK_STATIONS_ERR ((Station*)-1) |
124 |
||
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
125 |
static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest_station) |
0 | 126 |
{ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
127 |
/* check around to see if there's any stations there */ |
1981 | 128 |
BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) |
1035
0a170deb6e33
(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
|
129 |
if (IsTileType(tile_cur, MP_STATION)) { |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
130 |
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
|
131 |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
132 |
if (closest_station == INVALID_STATION) { |
0 | 133 |
closest_station = t; |
134 |
} else if (closest_station != t) { |
|
135 |
_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING; |
|
136 |
return CHECK_STATIONS_ERR; |
|
137 |
} |
|
138 |
} |
|
1981 | 139 |
END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
140 |
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station); |
0 | 141 |
} |
142 |
||
143 |
||
3515
b14c49efef1e
(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
|
144 |
/** |
b14c49efef1e
(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
|
145 |
* Counts the numbers of tiles matching a specific type in the area around |
b14c49efef1e
(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
|
146 |
* @param tile the center tile of the 'count area' |
b14c49efef1e
(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
|
147 |
* @param type the type of tile searched for |
b14c49efef1e
(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
|
148 |
* @param industry when type == MP_INDUSTRY, the type of the industry, |
b14c49efef1e
(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
|
149 |
* in all other cases this parameter is ignored |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6524
diff
changeset
|
150 |
* @return the result the noumber of matching tiles around |
3515
b14c49efef1e
(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
|
151 |
*/ |
b14c49efef1e
(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
|
152 |
static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
153 |
{ |
0 | 154 |
int num = 0; |
155 |
||
6395 | 156 |
for (int dx = -3; dx <= 3; dx++) { |
157 |
for (int dy = -3; dy <= 3; dy++) { |
|
158 |
TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(dx, dy)); |
|
3515
b14c49efef1e
(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
|
159 |
|
b14c49efef1e
(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
|
160 |
if (IsTileType(cur_tile, type)) { |
b14c49efef1e
(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
|
161 |
switch (type) { |
b14c49efef1e
(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
|
162 |
case MP_INDUSTRY: |
b14c49efef1e
(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
|
163 |
if (GetIndustryType(cur_tile) == industry) |
b14c49efef1e
(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
|
164 |
num++; |
b14c49efef1e
(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
|
165 |
break; |
b14c49efef1e
(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
|
166 |
|
b14c49efef1e
(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
|
167 |
case MP_WATER: |
b14c49efef1e
(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
|
168 |
if (!IsWater(cur_tile)) |
b14c49efef1e
(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
|
169 |
break; |
b14c49efef1e
(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
|
170 |
/* FALL THROUGH WHEN WATER TILE */ |
b14c49efef1e
(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
|
171 |
case MP_TREES: |
b14c49efef1e
(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
|
172 |
num++; |
b14c49efef1e
(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
|
173 |
break; |
b14c49efef1e
(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
|
174 |
|
b14c49efef1e
(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
|
175 |
default: |
b14c49efef1e
(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
|
176 |
break; |
b14c49efef1e
(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
|
177 |
} |
b14c49efef1e
(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
|
178 |
} |
b14c49efef1e
(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
|
179 |
} |
0 | 180 |
} |
181 |
||
182 |
return num; |
|
183 |
} |
|
184 |
||
185 |
#define M(x) ((x) - STR_SV_STNAME) |
|
186 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
187 |
static bool GenerateStationName(Station *st, TileIndex tile, int flag) |
0 | 188 |
{ |
189 |
static const uint32 _gen_station_name_bits[] = { |
|
1454 | 190 |
0, /* 0 */ |
191 |
1 << M(STR_SV_STNAME_AIRPORT), /* 1 */ |
|
192 |
1 << M(STR_SV_STNAME_OILFIELD), /* 2 */ |
|
193 |
1 << M(STR_SV_STNAME_DOCKS), /* 3 */ |
|
194 |
0x1FF << M(STR_SV_STNAME_BUOY_1), /* 4 */ |
|
195 |
1 << M(STR_SV_STNAME_HELIPORT), /* 5 */ |
|
0 | 196 |
}; |
197 |
||
198 |
Town *t = st->town; |
|
199 |
uint32 free_names = (uint32)-1; |
|
200 |
int found; |
|
201 |
unsigned long tmp; |
|
202 |
||
203 |
{ |
|
204 |
Station *s; |
|
205 |
||
206 |
FOR_ALL_STATIONS(s) { |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
207 |
if (s != st && s->town == t) { |
0 | 208 |
uint str = M(s->string_id); |
209 |
if (str <= 0x20) { |
|
210 |
if (str == M(STR_SV_STNAME_FOREST)) |
|
211 |
str = M(STR_SV_STNAME_WOODS); |
|
212 |
CLRBIT(free_names, str); |
|
213 |
} |
|
214 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
215 |
} |
0 | 216 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
217 |
|
0 | 218 |
/* check default names */ |
219 |
tmp = free_names & _gen_station_name_bits[flag]; |
|
220 |
if (tmp != 0) { |
|
221 |
found = FindFirstBit(tmp); |
|
222 |
goto done; |
|
223 |
} |
|
224 |
||
225 |
/* check mine? */ |
|
226 |
if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) { |
|
3515
b14c49efef1e
(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
|
227 |
if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 || |
b14c49efef1e
(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
|
228 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 || |
b14c49efef1e
(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
|
229 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 || |
b14c49efef1e
(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
|
230 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 || |
b14c49efef1e
(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
|
231 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) { |
1454 | 232 |
found = M(STR_SV_STNAME_MINES); |
233 |
goto done; |
|
234 |
} |
|
0 | 235 |
} |
236 |
||
237 |
/* check close enough to town to get central as name? */ |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
238 |
if (DistanceMax(tile, t->xy) < 8) { |
0 | 239 |
found = M(STR_SV_STNAME); |
240 |
if (HASBIT(free_names, M(STR_SV_STNAME))) goto done; |
|
241 |
||
242 |
found = M(STR_SV_STNAME_CENTRAL); |
|
243 |
if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done; |
|
244 |
} |
|
245 |
||
246 |
/* Check lakeside */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
247 |
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) && |
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
248 |
DistanceFromEdge(tile) < 20 && |
3515
b14c49efef1e
(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
|
249 |
CountMapSquareAround(tile, MP_WATER, 0) >= 5) { |
1454 | 250 |
found = M(STR_SV_STNAME_LAKESIDE); |
251 |
goto done; |
|
252 |
} |
|
0 | 253 |
|
254 |
/* Check woods */ |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
255 |
if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && ( |
3515
b14c49efef1e
(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
|
256 |
CountMapSquareAround(tile, MP_TREES, 0) >= 8 || |
b14c49efef1e
(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
|
257 |
CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2) |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
258 |
) { |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6676
diff
changeset
|
259 |
found = _opt.landscape == LT_TROPIC ? |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
260 |
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS); |
1454 | 261 |
goto done; |
0 | 262 |
} |
263 |
||
264 |
/* check elevation compared to town */ |
|
6395 | 265 |
{ |
266 |
uint z = GetTileZ(tile); |
|
267 |
uint z2 = GetTileZ(t->xy); |
|
268 |
if (z < z2) { |
|
269 |
found = M(STR_SV_STNAME_VALLEY); |
|
270 |
if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done; |
|
271 |
} else if (z > z2) { |
|
272 |
found = M(STR_SV_STNAME_HEIGHTS); |
|
273 |
if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done; |
|
274 |
} |
|
0 | 275 |
} |
276 |
||
277 |
/* check direction compared to town */ |
|
278 |
{ |
|
279 |
static const int8 _direction_and_table[] = { |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
280 |
~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
281 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
282 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ), |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
283 |
~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ), |
0 | 284 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
285 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
286 |
free_names &= _direction_and_table[ |
926
bd4312619522
(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
|
287 |
(TileX(tile) < TileX(t->xy)) + |
bd4312619522
(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
|
288 |
(TileY(tile) < TileY(t->xy)) * 2]; |
0 | 289 |
} |
290 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
291 |
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)); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
292 |
found = (tmp == 0) ? M(STR_SV_STNAME_FALLBACK) : FindFirstBit(tmp); |
0 | 293 |
|
294 |
done: |
|
295 |
st->string_id = found + STR_SV_STNAME; |
|
296 |
return true; |
|
297 |
} |
|
298 |
#undef M |
|
299 |
||
6378 | 300 |
static Station* GetClosestStationFromTile(TileIndex tile) |
0 | 301 |
{ |
6378 | 302 |
uint threshold = 8; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
303 |
Station* best_station = NULL; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
304 |
Station* st; |
0 | 305 |
|
306 |
FOR_ALL_STATIONS(st) { |
|
6378 | 307 |
if (st->facilities == 0 && st->owner == _current_player) { |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
308 |
uint cur_dist = DistanceManhattan(tile, st->xy); |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
309 |
|
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
310 |
if (cur_dist < threshold) { |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
311 |
threshold = cur_dist; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
312 |
best_station = st; |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
313 |
} |
0 | 314 |
} |
315 |
} |
|
316 |
||
317 |
return best_station; |
|
318 |
} |
|
319 |
||
320 |
// Update the virtual coords needed to draw the station sign. |
|
321 |
// st = Station to update for. |
|
322 |
static void UpdateStationVirtCoord(Station *st) |
|
323 |
{ |
|
3422
12cdb13ddb56
(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
|
324 |
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
325 |
|
0 | 326 |
pt.y -= 32; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
327 |
if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16; |
0 | 328 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
329 |
SetDParam(0, st->index); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
330 |
SetDParam(1, st->facilities); |
0 | 331 |
UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0); |
332 |
} |
|
333 |
||
334 |
// Update the virtual coords needed to draw the station sign for all stations. |
|
6573 | 335 |
void UpdateAllStationVirtCoord() |
0 | 336 |
{ |
2639 | 337 |
Station* st; |
338 |
||
0 | 339 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
340 |
UpdateStationVirtCoord(st); |
0 | 341 |
} |
342 |
} |
|
343 |
||
344 |
// Update the station virt coords while making the modified parts dirty. |
|
345 |
static void UpdateStationVirtCoordDirty(Station *st) |
|
346 |
{ |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
347 |
st->MarkDirty(); |
0 | 348 |
UpdateStationVirtCoord(st); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
349 |
st->MarkDirty(); |
0 | 350 |
} |
351 |
||
352 |
// Get a mask of the cargo types that the station accepts. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
353 |
static uint GetAcceptanceMask(const Station *st) |
0 | 354 |
{ |
355 |
uint mask = 0; |
|
6395 | 356 |
|
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
357 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
358 |
if (st->goods[i].acceptance) mask |= 1 << i; |
0 | 359 |
} |
360 |
return mask; |
|
361 |
} |
|
362 |
||
363 |
// Items contains the two cargo names that are to be accepted or rejected. |
|
364 |
// msg is the string id of the message to display. |
|
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
365 |
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg) |
0 | 366 |
{ |
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
367 |
for (uint i = 0; i < num_items; i++) { |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6413
diff
changeset
|
368 |
SetDParam(i + 1, GetCargo(cargo[i])->name); |
0 | 369 |
} |
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
370 |
|
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
371 |
SetDParam(0, st->index); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
372 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); |
0 | 373 |
} |
374 |
||
375 |
// Get a list of the cargo types being produced around the tile. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
376 |
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
377 |
int w, int h, int rad) |
0 | 378 |
{ |
2133 | 379 |
memset(produced, 0, sizeof(AcceptedCargo)); |
0 | 380 |
|
6395 | 381 |
int x = TileX(tile); |
382 |
int y = TileY(tile); |
|
0 | 383 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
384 |
// expand the region by rad tiles on each side |
0 | 385 |
// while making sure that we remain inside the board. |
6395 | 386 |
int x2 = min(x + w + rad, MapSizeX()); |
387 |
int x1 = max(x - rad, 0); |
|
388 |
||
389 |
int y2 = min(y + h + rad, MapSizeY()); |
|
390 |
int y1 = max(y - rad, 0); |
|
0 | 391 |
|
392 |
assert(x1 < x2); |
|
393 |
assert(y1 < y2); |
|
394 |
assert(w > 0); |
|
395 |
assert(h > 0); |
|
396 |
||
6395 | 397 |
for (int yc = y1; yc != y2; yc++) { |
398 |
for (int xc = x1; xc != x2; xc++) { |
|
0 | 399 |
if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) { |
1981 | 400 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
401 |
|
6395 | 402 |
GetProducedCargoProc *gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc; |
0 | 403 |
if (gpc != NULL) { |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3334
diff
changeset
|
404 |
CargoID cargos[2] = { CT_INVALID, CT_INVALID }; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
405 |
|
0 | 406 |
gpc(tile, cargos); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
407 |
if (cargos[0] != CT_INVALID) { |
0 | 408 |
produced[cargos[0]]++; |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
409 |
if (cargos[1] != CT_INVALID) { |
0 | 410 |
produced[cargos[1]]++; |
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
415 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
416 |
} |
0 | 417 |
} |
418 |
||
419 |
// Get a list of the cargo types that are accepted around the tile. |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
420 |
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
421 |
int w, int h, int rad) |
0 | 422 |
{ |
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
423 |
memset(accepts, 0, sizeof(AcceptedCargo)); |
0 | 424 |
|
6395 | 425 |
int x = TileX(tile); |
426 |
int y = TileY(tile); |
|
0 | 427 |
|
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
428 |
// expand the region by rad tiles on each side |
0 | 429 |
// while making sure that we remain inside the board. |
6395 | 430 |
int x2 = min(x + w + rad, MapSizeX()); |
431 |
int y2 = min(y + h + rad, MapSizeY()); |
|
432 |
int x1 = max(x - rad, 0); |
|
433 |
int y1 = max(y - rad, 0); |
|
0 | 434 |
|
435 |
assert(x1 < x2); |
|
436 |
assert(y1 < y2); |
|
437 |
assert(w > 0); |
|
438 |
assert(h > 0); |
|
439 |
||
6395 | 440 |
for (int yc = y1; yc != y2; yc++) { |
441 |
for (int xc = x1; xc != x2; xc++) { |
|
1981 | 442 |
TileIndex tile = TileXY(xc, yc); |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
443 |
|
1035
0a170deb6e33
(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
|
444 |
if (!IsTileType(tile, MP_STATION)) { |
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
445 |
AcceptedCargo ac; |
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
446 |
|
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
457
diff
changeset
|
447 |
GetAcceptedCargo(tile, ac); |
6395 | 448 |
for (uint i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; |
0 | 449 |
} |
1424
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
450 |
} |
c6d120592e98
(svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents:
1423
diff
changeset
|
451 |
} |
0 | 452 |
} |
453 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
454 |
struct ottd_Rectangle { |
1423
50abec7ebe37
(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
|
455 |
uint min_x; |
50abec7ebe37
(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
|
456 |
uint min_y; |
50abec7ebe37
(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
|
457 |
uint max_x; |
50abec7ebe37
(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
|
458 |
uint max_y; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
459 |
}; |
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
460 |
|
5103
db210d789741
(svn r7174) -CodeChange: CheckStationSpreadOut() now uses MergePoint() for bounding rectangle calculation.
KUDr
parents:
5098
diff
changeset
|
461 |
static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile) |
1423
50abec7ebe37
(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
|
462 |
{ |
50abec7ebe37
(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
|
463 |
uint x = TileX(tile); |
50abec7ebe37
(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
|
464 |
uint y = TileY(tile); |
50abec7ebe37
(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
|
465 |
|
50abec7ebe37
(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
|
466 |
if (rect->min_x > x) rect->min_x = x; |
50abec7ebe37
(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
|
467 |
if (rect->min_y > y) rect->min_y = y; |
50abec7ebe37
(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
|
468 |
if (rect->max_x < x) rect->max_x = x; |
50abec7ebe37
(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
|
469 |
if (rect->max_y < y) rect->max_y = y; |
50abec7ebe37
(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
|
470 |
} |
50abec7ebe37
(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
|
471 |
|
0 | 472 |
// Update the acceptance for a station. |
473 |
// show_msg controls whether to display a message that acceptance was changed. |
|
474 |
static void UpdateStationAcceptance(Station *st, bool show_msg) |
|
475 |
{ |
|
6395 | 476 |
// Don't update acceptance for a buoy |
477 |
if (st->IsBuoy()) return; |
|
478 |
||
2793
d613eb566917
(svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents:
2767
diff
changeset
|
479 |
ottd_Rectangle rect; |
1507
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
480 |
rect.min_x = MapSizeX(); |
2d09b13f049f
(svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents:
1477
diff
changeset
|
481 |
rect.min_y = MapSizeY(); |
6395 | 482 |
rect.max_x = 0; |
483 |
rect.max_y = 0; |
|
0 | 484 |
|
485 |
/* old accepted goods types */ |
|
6395 | 486 |
uint old_acc = GetAcceptanceMask(st); |
0 | 487 |
|
488 |
// Put all the tiles that span an area in the table. |
|
489 |
if (st->train_tile != 0) { |
|
1423
50abec7ebe37
(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
|
490 |
MergePoint(&rect, st->train_tile); |
50abec7ebe37
(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
|
491 |
MergePoint(&rect, |
1981 | 492 |
st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1) |
1423
50abec7ebe37
(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
|
493 |
); |
0 | 494 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
495 |
|
0 | 496 |
if (st->airport_tile != 0) { |
6738
72d1a2997952
(svn r10683) [NewGRF_ports] -Revert: Too eager to un-const... global search/replace removed too many. Restores necessary ones... for the moment ;)
richk
parents:
6734
diff
changeset
|
497 |
const AirportFTAClass* afc = st->Airport(); |
3876
c0d426e78b56
(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
|
498 |
|
1423
50abec7ebe37
(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
|
499 |
MergePoint(&rect, st->airport_tile); |
50abec7ebe37
(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
|
500 |
MergePoint(&rect, |
3876
c0d426e78b56
(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
|
501 |
st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1) |
1423
50abec7ebe37
(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
|
502 |
); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
503 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
504 |
|
1423
50abec7ebe37
(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
|
505 |
if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile); |
50abec7ebe37
(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
|
506 |
|
6395 | 507 |
for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) { |
508 |
MergePoint(&rect, rs->xy); |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
509 |
} |
0 | 510 |
|
6395 | 511 |
for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) { |
512 |
MergePoint(&rect, rs->xy); |
|
0 | 513 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
514 |
|
0 | 515 |
// And retrieve the acceptance. |
6395 | 516 |
AcceptedCargo accepts; |
1423
50abec7ebe37
(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
|
517 |
if (rect.max_x >= rect.min_x) { |
50abec7ebe37
(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
|
518 |
GetAcceptanceAroundTiles( |
50abec7ebe37
(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
|
519 |
accepts, |
1981 | 520 |
TileXY(rect.min_x, rect.min_y), |
1423
50abec7ebe37
(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
|
521 |
rect.max_x - rect.min_x + 1, |
50abec7ebe37
(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
|
522 |
rect.max_y - rect.min_y + 1, |
6395 | 523 |
_patches.modified_catchment ? FindCatchmentRadius(st) : 4 |
1423
50abec7ebe37
(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
|
524 |
); |
0 | 525 |
} else { |
526 |
memset(accepts, 0, sizeof(accepts)); |
|
527 |
} |
|
528 |
||
529 |
// Adjust in case our station only accepts fewer kinds of goods |
|
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
530 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
0 | 531 |
uint amt = min(accepts[i], 15); |
532 |
||
533 |
// Make sure the station can accept the goods type. |
|
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
534 |
bool is_passengers = IsCargoInClass(i, CC_PASSENGERS); |
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
535 |
if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) || |
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
536 |
(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) |
0 | 537 |
amt = 0; |
538 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
539 |
st->goods[i].acceptance = (amt >= 8); |
0 | 540 |
} |
541 |
||
542 |
// Only show a message in case the acceptance was actually changed. |
|
6395 | 543 |
uint new_acc = GetAcceptanceMask(st); |
0 | 544 |
if (old_acc == new_acc) |
545 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
546 |
|
0 | 547 |
// show a message to report that the acceptance was changed? |
548 |
if (show_msg && st->owner == _local_player && st->facilities) { |
|
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
549 |
/* List of accept and reject strings for different number of |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
550 |
* cargo types */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
551 |
static const StringID accept_msg[] = { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
552 |
STR_3040_NOW_ACCEPTS, |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
553 |
STR_3041_NOW_ACCEPTS_AND, |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
554 |
}; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
555 |
static const StringID reject_msg[] = { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
556 |
STR_303E_NO_LONGER_ACCEPTS, |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
557 |
STR_303F_NO_LONGER_ACCEPTS_OR, |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
558 |
}; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
559 |
|
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
560 |
/* Array of accepted and rejected cargo types */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
561 |
CargoID accepts[2] = { CT_INVALID, CT_INVALID }; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
562 |
CargoID rejects[2] = { CT_INVALID, CT_INVALID }; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
563 |
uint num_acc = 0; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
564 |
uint num_rej = 0; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
565 |
|
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
566 |
/* Test each cargo type to see if its acceptange has changed */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
567 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
568 |
if (HASBIT(new_acc, i)) { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
569 |
if (!HASBIT(old_acc, i) && num_acc < lengthof(accepts)) { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
570 |
/* New cargo is accepted */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
571 |
accepts[num_acc++] = i; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
572 |
} |
0 | 573 |
} else { |
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
574 |
if (HASBIT(old_acc, i) && num_rej < lengthof(rejects)) { |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
575 |
/* Old cargo is no longer accepted */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
576 |
rejects[num_rej++] = i; |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
577 |
} |
0 | 578 |
} |
5941
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
579 |
} |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
580 |
|
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
581 |
/* Show news message if there are any changes */ |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
582 |
if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]); |
3eadff67530f
(svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents:
5934
diff
changeset
|
583 |
if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]); |
0 | 584 |
} |
585 |
||
586 |
// redraw the station view since acceptance changed |
|
587 |
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4); |
|
588 |
} |
|
589 |
||
5098
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
590 |
static void UpdateStationSignCoord(Station *st) |
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
591 |
{ |
6395 | 592 |
const StationRect *r = &st->rect; |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
593 |
|
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
594 |
if (r->IsEmpty()) return; // no tiles belong to this station |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
595 |
|
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
596 |
// clamp sign coord to be inside the station rect |
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
597 |
st->xy = TileXY(clampu(TileX(st->xy), r->left, r->right), clampu(TileY(st->xy), r->top, r->bottom)); |
5098
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
598 |
UpdateStationVirtCoordDirty(st); |
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
599 |
} |
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
600 |
|
0 | 601 |
// This is called right after a station was deleted. |
602 |
// It checks if the whole station is free of substations, and if so, the station will be |
|
603 |
// deleted after a little while. |
|
2639 | 604 |
static void DeleteStationIfEmpty(Station* st) |
605 |
{ |
|
0 | 606 |
if (st->facilities == 0) { |
607 |
st->delete_ctr = 0; |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
608 |
RebuildStationLists(); |
28
635ad4c62bec
(svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents:
27
diff
changeset
|
609 |
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
|
610 |
} |
5098
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
611 |
/* station remains but it probably lost some parts - station sign should stay in the station boundaries */ |
bd3e82d14997
(svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents:
4982
diff
changeset
|
612 |
UpdateStationSignCoord(st); |
0 | 613 |
} |
614 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
615 |
static CommandCost ClearTile_Station(TileIndex tile, byte flags); |
977
bcafa4f6550a
(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
|
616 |
|
0 | 617 |
// Tries to clear the given area. Returns the cost in case of success. |
618 |
// Or an error code if it failed. |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
619 |
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true) |
0 | 620 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
621 |
CommandCost cost; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
622 |
int allowed_z = -1; |
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
623 |
uint8 airport_type = 0; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
624 |
const byte *b = _airport_sections[(invalid_dirs & 0x78) >> 3]; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
625 |
bool do_tile_test; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
626 |
/* |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
627 |
if (invalid_dirs & 0x80) { // this is an airport |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
628 |
airport_type = (invalid_dirs & 0x78) >> 3; // airport type defined by bits 6..3 |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
629 |
*b = _airport_sections[airport_type]; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
630 |
} |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
631 |
*/ |
6395 | 632 |
|
633 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
634 |
if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
635 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
636 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
637 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
638 |
if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR; |
0 | 639 |
|
6395 | 640 |
uint z; |
641 |
Slope tileh = GetTileSlope(tile_cur, &z); |
|
0 | 642 |
|
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
643 |
/* Prohibit building if |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
644 |
* 1) The tile is "steep" (i.e. stretches two height levels) |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
645 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
646 |
* 2) The tile is non-flat if |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
647 |
* a) the player building is an "old-school" AI |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
648 |
* -OR- |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
649 |
* b) the build_on_slopes switch is disabled |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
650 |
*/ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
651 |
if (IsSteepSlope(tileh) || |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
652 |
((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
653 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 654 |
} |
655 |
||
6395 | 656 |
int flat_z = z; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
657 |
if (tileh != SLOPE_FLAT) { |
0 | 658 |
// need to check so the entrance to the station is not pointing at a slope. |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
659 |
if ((invalid_dirs & 1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) || |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
660 |
(invalid_dirs & 2 && !(tileh & SLOPE_SE) && h_cur == 1) || |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
661 |
(invalid_dirs & 4 && !(tileh & SLOPE_SW) && w_cur == 1) || |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
662 |
(invalid_dirs & 8 && !(tileh & SLOPE_NW) && (uint)h_cur == h)) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
663 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 664 |
} |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
665 |
cost.AddCost(_price.terraform); |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
666 |
flat_z += TILE_HEIGHT; |
0 | 667 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
668 |
|
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
669 |
// do tile tests if it is not an airport or airport tile is 255 |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
670 |
do_tile_test = true; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
671 |
if (invalid_dirs & 0x80) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
672 |
if ((byte)*b++ == (byte)255) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
673 |
do_tile_test = false; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
674 |
} |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
675 |
}; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
676 |
|
0 | 677 |
// get corresponding flat level and make sure that all parts of the station have the same level. |
678 |
if (allowed_z == -1) { |
|
679 |
// first tile |
|
680 |
allowed_z = flat_z; |
|
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
681 |
} else if (do_tile_test && (allowed_z != flat_z)) { |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
682 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
0 | 683 |
} |
684 |
||
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
685 |
if (do_tile_test) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
686 |
// if station is set, then we have special handling to allow building on top of already existing stations. |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
687 |
// 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 |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
688 |
// on exactly that station. |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
689 |
if (station != NULL && IsTileType(tile_cur, MP_STATION)) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
690 |
if (!IsRailwayStation(tile_cur)) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
691 |
return ClearTile_Station(tile_cur, DC_AUTO); // get error message |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
692 |
} else { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
693 |
StationID st = GetStationIndex(tile_cur); |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
694 |
if (*station == INVALID_STATION) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
695 |
*station = st; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
696 |
} else if (*station != st) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
697 |
return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING); |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
698 |
} |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
699 |
} |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
700 |
} else if (check_clear) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
701 |
CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
702 |
if (CmdFailed(ret)) return ret; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
703 |
cost.AddCost(ret); |
0 | 704 |
} |
705 |
} |
|
6395 | 706 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 707 |
|
708 |
return cost; |
|
709 |
} |
|
710 |
||
6395 | 711 |
static bool CanExpandRailroadStation(const Station* st, uint* fin, Axis axis) |
0 | 712 |
{ |
6395 | 713 |
uint curw = st->trainst_w; |
714 |
uint curh = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
715 |
TileIndex tile = fin[0]; |
0 | 716 |
uint w = fin[1]; |
717 |
uint h = fin[2]; |
|
718 |
||
719 |
if (_patches.nonuniform_stations) { |
|
720 |
// determine new size of train station region.. |
|
926
bd4312619522
(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
|
721 |
int x = min(TileX(st->train_tile), TileX(tile)); |
bd4312619522
(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
|
722 |
int y = min(TileY(st->train_tile), TileY(tile)); |
bd4312619522
(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
|
723 |
curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x; |
bd4312619522
(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
|
724 |
curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y; |
1981 | 725 |
tile = TileXY(x, y); |
0 | 726 |
} else { |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
727 |
// check so the orientation is the same |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
728 |
if (GetRailStationAxis(st->train_tile) != axis) { |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
729 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
730 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
731 |
} |
0 | 732 |
|
733 |
// check if the new station adjoins the old station in either direction |
|
1981 | 734 |
if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) { |
0 | 735 |
// above |
736 |
curh += h; |
|
1981 | 737 |
} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) { |
0 | 738 |
// below |
1981 | 739 |
tile -= TileDiffXY(0, curh); |
0 | 740 |
curh += h; |
1981 | 741 |
} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) { |
0 | 742 |
// to the left |
743 |
curw += w; |
|
1981 | 744 |
} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) { |
0 | 745 |
// to the right |
1981 | 746 |
tile -= TileDiffXY(curw, 0); |
0 | 747 |
curw += w; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
748 |
} else { |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
749 |
_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED; |
0 | 750 |
return false; |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
751 |
} |
0 | 752 |
} |
753 |
// make sure the final size is not too big. |
|
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
754 |
if (curw > _patches.station_spread || curh > _patches.station_spread) { |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
755 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
756 |
return false; |
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
757 |
} |
0 | 758 |
|
759 |
// now tile contains the new value for st->train_tile |
|
760 |
// curw, curh contain the new value for width and height |
|
761 |
fin[0] = tile; |
|
762 |
fin[1] = curw; |
|
763 |
fin[2] = curh; |
|
764 |
return true; |
|
765 |
} |
|
766 |
||
536 | 767 |
static inline byte *CreateSingle(byte *layout, int n) |
0 | 768 |
{ |
769 |
int i = n; |
|
770 |
do *layout++ = 0; while (--i); |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
771 |
layout[((n - 1) >> 1) - n] = 2; |
0 | 772 |
return layout; |
773 |
} |
|
774 |
||
536 | 775 |
static inline byte *CreateMulti(byte *layout, int n, byte b) |
0 | 776 |
{ |
777 |
int i = n; |
|
778 |
do *layout++ = b; while (--i); |
|
779 |
if (n > 4) { |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
780 |
layout[0 - n] = 0; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
781 |
layout[n - 1 - n] = 0; |
0 | 782 |
} |
783 |
return layout; |
|
784 |
} |
|
785 |
||
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
786 |
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec) |
0 | 787 |
{ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
788 |
if (statspec != NULL && statspec->lengths >= plat_len && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
789 |
statspec->platforms[plat_len - 1] >= numtracks && |
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
790 |
statspec->layouts[plat_len - 1][numtracks - 1]) { |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
791 |
/* Custom layout defined, follow it. */ |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3657
diff
changeset
|
792 |
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1], |
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
793 |
plat_len * numtracks); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
794 |
return; |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
795 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
796 |
|
0 | 797 |
if (plat_len == 1) { |
798 |
CreateSingle(layout, numtracks); |
|
799 |
} else { |
|
2639 | 800 |
if (numtracks & 1) layout = CreateSingle(layout, plat_len); |
801 |
numtracks >>= 1; |
|
0 | 802 |
|
803 |
while (--numtracks >= 0) { |
|
804 |
layout = CreateMulti(layout, plat_len, 4); |
|
805 |
layout = CreateMulti(layout, plat_len, 6); |
|
806 |
} |
|
807 |
} |
|
808 |
} |
|
809 |
||
1775
08ff0f12ccdc
(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
|
810 |
/** Build railroad station |
3491
4c8427796c64
(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
|
811 |
* @param tile_org starting position of station dragging/placement |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
812 |
* @param flags operation to perform |
1775
08ff0f12ccdc
(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
|
813 |
* @param p1 various bitstuffed elements |
6460 | 814 |
* - p1 = (bit 0) - orientation (Axis) |
2140
d708eb80ab8b
(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
|
815 |
* - p1 = (bit 8-15) - number of tracks |
d708eb80ab8b
(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
|
816 |
* - p1 = (bit 16-23) - platform length |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
817 |
* - p1 = (bit 24) - allow stations directly adjacent to other stations. |
1775
08ff0f12ccdc
(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
|
818 |
* @param p2 various bitstuffed elements |
08ff0f12ccdc
(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
|
819 |
* - p2 = (bit 0- 3) - railtype (p2 & 0xF) |
3587 | 820 |
* - p2 = (bit 8-15) - custom station class |
821 |
* - p2 = (bit 16-23) - custom station id |
|
0 | 822 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
823 |
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2) |
0 | 824 |
{ |
1775
08ff0f12ccdc
(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
|
825 |
int w_org, h_org; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
826 |
CommandCost ret; |
0 | 827 |
|
828 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
829 |
||
830 |
/* Does the authority allow this? */ |
|
1775
08ff0f12ccdc
(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
|
831 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR; |
08ff0f12ccdc
(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
|
832 |
if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR; |
08ff0f12ccdc
(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
|
833 |
|
08ff0f12ccdc
(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
|
834 |
/* unpack parameters */ |
6460 | 835 |
Axis axis = Extract<Axis, 0>(p1); |
6395 | 836 |
uint numtracks = GB(p1, 8, 8); |
837 |
uint plat_len = GB(p1, 16, 8); |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
838 |
if (axis == AXIS_X) { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
839 |
w_org = plat_len; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
840 |
h_org = numtracks; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
841 |
} else { |
1775
08ff0f12ccdc
(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
|
842 |
h_org = plat_len; |
08ff0f12ccdc
(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
|
843 |
w_org = numtracks; |
0 | 844 |
} |
845 |
||
1781
92e08797c84b
(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
|
846 |
if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR; |
92e08797c84b
(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
|
847 |
|
0 | 848 |
// these values are those that will be stored in train_tile and station_platforms |
6395 | 849 |
uint finalvalues[3]; |
0 | 850 |
finalvalues[0] = tile_org; |
851 |
finalvalues[1] = w_org; |
|
852 |
finalvalues[2] = h_org; |
|
853 |
||
854 |
// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) |
|
6395 | 855 |
StationID est = INVALID_STATION; |
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
856 |
// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
857 |
// for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
858 |
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL); |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
859 |
if (CmdFailed(ret)) return ret; |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
860 |
CommandCost cost(ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len); |
0 | 861 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
862 |
Station *st = NULL; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
863 |
bool check_surrounding = true; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
864 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
865 |
if (_patches.adjacent_stations) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
866 |
if (est != INVALID_STATION) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
867 |
if (HASBIT(p1, 24)) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
868 |
/* You can't build an adjacent station over the top of one that |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
869 |
* already exists. */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
870 |
return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
871 |
} else { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
872 |
/* Extend the current station, and don't check whether it will |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
873 |
* be near any other stations. */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
874 |
st = GetStation(est); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
875 |
check_surrounding = false; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
876 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
877 |
} else { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
878 |
/* There's no station here. Don't check the tiles surrounding this |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
879 |
* one if the player wanted to build an adjacent station. */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
880 |
if (HASBIT(p1, 24)) check_surrounding = false; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
881 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
882 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
883 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
884 |
if (check_surrounding) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
885 |
// Make sure there are no similar stations around us. |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
886 |
st = GetStationAround(tile_org, w_org, h_org, est); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
887 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
888 |
} |
0 | 889 |
|
890 |
// See if there is a deleted station close to us. |
|
6378 | 891 |
if (st == NULL) st = GetClosestStationFromTile(tile_org); |
0 | 892 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
893 |
/* In case of new station if DC_EXEC is NOT set we still need to create the station |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
894 |
* to test if everything is OK. In this case we need to delete it before return. */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
895 |
AutoPtrT<Station> st_auto_delete; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
896 |
|
0 | 897 |
if (st != NULL) { |
898 |
// Reuse an existing station. |
|
6390 | 899 |
if (st->owner != _current_player) |
0 | 900 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
901 |
||
902 |
if (st->train_tile != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
71
diff
changeset
|
903 |
// check if we want to expanding an already existing station? |
2422
914a12dee832
(svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents:
2395
diff
changeset
|
904 |
if (_is_old_ai_player || !_patches.join_stations) |
0 | 905 |
return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD); |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
906 |
if (!CanExpandRailroadStation(st, finalvalues, axis)) |
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
907 |
return CMD_ERROR; |
0 | 908 |
} |
909 |
||
1189
5ff98d7485b3
(svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents:
1174
diff
changeset
|
910 |
//XXX can't we pack this in the "else" part of the if above? |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
911 |
if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4399
diff
changeset
|
912 |
} else { |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
913 |
/* allocate and initialize new station */ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
914 |
st = new Station(tile_org); |
2639 | 915 |
if (st == NULL) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
916 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
917 |
/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
918 |
st_auto_delete = st; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
919 |
|
0 | 920 |
st->town = ClosestTownFromTile(tile_org, (uint)-1); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
921 |
if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR; |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
922 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
923 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 924 |
SETBIT(st->town->have_ratings, _current_player); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
925 |
} |
0 | 926 |
} |
927 |
||
3587 | 928 |
/* Check if the given station class is valid */ |
929 |
if (GB(p2, 8, 8) >= STAT_CLASS_MAX) return CMD_ERROR; |
|
930 |
||
931 |
/* Check if we can allocate a custom stationspec to this station */ |
|
6395 | 932 |
const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8)); |
933 |
int specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC); |
|
3587 | 934 |
if (specindex == -1) return CMD_ERROR; |
935 |
||
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
936 |
if (statspec != NULL) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
937 |
/* Perform NewStation checks */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
938 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
939 |
/* Check if the station size is permitted */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
940 |
if (HASBIT(statspec->disallowed_platforms, numtracks - 1) || HASBIT(statspec->disallowed_lengths, plat_len - 1)) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
941 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
942 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
943 |
|
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
944 |
/* Check if the station is buildable */ |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
945 |
if (HASBIT(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
946 |
return CMD_ERROR; |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
947 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
948 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
949 |
|
0 | 950 |
if (flags & DC_EXEC) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
951 |
TileIndexDiff tile_delta; |
0 | 952 |
byte *layout_ptr; |
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
953 |
byte numtracks_orig; |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
954 |
Track track; |
0 | 955 |
|
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
956 |
// Now really clear the land below the station |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
957 |
// It should never return CMD_ERROR.. but you never know ;) |
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
958 |
// (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
959 |
ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL); |
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3161
diff
changeset
|
960 |
if (CmdFailed(ret)) return ret; |
313
6660bb7b38f1
(svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents:
243
diff
changeset
|
961 |
|
0 | 962 |
st->train_tile = finalvalues[0]; |
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
963 |
st->AddFacility(FACIL_TRAIN, finalvalues[0]); |
0 | 964 |
|
965 |
st->trainst_w = finalvalues[1]; |
|
966 |
st->trainst_h = finalvalues[2]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
967 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
968 |
st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
969 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3123
diff
changeset
|
970 |
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
4158 | 971 |
track = AxisToTrack(axis); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
972 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
973 |
layout_ptr = (byte*)alloca(numtracks * plat_len); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
974 |
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
|
975 |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
976 |
numtracks_orig = numtracks; |
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
977 |
|
0 | 978 |
do { |
1775
08ff0f12ccdc
(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 |
TileIndex tile = tile_org; |
0 | 980 |
int w = plat_len; |
981 |
do { |
|
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
982 |
byte layout = *layout_ptr++; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
983 |
MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4)); |
3587 | 984 |
SetCustomStationSpecIndex(tile, specindex); |
3742
8528d7737361
(svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents:
3741
diff
changeset
|
985 |
SetStationTileRandomBits(tile, GB(Random(), 0, 4)); |
0 | 986 |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
987 |
if (statspec != NULL) { |
3784
41d43d1191a5
(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
|
988 |
/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */ |
41d43d1191a5
(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
|
989 |
uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false); |
3769
2fd087fd336f
(svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents:
3766
diff
changeset
|
990 |
uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
991 |
if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis); |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
992 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
993 |
|
0 | 994 |
tile += tile_delta; |
995 |
} while (--w); |
|
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
996 |
SetSignalsOnBothDir(tile_org, track); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
997 |
YapfNotifyTrackLayoutChange(tile_org, track); |
1981 | 998 |
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta |
0 | 999 |
} while (--numtracks); |
1000 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1001 |
st->MarkTilesDirty(false); |
0 | 1002 |
UpdateStationVirtCoordDirty(st); |
1003 |
UpdateStationAcceptance(st, false); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1004 |
RebuildStationLists(); |
0 | 1005 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1006 |
/* success, so don't delete the new station */ |
6732
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1007 |
st_auto_delete.Detach(); |
0 | 1008 |
} |
1009 |
||
1010 |
return cost; |
|
1011 |
} |
|
1012 |
||
1013 |
static void MakeRailwayStationAreaSmaller(Station *st) |
|
1014 |
{ |
|
1015 |
uint w = st->trainst_w; |
|
1016 |
uint h = st->trainst_h; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1017 |
TileIndex tile = st->train_tile; |
0 | 1018 |
|
1019 |
restart: |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1020 |
|
0 | 1021 |
// too small? |
1022 |
if (w != 0 && h != 0) { |
|
1023 |
// check the left side, x = constant, y changes |
|
6395 | 1024 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) { |
0 | 1025 |
// the left side is unused? |
1981 | 1026 |
if (++i == h) { |
1027 |
tile += TileDiffXY(1, 0); |
|
1028 |
w--; |
|
1029 |
goto restart; |
|
1030 |
} |
|
1031 |
} |
|
0 | 1032 |
|
1033 |
// check the right side, x = constant, y changes |
|
6395 | 1034 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) { |
0 | 1035 |
// the right side is unused? |
1981 | 1036 |
if (++i == h) { |
1037 |
w--; |
|
1038 |
goto restart; |
|
1039 |
} |
|
1040 |
} |
|
0 | 1041 |
|
1042 |
// check the upper side, y = constant, x changes |
|
6395 | 1043 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) { |
0 | 1044 |
// the left side is unused? |
1981 | 1045 |
if (++i == w) { |
1046 |
tile += TileDiffXY(0, 1); |
|
1047 |
h--; |
|
1048 |
goto restart; |
|
1049 |
} |
|
1050 |
} |
|
0 | 1051 |
|
1052 |
// check the lower side, y = constant, x changes |
|
6395 | 1053 |
for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) { |
0 | 1054 |
// the left side is unused? |
1981 | 1055 |
if (++i == w) { |
1056 |
h--; |
|
1057 |
goto restart; |
|
1058 |
} |
|
1059 |
} |
|
0 | 1060 |
} else { |
1061 |
tile = 0; |
|
1062 |
} |
|
1063 |
||
1064 |
st->trainst_w = w; |
|
1065 |
st->trainst_h = h; |
|
1066 |
st->train_tile = tile; |
|
1067 |
} |
|
1068 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1069 |
/** Remove a single tile from a railroad station. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1070 |
* This allows for custom-built station with holes and weird layouts |
3491
4c8427796c64
(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
|
1071 |
* @param tile tile of station piece to remove |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1072 |
* @param flags operation to perform |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1073 |
* @param p1 start_tile |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1074 |
* @param p2 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1075 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1076 |
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1077 |
{ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1078 |
TileIndex start = p1 == 0 ? tile : p1; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1079 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1080 |
/* Count of the number of tiles removed */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1081 |
int quantity = 0; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1082 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1083 |
if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1084 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1085 |
/* make sure sx,sy are smaller than ex,ey */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1086 |
int ex = TileX(tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1087 |
int ey = TileY(tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1088 |
int sx = TileX(start); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1089 |
int sy = TileY(start); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1090 |
if (ex < sx) Swap(ex, sx); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1091 |
if (ey < sy) Swap(ey, sy); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1092 |
tile = TileXY(sx, sy); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1093 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1094 |
int size_x = ex - sx + 1; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1095 |
int size_y = ey - sy + 1; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1096 |
|
889
7f8630bfea41
(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
|
1097 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
7f8630bfea41
(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
|
1098 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1099 |
/* Do the action for every tile into the area */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1100 |
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1101 |
/* Make sure the specified tile belongs to the current player, and that it is a railroad station. */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1102 |
if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2) || !_patches.nonuniform_stations) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1103 |
continue; |
0 | 1104 |
} |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1105 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1106 |
/* Check ownership of station */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1107 |
Station *st = GetStationByTile(tile2); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1108 |
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile2))) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1109 |
continue; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1110 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1111 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1112 |
/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1113 |
quantity++; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1114 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1115 |
if (flags & DC_EXEC) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1116 |
uint specindex = GetCustomStationSpecIndex(tile2); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1117 |
Track track = GetRailStationTrack(tile2); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1118 |
DoClearSquare(tile2); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1119 |
st->rect.AfterRemoveTile(st, tile2); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1120 |
SetSignalsOnBothDir(tile2, track); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1121 |
YapfNotifyTrackLayoutChange(tile2, track); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1122 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1123 |
DeallocateSpecFromStation(st, specindex); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1124 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1125 |
// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges. |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1126 |
// we also need to adjust train_tile. |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1127 |
MakeRailwayStationAreaSmaller(st); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1128 |
st->MarkTilesDirty(false); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1129 |
UpdateStationSignCoord(st); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1130 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1131 |
// if we deleted the whole station, delete the train facility. |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1132 |
if (st->train_tile == 0) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1133 |
st->facilities &= ~FACIL_TRAIN; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1134 |
UpdateStationVirtCoordDirty(st); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1135 |
DeleteStationIfEmpty(st); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1136 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1137 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1138 |
} END_TILE_LOOP(tile2, size_x, size_y, tile) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1139 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1140 |
/* If we've not removed any tiles, give an error */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1141 |
if (quantity == 0) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1142 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1143 |
return CommandCost(_price.remove_rail_station * quantity); |
0 | 1144 |
} |
1145 |
||
3928
791f04fb29ad
(svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents:
3900
diff
changeset
|
1146 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1147 |
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags) |
0 | 1148 |
{ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
123
diff
changeset
|
1149 |
/* 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
|
1150 |
if (_current_player == OWNER_WATER && _patches.nonuniform_stations) |
3491
4c8427796c64
(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
|
1151 |
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
|
1152 |
|
0 | 1153 |
/* Current player owns the station? */ |
1154 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
|
1155 |
return CMD_ERROR; |
|
1156 |
||
1157 |
/* determine width and height of platforms */ |
|
1158 |
tile = st->train_tile; |
|
6395 | 1159 |
int w = st->trainst_w; |
1160 |
int h = st->trainst_h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1161 |
|
0 | 1162 |
assert(w != 0 && h != 0); |
1163 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1164 |
CommandCost cost; |
0 | 1165 |
/* clear all areas of the station */ |
1166 |
do { |
|
1167 |
int w_bak = w; |
|
1168 |
do { |
|
1169 |
// for nonuniform stations, only remove tiles that are actually train station tiles |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1170 |
if (st->TileBelongsToRailStation(tile)) { |
0 | 1171 |
if (!EnsureNoVehicle(tile)) |
1172 |
return CMD_ERROR; |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1173 |
cost.AddCost(_price.remove_rail_station); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1174 |
if (flags & DC_EXEC) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1175 |
Track track = GetRailStationTrack(tile); |
0 | 1176 |
DoClearSquare(tile); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1177 |
SetSignalsOnBothDir(tile, track); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1178 |
YapfNotifyTrackLayoutChange(tile, track); |
2824
a7a9d3239884
(svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents:
2817
diff
changeset
|
1179 |
} |
0 | 1180 |
} |
1981 | 1181 |
tile += TileDiffXY(1, 0); |
0 | 1182 |
} while (--w); |
1183 |
w = w_bak; |
|
1981 | 1184 |
tile += TileDiffXY(-w, 1); |
0 | 1185 |
} while (--h); |
1186 |
||
1187 |
if (flags & DC_EXEC) { |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1188 |
st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1189 |
|
0 | 1190 |
st->train_tile = 0; |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1191 |
st->trainst_w = st->trainst_h = 0; |
0 | 1192 |
st->facilities &= ~FACIL_TRAIN; |
1193 |
||
3587 | 1194 |
free(st->speclist); |
1195 |
st->num_specs = 0; |
|
1196 |
st->speclist = NULL; |
|
1197 |
||
0 | 1198 |
UpdateStationVirtCoordDirty(st); |
1199 |
DeleteStationIfEmpty(st); |
|
1200 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1201 |
|
0 | 1202 |
return cost; |
1203 |
} |
|
1204 |
||
6694
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1205 |
/** |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1206 |
* Switches the rail type at a railway station tile. |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1207 |
* @param tile The tile on which the railtype is to be convert. |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1208 |
* @param totype The railtype we want to convert to |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1209 |
* @param exec Switches between test and execute mode |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1210 |
* @return The cost and state of the operation |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1211 |
* @retval CMD_ERROR An error occured during the operation. |
a10a42eefd52
(svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents:
6683
diff
changeset
|
1212 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1213 |
CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec) |
0 | 1214 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1215 |
const Station* st = GetStationByTile(tile); |
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
1216 |
|
0 | 1217 |
if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
1218 |
||
1219 |
// tile is not a railroad station? |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1220 |
if (!IsRailwayStation(tile)) return CMD_ERROR; |
0 | 1221 |
|
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1222 |
if (GetRailType(tile) == totype) return CMD_ERROR; |
0 | 1223 |
|
5116
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5103
diff
changeset
|
1224 |
// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled |
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5103
diff
changeset
|
1225 |
if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; |
2a33a74925c5
(svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents:
5103
diff
changeset
|
1226 |
|
0 | 1227 |
if (exec) { |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3222
diff
changeset
|
1228 |
SetRailType(tile, totype); |
0 | 1229 |
MarkTileDirtyByTile(tile); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
1230 |
YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile)); |
0 | 1231 |
} |
1232 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1233 |
return CommandCost(_price.build_rail / 2); |
0 | 1234 |
} |
1235 |
||
6157 | 1236 |
/** |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1237 |
* @param truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1238 |
* @param st The Station to do the whole procedure for |
6157 | 1239 |
* @return a pointer to where to link a new RoadStop* |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4528
diff
changeset
|
1240 |
*/ |
6157 | 1241 |
static RoadStop **FindRoadStopSpot(bool truck_station, Station* st) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1242 |
{ |
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1243 |
RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1244 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1245 |
if (*primary_stop == NULL) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1246 |
/* we have no roadstop of the type yet, so write a "primary stop" */ |
6157 | 1247 |
return primary_stop; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1248 |
} else { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1249 |
/* there are stops already, so append to the end of the list */ |
6157 | 1250 |
RoadStop *stop = *primary_stop; |
1251 |
while (stop->next != NULL) stop = stop->next; |
|
1252 |
return &stop->next; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1253 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1254 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1255 |
|
3691
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1256 |
/** Build a bus or truck stop |
7e1ad0718ed8
(svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents:
3687
diff
changeset
|
1257 |
* @param tile tile to build the stop at |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1258 |
* @param flags operation to perform |
3333 | 1259 |
* @param p1 entrance direction (DiagDirection) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1260 |
* @param p2 bit 0: 0 for Bus stops, 1 for truck stops |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1261 |
* bit 1: 0 for normal, 1 for drive-through |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1262 |
* bit 2..4: the roadtypes |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1263 |
* bit 5: allow stations directly adjacent to other stations. |
0 | 1264 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1265 |
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1266 |
{ |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1267 |
bool type = HASBIT(p2, 0); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1268 |
bool is_drive_through = HASBIT(p2, 1); |
6344
c5c1b17c8925
(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents:
6338
diff
changeset
|
1269 |
bool build_over_road = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL; |
6393
7c0211e6a6c8
(svn r8797) -Fix (8741): the 'drive through station built on town owned road' bit was not set.
rubidium
parents:
6392
diff
changeset
|
1270 |
bool town_owned_road = build_over_road && IsTileOwner(tile, OWNER_TOWN); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1271 |
RoadTypes rts = (RoadTypes)GB(p2, 2, 3); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1272 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1273 |
if (rts == ROADTYPES_NONE || HASBIT(rts, ROADTYPE_HWAY)) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1274 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1275 |
/* Trams only have drive through stops */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1276 |
if (!is_drive_through && HASBIT(rts, ROADTYPE_TRAM)) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1277 |
|
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
1278 |
/* Saveguard the parameters */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1279 |
if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR; |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1280 |
/* If it is a drive-through stop check for valid axis */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1281 |
if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR; |
6344
c5c1b17c8925
(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents:
6338
diff
changeset
|
1282 |
/* Road bits in the wrong direction */ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1283 |
if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION); |
0 | 1284 |
|
1285 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1286 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1287 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1288 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1289 |
CommandCost cost; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1290 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1291 |
/* Not allowed to build over this road */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1292 |
if (build_over_road) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1293 |
if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1294 |
if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1295 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1296 |
/* Don't allow building the roadstop when vehicles are already driving on it */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1297 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1298 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1299 |
RoadTypes cur_rts = GetRoadTypes(tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1300 |
if (GetRoadOwner(tile, ROADTYPE_ROAD) != OWNER_TOWN && HASBIT(cur_rts, ROADTYPE_ROAD) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_ROAD))) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1301 |
if (HASBIT(cur_rts, ROADTYPE_TRAM) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_TRAM))) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1302 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1303 |
/* Do not remove roadtypes! */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1304 |
rts |= cur_rts; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1305 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1306 |
cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1307 |
if (CmdFailed(cost)) return cost; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1308 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1309 |
Station *st = NULL; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1310 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1311 |
if (!_patches.adjacent_stations || !HASBIT(p2, 5)) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1312 |
st = GetStationAround(tile, 1, 1, INVALID_STATION); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1313 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1314 |
} |
0 | 1315 |
|
1316 |
/* Find a station close to us */ |
|
6378 | 1317 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
0 | 1318 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1319 |
//give us a road stop in the list, and check if something went wrong |
6395 | 1320 |
RoadStop *road_stop = new RoadStop(tile); |
2951 | 1321 |
if (road_stop == NULL) { |
1322 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
|
1323 |
} |
|
1324 |
||
6084
75d052b142e5
(svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents:
5972
diff
changeset
|
1325 |
/* ensure that in case of error (or no DC_EXEC) the new road stop gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1326 |
AutoPtrT<RoadStop> rs_auto_delete(road_stop); |
6084
75d052b142e5
(svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents:
5972
diff
changeset
|
1327 |
|
2989 | 1328 |
if (st != NULL && |
6088
c11f7acc18bd
(svn r8403) -Fix (r8402): Forgot to remove an enum
celestar
parents:
6087
diff
changeset
|
1329 |
GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) { |
2951 | 1330 |
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS); |
1331 |
} |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1332 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1333 |
/* In case of new station if DC_EXEC is NOT set we still need to create the station |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1334 |
* to test if everything is OK. In this case we need to delete it before return. */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1335 |
AutoPtrT<Station> st_auto_delete; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1336 |
|
0 | 1337 |
if (st != NULL) { |
6390 | 1338 |
if (st->owner != _current_player) { |
0 | 1339 |
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION); |
2951 | 1340 |
} |
1341 |
||
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1342 |
if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1343 |
} else { |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1344 |
/* allocate and initialize new station */ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1345 |
st = new Station(tile); |
2639 | 1346 |
if (st == NULL) return CMD_ERROR; |
0 | 1347 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1348 |
/* ensure that in case of error (or no DC_EXEC) the new station gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1349 |
st_auto_delete = st; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1350 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1351 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1352 |
Town *t = st->town = ClosestTownFromTile(tile, (uint)-1); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1353 |
if (!GenerateStationName(st, tile, 0)) return CMD_ERROR; |
0 | 1354 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1355 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1356 |
SETBIT(t->have_ratings, _current_player); |
2951 | 1357 |
} |
0 | 1358 |
|
1359 |
st->sign.width_1 = 0; |
|
1360 |
} |
|
1361 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1362 |
cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station); |
0 | 1363 |
|
1364 |
if (flags & DC_EXEC) { |
|
6157 | 1365 |
// Insert into linked list of RoadStops |
1366 |
RoadStop **currstop = FindRoadStopSpot(type, st); |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1367 |
*currstop = road_stop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1368 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1369 |
//initialize an empty station |
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
1370 |
st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile); |
0 | 1371 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1372 |
st->rect.BeforeAddTile(tile, StationRect::ADD_TRY); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1373 |
|
6424 | 1374 |
RoadStop::Type rs_type = type ? RoadStop::TRUCK : RoadStop::BUS; |
1375 |
if (is_drive_through) { |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1376 |
MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road); |
6424 | 1377 |
} else { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1378 |
MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1); |
6424 | 1379 |
} |
0 | 1380 |
|
1381 |
UpdateStationVirtCoordDirty(st); |
|
1382 |
UpdateStationAcceptance(st, false); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1383 |
RebuildStationLists(); |
0 | 1384 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
6084
75d052b142e5
(svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents:
5972
diff
changeset
|
1385 |
/* success, so don't delete the new station and the new road stop */ |
6732
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1386 |
st_auto_delete.Detach(); |
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1387 |
rs_auto_delete.Detach(); |
0 | 1388 |
} |
1389 |
return cost; |
|
1390 |
} |
|
1391 |
||
1392 |
// Remove a bus station |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1393 |
static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) |
0 | 1394 |
{ |
2951 | 1395 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) { |
0 | 1396 |
return CMD_ERROR; |
2951 | 1397 |
} |
0 | 1398 |
|
6395 | 1399 |
bool is_truck = IsTruckStop(tile); |
1400 |
||
1401 |
RoadStop **primary_stop; |
|
1402 |
RoadStop *cur_stop; |
|
2639 | 1403 |
if (is_truck) { // truck stop |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1404 |
primary_stop = &st->truck_stops; |
6087
b56c54f79335
(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents:
6085
diff
changeset
|
1405 |
cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1406 |
} else { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1407 |
primary_stop = &st->bus_stops; |
6087
b56c54f79335
(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents:
6085
diff
changeset
|
1408 |
cur_stop = GetRoadStopByTile(tile, RoadStop::BUS); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1409 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1410 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1411 |
assert(cur_stop != NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1412 |
|
2951 | 1413 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
0 | 1414 |
|
1415 |
if (flags & DC_EXEC) { |
|
6118 | 1416 |
if (*primary_stop == cur_stop) { |
1417 |
// removed the first stop in the list |
|
1418 |
*primary_stop = cur_stop->next; |
|
1419 |
// removed the only stop? |
|
1420 |
if (*primary_stop == NULL) { |
|
1421 |
st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP); |
|
1422 |
} |
|
1423 |
} else { |
|
1424 |
// tell the predecessor in the list to skip this stop |
|
1425 |
RoadStop *pred = *primary_stop; |
|
1426 |
while (pred->next != cur_stop) pred = pred->next; |
|
1427 |
pred->next = cur_stop->next; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
1428 |
} |
0 | 1429 |
|
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5948
diff
changeset
|
1430 |
delete cur_stop; |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1431 |
DoClearSquare(tile); |
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1432 |
st->rect.AfterRemoveTile(st, tile); |
4398
e889842a75a1
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents:
4397
diff
changeset
|
1433 |
|
0 | 1434 |
UpdateStationVirtCoordDirty(st); |
1435 |
DeleteStationIfEmpty(st); |
|
1436 |
} |
|
1437 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1438 |
return CommandCost((is_truck) ? _price.remove_truck_station : _price.remove_bus_station); |
0 | 1439 |
} |
1440 |
||
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1441 |
/** Remove a bus or truck stop |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1442 |
* @param tile tile to remove the stop from |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1443 |
* @param flags operation to perform |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1444 |
* @param p1 not used |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1445 |
* @param p2 bit 0: 0 for Bus stops, 1 for truck stops |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1446 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1447 |
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1448 |
{ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1449 |
/* Make sure the specified tile is a road stop of the correct type */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1450 |
if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != p2) return CMD_ERROR; |
6395 | 1451 |
Station *st = GetStationByTile(tile); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1452 |
/* Save the stop info before it is removed */ |
6395 | 1453 |
bool is_drive_through = IsDriveThroughStopTile(tile); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1454 |
RoadTypes rts = GetRoadTypes(tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1455 |
RoadBits road_bits = IsDriveThroughStopTile(tile) ? |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1456 |
((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) : |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1457 |
DiagDirToRoadBits(GetRoadStopDir(tile)); |
6395 | 1458 |
bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile); |
1459 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1460 |
CommandCost ret = RemoveRoadStop(st, flags, tile); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1461 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1462 |
/* If the stop was a drive-through stop replace the road */ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1463 |
if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1464 |
/* Rebuild the drive throuhg road stop. As a road stop can only be |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1465 |
* removed by the owner of the roadstop, _current_player is the |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1466 |
* owner of the road stop. */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1467 |
MakeRoadNormal(tile, road_bits, rts, is_towns_road ? ClosestTownFromTile(tile, (uint)-1)->index : 0, |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1468 |
is_towns_road ? OWNER_TOWN : _current_player, _current_player, _current_player); |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1469 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1470 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1471 |
return ret; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
1472 |
} |
0 | 1473 |
|
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1474 |
static void GetFSMportsLayout(byte *layout, int width, int length, const FSMportsSpec *fsmportspec) |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1475 |
{ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1476 |
if (fsmportspec != NULL) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1477 |
/* Custom layout defined, follow it. */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1478 |
memcpy(layout, fsmportspec->layouts[width - 1][length - 1], |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1479 |
length * width); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1480 |
return; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1481 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1482 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1483 |
while (--width >= 0) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1484 |
layout = CreateMulti(layout, length, 4); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1485 |
layout = CreateMulti(layout, length, 6); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1486 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1487 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1488 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1489 |
/** Place an Airport. |
3491
4c8427796c64
(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
|
1490 |
* @param tile tile where airport will be built |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1491 |
* @param flags operation to perform |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1492 |
* @param p1 various bitstuffed elements |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1493 |
* - p1 = (bit 0) - orientation (Axis) |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1494 |
* - p1 = (bit 8-15) - length |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1495 |
* - p1 = (bit 16-23) - width |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1496 |
* - p1 = (bit 24) - allow stations directly adjacent to other stations. |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1497 |
* @param p2 various bitstuffed elements |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1498 |
* - p2 = (bit 0- 3) - airport type |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1499 |
* - p2 = (bit 7) - newstation (1) or original (0) |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1500 |
* - p2 = (bit 8-15) - custom fsmport class |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1501 |
* - p2 = (bit 16-23) - custom fsmport id |
0 | 1502 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1503 |
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1504 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1505 |
bool airport_upgrade = true; |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1506 |
const uint airport_type_for_flat_check = 0x80 | (GB(p2, 0, 4) << 3); |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1507 |
bool newfsmairport = (HASBIT(p2, 7)); |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1508 |
byte original_airport_type = GB(p2, 0, 4); |
0 | 1509 |
|
1510 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1511 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1512 |
/* Check if a valid, buildable airport was chosen for construction */ |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1513 |
//if (p1 > lengthof(_airport_sections) || !HASBIT(GetValidAirports(), p1)) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1514 |
|
0 | 1515 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
1516 |
return CMD_ERROR; |
|
1517 |
||
6395 | 1518 |
Town *t = ClosestTownFromTile(tile, (uint)-1); |
0 | 1519 |
|
1520 |
/* Check if local auth refuses a new airport */ |
|
1521 |
{ |
|
1522 |
uint num = 0; |
|
6395 | 1523 |
const Station *st; |
0 | 1524 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1525 |
if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG) |
0 | 1526 |
num++; |
1527 |
} |
|
1528 |
if (num >= 2) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1529 |
SetDParam(0, t->index); |
0 | 1530 |
return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES); |
1531 |
} |
|
1532 |
} |
|
1533 |
||
6738
72d1a2997952
(svn r10683) [NewGRF_ports] -Revert: Too eager to un-const... global search/replace removed too many. Restores necessary ones... for the moment ;)
richk
parents:
6734
diff
changeset
|
1534 |
const AirportFTAClass *afc = GetAirport(original_airport_type); |
6395 | 1535 |
int w = afc->size_x; |
1536 |
int h = afc->size_y; |
|
1537 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1538 |
Station *st = NULL; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1539 |
|
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1540 |
/* Check if the given station class is valid */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1541 |
if (GB(p2, 8, 8) >= FSMPORTS_CLASS_MAX) return CMD_ERROR; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1542 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1543 |
/* Check if we can allocate a custom stationspec to this station */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1544 |
const FSMportsSpec *fsmportsspec = GetCustomFSMportsSpec((FSMportsClassID)GB(p2, 8, 8), GB(p2, 16, 8)); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1545 |
|
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1546 |
if (newfsmairport) { |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1547 |
/* Perform NewStation checks */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1548 |
w = fsmportsspec->width; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1549 |
h = fsmportsspec->lengths; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1550 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1551 |
/* Check if the station is buildable */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1552 |
if (HASBIT(fsmportsspec->callbackmask, CBM_STATION_AVAIL) && GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, fsmportsspec, NULL, INVALID_TILE) == 0) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1553 |
return CMD_ERROR; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1554 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1555 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1556 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1557 |
if (!_patches.adjacent_stations || !HASBIT(p1, 24)) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1558 |
st = GetStationAround(tile, w, h, INVALID_STATION); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1559 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1560 |
} |
0 | 1561 |
|
1562 |
/* Find a station close to us */ |
|
6378 | 1563 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
0 | 1564 |
|
5764
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1565 |
if (w > _patches.station_spread || h > _patches.station_spread) { |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1566 |
_error_message = STR_306C_STATION_TOO_SPREAD_OUT; |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1567 |
return CMD_ERROR; |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1568 |
} |
483bcb05ccf3
(svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents:
5726
diff
changeset
|
1569 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1570 |
/* In case of new station if DC_EXEC is NOT set we still need to create the station |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1571 |
* to test if everything is OK. In this case we need to delete it before return. */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1572 |
AutoPtrT<Station> st_auto_delete; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1573 |
|
0 | 1574 |
if (st != NULL) { |
6390 | 1575 |
if (st->owner != _current_player) |
0 | 1576 |
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
|
1577 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1578 |
if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR; |
0 | 1579 |
|
1580 |
if (st->airport_tile != 0) |
|
1581 |
return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT); |
|
1582 |
} else { |
|
1583 |
airport_upgrade = false; |
|
1584 |
||
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1585 |
/* allocate and initialize new station */ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1586 |
st = new Station(tile); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1587 |
if (st == NULL) return CMD_ERROR; |
0 | 1588 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1589 |
/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1590 |
st_auto_delete = st; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1591 |
|
1265
0430e635b116
(svn r1769) Don't compute the same value twice, remove one function call
tron
parents:
1247
diff
changeset
|
1592 |
st->town = t; |
0 | 1593 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1594 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1595 |
SETBIT(t->have_ratings, _current_player); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1596 |
} |
0 | 1597 |
|
1598 |
st->sign.width_1 = 0; |
|
1599 |
||
6375 | 1600 |
/* If only helicopters may use the airport generate a helicopter related (5) |
1601 |
* station name, otherwise generate a normal airport name (1) */ |
|
1602 |
if (!GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? 5 : 1)) { |
|
0 | 1603 |
return CMD_ERROR; |
6375 | 1604 |
} |
0 | 1605 |
} |
1606 |
||
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1607 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1608 |
CommandCost ret = CheckFlatLandBelow(tile, w, h, flags, airport_type_for_flat_check, NULL); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1609 |
if (CmdFailed(ret)) return ret; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1610 |
CommandCost cost(ret.GetCost()); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1611 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1612 |
cost.AddCost(_price.build_airport * w * h); |
0 | 1613 |
|
1614 |
if (flags & DC_EXEC) { |
|
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1615 |
byte *layout_ptr; |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1616 |
byte layout; |
6731
d5fc4446b833
(svn r10652) [NewGRF_ports] -Fix: Initialise variable to eliminate warning.
richk
parents:
6730
diff
changeset
|
1617 |
int fsmportspecindex = 0; |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1618 |
|
0 | 1619 |
st->airport_tile = tile; |
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
1620 |
st->AddFacility(FACIL_AIRPORT, tile); |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1621 |
st->airport_type = (byte)original_airport_type; |
6739
3f2ca4d0abda
(svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
6738
diff
changeset
|
1622 |
st->airport_flags.ResetAll(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1623 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1624 |
st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1625 |
|
2639 | 1626 |
/* if airport was demolished while planes were en-route to it, the |
1627 |
* positions can no longer be the same (v->u.air.pos), since different |
|
1628 |
* airports have different indexes. So update all planes en-route to this |
|
1629 |
* airport. Only update if |
|
1630 |
* 1. airport is upgraded |
|
1631 |
* 2. airport is added to existing station (unfortunately unavoideable) |
|
1632 |
*/ |
|
2549 | 1633 |
if (airport_upgrade) UpdateAirplanesOnNewStation(st); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1634 |
|
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1635 |
if (newfsmairport) { |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1636 |
fsmportspecindex = AllocateFSMportsSpecToStation(fsmportsspec, st, flags & DC_EXEC); |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1637 |
if (fsmportspecindex == -1) return CMD_ERROR; |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1638 |
|
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1639 |
layout_ptr = (byte*)alloca(w * h); |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1640 |
GetFSMportsLayout(layout_ptr, w, h, fsmportsspec); |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1641 |
} else { |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1642 |
layout_ptr = (byte*)_airport_sections[original_airport_type]; |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1643 |
} |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
1644 |
|
0 | 1645 |
{ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1646 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) { |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1647 |
layout = *layout_ptr++; |
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
1648 |
MakeAirport(tile_cur, st->owner, st->index, layout - (newfsmairport ? 0 : (layout < 67) ? 8 : 24)); |
6724
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1649 |
if (newfsmairport) { |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1650 |
SetCustomFSMportsSpecIndex(tile_cur, fsmportspecindex); //set top bit of m6 to indicate an fsmportsspec |
cfa62b4744d4
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
richk
parents:
6722
diff
changeset
|
1651 |
} |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1652 |
} END_TILE_LOOP(tile_cur, w, h, tile) |
0 | 1653 |
} |
1654 |
||
1655 |
UpdateStationVirtCoordDirty(st); |
|
1656 |
UpdateStationAcceptance(st, false); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1657 |
RebuildStationLists(); |
0 | 1658 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1659 |
/* success, so don't delete the new station */ |
6732
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1660 |
st_auto_delete.Detach(); |
0 | 1661 |
} |
1662 |
||
1663 |
return cost; |
|
1664 |
} |
|
1665 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1666 |
static CommandCost RemoveAirport(Station *st, uint32 flags) |
0 | 1667 |
{ |
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1668 |
int w, h; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1669 |
const FSMportsSpec *fsmportsspec; |
6738
72d1a2997952
(svn r10683) [NewGRF_ports] -Revert: Too eager to un-const... global search/replace removed too many. Restores necessary ones... for the moment ;)
richk
parents:
6734
diff
changeset
|
1670 |
const AirportFTAClass *afc; |
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1671 |
|
0 | 1672 |
if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) |
1673 |
return CMD_ERROR; |
|
1674 |
||
6395 | 1675 |
TileIndex tile = st->airport_tile; |
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1676 |
bool newfsmairport = IsCustomFSMportsSpecIndex(tile); |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1677 |
|
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1678 |
if (newfsmairport) { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1679 |
fsmportsspec = st->fsmportsspeclist[GetCustomStationSpecIndex(tile)].spec; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1680 |
w = fsmportsspec->width; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1681 |
h = fsmportsspec->lengths; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1682 |
} else { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1683 |
afc = st->Airport(); |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1684 |
w = afc->size_x; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1685 |
h = afc->size_y; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1686 |
} |
6395 | 1687 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1688 |
CommandCost cost(w * h * _price.remove_airport); |
0 | 1689 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1690 |
Vehicle *v; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1691 |
FOR_ALL_VEHICLES(v) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1692 |
if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1693 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1694 |
if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1695 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1696 |
|
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1697 |
byte *layout_ptr; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1698 |
byte layout; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1699 |
|
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1700 |
if (newfsmairport) { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1701 |
layout_ptr = (byte*)alloca(w * h); |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1702 |
GetFSMportsLayout(layout_ptr, w, h, fsmportsspec); |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1703 |
} else { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1704 |
layout_ptr = (byte*)_airport_sections[st->airport_type]; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1705 |
} |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1706 |
|
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1707 |
{ |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1708 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1709 |
layout = *layout_ptr++; |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1710 |
if ((byte)layout != (byte)255) { |
6718
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1711 |
if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1712 |
|
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1713 |
if (flags & DC_EXEC) { |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1714 |
DeleteAnimatedTile(tile_cur); |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1715 |
DoClearSquare(tile_cur); |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1716 |
} |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1717 |
} |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1718 |
END_TILE_LOOP(tile_cur, w,h,tile) |
5a8b295aa345
(svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents:
6717
diff
changeset
|
1719 |
} |
0 | 1720 |
|
1721 |
if (flags & DC_EXEC) { |
|
6729
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1722 |
if (!newfsmairport) { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1723 |
for (uint i = 0; i < afc->nof_depots; ++i) { |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1724 |
DeleteWindowById( |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1725 |
WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i]) |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1726 |
); |
76133dcea48b
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents:
6724
diff
changeset
|
1727 |
} |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1728 |
} |
755
823358e83abf
(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
|
1729 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1730 |
st->rect.AfterRemoveRect(st, tile, w, h); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1731 |
|
0 | 1732 |
st->airport_tile = 0; |
1733 |
st->facilities &= ~FACIL_AIRPORT; |
|
1734 |
||
1735 |
UpdateStationVirtCoordDirty(st); |
|
1736 |
DeleteStationIfEmpty(st); |
|
1737 |
} |
|
1738 |
||
1739 |
return cost; |
|
1740 |
} |
|
1741 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1742 |
/** Build a buoy. |
3491
4c8427796c64
(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
|
1743 |
* @param tile tile where to place the bouy |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1744 |
* @param flags operation to perform |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1745 |
* @param p1 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1746 |
* @param p2 unused |
0 | 1747 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1748 |
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1749 |
{ |
1750 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1751 |
||
3374
9721c51bea25
(svn r4173) -Codechange: Use IsClearWaterTile for buoy construction
celestar
parents:
3362
diff
changeset
|
1752 |
if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE); |
6632
1a46c01ff627
(svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents:
6630
diff
changeset
|
1753 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
0 | 1754 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1755 |
/* allocate and initialize new station */ |
6395 | 1756 |
Station *st = new Station(tile); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1757 |
if (st == NULL) return CMD_ERROR; |
0 | 1758 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1759 |
/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1760 |
AutoPtrT<Station> st_auto_delete(st); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1761 |
|
3055
25fd76668365
(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
|
1762 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
0 | 1763 |
st->sign.width_1 = 0; |
1764 |
||
3055
25fd76668365
(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
|
1765 |
if (!GenerateStationName(st, tile, 4)) return CMD_ERROR; |
0 | 1766 |
|
1767 |
if (flags & DC_EXEC) { |
|
3055
25fd76668365
(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
|
1768 |
st->dock_tile = tile; |
0 | 1769 |
st->facilities |= FACIL_DOCK; |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1770 |
/* Buoys are marked in the Station struct by this flag. Yes, it is this |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1771 |
* braindead.. */ |
0 | 1772 |
st->had_vehicle_of_type |= HVOT_BUOY; |
1773 |
st->owner = OWNER_NONE; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1774 |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
65
diff
changeset
|
1775 |
st->build_date = _date; |
0 | 1776 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1777 |
MakeBuoy(tile, st->index); |
0 | 1778 |
|
1779 |
UpdateStationVirtCoordDirty(st); |
|
1780 |
UpdateStationAcceptance(st, false); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1781 |
RebuildStationLists(); |
0 | 1782 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1783 |
/* success, so don't delete the new station */ |
6732
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1784 |
st_auto_delete.Detach(); |
0 | 1785 |
} |
1786 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1787 |
return CommandCost(_price.build_dock); |
0 | 1788 |
} |
1789 |
||
1078
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1790 |
/* Checks if any ship is servicing the buoy specified. Returns yes or no */ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1791 |
static bool CheckShipsOnBuoy(Station *st) |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1792 |
{ |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1793 |
const Vehicle *v; |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1794 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1795 |
if (v->type == VEH_SHIP) { |
1078
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1796 |
const Order *order; |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1797 |
FOR_VEHICLE_ORDERS(v, order) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4467
diff
changeset
|
1798 |
if (order->type == OT_GOTO_STATION && order->dest == st->index) { |
1078
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1799 |
return true; |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1800 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1801 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1802 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1803 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1804 |
return false; |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1805 |
} |
326bae748bcb
(svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents:
1067
diff
changeset
|
1806 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1807 |
static CommandCost RemoveBuoy(Station *st, uint32 flags) |
0 | 1808 |
{ |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1809 |
/* XXX: strange stuff */ |
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
1810 |
if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID); |
0 | 1811 |
|
6395 | 1812 |
TileIndex tile = st->dock_tile; |
0 | 1813 |
|
2639 | 1814 |
if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE); |
1815 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
0 | 1816 |
|
1817 |
if (flags & DC_EXEC) { |
|
1818 |
st->dock_tile = 0; |
|
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1819 |
/* Buoys are marked in the Station struct by this flag. Yes, it is this |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1706
diff
changeset
|
1820 |
* braindead.. */ |
0 | 1821 |
st->facilities &= ~FACIL_DOCK; |
1822 |
st->had_vehicle_of_type &= ~HVOT_BUOY; |
|
1823 |
||
6204
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1824 |
/* We have to set the water tile's state to the same state as before the |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1825 |
* buoy was placed. Otherwise one could plant a buoy on a canal edge, |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1826 |
* remove it and flood the land (if the canal edge is at level 0) */ |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1827 |
Owner o = GetTileOwner(tile); |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1828 |
if (o == OWNER_WATER) { |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1829 |
MakeWater(tile); |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1830 |
} else { |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1831 |
MakeCanal(tile, o); |
c237d8081b58
(svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents:
6165
diff
changeset
|
1832 |
} |
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1833 |
MarkTileDirtyByTile(tile); |
0 | 1834 |
|
1835 |
UpdateStationVirtCoordDirty(st); |
|
1836 |
DeleteStationIfEmpty(st); |
|
1837 |
} |
|
1838 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1839 |
return CommandCost(_price.remove_truck_station); |
0 | 1840 |
} |
1841 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1842 |
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1843 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1844 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1845 |
{ 0, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1846 |
{ 0, -1} |
0 | 1847 |
}; |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1848 |
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 }; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1849 |
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 }; |
0 | 1850 |
|
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1851 |
/** Build a dock/haven. |
3491
4c8427796c64
(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
|
1852 |
* @param tile tile where dock will be built |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1853 |
* @param flags operation to perform |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1854 |
* @param p1 (bit 0) - allow docks directly adjacent to other docks. |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1855 |
* @param p2 unused |
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1856 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1857 |
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1858 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1859 |
CommandCost cost; |
0 | 1860 |
|
1861 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1862 |
||
6395 | 1863 |
DiagDirection direction; |
3055
25fd76668365
(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
|
1864 |
switch (GetTileSlope(tile, NULL)) { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1865 |
case SLOPE_SW: direction = DIAGDIR_NE; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1866 |
case SLOPE_SE: direction = DIAGDIR_NW; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1867 |
case SLOPE_NW: direction = DIAGDIR_SE; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1868 |
case SLOPE_NE: direction = DIAGDIR_SW; break; |
3055
25fd76668365
(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
|
1869 |
default: return_cmd_error(STR_304B_SITE_UNSUITABLE); |
25fd76668365
(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
|
1870 |
} |
25fd76668365
(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
|
1871 |
|
4619
fc11bc6a7fe7
(svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents:
4559
diff
changeset
|
1872 |
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR; |
fc11bc6a7fe7
(svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents:
4559
diff
changeset
|
1873 |
|
6632
1a46c01ff627
(svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents:
6630
diff
changeset
|
1874 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
1a46c01ff627
(svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents:
6630
diff
changeset
|
1875 |
|
3491
4c8427796c64
(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
|
1876 |
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1877 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1878 |
|
6395 | 1879 |
TileIndex tile_cur = tile + TileOffsByDiagDir(direction); |
0 | 1880 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1881 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
3055
25fd76668365
(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
|
1882 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
25fd76668365
(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
|
1883 |
} |
0 | 1884 |
|
6632
1a46c01ff627
(svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents:
6630
diff
changeset
|
1885 |
if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
1a46c01ff627
(svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents:
6630
diff
changeset
|
1886 |
|
3491
4c8427796c64
(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
|
1887 |
cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1888 |
if (CmdFailed(cost)) return CMD_ERROR; |
0 | 1889 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1890 |
tile_cur += TileOffsByDiagDir(direction); |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
1891 |
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) { |
0 | 1892 |
return_cmd_error(STR_304B_SITE_UNSUITABLE); |
3055
25fd76668365
(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
|
1893 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1894 |
|
0 | 1895 |
/* middle */ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1896 |
Station *st = NULL; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1897 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1898 |
if (!_patches.adjacent_stations || !HASBIT(p1, 0)) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1899 |
st = GetStationAround( |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1900 |
tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1901 |
_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1902 |
if (st == CHECK_STATIONS_ERR) return CMD_ERROR; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1903 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1904 |
|
0 | 1905 |
/* Find a station close to us */ |
6378 | 1906 |
if (st == NULL) st = GetClosestStationFromTile(tile); |
0 | 1907 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1908 |
/* In case of new station if DC_EXEC is NOT set we still need to create the station |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1909 |
* to test if everything is OK. In this case we need to delete it before return. */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1910 |
AutoPtrT<Station> st_auto_delete; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1911 |
|
0 | 1912 |
if (st != NULL) { |
6390 | 1913 |
if (st->owner != _current_player) |
0 | 1914 |
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
|
1915 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1916 |
if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR; |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1917 |
|
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1918 |
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK); |
0 | 1919 |
} else { |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1920 |
/* allocate and initialize new station */ |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1921 |
st = new Station(tile); |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1922 |
if (st == NULL) return CMD_ERROR; |
0 | 1923 |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1924 |
/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */ |
6095
55d5c0e6be3a
(svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents:
6088
diff
changeset
|
1925 |
st_auto_delete = st; |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1926 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1927 |
Town *t = st->town = ClosestTownFromTile(tile, (uint)-1); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1928 |
|
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1929 |
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) { |
0 | 1930 |
SETBIT(t->have_ratings, _current_player); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1931 |
} |
0 | 1932 |
|
1933 |
st->sign.width_1 = 0; |
|
1934 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
1935 |
if (!GenerateStationName(st, tile, 3)) return CMD_ERROR; |
0 | 1936 |
} |
1937 |
||
1938 |
if (flags & DC_EXEC) { |
|
1939 |
st->dock_tile = tile; |
|
5972
564f98b055d1
(svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents:
5969
diff
changeset
|
1940 |
st->AddFacility(FACIL_DOCK, tile); |
0 | 1941 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1942 |
st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1943 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
1944 |
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
|
1945 |
|
0 | 1946 |
UpdateStationVirtCoordDirty(st); |
1947 |
UpdateStationAcceptance(st, false); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
1948 |
RebuildStationLists(); |
0 | 1949 |
InvalidateWindow(WC_STATION_LIST, st->owner); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
1950 |
/* success, so don't delete the new station */ |
6732
ca1b466db422
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents:
6731
diff
changeset
|
1951 |
st_auto_delete.Detach(); |
0 | 1952 |
} |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1953 |
return CommandCost(_price.build_dock); |
0 | 1954 |
} |
1955 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1956 |
static CommandCost RemoveDock(Station *st, uint32 flags) |
0 | 1957 |
{ |
2639 | 1958 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
0 | 1959 |
|
6395 | 1960 |
TileIndex tile1 = st->dock_tile; |
1961 |
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1)); |
|
0 | 1962 |
|
2639 | 1963 |
if (!EnsureNoVehicle(tile1)) return CMD_ERROR; |
1964 |
if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
|
0 | 1965 |
|
1966 |
if (flags & DC_EXEC) { |
|
1967 |
DoClearSquare(tile1); |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1968 |
MakeWater(tile2); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1969 |
|
5927
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1970 |
st->rect.AfterRemoveTile(st, tile1); |
d740cab19ca0
(svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents:
5919
diff
changeset
|
1971 |
st->rect.AfterRemoveTile(st, tile2); |
5583
ed718fa4c69c
(svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents:
5573
diff
changeset
|
1972 |
|
3111
1edf71aa942e
(svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents:
3102
diff
changeset
|
1973 |
MarkTileDirtyByTile(tile2); |
0 | 1974 |
|
1975 |
st->dock_tile = 0; |
|
1976 |
st->facilities &= ~FACIL_DOCK; |
|
1977 |
||
1978 |
UpdateStationVirtCoordDirty(st); |
|
1979 |
DeleteStationIfEmpty(st); |
|
1980 |
} |
|
1981 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1982 |
return CommandCost(_price.remove_dock); |
0 | 1983 |
} |
1984 |
||
1985 |
#include "table/station_land.h" |
|
1986 |
||
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
1987 |
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx) |
3763
460bbb4a8154
(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
|
1988 |
{ |
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
1989 |
return &_station_display_datas[st][gfx]; |
3763
460bbb4a8154
(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
|
1990 |
} |
0 | 1991 |
|
6214
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
1992 |
/* For drawing canal edges on buoys */ |
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
1993 |
extern void DrawCanalWater(TileIndex tile); |
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
1994 |
|
0 | 1995 |
static void DrawTile_Station(TileInfo *ti) |
1996 |
{ |
|
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
1997 |
const DrawTileSprites *t = NULL; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1998 |
RailType railtype; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
1999 |
RoadTypes roadtypes; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2000 |
if (IsRailwayStation(ti->tile)) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2001 |
railtype = GetRailType(ti->tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2002 |
roadtypes = ROADTYPES_NONE; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2003 |
} else { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2004 |
roadtypes = GetRoadTypes(ti->tile); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2005 |
railtype = RAILTYPE_BEGIN; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2006 |
} |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2007 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2008 |
uint32 relocation = 0; |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2009 |
const Station *st = NULL; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2010 |
const StationSpec *statspec = NULL; |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2011 |
const FSMportsSpec *fsmportspec = NULL; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2012 |
bool FSMport = false; |
4227
55651eaaedb5
(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
|
2013 |
PlayerID owner = GetTileOwner(ti->tile); |
6395 | 2014 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2015 |
SpriteID palette; |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
2016 |
if (IsValidPlayer(owner)) { |
4227
55651eaaedb5
(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
|
2017 |
palette = PLAYER_SPRITE_COLOR(owner); |
55651eaaedb5
(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
|
2018 |
} else { |
55651eaaedb5
(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
|
2019 |
// Some stations are not owner by a player, namely oil rigs |
55651eaaedb5
(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
|
2020 |
palette = PALETTE_TO_GREY; |
0 | 2021 |
} |
2022 |
||
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2023 |
// don't show foundation for docks |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3630
diff
changeset
|
2024 |
if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) |
0 | 2025 |
DrawFoundation(ti, ti->tileh); |
2026 |
||
3568
c1abc31df35b
(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
|
2027 |
if (IsCustomStationSpecIndex(ti->tile)) { |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2028 |
// look for customization |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2029 |
st = GetStationByTile(ti->tile); |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2030 |
int specindex = GetCustomStationSpecIndex(ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2031 |
FSMport = IsCustomFSMportsSpecIndex(ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2032 |
if (FSMport) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2033 |
fsmportspec = st->fsmportsspeclist[specindex].spec; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2034 |
} else { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2035 |
statspec = st->speclist[specindex].spec; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2036 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2037 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2038 |
//debug("Cust-o-mized %p", statspec); |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2039 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2040 |
if (statspec != NULL) { |
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2041 |
uint tile = GetStationGfx(ti->tile); |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2042 |
|
3751
785501c18d0d
(svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents:
3742
diff
changeset
|
2043 |
relocation = GetCustomStationRelocation(statspec, st, ti->tile); |
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2044 |
|
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2045 |
if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2046 |
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile); |
4886
d89110a382ae
(svn r6823) - Codechange: Ignore bit 0 of a NewStation custom tile callback result. This fixes cosmetic problems with some add on stations.
peter1138
parents:
4873
diff
changeset
|
2047 |
if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile); |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2048 |
} |
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2049 |
|
3576
007e6b163bf5
(svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents:
3574
diff
changeset
|
2050 |
/* Ensure the chosen tile layout is valid for this custom station */ |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2051 |
if (statspec->renderdata != NULL) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2052 |
t = &statspec->renderdata[tile < statspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)]; |
3754
04356ae401b4
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents:
3751
diff
changeset
|
2053 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2054 |
} |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2055 |
if (fsmportspec != NULL) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2056 |
uint tile = GetStationGfx(ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2057 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2058 |
relocation = GetCustomFSMportsRelocation(fsmportspec, st, ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2059 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2060 |
//if (HASBIT(fsmportspec->callbackmask, CBM_CUSTOM_LAYOUT)) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2061 |
// uint16 callback = GetFSMportsCallback(CBID_FSMPORTS_SPRITE_LAYOUT, 0, 0, fsmportspec, st, ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2062 |
// if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile); |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2063 |
//} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2064 |
|
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2065 |
/* Ensure the chosen tile layout is valid for this custom station */ |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2066 |
if (fsmportspec->renderdata != NULL) { |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2067 |
t = &fsmportspec->renderdata[tile < fsmportspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)]; |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2068 |
} |
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2069 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2070 |
} |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2071 |
|
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2072 |
if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)]; |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2073 |
|
6395 | 2074 |
SpriteID image = t->ground_sprite; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2075 |
if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) { |
6722
72f280229ee1
(svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
6720
diff
changeset
|
2076 |
image += (FSMport)? GetCustomFSMportsGroundRelocation(fsmportspec, st, ti->tile) : GetCustomStationGroundRelocation(statspec, st, ti->tile); |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2077 |
image += rti->custom_ground_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2078 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2079 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2080 |
} |
449
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2081 |
|
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2082 |
// station_land array has been increased from 82 elements to 114 |
d9325d9f24bb
(svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents:
445
diff
changeset
|
2083 |
// but this is something else. If AI builds station with 114 it looks all weird |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2084 |
DrawGroundSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE); |
0 | 2085 |
|
3789
bf75e48227de
(svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents:
3784
diff
changeset
|
2086 |
if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti); |
3355
a653b8e47f27
(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
|
2087 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2088 |
if (HASBIT(roadtypes, ROADTYPE_TRAM)) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2089 |
Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2090 |
DrawGroundSprite((HASBIT(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2091 |
DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2092 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2093 |
|
6214
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
2094 |
if (IsBuoyTile(ti->tile) && (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER))) DrawCanalWater(ti->tile); |
aab08beb5652
(svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents:
6204
diff
changeset
|
2095 |
|
6395 | 2096 |
const DrawTileSeqStruct *dtss; |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2097 |
foreach_draw_tile_seq(dtss, t->seq) { |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2098 |
image = dtss->image; |
5960
8ba5759e1d8d
(svn r8186) -Fix (FS#557): Apply railtype offset to station graphics if no custom station is in use.
peter1138
parents:
5959
diff
changeset
|
2099 |
if (relocation == 0 || HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) { |
3775
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2100 |
image += rti->total_offset; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2101 |
} else { |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2102 |
image += relocation; |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2103 |
} |
f3f1ba3111fa
(svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents:
3771
diff
changeset
|
2104 |
|
6395 | 2105 |
SpriteID pal; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2106 |
if (HASBIT(_transparent_opt, TO_BUILDINGS)) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2107 |
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2108 |
pal = PALETTE_TO_TRANSPARENT; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2109 |
} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2110 |
pal = palette; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2111 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2112 |
pal = dtss->pal; |
384
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2113 |
} |
bf1303e754ff
(svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents:
354
diff
changeset
|
2114 |
|
0 | 2115 |
if ((byte)dtss->delta_z != 0x80) { |
4230
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2116 |
AddSortableSpriteToDraw( |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2117 |
image, pal, |
4230
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2118 |
ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2119 |
dtss->size_x, dtss->size_y, |
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2120 |
dtss->size_z, ti->z + dtss->delta_z |
cd86b1c47f33
(svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents:
4227
diff
changeset
|
2121 |
); |
0 | 2122 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2123 |
AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y); |
0 | 2124 |
} |
2125 |
} |
|
2126 |
} |
|
2127 |
||
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2128 |
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image) |
0 | 2129 |
{ |
2254
72f8883ff3ac
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents:
2213
diff
changeset
|
2130 |
const RailtypeInfo *rti = GetRailTypeInfo(railtype); |
6395 | 2131 |
SpriteID pal = PLAYER_SPRITE_COLOR(_local_player); |
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2132 |
const DrawTileSprites *t = &_station_display_datas[st][image]; |
6395 | 2133 |
|
2134 |
SpriteID img = t->ground_sprite; |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2135 |
DrawSprite(img + rti->total_offset, HASBIT(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y); |
0 | 2136 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2137 |
if (roadtype == ROADTYPE_TRAM) { |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2138 |
DrawSprite(SPR_TRAMWAY_TRAM + (t->ground_sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2139 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2140 |
|
6395 | 2141 |
const DrawTileSeqStruct *dtss; |
384
bf1303e754ff
(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); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5918
diff
changeset
|
2144 |
DrawSprite(dtss->image + rti->total_offset, pal, x + pt.x, y + pt.y); |
0 | 2145 |
} |
2146 |
} |
|
2147 |
||
4231
dea6a63dd058
(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
dea6a63dd058
(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
d87b21df2944
(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
d87b21df2944
(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
4392ae3d8e31
(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
4392ae3d8e31
(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 |
{ |
1901
fb05044cf5c3
(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
|
2165 |
td->owner = GetTileOwner(tile); |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2166 |
td->build_date = GetStationByTile(tile)->build_date; |
2049
ad0d49c916d4
(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
|
2167 |
|
6395 | 2168 |
StringID str; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2169 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2170 |
default: NOT_REACHED(); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2171 |
case STATION_RAIL: str = STR_305E_RAILROAD_STATION; break; |
3882
86380e989bad
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2172 |
case STATION_AIRPORT: |
86380e989bad
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2173 |
str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT); |
86380e989bad
(svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents:
3876
diff
changeset
|
2174 |
break; |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2175 |
case STATION_TRUCK: str = STR_3061_TRUCK_LOADING_AREA; break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2176 |
case STATION_BUS: str = STR_3062_BUS_STATION; break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2177 |
case STATION_OILRIG: str = STR_4807_OIL_RIG; break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2178 |
case STATION_DOCK: str = STR_3063_SHIP_DOCK; break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2179 |
case STATION_BUOY: str = STR_3069_BUOY; break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2180 |
} |
0 | 2181 |
td->str = str; |
2182 |
} |
|
2183 |
||
2184 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2185 |
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2186 |
{ |
1032
6020f9143b17
(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
|
2187 |
switch (mode) { |
6020f9143b17
(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 |
case TRANSPORT_RAIL: |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2189 |
if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2190 |
return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101; |
1032
6020f9143b17
(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
|
2191 |
} |
6020f9143b17
(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 |
break; |
6020f9143b17
(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 |
|
6020f9143b17
(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 |
case TRANSPORT_WATER: |
6020f9143b17
(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 |
// buoy is coded as a station, it is always on open water |
6165
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2196 |
if (IsBuoy(tile)) { |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2197 |
TrackBits ts = TRACK_BIT_ALL; |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2198 |
// remove tracks that connect NE map edge |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2199 |
if (TileX(tile) == 0) ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT); |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2200 |
// remove tracks that connect NW map edge |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2201 |
if (TileY(tile) == 0) ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER); |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2202 |
return uint32(ts) * 0x101; |
4da5ead702ad
(svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents:
6164
diff
changeset
|
2203 |
} |
1032
6020f9143b17
(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
|
2204 |
break; |
6020f9143b17
(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
|
2205 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2206 |
case TRANSPORT_ROAD: |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2207 |
if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStopTile(tile)) { |
4158 | 2208 |
return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2209 |
} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2210 |
break; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3884
diff
changeset
|
2211 |
|
1032
6020f9143b17
(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
|
2212 |
default: |
6020f9143b17
(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
|
2213 |
break; |
0 | 2214 |
} |
1032
6020f9143b17
(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
|
2215 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2216 |
return 0; |
0 | 2217 |
} |
2218 |
||
2660 | 2219 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2220 |
static void TileLoop_Station(TileIndex tile) |
0 | 2221 |
{ |
2660 | 2222 |
// FIXME -- GetTileTrackStatus_Station -> animated stationtiles |
2223 |
// hardcoded.....not good |
|
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2224 |
switch (GetStationType(tile)) { |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2225 |
case STATION_AIRPORT: |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2226 |
switch (GetStationGfx(tile)) { |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2227 |
case GFX_RADAR_LARGE_FIRST: |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2228 |
case GFX_WINDSACK_FIRST : // for small airport |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2229 |
case GFX_RADAR_INTERNATIONAL_FIRST: |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2230 |
case GFX_RADAR_METROPOLITAN_FIRST: |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2231 |
case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2232 |
case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2233 |
AddAnimatedTile(tile); |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2234 |
break; |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2235 |
} |
2660 | 2236 |
break; |
2237 |
||
6730
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2238 |
case STATION_OILRIG: //(station part) |
f09255ea0123
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents:
6729
diff
changeset
|
2239 |
case STATION_BUOY: |
2660 | 2240 |
TileLoop_Water(tile); |
2241 |
break; |
|
2242 |
||
2243 |
default: break; |
|
2244 |
} |
|
0 | 2245 |
} |
2246 |
||
2247 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2248 |
static void AnimateTile_Station(TileIndex tile) |
0 | 2249 |
{ |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2250 |
struct AnimData { |
4467
dede0d254ffb
(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 |
StationGfx from; // first sprite |
dede0d254ffb
(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 |
StationGfx to; // last sprite |
dede0d254ffb
(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 |
byte delay; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2254 |
}; |
4467
dede0d254ffb
(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
|
2255 |
|
dede0d254ffb
(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 |
static const AnimData data[] = { |
dede0d254ffb
(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 |
{ GFX_RADAR_LARGE_FIRST, GFX_RADAR_LARGE_LAST, 3 }, |
dede0d254ffb
(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 |
{ GFX_WINDSACK_FIRST, GFX_WINDSACK_LAST, 1 }, |
dede0d254ffb
(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 |
{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 }, |
dede0d254ffb
(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 |
{ GFX_RADAR_METROPOLITAN_FIRST, GFX_RADAR_METROPOLITAN_LAST, 3 }, |
dede0d254ffb
(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 |
{ GFX_RADAR_DISTRICTWE_FIRST, GFX_RADAR_DISTRICTWE_LAST, 3 }, |
dede0d254ffb
(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 |
{ GFX_WINDSACK_INTERCON_FIRST, GFX_WINDSACK_INTERCON_LAST, 1 } |
dede0d254ffb
(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 |
}; |
dede0d254ffb
(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 |
|
3545
3e66bf329257
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2265 |
StationGfx gfx = GetStationGfx(tile); |
6395 | 2266 |
|
2267 |
for (const AnimData *i = data; i != endof(data); i++) { |
|
4467
dede0d254ffb
(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
|
2268 |
if (i->from <= gfx && gfx <= i->to) { |
dede0d254ffb
(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
|
2269 |
if ((_tick_counter & i->delay) == 0) { |
dede0d254ffb
(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
|
2270 |
SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from); |
dede0d254ffb
(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
|
2271 |
MarkTileDirtyByTile(tile); |
dede0d254ffb
(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
|
2272 |
} |
dede0d254ffb
(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
|
2273 |
break; |
3545
3e66bf329257
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3540
diff
changeset
|
2274 |
} |
0 | 2275 |
} |
2276 |
} |
|
2277 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
2278 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2279 |
static void ClickTile_Station(TileIndex tile) |
0 | 2280 |
{ |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2281 |
if (IsHangar(tile)) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2282 |
ShowDepotWindow(tile, VEH_AIRCRAFT); |
0 | 2283 |
} else { |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2284 |
ShowStationViewWindow(GetStationIndex(tile)); |
0 | 2285 |
} |
2286 |
} |
|
2287 |
||
2288 |
static const byte _enter_station_speedtable[12] = { |
|
2289 |
215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 |
|
2290 |
}; |
|
2291 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2292 |
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) |
0 | 2293 |
{ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2294 |
if (v->type == VEH_TRAIN) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2295 |
if (IsRailwayStation(tile) && IsFrontEngine(v) && |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
2296 |
!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) { |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2297 |
StationID station_id = GetStationIndex(tile); |
2989 | 2298 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2299 |
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) || |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4467
diff
changeset
|
2300 |
(v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2301 |
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2302 |
v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
2303 |
v->last_station_visited != station_id) { |
3482
ba2072e463c8
(svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents:
3480
diff
changeset
|
2304 |
DiagDirection dir = DirToDiagDir(v->direction); |
2989 | 2305 |
|
0 | 2306 |
x &= 0xF; |
2307 |
y &= 0xF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2308 |
|
6432 | 2309 |
if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2310 |
if (y == TILE_SIZE / 2) { |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
2311 |
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
2312 |
if (x == 12) return VETSB_ENTERED_STATION | (station_id << VETS_STATION_ID_OFFSET); /* enter station */ |
0 | 2313 |
if (x < 12) { |
2639 | 2314 |
uint16 spd; |
2315 |
||
0 | 2316 |
v->vehstatus |= VS_TRAIN_SLOWING; |
2317 |
spd = _enter_station_speedtable[x]; |
|
2639 | 2318 |
if (spd < v->cur_speed) v->cur_speed = spd; |
0 | 2319 |
} |
2320 |
} |
|
2321 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2322 |
} |
0 | 2323 |
} |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2324 |
} else if (v->type == VEH_ROAD) { |
6402
d8d29aef051f
(svn r8809) -Fix (r8715): accidentally removed a part of an expression.
rubidium
parents:
6396
diff
changeset
|
2325 |
if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2326 |
if (IsRoadStop(tile) && IsRoadVehFront(v)) { |
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2327 |
/* Attempt to allocate a parking bay in a road stop */ |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2328 |
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
2671
457c6cdbf9e7
(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 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2330 |
if (IsDriveThroughStopTile(tile)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2331 |
/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2332 |
byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2333 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2334 |
if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2335 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2336 |
/* Check if the vehicle is stopping at this road stop */ |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
2337 |
if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) && |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2338 |
v->current_order.dest == GetStationIndex(tile)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2339 |
SETBIT(v->u.road.state, RVS_IS_STOPPING); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2340 |
rs->AllocateDriveThroughBay(side); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2341 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2342 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2343 |
/* Indicate if vehicle is using second bay. */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2344 |
if (side == 1) SETBIT(v->u.road.state, RVS_USING_SECOND_BAY); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2345 |
/* Indicate a drive-through stop */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2346 |
SETBIT(v->u.road.state, RVS_IN_DT_ROAD_STOP); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2347 |
return VETSB_CONTINUE; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2348 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2349 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2350 |
/* For normal (non drive-through) road stops */ |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2351 |
/* Check if station is busy or if there are no free bays. */ |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
2352 |
if (rs->IsEntranceBusy() || !rs->HasFreeBay()) return VETSB_CANNOT_ENTER; |
0 | 2353 |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6324
diff
changeset
|
2354 |
SETBIT(v->u.road.state, RVS_IN_ROAD_STOP); |
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2660
diff
changeset
|
2355 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2356 |
/* Allocate a bay and update the road state */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2357 |
uint bay_nr = rs->AllocateBay(); |
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6324
diff
changeset
|
2358 |
SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr); |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2359 |
|
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2360 |
/* Mark the station entrace as busy */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6214
diff
changeset
|
2361 |
rs->SetEntranceBusy(true); |
0 | 2362 |
} |
2363 |
} |
|
2364 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2365 |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
2366 |
return VETSB_CONTINUE; |
0 | 2367 |
} |
2368 |
||
2369 |
/* this function is called for one station each tick */ |
|
2370 |
static void StationHandleBigTick(Station *st) |
|
2371 |
{ |
|
2372 |
UpdateStationAcceptance(st, true); |
|
2373 |
||
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
2374 |
if (st->facilities == 0 && ++st->delete_ctr >= 8) delete st; |
1239
6e61c510580e
(svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents:
1231
diff
changeset
|
2375 |
|
0 | 2376 |
} |
2377 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
497
diff
changeset
|
2378 |
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } |
0 | 2379 |
|
2380 |
static void UpdateStationRating(Station *st) |
|
2381 |
{ |
|
2382 |
bool waiting_changed = false; |
|
2383 |
||
2384 |
byte_inc_sat(&st->time_since_load); |
|
2385 |
byte_inc_sat(&st->time_since_unload); |
|
2386 |
||
6395 | 2387 |
GoodsEntry *ge = st->goods; |
0 | 2388 |
do { |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2389 |
/* Slowly increase the rating back to his original level in the case we |
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2390 |
* didn't deliver cargo yet to this station. This happens when a bribe |
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2391 |
* failed while you didn't moved that cargo yet to a station. */ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2392 |
if (ge->days_since_pickup == 255 && ge->rating < INITIAL_STATION_RATING) |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2393 |
ge->rating++; |
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2394 |
/* Only change the rating if we are moving this cargo */ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2395 |
if (ge->last_speed != 0) { |
0 | 2396 |
byte_inc_sat(&ge->days_since_pickup); |
2397 |
||
6395 | 2398 |
int rating = 0; |
0 | 2399 |
|
2400 |
{ |
|
2401 |
int b = ge->last_speed; |
|
2402 |
if ((b-=85) >= 0) |
|
2403 |
rating += b >> 2; |
|
2404 |
} |
|
2405 |
||
2406 |
{ |
|
2407 |
byte age = ge->last_age; |
|
2408 |
(age >= 3) || |
|
2409 |
(rating += 10, age >= 2) || |
|
2410 |
(rating += 10, age >= 1) || |
|
2411 |
(rating += 13, true); |
|
2412 |
} |
|
2413 |
||
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4848
diff
changeset
|
2414 |
if (IsValidPlayer(st->owner) && HASBIT(st->town->statues, st->owner)) rating += 26; |
0 | 2415 |
|
2416 |
{ |
|
2417 |
byte days = ge->days_since_pickup; |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2418 |
if (st->last_vehicle_type == VEH_SHIP) |
0 | 2419 |
days >>= 2; |
2420 |
(days > 21) || |
|
2421 |
(rating += 25, days > 12) || |
|
2422 |
(rating += 25, days > 6) || |
|
2423 |
(rating += 45, days > 3) || |
|
2424 |
(rating += 35, true); |
|
2425 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2426 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2427 |
uint waiting = ge->cargo.Count(); |
6395 | 2428 |
(rating -= 90, waiting > 1500) || |
2429 |
(rating += 55, waiting > 1000) || |
|
2430 |
(rating += 35, waiting > 600) || |
|
2431 |
(rating += 10, waiting > 300) || |
|
2432 |
(rating += 20, waiting > 100) || |
|
2433 |
(rating += 10, true); |
|
0 | 2434 |
|
2435 |
{ |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2436 |
int or_ = ge->rating; // old rating |
0 | 2437 |
|
2438 |
// only modify rating in steps of -2, -1, 0, 1 or 2 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2439 |
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
|
2440 |
|
0 | 2441 |
// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station |
2442 |
if (rating <= 64 && waiting >= 200) { |
|
2443 |
int dec = Random() & 0x1F; |
|
2444 |
if (waiting < 400) dec &= 7; |
|
2445 |
waiting -= dec + 1; |
|
2446 |
waiting_changed = true; |
|
2447 |
} |
|
2448 |
||
2449 |
// if rating is <= 127 and there are any items waiting, maybe remove some goods. |
|
2450 |
if (rating <= 127 && waiting != 0) { |
|
2451 |
uint32 r = Random(); |
|
5911
bb8088c97103
(svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents:
5860
diff
changeset
|
2452 |
if (rating <= (int)GB(r, 0, 7)) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2453 |
/* Need to have int, otherwise it will just overflow etc. */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2454 |
waiting = max((int)waiting - (int)GB(r, 8, 2) - 1, 0); |
0 | 2455 |
waiting_changed = true; |
2456 |
} |
|
2457 |
} |
|
2458 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2459 |
/* At some point we really must cap the cargo. Previously this |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2460 |
* was a strict 4095, but now we'll have a less strict, but |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2461 |
* increasingly agressive truncation of the amount of cargo. */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2462 |
static const uint WAITING_CARGO_THRESHOLD = 1 << 12; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2463 |
static const uint WAITING_CARGO_CUT_FACTOR = 1 << 6; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2464 |
static const uint MAX_WAITING_CARGO = 1 << 15; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2465 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2466 |
if (waiting > WAITING_CARGO_THRESHOLD) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2467 |
uint difference = waiting - WAITING_CARGO_THRESHOLD; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2468 |
waiting -= (difference / WAITING_CARGO_CUT_FACTOR); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2469 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2470 |
waiting = min(waiting, MAX_WAITING_CARGO); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2471 |
waiting_changed = true; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2472 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2473 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2474 |
if (waiting_changed) ge->cargo.Truncate(waiting); |
0 | 2475 |
} |
2476 |
} |
|
2477 |
} while (++ge != endof(st->goods)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2478 |
|
6395 | 2479 |
StationID index = st->index; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2480 |
if (waiting_changed) { |
0 | 2481 |
InvalidateWindow(WC_STATION_VIEW, index); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2482 |
} else { |
0 | 2483 |
InvalidateWindowWidget(WC_STATION_VIEW, index, 5); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4066
diff
changeset
|
2484 |
} |
0 | 2485 |
} |
2486 |
||
2487 |
/* called for every station each tick */ |
|
2488 |
static void StationHandleSmallTick(Station *st) |
|
2489 |
{ |
|
2639 | 2490 |
if (st->facilities == 0) return; |
0 | 2491 |
|
6395 | 2492 |
byte b = st->delete_ctr + 1; |
0 | 2493 |
if (b >= 185) b = 0; |
2494 |
st->delete_ctr = b; |
|
2495 |
||
2639 | 2496 |
if (b == 0) UpdateStationRating(st); |
0 | 2497 |
} |
2498 |
||
6573 | 2499 |
void OnTick_Station() |
0 | 2500 |
{ |
2639 | 2501 |
if (_game_mode == GM_EDITOR) return; |
0 | 2502 |
|
6395 | 2503 |
uint i = _station_tick_ctr; |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5220
diff
changeset
|
2504 |
if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 2505 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2506 |
if (IsValidStationID(i)) StationHandleBigTick(GetStation(i)); |
0 | 2507 |
|
6395 | 2508 |
Station *st; |
2509 |
FOR_ALL_STATIONS(st) StationHandleSmallTick(st); |
|
0 | 2510 |
} |
2511 |
||
6573 | 2512 |
void StationMonthlyLoop() |
0 | 2513 |
{ |
2514 |
} |
|
2515 |
||
2516 |
||
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
2517 |
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) |
0 | 2518 |
{ |
2519 |
Station *st; |
|
2520 |
||
2521 |
FOR_ALL_STATIONS(st) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2522 |
if (st->owner == owner && |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
2523 |
DistanceManhattan(tile, st->xy) <= radius) { |
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
2524 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
2549 | 2525 |
GoodsEntry* ge = &st->goods[i]; |
2526 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2527 |
if (ge->days_since_pickup != 255) { |
0 | 2528 |
ge->rating = clamp(ge->rating + amount, 0, 255); |
2529 |
} |
|
2530 |
} |
|
2531 |
} |
|
2532 |
} |
|
2533 |
} |
|
2534 |
||
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
2535 |
static void UpdateStationWaiting(Station *st, CargoID type, uint amount) |
0 | 2536 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2537 |
st->goods[type].cargo.Append(new CargoPacket(st->index, amount)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2538 |
|
0 | 2539 |
InvalidateWindow(WC_STATION_VIEW, st->index); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2540 |
st->MarkTilesDirty(true); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2541 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2542 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2543 |
static bool IsUniqueStationName(const char *name) |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2544 |
{ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2545 |
const Station *st; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2546 |
char buf[512]; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2547 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2548 |
FOR_ALL_STATIONS(st) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2549 |
SetDParam(0, st->index); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2550 |
GetString(buf, STR_STATION, lastof(buf)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2551 |
if (strcmp(buf, name) == 0) return false; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2552 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2553 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2554 |
return true; |
0 | 2555 |
} |
2556 |
||
1786
a54634efeb98
(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
|
2557 |
/** Rename a station |
3491
4c8427796c64
(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
|
2558 |
* @param tile unused |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2559 |
* @param flags operation to perform |
1786
a54634efeb98
(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
|
2560 |
* @param p1 station ID that is to be renamed |
a54634efeb98
(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
|
2561 |
* @param p2 unused |
a54634efeb98
(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
|
2562 |
*/ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2563 |
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2564 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2565 |
if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
6395 | 2566 |
Station *st = GetStation(p1); |
1774
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2567 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
2568 |
if (!CheckOwnership(st->owner)) return CMD_ERROR; |
1774
0fc4a31265c2
(svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents:
1751
diff
changeset
|
2569 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2570 |
if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2571 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2572 |
StringID str = AllocateName(_cmd_text, 6); |
1786
a54634efeb98
(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
|
2573 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2574 |
|
0 | 2575 |
if (flags & DC_EXEC) { |
2639 | 2576 |
StringID old_str = st->string_id; |
2577 |
||
0 | 2578 |
st->string_id = str; |
2579 |
UpdateStationVirtCoord(st); |
|
2580 |
DeleteName(old_str); |
|
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
2581 |
ResortStationLists(); |
0 | 2582 |
MarkWholeScreenDirty(); |
2583 |
} else { |
|
2584 |
DeleteName(str); |
|
2585 |
} |
|
2586 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2587 |
return CommandCost(); |
0 | 2588 |
} |
2589 |
||
2590 |
||
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
2591 |
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount) |
0 | 2592 |
{ |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2593 |
Station* around[8]; |
6395 | 2594 |
|
2595 |
for (uint i = 0; i < lengthof(around); i++) around[i] = NULL; |
|
2596 |
||
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2597 |
int w_prod; //width and height of the "producer" of the cargo |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2598 |
int h_prod; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2599 |
int max_rad; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2600 |
if (_patches.modified_catchment) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2601 |
w_prod = w; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2602 |
h_prod = h; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2603 |
w += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2604 |
h += 16; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2605 |
max_rad = 8; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2606 |
} else { |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2607 |
w_prod = 0; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2608 |
h_prod = 0; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2609 |
w += 8; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2610 |
h += 8; |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2611 |
max_rad = 4; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2612 |
} |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
555
diff
changeset
|
2613 |
|
1981 | 2614 |
BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2615 |
cur_tile = TILE_MASK(cur_tile); |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2616 |
if (!IsTileType(cur_tile, MP_STATION)) continue; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2617 |
|
6395 | 2618 |
Station *st = GetStationByTile(cur_tile); |
2619 |
||
2620 |
for (uint i = 0; i != lengthof(around); i++) { |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2621 |
if (around[i] == NULL) { |
6147
2345f00d2a33
(svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents:
6141
diff
changeset
|
2622 |
if (!st->IsBuoy() && |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2623 |
(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2624 |
st->goods[type].rating != 0 && st->goods[type].last_speed != 0 && // we actually service the station |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2625 |
(!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there. |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
2626 |
((st->facilities & ~FACIL_BUS_STOP) != 0 || IsCargoInClass(type, CC_PASSENGERS)) && // if we have other fac. than a bus stop, or the cargo is passengers |
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6632
diff
changeset
|
2627 |
((st->facilities & ~FACIL_TRUCK_STOP) != 0 || !IsCargoInClass(type, CC_PASSENGERS))) { // if we have other fac. than a cargo bay or the cargo is not passengers |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2628 |
if (_patches.modified_catchment) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2629 |
// min and max coordinates of the producer relative |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2630 |
const int x_min_prod = 9; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2631 |
const int x_max_prod = 8 + w_prod; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2632 |
const int y_min_prod = 9; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2633 |
const int y_max_prod = 8 + h_prod; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2634 |
|
6396 | 2635 |
int rad = FindCatchmentRadius(st); |
2636 |
||
2637 |
int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); |
|
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2638 |
if (w_cur < x_min_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2639 |
x_dist = x_min_prod - w_cur; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2640 |
} else if (w_cur > x_max_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2641 |
x_dist = w_cur - x_max_prod; |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2642 |
} |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2643 |
|
6396 | 2644 |
int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2645 |
if (h_cur < y_min_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2646 |
y_dist = y_min_prod - h_cur; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2647 |
} else if (h_cur > y_max_prod) { |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2648 |
y_dist = h_cur - y_max_prod; |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2649 |
} |
6396 | 2650 |
|
2651 |
if (x_dist > rad || y_dist > rad) break; |
|
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2652 |
} |
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2653 |
|
6396 | 2654 |
around[i] = st; |
3001
0a2cf92beeed
(svn r3581) Just noticed the indentation was totally off, fix it
tron
parents:
3000
diff
changeset
|
2655 |
} |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2656 |
break; |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2657 |
} else if (around[i] == st) { |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2658 |
break; |
0 | 2659 |
} |
2660 |
} |
|
1981 | 2661 |
END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad)) |
0 | 2662 |
|
2663 |
/* no stations around at all? */ |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2664 |
if (around[0] == NULL) return 0; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2665 |
|
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2666 |
if (around[1] == NULL) { |
0 | 2667 |
/* only one station around */ |
6395 | 2668 |
uint moved = (amount * around[0]->goods[type].rating >> 8) + 1; |
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2669 |
UpdateStationWaiting(around[0], type, moved); |
0 | 2670 |
return moved; |
2671 |
} |
|
2672 |
||
2673 |
/* several stations around, find the two with the highest rating */ |
|
6395 | 2674 |
Station *st1 = NULL; |
2675 |
Station *st2 = NULL; |
|
2676 |
uint best_rating = 0; |
|
2677 |
uint best_rating2 = 0; |
|
2678 |
||
2679 |
for (uint i = 0; i != lengthof(around) && around[i] != NULL; i++) { |
|
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2680 |
if (around[i]->goods[type].rating >= best_rating) { |
0 | 2681 |
best_rating2 = best_rating; |
2682 |
st2 = st1; |
|
2683 |
||
3002
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2684 |
best_rating = around[i]->goods[type].rating; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2685 |
st1 = around[i]; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2686 |
} else if (around[i]->goods[type].rating >= best_rating2) { |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2687 |
best_rating2 = around[i]->goods[type].rating; |
c4f3a6ebfb25
(svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents:
3001
diff
changeset
|
2688 |
st2 = around[i]; |
0 | 2689 |
} |
2690 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2691 |
|
0 | 2692 |
assert(st1 != NULL); |
2693 |
assert(st2 != NULL); |
|
2694 |
assert(best_rating != 0 || best_rating2 != 0); |
|
2695 |
||
2696 |
/* the 2nd highest one gets a penalty */ |
|
2697 |
best_rating2 >>= 1; |
|
2698 |
||
2699 |
/* amount given to station 1 */ |
|
6395 | 2700 |
uint t = (best_rating * (amount + 1)) / (best_rating + best_rating2); |
2701 |
||
2702 |
uint moved = 0; |
|
0 | 2703 |
if (t != 0) { |
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2704 |
moved = t * best_rating / 256 + 1; |
0 | 2705 |
amount -= t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2706 |
UpdateStationWaiting(st1, type, moved); |
0 | 2707 |
} |
2708 |
||
2709 |
if (amount != 0) { |
|
3000
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2710 |
amount = amount * best_rating2 / 256 + 1; |
711d2ababe20
(svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents:
2989
diff
changeset
|
2711 |
moved += amount; |
0 | 2712 |
UpdateStationWaiting(st2, type, amount); |
2713 |
} |
|
2714 |
||
2715 |
return moved; |
|
2716 |
} |
|
2717 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2718 |
void BuildOilRig(TileIndex tile) |
0 | 2719 |
{ |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
2720 |
Station *st = new Station(); |
2427
b7a0ad02af26
(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
|
2721 |
|
b7a0ad02af26
(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
|
2722 |
if (st == NULL) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5550
diff
changeset
|
2723 |
DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile); |
2427
b7a0ad02af26
(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
|
2724 |
return; |
0 | 2725 |
} |
2427
b7a0ad02af26
(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
|
2726 |
if (!GenerateStationName(st, tile, 2)) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5550
diff
changeset
|
2727 |
DEBUG(misc, 0, "Can't allocate station-name for oilrig at 0x%X, reverting to oilrig only", tile); |
2427
b7a0ad02af26
(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
|
2728 |
return; |
b7a0ad02af26
(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
|
2729 |
} |
b7a0ad02af26
(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
|
2730 |
|
b7a0ad02af26
(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
|
2731 |
st->town = ClosestTownFromTile(tile, (uint)-1); |
b7a0ad02af26
(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
|
2732 |
st->sign.width_1 = 0; |
b7a0ad02af26
(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
|
2733 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2734 |
MakeOilrig(tile, st->index); |
2427
b7a0ad02af26
(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
|
2735 |
|
b7a0ad02af26
(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
|
2736 |
st->owner = OWNER_NONE; |
6739
3f2ca4d0abda
(svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
6738
diff
changeset
|
2737 |
st->airport_flags.ResetAll(); |
2427
b7a0ad02af26
(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
|
2738 |
st->airport_type = AT_OILRIG; |
b7a0ad02af26
(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
|
2739 |
st->xy = tile; |
b7a0ad02af26
(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
|
2740 |
st->bus_stops = NULL; |
b7a0ad02af26
(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
|
2741 |
st->truck_stops = NULL; |
b7a0ad02af26
(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
|
2742 |
st->airport_tile = tile; |
b7a0ad02af26
(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
|
2743 |
st->dock_tile = tile; |
b7a0ad02af26
(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
|
2744 |
st->train_tile = 0; |
b7a0ad02af26
(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
|
2745 |
st->had_vehicle_of_type = 0; |
b7a0ad02af26
(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
|
2746 |
st->time_since_load = 255; |
b7a0ad02af26
(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
|
2747 |
st->time_since_unload = 255; |
b7a0ad02af26
(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
|
2748 |
st->delete_ctr = 0; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
2749 |
st->last_vehicle_type = VEH_INVALID; |
2427
b7a0ad02af26
(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
|
2750 |
st->facilities = FACIL_AIRPORT | FACIL_DOCK; |
b7a0ad02af26
(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
|
2751 |
st->build_date = _date; |
b7a0ad02af26
(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 |
|
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6655
diff
changeset
|
2753 |
for (CargoID j = 0; j < NUM_CARGO; j++) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2754 |
st->goods[j].acceptance = false; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2755 |
st->goods[j].days_since_pickup = 255; |
6587
bc0bd6259485
(svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents:
6585
diff
changeset
|
2756 |
st->goods[j].rating = INITIAL_STATION_RATING; |
2427
b7a0ad02af26
(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
|
2757 |
st->goods[j].last_speed = 0; |
b7a0ad02af26
(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 |
st->goods[j].last_age = 255; |
b7a0ad02af26
(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
|
2759 |
} |
b7a0ad02af26
(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 |
|
b7a0ad02af26
(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 |
UpdateStationVirtCoordDirty(st); |
b7a0ad02af26
(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 |
UpdateStationAcceptance(st, false); |
0 | 2763 |
} |
2764 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2765 |
void DeleteOilRig(TileIndex tile) |
0 | 2766 |
{ |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2767 |
Station* st = GetStationByTile(tile); |
0 | 2768 |
|
6138 | 2769 |
MakeWater(tile); |
0 | 2770 |
|
2771 |
st->dock_tile = 0; |
|
2772 |
st->airport_tile = 0; |
|
2773 |
st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK); |
|
6739
3f2ca4d0abda
(svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
6738
diff
changeset
|
2774 |
st->airport_flags.ResetAll(); |
0 | 2775 |
UpdateStationVirtCoordDirty(st); |
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
2776 |
if (st->facilities == 0) delete st; |
0 | 2777 |
} |
2778 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2427
diff
changeset
|
2779 |
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 2780 |
{ |
1901
fb05044cf5c3
(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
|
2781 |
if (!IsTileOwner(tile, old_player)) return; |
0 | 2782 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4638
diff
changeset
|
2783 |
if (new_player != PLAYER_SPECTATOR) { |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2784 |
Station* st = GetStationByTile(tile); |
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3282
diff
changeset
|
2785 |
|
1902 | 2786 |
SetTileOwner(tile, new_player); |
0 | 2787 |
st->owner = new_player; |
3812
d9b3041ee3d0
(svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents:
3789
diff
changeset
|
2788 |
RebuildStationLists(); |
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
59
diff
changeset
|
2789 |
InvalidateWindowClasses(WC_STATION_LIST); |
0 | 2790 |
} else { |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2791 |
if (IsDriveThroughStopTile(tile) && GetStopBuiltOnTownRoad(tile)) { |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2792 |
/* For a drive-through stop on a town-owned road remove the stop and replace the road */ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2793 |
DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC, CMD_REMOVE_ROAD_STOP); |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2794 |
} else { |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2795 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2796 |
} |
0 | 2797 |
} |
2798 |
} |
|
2799 |
||
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2800 |
/** |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2801 |
* Check if a drive-through road stop tile can be cleared. |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2802 |
* Road stops built on town-owned roads check the conditions |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2803 |
* that would allow clearing of the original road. |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2804 |
* @param tile road stop tile to check |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2805 |
* @return true if the road can be cleared |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2806 |
*/ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2807 |
static bool CanRemoveRoadWithStop(TileIndex tile) |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2808 |
{ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2809 |
/* The road can always be cleared if it was not a town-owned road */ |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2810 |
if (!GetStopBuiltOnTownRoad(tile)) return true; |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2811 |
|
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2812 |
bool edge_road; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2813 |
return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, &edge_road, ROADTYPE_ROAD) && |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2814 |
CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_TRAM), OWNER_TOWN, &edge_road, ROADTYPE_TRAM); |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2815 |
} |
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2816 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2817 |
static CommandCost ClearTile_Station(TileIndex tile, byte flags) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
2818 |
{ |
0 | 2819 |
if (flags & DC_AUTO) { |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2820 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2821 |
case STATION_RAIL: return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2822 |
case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2823 |
case STATION_TRUCK: return_cmd_error(HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) ? STR_3047_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2824 |
case STATION_BUS: return_cmd_error(HASBIT(GetRoadTypes(tile), ROADTYPE_TRAM) ? STR_3046_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION); |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2825 |
case STATION_BUOY: return_cmd_error(STR_306A_BUOY_IN_THE_WAY); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2826 |
case STATION_DOCK: return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2827 |
case STATION_OILRIG: |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2828 |
SetDParam(0, STR_4807_OIL_RIG); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2829 |
return_cmd_error(STR_4800_IN_THE_WAY); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2830 |
} |
0 | 2831 |
} |
2832 |
||
6395 | 2833 |
Station *st = GetStationByTile(tile); |
0 | 2834 |
|
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2835 |
switch (GetStationType(tile)) { |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2836 |
case STATION_RAIL: return RemoveRailroadStation(st, tile, flags); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2837 |
case STATION_AIRPORT: return RemoveAirport(st, flags); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2838 |
case STATION_TRUCK: |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2839 |
if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile)) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2840 |
return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2841 |
return RemoveRoadStop(st, flags, tile); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2842 |
case STATION_BUS: |
6442
10b44714b85d
(svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents:
6441
diff
changeset
|
2843 |
if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile)) |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2844 |
return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6326
diff
changeset
|
2845 |
return RemoveRoadStop(st, flags, tile); |
3334
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2846 |
case STATION_BUOY: return RemoveBuoy(st, flags); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2847 |
case STATION_DOCK: return RemoveDock(st, flags); |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2848 |
default: break; |
b72ac8637a30
(svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents:
3333
diff
changeset
|
2849 |
} |
0 | 2850 |
|
2851 |
return CMD_ERROR; |
|
2852 |
} |
|
2853 |
||
6573 | 2854 |
void InitializeStations() |
0 | 2855 |
{ |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1266
diff
changeset
|
2856 |
/* Clean the station pool and create 1 block in it */ |
4980 | 2857 |
CleanPool(&_Station_pool); |
2858 |
AddBlockToPool(&_Station_pool); |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2859 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
2860 |
/* Clean the roadstop pool and create 1 block in it */ |
4981
f19132348a43
(svn r6984) Use the pool macros for the RoadStop pool
tron
parents:
4980
diff
changeset
|
2861 |
CleanPool(&_RoadStop_pool); |
f19132348a43
(svn r6984) Use the pool macros for the RoadStop pool
tron
parents:
4980
diff
changeset
|
2862 |
AddBlockToPool(&_RoadStop_pool); |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2863 |
|
0 | 2864 |
_station_tick_ctr = 0; |
243
9a40daa560ae
(svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents:
222
diff
changeset
|
2865 |
|
0 | 2866 |
} |
2867 |
||
2868 |
||
6573 | 2869 |
void AfterLoadStations() |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2870 |
{ |
6395 | 2871 |
/* Update the speclists of all stations to point to the currently loaded custom stations. */ |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2872 |
Station *st; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2873 |
FOR_ALL_STATIONS(st) { |
6395 | 2874 |
for (uint i = 0; i < st->num_specs; i++) { |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2875 |
if (st->speclist[i].grfid == 0) continue; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2876 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2877 |
st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx); |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2878 |
} |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2879 |
|
6733
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2880 |
for (uint i = 0; i < st->num_fsmportsspecs; i++) { |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2881 |
if (st->fsmportsspeclist[i].grfid == 0) continue; |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2882 |
|
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2883 |
st->fsmportsspeclist[i].spec = GetCustomFSMportsSpecByGrf(st->fsmportsspeclist[i].grfid, st->fsmportsspeclist[i].localidx); |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2884 |
} |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2885 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2886 |
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache(); |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2887 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2888 |
} |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2889 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
2890 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2891 |
extern const TileTypeProcs _tile_type_station_procs = { |
3554
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2892 |
DrawTile_Station, /* draw_tile_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2893 |
GetSlopeZ_Station, /* get_slope_z_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2894 |
ClearTile_Station, /* clear_tile_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2895 |
GetAcceptedCargo_Station, /* get_accepted_cargo_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2896 |
GetTileDesc_Station, /* get_tile_desc_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2897 |
GetTileTrackStatus_Station, /* get_tile_track_status_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2898 |
ClickTile_Station, /* click_tile_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2899 |
AnimateTile_Station, /* animate_tile_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2900 |
TileLoop_Station, /* tile_loop_clear */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2901 |
ChangeTileOwner_Station, /* change_tile_owner_clear */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2902 |
NULL, /* get_produced_cargo_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2903 |
VehicleEnter_Station, /* vehicle_enter_tile_proc */ |
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2904 |
GetSlopeTileh_Station, /* get_slope_tileh_proc */ |
0 | 2905 |
}; |
2906 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1876
diff
changeset
|
2907 |
static const SaveLoad _roadstop_desc[] = { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2908 |
SLE_VAR(RoadStop,xy, SLE_UINT32), |
5969 | 2909 |
SLE_CONDNULL(1, 0, 44), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2910 |
SLE_VAR(RoadStop,status, SLE_UINT8), |
1285
dee20e32bffe
(svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents:
1284
diff
changeset
|
2911 |
/* Index was saved in some versions, but this is not needed */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2912 |
SLE_CONDNULL(4, 0, 8), |
5967 | 2913 |
SLE_CONDNULL(2, 0, 44), |
3479
a4d992b5d24d
(svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents:
3478
diff
changeset
|
2914 |
SLE_CONDNULL(1, 0, 25), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2915 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2916 |
SLE_REF(RoadStop,next, REF_ROADSTOPS), |
6118 | 2917 |
SLE_CONDNULL(2, 0, 44), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2918 |
|
3431 | 2919 |
SLE_CONDNULL(4, 0, 24), |
3475
1b68d263ae0e
(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
|
2920 |
SLE_CONDNULL(1, 25, 25), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2921 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2922 |
SLE_END() |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2923 |
}; |
0 | 2924 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1876
diff
changeset
|
2925 |
static const SaveLoad _station_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2926 |
SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2927 |
SLE_CONDVAR(Station, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
6130 | 2928 |
SLE_CONDNULL(4, 0, 5), // bus/lorry tile |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2929 |
SLE_CONDVAR(Station, train_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2930 |
SLE_CONDVAR(Station, train_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2931 |
SLE_CONDVAR(Station, airport_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2932 |
SLE_CONDVAR(Station, airport_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2933 |
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2934 |
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2935 |
SLE_REF(Station, town, REF_TOWN), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2936 |
SLE_VAR(Station, trainst_w, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2937 |
SLE_CONDVAR(Station, trainst_h, SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2938 |
|
2939 |
// alpha_order was stored here in savegame format 0 - 3 |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2940 |
SLE_CONDNULL(1, 0, 3), |
0 | 2941 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2942 |
SLE_VAR(Station, string_id, SLE_STRINGID), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2943 |
SLE_VAR(Station, had_vehicle_of_type, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2944 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2945 |
SLE_VAR(Station, time_since_load, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2946 |
SLE_VAR(Station, time_since_unload, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2947 |
SLE_VAR(Station, delete_ctr, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2948 |
SLE_VAR(Station, owner, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2949 |
SLE_VAR(Station, facilities, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2950 |
SLE_VAR(Station, airport_type, SLE_UINT8), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2951 |
|
6129 | 2952 |
SLE_CONDNULL(2, 0, 5), // Truck/bus stop status |
6128 | 2953 |
SLE_CONDNULL(1, 0, 4), // Blocked months |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2954 |
|
6321
62564548351b
(svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents:
6317
diff
changeset
|
2955 |
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U16, 0, 2), |
62564548351b
(svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents:
6317
diff
changeset
|
2956 |
SLE_CONDVAR(Station, airport_flags, SLE_VAR_U64 | SLE_FILE_U32, 3, 45), |
62564548351b
(svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents:
6317
diff
changeset
|
2957 |
SLE_CONDVAR(Station, airport_flags, SLE_UINT64, 46, SL_MAX_VERSION), |
3554
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2958 |
|
3580
607e4245d024
(svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents:
3576
diff
changeset
|
2959 |
SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2960 |
SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION), |
3554
c16eadc2d060
(svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents:
3553
diff
changeset
|
2961 |
|
3574
bf5f6c1af32c
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2962 |
// Was custom station class and id |
bf5f6c1af32c
(svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents:
3568
diff
changeset
|
2963 |
SLE_CONDNULL(2, 3, 25), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2964 |
SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2965 |
SLE_CONDVAR(Station, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2966 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2967 |
SLE_CONDREF(Station, bus_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2968 |
SLE_CONDREF(Station, truck_stops, REF_ROADSTOPS, 6, SL_MAX_VERSION), |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2969 |
|
3687
109ec5cdb932
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2970 |
/* Used by newstations for graphic variations */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2971 |
SLE_CONDVAR(Station, random_bits, SLE_UINT16, 27, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2972 |
SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2973 |
SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION), |
6733
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
2974 |
SLE_CONDVAR(Station, num_fsmportsspecs, SLE_UINT8, 73, SL_MAX_VERSION), |
3687
109ec5cdb932
(svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents:
3682
diff
changeset
|
2975 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2976 |
SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION), |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
2977 |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2978 |
// reserve extra space in savegame here. (currently 32 bytes) |
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3183
diff
changeset
|
2979 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 2980 |
|
2981 |
SLE_END() |
|
2982 |
}; |
|
2983 |
||
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2984 |
static uint16 _waiting_acceptance; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2985 |
static uint16 _cargo_source; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2986 |
static uint32 _cargo_source_xy; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2987 |
static uint16 _cargo_days; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2988 |
static Money _cargo_feeder_share; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2989 |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1876
diff
changeset
|
2990 |
static const SaveLoad _goods_desc[] = { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2991 |
SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2992 |
SLE_CONDVAR(GoodsEntry, acceptance, SLE_BOOL, 68, SL_MAX_VERSION), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2993 |
SLE_CONDNULL(2, 51, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2994 |
SLE_VAR(GoodsEntry, days_since_pickup, SLE_UINT8), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2995 |
SLE_VAR(GoodsEntry, rating, SLE_UINT8), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2996 |
SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2997 |
SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2998 |
SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
2999 |
SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3000 |
SLE_VAR(GoodsEntry, last_speed, SLE_UINT8), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3001 |
SLE_VAR(GoodsEntry, last_age, SLE_UINT8), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3002 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3003 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3004 |
SLE_CONDLST(GoodsEntry, cargo, REF_CARGO_PACKET, 68, SL_MAX_VERSION), |
0 | 3005 |
|
3006 |
SLE_END() |
|
3007 |
}; |
|
3008 |
||
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3009 |
static const SaveLoad _station_speclist_desc[] = { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3010 |
SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, 27, SL_MAX_VERSION), |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3011 |
SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8, 27, SL_MAX_VERSION), |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3012 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3013 |
SLE_END() |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3014 |
}; |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3015 |
|
6733
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3016 |
static const SaveLoad _fsmports_speclist_desc[] = { |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3017 |
SLE_CONDVAR(FSMportsSpecList, grfid, SLE_UINT32, 73, SL_MAX_VERSION), |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3018 |
SLE_CONDVAR(FSMportsSpecList, localidx, SLE_UINT8, 73, SL_MAX_VERSION), |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3019 |
|
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3020 |
SLE_END() |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3021 |
}; |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3022 |
|
0 | 3023 |
|
3024 |
static void SaveLoad_STNS(Station *st) |
|
3025 |
{ |
|
3026 |
SlObject(st, _station_desc); |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
3027 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3028 |
_waiting_acceptance = 0; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3029 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
3030 |
uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6718
diff
changeset
|
3031 |
for (CargoID i = 0; i < num_cargo; i++) { |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3032 |
GoodsEntry *ge = &st->goods[i]; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3033 |
SlObject(ge, _goods_desc); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3034 |
if (CheckSavegameVersion(68)) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3035 |
ge->acceptance = HASBIT(_waiting_acceptance, 15); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3036 |
if (GB(_waiting_acceptance, 0, 12) != 0) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3037 |
/* Don't construct the packet with station here, because that'll fail with old savegames */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3038 |
CargoPacket *cp = new CargoPacket(); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3039 |
/* In old versions, enroute_from used 0xFF as INVALID_STATION */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3040 |
cp->source = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3041 |
cp->count = GB(_waiting_acceptance, 0, 12); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3042 |
cp->days_in_transit = _cargo_days; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3043 |
cp->feeder_share = _cargo_feeder_share; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3044 |
cp->source_xy = _cargo_source_xy; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3045 |
cp->days_in_transit = _cargo_days; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3046 |
cp->feeder_share = _cargo_feeder_share; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3047 |
ge->cargo.Append(cp); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3048 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3049 |
ge->days_since_pickup = 255; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3050 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
3051 |
} |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1265
diff
changeset
|
3052 |
} |
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3053 |
|
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3054 |
if (st->num_specs != 0) { |
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3055 |
/* Allocate speclist memory when loading a game */ |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5852
diff
changeset
|
3056 |
if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs); |
6395 | 3057 |
for (uint i = 0; i < st->num_specs; i++) { |
3058 |
SlObject(&st->speclist[i], _station_speclist_desc); |
|
3059 |
} |
|
3765
e057e2b740d4
(svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents:
3763
diff
changeset
|
3060 |
} |
6733
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3061 |
|
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3062 |
if (st->num_fsmportsspecs != 0) { |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3063 |
/* Allocate fsmspeclist memory when loading a game */ |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3064 |
if (st->fsmportsspeclist == NULL) st->fsmportsspeclist = CallocT<FSMportsSpecList>(st->num_fsmportsspecs); |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3065 |
for (uint i = 0; i < st->num_fsmportsspecs; i++) { |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3066 |
SlObject(&st->fsmportsspeclist[i], _fsmports_speclist_desc); |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3067 |
} |
240d846d5149
(svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents:
6732
diff
changeset
|
3068 |
} |
0 | 3069 |
} |
3070 |
||
6573 | 3071 |
static void Save_STNS() |
0 | 3072 |
{ |
3073 |
Station *st; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3074 |
// Write the stations |
0 | 3075 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3076 |
SlSetArrayIndex(st->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3077 |
SlAutolength((AutolengthProc*)SaveLoad_STNS, st); |
0 | 3078 |
} |
3079 |
} |
|
3080 |
||
6573 | 3081 |
static void Load_STNS() |
0 | 3082 |
{ |
3083 |
int index; |
|
3084 |
while ((index = SlIterateArray()) != -1) { |
|
5916
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
3085 |
Station *st = new (index) Station(); |
75c6d5cf1600
(svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
5911
diff
changeset
|
3086 |
|
0 | 3087 |
SaveLoad_STNS(st); |
3088 |
||
3089 |
// this means it's an oldstyle savegame without support for nonuniform stations |
|
2639 | 3090 |
if (st->train_tile != 0 && st->trainst_h == 0) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3091 |
uint w = GB(st->trainst_w, 4, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3092 |
uint h = GB(st->trainst_w, 0, 4); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
3093 |
|
6432 | 3094 |
if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h); |
0 | 3095 |
st->trainst_w = w; |
3096 |
st->trainst_h = h; |
|
3097 |
} |
|
3098 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
3099 |
|
1472
043304846688
(svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents:
1457
diff
changeset
|
3100 |
/* This is to ensure all pointers are within the limits of _stations_size */ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5220
diff
changeset
|
3101 |
if (_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0; |
0 | 3102 |
} |
3103 |
||
6573 | 3104 |
static void Save_ROADSTOP() |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3105 |
{ |
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3106 |
RoadStop *rs; |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3107 |
|
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3108 |
FOR_ALL_ROADSTOPS(rs) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3109 |
SlSetArrayIndex(rs->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3110 |
SlObject(rs, _roadstop_desc); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3111 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3112 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3113 |
|
6573 | 3114 |
static void Load_ROADSTOP() |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3115 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3116 |
int index; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3117 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3118 |
while ((index = SlIterateArray()) != -1) { |
5967 | 3119 |
RoadStop *rs = new (index) RoadStop(INVALID_TILE); |
5959
6a4c261987c3
(svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents:
5948
diff
changeset
|
3120 |
|
1284
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3121 |
SlObject(rs, _roadstop_desc); |
06a52178bf46
(svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents:
1272
diff
changeset
|
3122 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3123 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3124 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3125 |
extern const ChunkHandler _station_chunk_handlers[] = { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3126 |
{ 'STNS', Save_STNS, Load_STNS, CH_ARRAY }, |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
3127 |
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST}, |
0 | 3128 |
}; |